Widow – Blame information for rev 11
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | using System.ComponentModel; |
||
3 | using System.Configuration; |
||
8 | office | 4 | using System.Globalization; |
1 | office | 5 | using System.Threading.Tasks; |
6 | using System.Windows.Forms; |
||
7 | using Widow.Properties; |
||
8 | using Widow.Serialization; |
||
9 | |||
10 | namespace Widow |
||
11 | { |
||
6 | office | 12 | public partial class MainForm : Form |
1 | office | 13 | { |
14 | #region Public Events & Delegates |
||
15 | |||
16 | public event EventHandler<WindowCreatedEventArgs> WindowCreated; |
||
17 | |||
18 | public event EventHandler<WindowDestroyedEventArgs> WindowDestroyed; |
||
19 | |||
20 | #endregion |
||
21 | |||
22 | #region Public Enums, Properties and Fields |
||
23 | |||
24 | public Windows.Windows Windows { get; set; } |
||
25 | |||
26 | public RuleEditForm RuleEditForm { get; set; } |
||
27 | |||
9 | office | 28 | public WindowManipulation WindowManipulation { get; set; } |
1 | office | 29 | |
5 | office | 30 | public AboutForm AboutForm { get; set; } |
31 | |||
1 | office | 32 | #endregion |
33 | |||
34 | #region Constructors, Destructors and Finalizers |
||
35 | |||
6 | office | 36 | public MainForm() |
1 | office | 37 | { |
38 | InitializeComponent(); |
||
6 | office | 39 | |
1 | office | 40 | // Bind to settings changed event. |
41 | Settings.Default.SettingsLoaded += Default_SettingsLoaded; |
||
42 | Settings.Default.SettingsSaving += Default_SettingsSaving; |
||
43 | Settings.Default.PropertyChanged += Default_PropertyChanged; |
||
44 | |||
45 | Natives.RegisterShellHookWindow(Handle); |
||
46 | |||
6 | office | 47 | LoadWindows().ContinueWith(task => |
48 | { |
||
9 | office | 49 | WindowManipulation = new WindowManipulation(this, Windows, Settings.Default); |
6 | office | 50 | }); |
1 | office | 51 | } |
52 | |||
53 | /// <summary> |
||
54 | /// Clean up any resources being used. |
||
55 | /// </summary> |
||
56 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
||
57 | protected override void Dispose(bool disposing) |
||
58 | { |
||
59 | if (disposing && components != null) |
||
60 | { |
||
61 | Settings.Default.SettingsLoaded -= Default_SettingsLoaded; |
||
62 | Settings.Default.SettingsSaving -= Default_SettingsSaving; |
||
63 | Settings.Default.PropertyChanged -= Default_PropertyChanged; |
||
64 | |||
65 | components.Dispose(); |
||
66 | } |
||
67 | |||
68 | base.Dispose(disposing); |
||
69 | } |
||
70 | |||
71 | #endregion |
||
72 | |||
73 | #region Private Overrides |
||
74 | |||
75 | protected override void WndProc(ref Message m) |
||
76 | { |
||
77 | var handle = m.LParam; |
||
78 | var windowName = Helpers.GetWindowTitle(handle); |
||
79 | |||
80 | switch (m.WParam.ToInt32()) |
||
81 | { |
||
82 | case (int) Natives.WM.HSHELL_WINDOWCREATED: |
||
83 | WindowCreated?.Invoke(this, new WindowCreatedEventArgs(windowName, handle)); |
||
84 | break; |
||
85 | case (int) Natives.WM.HSHELL_WINDOWDESTROYED: |
||
86 | WindowDestroyed?.Invoke(this, new WindowDestroyedEventArgs(windowName, handle)); |
||
87 | break; |
||
88 | } |
||
89 | |||
90 | base.WndProc(ref m); |
||
91 | } |
||
92 | |||
93 | #endregion |
||
94 | |||
95 | #region Event Handlers |
||
96 | |||
8 | office | 97 | private static void Default_PropertyChanged(object sender, PropertyChangedEventArgs e) |
1 | office | 98 | { |
99 | Settings.Default.Save(); |
||
100 | } |
||
101 | |||
8 | office | 102 | private static void Default_SettingsSaving(object sender, CancelEventArgs e) |
1 | office | 103 | { |
104 | } |
||
105 | |||
8 | office | 106 | private static void Default_SettingsLoaded(object sender, SettingsLoadedEventArgs e) |
1 | office | 107 | { |
108 | } |
||
109 | |||
110 | private void NewToolStripMenuItem_Click(object sender, EventArgs e) |
||
111 | { |
||
11 | office | 112 | if (RuleEditForm != null) |
113 | { |
||
114 | return; |
||
115 | } |
||
116 | |||
1 | office | 117 | RuleEditForm = new RuleEditForm(this, Windows); |
118 | RuleEditForm.Closed += RuleEditForm_Closed; |
||
119 | RuleEditForm.Show(); |
||
120 | } |
||
121 | |||
122 | private async void RuleEditForm_Closed(object sender, EventArgs e) |
||
123 | { |
||
124 | RuleEditForm.Closed -= RuleEditForm_Closed; |
||
125 | RuleEditForm.Dispose(); |
||
126 | RuleEditForm = null; |
||
127 | |||
128 | switch (await WindowsSerialization.Serialize(Windows, "Windows.xml")) |
||
129 | { |
||
130 | case SerializationSuccess serializationSuccess: |
||
131 | break; |
||
132 | case SerializationFailure serializationFailure: |
||
133 | break; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | private void ExitToolStripMenuItem_Click(object sender, EventArgs e) |
||
138 | { |
||
139 | Application.Exit(); |
||
140 | } |
||
141 | |||
142 | private void LaunchOnBootToolStripMenuItem_CheckedChanged(object sender, EventArgs e) |
||
143 | { |
||
144 | Settings.Default.LaunchOnBoot = ((ToolStripMenuItem) sender).Checked; |
||
145 | |||
146 | LaunchOnBoot.Set(Settings.Default.LaunchOnBoot); |
||
147 | } |
||
148 | |||
5 | office | 149 | private void OnWindowCreateToolStripMenuItem_CheckedChanged(object sender, EventArgs e) |
150 | { |
||
151 | Settings.Default.OnWindowCreate = ((ToolStripMenuItem) sender).Checked; |
||
152 | |||
9 | office | 153 | WindowManipulation.OnWindowCreate = Settings.Default.OnWindowCreate; |
5 | office | 154 | } |
155 | |||
156 | private void AboutToolStripMenuItem_Click(object sender, EventArgs e) |
||
157 | { |
||
158 | // Show the about form. |
||
159 | AboutForm = new AboutForm(); |
||
160 | AboutForm.Show(); |
||
161 | } |
||
162 | |||
11 | office | 163 | private async void ApplyNowToolStripMenuItem_Click(object sender, EventArgs e) |
7 | office | 164 | { |
11 | office | 165 | await WindowManipulation.Apply(); |
7 | office | 166 | } |
167 | |||
8 | office | 168 | private void OnEveryToolStripMenuItem_CheckedChanged(object sender, EventArgs e) |
169 | { |
||
170 | var toolStripMenuItem = (ToolStripMenuItem) sender; |
||
171 | |||
172 | if (!int.TryParse(toolStripTextBox1.Text, out var time)) |
||
173 | { |
||
174 | return; |
||
175 | } |
||
176 | |||
177 | Settings.Default.ApplyEveryTimeEnabled = toolStripMenuItem.Checked; |
||
178 | Settings.Default.ApplyEveryTime = time.ToString(CultureInfo.InvariantCulture); |
||
179 | |||
9 | office | 180 | WindowManipulation.ApplyEveryTime = time; |
181 | WindowManipulation.ApplyEveryTimeEnabled = toolStripMenuItem.Checked; |
||
8 | office | 182 | } |
183 | |||
1 | office | 184 | #endregion |
185 | |||
186 | #region Private Methods |
||
187 | |||
188 | private async Task LoadWindows() |
||
189 | { |
||
190 | switch (await WindowsSerialization.Deserialize("Windows.xml")) |
||
191 | { |
||
192 | case SerializationSuccess serializationSuccess: |
||
193 | Windows = serializationSuccess.Windows; |
||
194 | break; |
||
195 | case SerializationFailure serializationFailure: |
||
196 | Windows = new Windows.Windows(); |
||
197 | break; |
||
198 | } |
||
199 | } |
||
200 | |||
201 | #endregion |
||
11 | office | 202 | |
203 | private void NotifyIcon1_DoubleClick(object sender, EventArgs e) |
||
204 | { |
||
205 | if (RuleEditForm != null) |
||
206 | { |
||
207 | return; |
||
208 | } |
||
209 | |||
210 | RuleEditForm = new RuleEditForm(this, Windows); |
||
211 | RuleEditForm.Closed += RuleEditForm_Closed; |
||
212 | RuleEditForm.Show(); |
||
213 | } |
||
214 | |||
215 | private async void NotifyIcon1_Click(object sender, EventArgs e) |
||
216 | { |
||
217 | await WindowManipulation.Apply(); |
||
218 | } |
||
1 | office | 219 | } |
220 | } |