Widow – Diff between revs 6 and 7

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