-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
156 lines (112 loc) · 3.74 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using fuzzyLauncher.Utilitary;
using fuzzyLauncher.Windows;
namespace fuzzyLauncher
{
public partial class MainWindow : Window
{
private readonly AppCoreModel core;
public MainWindow()
{
InitializeComponent();
core = (AppCoreModel)DataContext;
CompositionTarget.Rendering += CheckForNonActive;
var hotKey = new HotKey(Key.Space, KeyModifier.Alt, OnHotKeyHandler);
}
private void CheckForNonActive(object sender, EventArgs e)
{
if (!IsActive && IsVisible)
Hide();
}
private void OnHotKeyHandler(HotKey obj)
{
Show();
}
private void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
// FancyBalloon balloon = new FancyBalloon();
//show balloon and close it after 4 seconds
if (e.Key == Key.Escape)
{
if (String.IsNullOrEmpty(core.QueryString))
Hide();
core.QueryString = "";
//Environment.Exit(0);
}
if (e.Key == Key.PageDown || e.Key == Key.PageUp)
{
var key = e.Key;
var target = ResultList;
var routedEvent = Keyboard.KeyDownEvent;
target.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target), 0, key) { RoutedEvent = routedEvent });
e.Handled = true;
}
if (ResultList.Items.Count > 0)
{
if (e.Key == Key.Down)
ResultList.SelectedIndex++;
if (e.Key == Key.Up && ResultList.SelectedIndex > 0)
ResultList.SelectedIndex--;
}
if (core.ProcessCompatibleConverter(sender, e))
{
SearchBox.CaretIndex = Int32.MaxValue;
}
else
{
if (core.ProcessQueryKeyEvent(sender, e))
{
Hide();
}
}
SearchBox.Focus();
}
private void CenterWindowOnScreen()
{
double screenWidth = SystemParameters.PrimaryScreenWidth;
double screenHeight = SystemParameters.PrimaryScreenHeight;
double windowWidth = Width;
double windowHeight = Height;
Left = (screenWidth / 2) - (windowWidth / 2);
Top = (screenHeight / 2) - (windowHeight / 2);
}
private void ResultList_MouseUp(object sender, MouseButtonEventArgs e)
{
SearchBox.Focus();
}
private void Window_Activated(object sender, EventArgs e)
{
Activate();
CenterWindowOnScreen();
Focus();
core.QueryString = "";
SearchBox.Focus();
}
private void SearchBoxOnKeyUp(object sender, KeyEventArgs e)
{
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Tab)
{
SearchBox.Focus();
e.Handled = true;
}
}
private void ResultList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//Browser.Document.
//Browser.ScriptErrorsSuppressed = true;
Browser.NavigateToString(File.ReadAllText("d:\\1.htm"));
}
private void ActivateSettingsForm(object sender, RoutedEventArgs e)
{
var ms = new MainSettings();
ms.ShowDialog();
}
}
}