Widow – Diff between revs 11 and 13

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