This repository has been archived by the owner on Sep 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMainWindow.xaml.cs
110 lines (94 loc) · 3.26 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using GalaSoft.MvvmLight.Messaging;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Twinder.ViewModel;
using System;
using Twinder.View;
using System.Collections.ObjectModel;
using Twinder.Model;
using System.ComponentModel;
using System.Windows.Data;
using Twinder.Helpers;
namespace Twinder
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var myViewModel = DataContext as MainViewModel;
myViewModel.MyView = this;
// Once loaded, starts setting up all the data
this.Loaded += myViewModel.StartInitialize;
this.Closing += (s, e) => ViewModelLocator.Cleanup();
Messenger.Default.Register<PassAroundItem>(this, MessengerToken.NewChatWindow, CreateChatWindow);
Messenger.Default.Register<PassAroundItem>(this, MessengerToken.ShowMatchProfile, CreateMatchProfileView);
Messenger.Default.Register<UserModel>(this, MessengerToken.OpenMyProfile, CreateMyProfileWindow);
Messenger.Default.Register<ObservableCollection<RecModel>>(this, MessengerToken.OpenRecommendations, OpenRecsWindow);
Messenger.Default.Register<string>(this, MessengerToken.ShowSetLocationWindow, CreateSetLocationWindow);
Messenger.Default.Register<string>(this, MessengerToken.ShowUpdateAvailableDialog, ShowUpdateAvailableDialog);
Messenger.Default.Register<SerializationPacket>(this, MessengerToken.ShowSerializationDialog, ShowDownloadDialog);
}
private void ShowUpdateAvailableDialog(string obj)
{
var updateDialog = new NewVersionView(obj);
updateDialog.Owner = this;
updateDialog.ShowDialog();
}
private void ShowDownloadDialog(SerializationPacket packet)
{
var downloadDialog = new DownloadDataView(packet);
downloadDialog.Owner = this;
downloadDialog.ShowDialog();
}
private void CreateMyProfileWindow(UserModel user)
{
var myProfileWindow = new UserProfileView(user);
myProfileWindow.Show();
}
private void CreateSetLocationWindow(string obj)
{
var locationWindow = new SetLocationView();
locationWindow.ShowDialog();
}
private void OpenRecsWindow(ObservableCollection<RecModel> recList)
{
var recsWindow = new RecommendationsView(recList);
recsWindow.Show();
}
private void CreateChatWindow(PassAroundItem obj)
{
var chatWindow = new ChatView((MatchModel)obj.Item, obj.DirPath);
chatWindow.Show();
}
private void CreateMatchProfileView(PassAroundItem obj)
{
var matchProfileWindow = new MatchProfileView(obj.Item, obj.DirPath);
matchProfileWindow.Show();
}
/// <summary>
/// Handles double click on match list, which opens a new chat
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void matchList_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var viewModel = DataContext as MainViewModel;
var item = sender as ListViewItem;
var match = item.Content as MatchModel;
// Workaround for losing focus
Action newWindow = () => viewModel.OpenChatCommand.Execute(match);
Dispatcher.BeginInvoke(newWindow);
}
/// <summary>
/// Explicit shutdown operation
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Closed(object sender, EventArgs e)
{
Application.Current.Shutdown();
}
}
}