Widow – Diff between revs 8 and 9

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 8 Rev 9
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 WindowRescale WindowRescale { 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 WindowRescale = new WindowRescale(this, Windows) {OnWindowCreate = Settings.Default.OnWindowCreate}; 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 RuleEditForm = new RuleEditForm(this, Windows); 112 RuleEditForm = new RuleEditForm(this, Windows);
113 RuleEditForm.Closed += RuleEditForm_Closed; 113 RuleEditForm.Closed += RuleEditForm_Closed;
114 RuleEditForm.Show(); 114 RuleEditForm.Show();
115 } 115 }
116   116  
117 private async void RuleEditForm_Closed(object sender, EventArgs e) 117 private async void RuleEditForm_Closed(object sender, EventArgs e)
118 { 118 {
119 RuleEditForm.Closed -= RuleEditForm_Closed; 119 RuleEditForm.Closed -= RuleEditForm_Closed;
120 RuleEditForm.Dispose(); 120 RuleEditForm.Dispose();
121 RuleEditForm = null; 121 RuleEditForm = null;
122   122  
123 switch (await WindowsSerialization.Serialize(Windows, "Windows.xml")) 123 switch (await WindowsSerialization.Serialize(Windows, "Windows.xml"))
124 { 124 {
125 case SerializationSuccess serializationSuccess: 125 case SerializationSuccess serializationSuccess:
126 break; 126 break;
127 case SerializationFailure serializationFailure: 127 case SerializationFailure serializationFailure:
128 break; 128 break;
129 } 129 }
130 } 130 }
131   131  
132 private void ExitToolStripMenuItem_Click(object sender, EventArgs e) 132 private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
133 { 133 {
134 Application.Exit(); 134 Application.Exit();
135 } 135 }
136   136  
137 private void LaunchOnBootToolStripMenuItem_CheckedChanged(object sender, EventArgs e) 137 private void LaunchOnBootToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
138 { 138 {
139 Settings.Default.LaunchOnBoot = ((ToolStripMenuItem) sender).Checked; 139 Settings.Default.LaunchOnBoot = ((ToolStripMenuItem) sender).Checked;
140   140  
141 LaunchOnBoot.Set(Settings.Default.LaunchOnBoot); 141 LaunchOnBoot.Set(Settings.Default.LaunchOnBoot);
142 } 142 }
143   143  
144 private void OnWindowCreateToolStripMenuItem_CheckedChanged(object sender, EventArgs e) 144 private void OnWindowCreateToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
145 { 145 {
146 Settings.Default.OnWindowCreate = ((ToolStripMenuItem) sender).Checked; 146 Settings.Default.OnWindowCreate = ((ToolStripMenuItem) sender).Checked;
147   147  
148 WindowRescale.OnWindowCreate = Settings.Default.OnWindowCreate; 148 WindowManipulation.OnWindowCreate = Settings.Default.OnWindowCreate;
149 } 149 }
150   150  
151 private void AboutToolStripMenuItem_Click(object sender, EventArgs e) 151 private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
152 { 152 {
153 // Show the about form. 153 // Show the about form.
154 AboutForm = new AboutForm(); 154 AboutForm = new AboutForm();
155 AboutForm.Show(); 155 AboutForm.Show();
156 } 156 }
157   157  
158 private void ApplyNowToolStripMenuItem_Click(object sender, EventArgs e) 158 private void ApplyNowToolStripMenuItem_Click(object sender, EventArgs e)
159 { 159 {
160 WindowRescale.Apply(); 160 WindowManipulation.Apply();
161 } 161 }
162   162  
163 private void OnEveryToolStripMenuItem_CheckedChanged(object sender, EventArgs e) 163 private void OnEveryToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
164 { 164 {
165 var toolStripMenuItem = (ToolStripMenuItem) sender; 165 var toolStripMenuItem = (ToolStripMenuItem) sender;
166   166  
167 if (!int.TryParse(toolStripTextBox1.Text, out var time)) 167 if (!int.TryParse(toolStripTextBox1.Text, out var time))
168 { 168 {
169 return; 169 return;
170 } 170 }
171   171  
172 Settings.Default.ApplyEveryTimeEnabled = toolStripMenuItem.Checked; 172 Settings.Default.ApplyEveryTimeEnabled = toolStripMenuItem.Checked;
173 Settings.Default.ApplyEveryTime = time.ToString(CultureInfo.InvariantCulture); 173 Settings.Default.ApplyEveryTime = time.ToString(CultureInfo.InvariantCulture);
174   174  
175 WindowRescale.ApplyEveryTime = time; 175 WindowManipulation.ApplyEveryTime = time;
176 WindowRescale.ApplyEveryTimeEnabled = toolStripMenuItem.Checked; 176 WindowManipulation.ApplyEveryTimeEnabled = toolStripMenuItem.Checked;
177 } 177 }
178   178  
179 #endregion 179 #endregion
180   180  
181 #region Private Methods 181 #region Private Methods
182   182  
183 private async Task LoadWindows() 183 private async Task LoadWindows()
184 { 184 {
185 switch (await WindowsSerialization.Deserialize("Windows.xml")) 185 switch (await WindowsSerialization.Deserialize("Windows.xml"))
186 { 186 {
187 case SerializationSuccess serializationSuccess: 187 case SerializationSuccess serializationSuccess:
188 Windows = serializationSuccess.Windows; 188 Windows = serializationSuccess.Windows;
189 break; 189 break;
190 case SerializationFailure serializationFailure: 190 case SerializationFailure serializationFailure:
191 Windows = new Windows.Windows(); 191 Windows = new Windows.Windows();
192 break; 192 break;
193 } 193 }
194 } 194 }
195   195  
196 #endregion 196 #endregion
197 } 197 }
198 } 198 }
199   199  
200
Generated by GNU Enscript 1.6.5.90.
200
Generated by GNU Enscript 1.6.5.90.
201   201  
202   202  
203   203