-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
99 lines (85 loc) · 3.22 KB
/
MainWindow.xaml.cs
File metadata and controls
99 lines (85 loc) · 3.22 KB
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
namespace SnippetManager
{
using System;
using System.Windows;
using System.Windows.Input;
using MahApps.Metro.Controls;
using ViewModels;
using System.Windows.Controls;
using CommonServiceLocator;
using SnippetManager.Interfaces;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : MetroWindow
{
/// <summary>
/// Access to the ViewModel.
/// </summary>
public MainViewModel MainViewModel => DataContext as MainViewModel;
public IEditWindowService ews => ServiceLocator.Current.GetInstance<IEditWindowService>();
public MainWindow()
{
InitializeComponent();
this.Closed += MainWindow_Closed;
//Tooltip improvements like do not hide Tooltips fix (credit: http://stackoverflow.com/a/8308254/828184)
ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(Int32.MaxValue));
ToolTipService.InitialShowDelayProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(0));
ToolTipService.BetweenShowDelayProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(0));
}
private void MainWindow_Closed(object sender, EventArgs e)
{
if (MainViewModel is IDisposable disposableViewModel)
{
disposableViewModel.Dispose();
}
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
Application.Current.Exit += ApplicationExit;
}
void ApplicationExit(object sender, ExitEventArgs e)
{
if (MainViewModel is IDisposable disposableViewModel)
{
disposableViewModel.Dispose();
}
MainViewModel.ExitMethod();
}
private void PresentButton_Click(object sender, RoutedEventArgs e)
{
MainViewModel.IsInPresentMode = true;
MainViewModel.ClipboardActions.StopListening();
MainViewModel.RaisePropertyChanged(nameof(MainViewModel.IsClipboardManager));
var presentWindow = new PresentWindow();
presentWindow.Show();
presentWindow.Closed += PresentWindowClosedAction;
this.Hide();
}
private void PresentWindowClosedAction(object sender, EventArgs e)
{
this.Show();
}
private void lstSnippets_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
ews.OpeningRequest(this.MainViewModel.SelectedSnippet);
}
private void LstSnippets_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (!MainViewModel.IsInPresentMode)
{
if (e.Key == Key.Up)
{
MainViewModel.MoveSnippetUpMethod();
e.Handled = true;
}
else if (e.Key == Key.Down)
{
MainViewModel.MoveSnippetDownMethod();
e.Handled = true;
}
}
}
}
}