Widow – Diff between revs 7 and 8

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