Widow – Diff between revs 6 and 9

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 6 Rev 9
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Windows.Forms; 3 using System.Windows.Forms;
4 using Windows; 4 using Windows;
5   5  
6 namespace Widow 6 namespace Widow
7 { 7 {
8 public partial class RuleEditForm : Form 8 public partial class RuleEditForm : Form
9 { 9 {
10 #region Public Enums, Properties and Fields 10 #region Public Enums, Properties and Fields
11   11  
12 public Windows.Windows Windows { get; } 12 public Windows.Windows Windows { get; }
13   13  
14 public MainForm Form { get; set; } 14 public MainForm Form { get; set; }
15   15  
16 #endregion 16 #endregion
17   17  
18 #region Constructors, Destructors and Finalizers 18 #region Constructors, Destructors and Finalizers
19   19  
20 public RuleEditForm(MainForm mainForm, Windows.Windows windows) : this(windows) 20 public RuleEditForm(MainForm mainForm, Windows.Windows windows) : this(windows)
21 { 21 {
22 Form = mainForm; 22 Form = mainForm;
23   23  
24 Form.WindowCreated += Form_WindowCreated; 24 Form.WindowCreated += Form_WindowCreated;
25 Form.WindowDestroyed += Form_WindowDestroyed; 25 Form.WindowDestroyed += Form_WindowDestroyed;
26 } 26 }
27   27  
28 public RuleEditForm(Windows.Windows windows) : this() 28 public RuleEditForm(Windows.Windows windows) : this()
29 { 29 {
30 Windows = windows; 30 Windows = windows;
31   31  
32 foreach (var window in windows.Window) 32 foreach (var window in windows.Window)
33 { 33 {
34 windowRulesListBox.Items.Add(window); 34 windowRulesListBox.Items.Add(window);
35 } 35 }
36 } 36 }
37   37  
38 private RuleEditForm() 38 private RuleEditForm()
39 { 39 {
40 InitializeComponent(); 40 InitializeComponent();
41   41  
42 desktopWindowsListBox.DisplayMember = "Name"; 42 desktopWindowsListBox.DisplayMember = "Name";
43 windowRulesListBox.DisplayMember = "Name"; 43 windowRulesListBox.DisplayMember = "Name";
44   44  
45 RefreshWindows(); 45 RefreshWindows();
46 } 46 }
47   47  
48 /// <summary> 48 /// <summary>
49 /// Clean up any resources being used. 49 /// Clean up any resources being used.
50 /// </summary> 50 /// </summary>
51 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 51 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
52 protected override void Dispose(bool disposing) 52 protected override void Dispose(bool disposing)
53 { 53 {
54 if (disposing && components != null) 54 if (disposing && components != null)
55 { 55 {
56 Form.WindowCreated -= Form_WindowCreated; 56 Form.WindowCreated -= Form_WindowCreated;
57 Form.WindowDestroyed -= Form_WindowDestroyed; 57 Form.WindowDestroyed -= Form_WindowDestroyed;
58   58  
59 components.Dispose(); 59 components.Dispose();
60 } 60 }
61   61  
62 base.Dispose(disposing); 62 base.Dispose(disposing);
63 } 63 }
64   64  
65 #endregion 65 #endregion
66   66  
67 #region Event Handlers 67 #region Event Handlers
68   68  
69 private void Form_WindowDestroyed(object sender, WindowDestroyedEventArgs e) 69 private void Form_WindowDestroyed(object sender, WindowDestroyedEventArgs e)
70 { 70 {
71 if (string.IsNullOrEmpty(e.Name)) 71 if (string.IsNullOrEmpty(e.Name))
72 { 72 {
73 return; 73 return;
74 } 74 }
75   75  
76 var indices = new List<int>(); 76 var indices = new List<int>();
77 for (var i = 0; i < desktopWindowsListBox.Items.Count; ++i) 77 for (var i = 0; i < desktopWindowsListBox.Items.Count; ++i)
78 { 78 {
79 if (((Window) desktopWindowsListBox.Items[i]).Name == e.Name) 79 if (((Window) desktopWindowsListBox.Items[i]).Name == e.Name)
80 { 80 {
81 indices.Add(i); 81 indices.Add(i);
82 } 82 }
83 } 83 }
84   84  
85 foreach (var index in indices) 85 foreach (var index in indices)
86 { 86 {
87 desktopWindowsListBox.Items.RemoveAt(index); 87 desktopWindowsListBox.Items.RemoveAt(index);
88 } 88 }
89 } 89 }
90   90  
91 private void Form_WindowCreated(object sender, WindowCreatedEventArgs e) 91 private void Form_WindowCreated(object sender, WindowCreatedEventArgs e)
92 { 92 {
93 if (string.IsNullOrEmpty(e.Name)) 93 if (string.IsNullOrEmpty(e.Name))
94 { 94 {
95 return; 95 return;
96 } 96 }
97   97  
98 var found = false; 98 var found = false;
99 foreach (var window in desktopWindowsListBox.Items) 99 foreach (var window in desktopWindowsListBox.Items)
100 { 100 {
101 if (((Window) window).Name == e.Name) 101 if (((Window) window).Name == e.Name)
102 { 102 {
103 found = true; 103 found = true;
104 break; 104 break;
105 } 105 }
106 } 106 }
107   107  
108 if (found) 108 if (found)
109 { 109 {
110 return; 110 return;
111 } 111 }
112   112  
113 if (Natives.GetWindowRect(e.Handle, out var rect)) 113 if (Natives.GetWindowRect(e.Handle, out var rect))
114 { 114 {
115 var window = new Window(e.Name, rect.Top, rect.Left, rect.Right - rect.Left, 115 var window = new Window(e.Name, rect.Top, rect.Left, rect.Right - rect.Left,
116 rect.Bottom - rect.Top); 116 rect.Bottom - rect.Top);
117   117  
118 desktopWindowsListBox.Items.Add(window); 118 desktopWindowsListBox.Items.Add(window);
119 } 119 }
120 } 120 }
121   121  
122 private void WindowRulesListBox_SelectedIndexChanged(object sender, EventArgs e) 122 private void WindowRulesListBox_SelectedIndexChanged(object sender, EventArgs e)
123 { 123 {
124 var listBox = (ListBox) sender; 124 var listBox = (ListBox) sender;
125   125  
126 if (listBox.SelectedIndex == -1) 126 if (listBox.SelectedIndex == -1)
127 { 127 {
128 WindowName.Text = string.Empty; 128 WindowName.Text = string.Empty;
-   129 ignoreLeftCheckBox.Checked = false;
129 WindowLeft.Text = string.Empty; 130 WindowLeft.Text = string.Empty;
-   131 ignoreTopCheckBox.Checked = false;
130 WindowTop.Text = string.Empty; 132 WindowTop.Text = string.Empty;
-   133 ignoreWidthCheckBox.Checked = false;
131 WindowWidth.Text = string.Empty; 134 WindowWidth.Text = string.Empty;
-   135 ignoreHeightCheckBox.Checked = false;
132 WindowHeight.Text = string.Empty; 136 WindowHeight.Text = string.Empty;
133 return; 137 return;
134 } 138 }
135   139  
136 var window = (Window) listBox.SelectedItem; 140 var window = (Window) listBox.SelectedItem;
137   141  
138 if (window == null) 142 if (window == null)
139 { 143 {
140 return; 144 return;
141 } 145 }
142   146  
143 WindowName.Text = window.Name; 147 WindowName.Text = window.Name;
-   148 ignoreLeftCheckBox.Checked = window.IgnoreLeft;
144 WindowLeft.Text = window.Left.ToString(); 149 WindowLeft.Text = window.Left.ToString();
-   150 ignoreTopCheckBox.Checked = window.IgnoreTop;
145 WindowTop.Text = window.Top.ToString(); 151 WindowTop.Text = window.Top.ToString();
-   152 ignoreWidthCheckBox.Checked = window.IgnoreWidth;
146 WindowWidth.Text = window.Width.ToString(); 153 WindowWidth.Text = window.Width.ToString();
-   154 ignoreHeightCheckBox.Checked = window.IgnoreHeight;
147 WindowHeight.Text = window.Height.ToString(); 155 WindowHeight.Text = window.Height.ToString();
148 } 156 }
149   157  
150 private void RefreshButton_Click(object sender, EventArgs e) 158 private void RefreshButton_Click(object sender, EventArgs e)
151 { 159 {
152 RefreshWindows(); 160 RefreshWindows();
153 } 161 }
154   162  
155 private void RemoveButton_Click(object sender, EventArgs e) 163 private void RemoveButton_Click(object sender, EventArgs e)
156 { 164 {
157 var window = (Window) windowRulesListBox.SelectedItem; 165 var window = (Window) windowRulesListBox.SelectedItem;
158 if (window == null) 166 if (window == null)
159 { 167 {
160 return; 168 return;
161 } 169 }
162   170  
163 var index = -1; 171 var index = -1;
164 for (var i = 0; i < windowRulesListBox.Items.Count; ++i) 172 for (var i = 0; i < windowRulesListBox.Items.Count; ++i)
165 { 173 {
166 if (((Window) windowRulesListBox.Items[i]).Name == window.Name) 174 if (((Window) windowRulesListBox.Items[i]).Name == window.Name)
167 { 175 {
168 index = i; 176 index = i;
169 break; 177 break;
170 } 178 }
171 } 179 }
172   180  
173 if (index == -1) 181 if (index == -1)
174 { 182 {
175 return; 183 return;
176 } 184 }
177   185  
178 windowRulesListBox.Items.RemoveAt(index); 186 windowRulesListBox.Items.RemoveAt(index);
179 Windows.Window.Remove(window); 187 Windows.Window.Remove(window);
180 } 188 }
181   189  
182 private void AddButton_Click(object sender, EventArgs e) 190 private void AddButton_Click(object sender, EventArgs e)
183 { 191 {
184 var window = (Window) desktopWindowsListBox.SelectedItem; 192 var window = (Window) desktopWindowsListBox.SelectedItem;
185 if (window == null) 193 if (window == null)
186 { 194 {
187 return; 195 return;
188 } 196 }
189   197  
190 var found = false; 198 var found = false;
191 foreach (var windowRule in windowRulesListBox.Items) 199 foreach (var windowRule in windowRulesListBox.Items)
192 { 200 {
193 if (((Window) windowRule).Name == window.Name) 201 if (((Window) windowRule).Name == window.Name)
194 { 202 {
195 found = true; 203 found = true;
196 break; 204 break;
197 } 205 }
198 } 206 }
199   207  
200 if (found) 208 if (found)
201 { 209 {
202 return; 210 return;
203 } 211 }
204   212  
205 windowRulesListBox.Items.Add(window); 213 windowRulesListBox.Items.Add(window);
206 Windows.Window.Add(window); 214 Windows.Window.Add(window);
207 } 215 }
208   216  
209 private void OnWindowSettings_TextChanged(object sender, EventArgs e) 217 private void OnWindowSettings_TextChanged(object sender, EventArgs e)
210 { 218 {
211 var selectedWindow = (Window) windowRulesListBox.SelectedItem; 219 var selectedWindow = (Window) windowRulesListBox.SelectedItem;
212   220  
213 if (selectedWindow == null) 221 if (selectedWindow == null)
214 { 222 {
215 WindowName.Text = string.Empty; 223 WindowName.Text = string.Empty;
216 WindowLeft.Text = string.Empty; 224 WindowLeft.Text = string.Empty;
217 WindowTop.Text = string.Empty; 225 WindowTop.Text = string.Empty;
218 WindowWidth.Text = string.Empty; 226 WindowWidth.Text = string.Empty;
219 WindowHeight.Text = string.Empty; 227 WindowHeight.Text = string.Empty;
220   228  
221 return; 229 return;
222 } 230 }
223   231  
224 var textBox = (TextBox) sender; 232 var textBox = (TextBox) sender;
225 switch (textBox.Name) 233 switch (textBox.Name)
226 { 234 {
227 case nameof(WindowName): 235 case nameof(WindowName):
228 selectedWindow.Name = textBox.Text; 236 selectedWindow.Name = textBox.Text;
229 break; 237 break;
230 case nameof(WindowLeft): 238 case nameof(WindowLeft):
231 if (int.TryParse(textBox.Text, out var left)) 239 if (int.TryParse(textBox.Text, out var left))
232 { 240 {
233 selectedWindow.Left = left; 241 selectedWindow.Left = left;
234 } 242 }
235   243  
236 break; 244 break;
237 case nameof(WindowTop): 245 case nameof(WindowTop):
238 if (int.TryParse(textBox.Text, out var top)) 246 if (int.TryParse(textBox.Text, out var top))
239 { 247 {
240 selectedWindow.Top = top; 248 selectedWindow.Top = top;
241 } 249 }
242   250  
243 break; 251 break;
244 case nameof(WindowWidth): 252 case nameof(WindowWidth):
245 if (int.TryParse(textBox.Text, out var width)) 253 if (int.TryParse(textBox.Text, out var width))
246 { 254 {
247 selectedWindow.Width = width; 255 selectedWindow.Width = width;
248 } 256 }
249   257  
250 break; 258 break;
251 case nameof(WindowHeight): 259 case nameof(WindowHeight):
252 if (int.TryParse(textBox.Text, out var height)) 260 if (int.TryParse(textBox.Text, out var height))
253 { 261 {
254 selectedWindow.Height = height; 262 selectedWindow.Height = height;
255 } 263 }
256   264  
257 break; 265 break;
-   266 }
-   267 }
-   268  
-   269 private void OnIgnoreWindowSettings_CheckedChanged(object sender, EventArgs e)
-   270 {
-   271 var selectedWindow = (Window) windowRulesListBox.SelectedItem;
-   272  
-   273 if (selectedWindow == null)
-   274 {
-   275 ignoreLeftCheckBox.Checked = false;
-   276 ignoreTopCheckBox.Checked = false;
-   277 ignoreWidthCheckBox.Checked = false;
-   278 ignoreHeightCheckBox.Checked = false;
-   279  
-   280 return;
-   281 }
-   282  
-   283 var checkBox = (CheckBox) sender;
-   284 switch (checkBox.Name)
-   285 {
-   286 case nameof(ignoreHeightCheckBox):
-   287 selectedWindow.IgnoreHeight = checkBox.Checked;
-   288 break;
-   289 case nameof(ignoreWidthCheckBox):
-   290 selectedWindow.IgnoreWidth = checkBox.Checked;
-   291 break;
-   292 case nameof(ignoreTopCheckBox):
-   293 selectedWindow.IgnoreTop = checkBox.Checked;
-   294 break;
-   295 case nameof(ignoreLeftCheckBox):
-   296 selectedWindow.IgnoreLeft = checkBox.Checked;
-   297 break;
258 } 298 }
259 } 299 }
260   300  
261 #endregion 301 #endregion
262   302  
263 #region Private Methods 303 #region Private Methods
264   304  
265 private void RefreshWindows() 305 private void RefreshWindows()
266 { 306 {
267 foreach (var desktopWindow in Helpers.GetDesktopWindows()) 307 foreach (var desktopWindow in Helpers.GetDesktopWindows())
268 { 308 {
269 if (string.IsNullOrEmpty(desktopWindow.Title)) 309 if (string.IsNullOrEmpty(desktopWindow.Title))
270 { 310 {
271 continue; 311 continue;
272 } 312 }
273   313  
274 if (Natives.GetWindowRect(desktopWindow.Handle, out var rect)) 314 if (Natives.GetWindowRect(desktopWindow.Handle, out var rect))
275 { 315 {
276 var window = new Window(desktopWindow.Title, rect.Top, rect.Left, rect.Right - rect.Left, 316 var window = new Window(desktopWindow.Title, rect.Top, rect.Left, rect.Right - rect.Left,
277 rect.Bottom - rect.Top); 317 rect.Bottom - rect.Top);
278   318  
279 var found = false; 319 var found = false;
280 foreach (var item in desktopWindowsListBox.Items) 320 foreach (var item in desktopWindowsListBox.Items)
281 { 321 {
282 if (((Window) item).Name == window.Name) 322 if (((Window) item).Name == window.Name)
283 { 323 {
284 found = true; 324 found = true;
285 break; 325 break;
286 } 326 }
287 } 327 }
288   328  
289 if (!found) 329 if (!found)
290 { 330 {
291 desktopWindowsListBox.Items.Add(window); 331 desktopWindowsListBox.Items.Add(window);
292 } 332 }
293 } 333 }
294 } 334 }
295 } 335 }
296   336  
297 #endregion 337 #endregion
298 } 338 }
299 } 339 }
300   340  
301
Generated by GNU Enscript 1.6.5.90.
341
Generated by GNU Enscript 1.6.5.90.
302   342  
303   343  
304   344