Skip to content

Commit 4304329

Browse files
committed
Improve code quality
1 parent 196a840 commit 4304329

File tree

1 file changed

+58
-53
lines changed

1 file changed

+58
-53
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44
using System.Windows;
55
using System.Windows.Controls;
66
using System.Windows.Documents;
7-
using System.Windows.Forms;
87
using Flow.Launcher.Infrastructure.Storage;
98
using Flow.Launcher.Plugin;
10-
using CheckBox = System.Windows.Controls.CheckBox;
11-
using ComboBox = System.Windows.Controls.ComboBox;
12-
using Control = System.Windows.Controls.Control;
13-
using Orientation = System.Windows.Controls.Orientation;
14-
using TextBox = System.Windows.Controls.TextBox;
15-
using UserControl = System.Windows.Controls.UserControl;
169

1710
#nullable enable
1811

@@ -34,7 +27,7 @@ public class JsonRPCPluginSettings
3427
// TODO: Move to resource
3528
private static readonly Thickness settingControlMargin = new(0, 9, 18, 9);
3629
private static readonly Thickness settingCheckboxMargin = new(0, 9, 9, 9);
37-
private static readonly Thickness settingPanelMargin = (Thickness)System.Windows.Application.Current.FindResource("SettingPanelMargin");
30+
private static readonly Thickness settingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin");
3831

3932
public async Task InitializeAsync()
4033
{
@@ -64,7 +57,9 @@ public async Task InitializeAsync()
6457
public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
6558
{
6659
if (settings == null || settings.Count == 0)
60+
{
6761
return;
62+
}
6863

6964
foreach (var (key, value) in settings)
7065
{
@@ -174,7 +169,7 @@ public void Save()
174169
Text = attributes.Description,
175170
FontSize = 12,
176171
VerticalAlignment = VerticalAlignment.Center,
177-
Margin = new(0, 2, 0, 0), // TODO: Use resource
172+
Margin = new(0, 2, 0, 0),
178173
TextWrapping = TextWrapping.WrapWithOverflow
179174
};
180175
desc.SetResourceReference(TextBlock.ForegroundProperty, "Color04B"); // for theme change
@@ -196,7 +191,7 @@ public void Save()
196191
{
197192
Text = attributes.Description?.Replace("\\r\\n", "\r\n") ?? string.Empty,
198193
Padding = new Thickness(0, 0, 0, 0),
199-
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
194+
HorizontalAlignment = HorizontalAlignment.Left,
200195
TextAlignment = TextAlignment.Left,
201196
TextWrapping = TextWrapping.Wrap
202197
};
@@ -209,7 +204,7 @@ public void Save()
209204
{
210205
Text = Settings[attributes.Name] as string ?? string.Empty,
211206
Margin = settingControlMargin,
212-
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
207+
HorizontalAlignment = HorizontalAlignment.Stretch,
213208
ToolTip = attributes.Description
214209
};
215210

@@ -229,7 +224,7 @@ public void Save()
229224
{
230225
Margin = new Thickness(10, 0, 0, 0),
231226
Text = Settings[attributes.Name] as string ?? string.Empty,
232-
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
227+
HorizontalAlignment = HorizontalAlignment.Stretch,
233228
ToolTip = attributes.Description
234229
};
235230

@@ -238,25 +233,29 @@ public void Save()
238233
Settings[attributes.Name] = textBox.Text;
239234
};
240235

241-
var Btn = new System.Windows.Controls.Button()
236+
var Btn = new Button()
242237
{
243238
Margin = new Thickness(10, 0, 0, 0), Content = "Browse"
244239
};
245240

246241
Btn.Click += (_, _) =>
247242
{
248-
using CommonDialog dialog = type switch
243+
using System.Windows.Forms.CommonDialog dialog = type switch
249244
{
250-
"inputWithFolderBtn" => new FolderBrowserDialog(),
251-
_ => new OpenFileDialog(),
245+
"inputWithFolderBtn" => new System.Windows.Forms.FolderBrowserDialog(),
246+
_ => new System.Windows.Forms.OpenFileDialog(),
252247
};
253-
if (dialog.ShowDialog() != DialogResult.OK) return;
248+
249+
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
250+
{
251+
return;
252+
}
254253

255254
var path = dialog switch
256255
{
257-
FolderBrowserDialog folderDialog => folderDialog.SelectedPath,
258-
OpenFileDialog fileDialog => fileDialog.FileName,
259-
_ => string.Empty
256+
System.Windows.Forms.FolderBrowserDialog folderDialog => folderDialog.SelectedPath,
257+
System.Windows.Forms.OpenFileDialog fileDialog => fileDialog.FileName,
258+
_ => throw new System.NotImplementedException()
260259
};
261260
textBox.Text = path;
262261
Settings[attributes.Name] = path;
@@ -280,7 +279,7 @@ public void Save()
280279
VerticalAlignment = VerticalAlignment.Center,
281280
TextWrapping = TextWrapping.WrapWithOverflow,
282281
AcceptsReturn = true,
283-
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
282+
HorizontalAlignment = HorizontalAlignment.Stretch,
284283
Text = Settings[attributes.Name] as string ?? string.Empty,
285284
ToolTip = attributes.Description
286285
};
@@ -301,7 +300,7 @@ public void Save()
301300
Margin = settingControlMargin,
302301
Password = Settings[attributes.Name] as string ?? string.Empty,
303302
PasswordChar = attributes.passwordChar == default ? '*' : attributes.passwordChar,
304-
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
303+
HorizontalAlignment = HorizontalAlignment.Stretch,
305304
ToolTip = attributes.Description
306305
};
307306

@@ -321,7 +320,7 @@ public void Save()
321320
ItemsSource = attributes.Options,
322321
SelectedItem = Settings[attributes.Name],
323322
Margin = settingControlMargin,
324-
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
323+
HorizontalAlignment = HorizontalAlignment.Right,
325324
ToolTip = attributes.Description
326325
};
327326

@@ -335,49 +334,55 @@ public void Save()
335334
break;
336335
}
337336
case "checkbox":
338-
var checkBox = new CheckBox
339337
{
340-
IsChecked =
338+
var checkBox = new CheckBox
339+
{
340+
IsChecked =
341341
Settings[attributes.Name] is bool isChecked
342342
? isChecked
343343
: bool.Parse(attributes.DefaultValue),
344-
Margin = settingCheckboxMargin,
345-
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
346-
ToolTip = attributes.Description
347-
};
344+
Margin = settingCheckboxMargin,
345+
HorizontalAlignment = HorizontalAlignment.Right,
346+
ToolTip = attributes.Description
347+
};
348348

349-
checkBox.Click += (sender, _) =>
350-
{
351-
Settings[attributes.Name] = ((CheckBox)sender).IsChecked!;
352-
};
349+
checkBox.Click += (sender, _) =>
350+
{
351+
Settings[attributes.Name] = ((CheckBox)sender).IsChecked!;
352+
};
353353

354-
contentControl = checkBox;
354+
contentControl = checkBox;
355355

356-
break;
356+
break;
357+
}
357358
case "hyperlink":
358-
var hyperlink = new Hyperlink { ToolTip = attributes.Description, NavigateUri = attributes.url };
359-
360-
var linkbtn = new System.Windows.Controls.Button
361359
{
362-
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
363-
Margin = settingControlMargin,
364-
Content = attributes.urlLabel
365-
};
360+
var hyperlink = new Hyperlink { ToolTip = attributes.Description, NavigateUri = attributes.url };
366361

367-
contentControl = linkbtn;
362+
var linkbtn = new Button
363+
{
364+
HorizontalAlignment = HorizontalAlignment.Right,
365+
Margin = settingControlMargin,
366+
Content = attributes.urlLabel
367+
};
368+
369+
contentControl = linkbtn;
368370

369-
break;
370-
case "seperator": // TODO: Support seperator
371-
// TODO: Use style for Seperator
372-
contentControl = new Separator
371+
break;
372+
}
373+
case "seperator":
373374
{
374-
VerticalAlignment = VerticalAlignment.Top,
375-
Margin = new(-70, 13.5, -18, 13.5),
376-
Height = 1
377-
};
378-
contentControl.SetResourceReference(Separator.BackgroundProperty, "Color03B");
375+
// TODO: Move to resource
376+
contentControl = new Separator
377+
{
378+
VerticalAlignment = VerticalAlignment.Top,
379+
Margin = new(-70, 13.5, -18, 13.5),
380+
Height = 1
381+
};
382+
contentControl.SetResourceReference(Separator.BackgroundProperty, "Color03B");
379383

380-
break;
384+
break;
385+
}
381386
default:
382387
continue;
383388
}

0 commit comments

Comments
 (0)