-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml.cs
96 lines (82 loc) · 3.06 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
namespace SnippetManager
{
using System;
using System.Windows;
using System.Windows.Input;
using MahApps.Metro.Controls;
using ViewModels;
using Models;
using System.ComponentModel;
using System.Windows.Controls;
/// <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 ClipboardNotification SnippetLogic { get; set; }
public MainWindow()
{
InitializeComponent();
//listen to clipboard
ClipboardNotification.ClipboardUpdate += ClipboardUpdate;
//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 ClipboardUpdate(object sender, EventArgs e)
{
if (this.MainViewModel.IsClipboardManager)
{
MainViewModel.InsertNewSnippetMethod(true);
}
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
Application.Current.Exit += ApplicationExit;
}
void ApplicationExit(object sender, ExitEventArgs e)
{
MainViewModel.ExitMethod();
}
private void PresentButton_Click(object sender, RoutedEventArgs e)
{
MainViewModel.IsInPresentMode = true;
MainViewModel.IsClipboardManager = false;
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)
{
var ewl = new EditWindowLogic(this.MainViewModel, this.LstSnippets);
ewl.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;
}
}
}
}
}