Widow – Diff between revs 1 and 5

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