Widow – Diff between revs 13 and 15

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