Skip to content

Commit 2af033b

Browse files
committed
Cleanup codes
1 parent 2b67f5b commit 2af033b

File tree

2 files changed

+40
-44
lines changed

2 files changed

+40
-44
lines changed

Flow.Launcher.Core/Resource/Theme.cs

+34-38
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using System.Windows;
88
using System.Windows.Controls;
9+
using System.Windows.Controls.Primitives;
910
using System.Windows.Markup;
1011
using System.Windows.Media;
1112
using System.Windows.Media.Effects;
@@ -16,8 +17,6 @@
1617
using Flow.Launcher.Infrastructure.UserSettings;
1718
using Flow.Launcher.Plugin;
1819
using Microsoft.Win32;
19-
using TextBox = System.Windows.Controls.TextBox;
20-
using System.Diagnostics;
2120

2221
namespace Flow.Launcher.Core.Resource
2322
{
@@ -59,8 +58,7 @@ public Theme(IPublicAPI publicAPI, Settings settings)
5958
var dicts = Application.Current.Resources.MergedDictionaries;
6059
_oldResource = dicts.FirstOrDefault(d =>
6160
{
62-
if (d.Source == null)
63-
return false;
61+
if (d.Source == null) return false;
6462

6563
var p = d.Source.AbsolutePath;
6664
return p.Contains(Folder) && Path.GetExtension(p) == Extension;
@@ -103,19 +101,19 @@ private void MakeSureThemeDirectoriesExist()
103101

104102
private void UpdateResourceDictionary(ResourceDictionary dictionaryToUpdate)
105103
{
106-
// Add the new theme resource first
104+
// Add new resources
107105
if (!Application.Current.Resources.MergedDictionaries.Contains(dictionaryToUpdate))
108106
{
109107
Application.Current.Resources.MergedDictionaries.Add(dictionaryToUpdate);
110108
}
111-
112-
// Then remove the old theme resource
113-
if (_oldResource != null &&
114-
_oldResource != dictionaryToUpdate &&
109+
110+
// Remove old resources
111+
if (_oldResource != null && _oldResource != dictionaryToUpdate &&
115112
Application.Current.Resources.MergedDictionaries.Contains(_oldResource))
116113
{
117114
Application.Current.Resources.MergedDictionaries.Remove(_oldResource);
118115
}
116+
119117
_oldResource = dictionaryToUpdate;
120118
}
121119

@@ -190,7 +188,7 @@ private void ApplyFontSettings(ResourceDictionary dict)
190188
/// <summary>
191189
/// Applies font properties to a Style.
192190
/// </summary>
193-
private void SetFontProperties(Style style, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, bool isTextBox)
191+
private static void SetFontProperties(Style style, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, bool isTextBox)
194192
{
195193
// Remove existing font-related setters
196194
if (isTextBox)
@@ -199,10 +197,10 @@ private void SetFontProperties(Style style, FontFamily fontFamily, FontStyle fon
199197
var settersToRemove = style.Setters
200198
.OfType<Setter>()
201199
.Where(setter =>
202-
setter.Property == TextBox.FontFamilyProperty ||
203-
setter.Property == TextBox.FontStyleProperty ||
204-
setter.Property == TextBox.FontWeightProperty ||
205-
setter.Property == TextBox.FontStretchProperty)
200+
setter.Property == Control.FontFamilyProperty ||
201+
setter.Property == Control.FontStyleProperty ||
202+
setter.Property == Control.FontWeightProperty ||
203+
setter.Property == Control.FontStretchProperty)
206204
.ToList();
207205

208206
// Remove each found setter one by one
@@ -212,17 +210,17 @@ private void SetFontProperties(Style style, FontFamily fontFamily, FontStyle fon
212210
}
213211

214212
// Add New font setter
215-
style.Setters.Add(new Setter(TextBox.FontFamilyProperty, fontFamily));
216-
style.Setters.Add(new Setter(TextBox.FontStyleProperty, fontStyle));
217-
style.Setters.Add(new Setter(TextBox.FontWeightProperty, fontWeight));
218-
style.Setters.Add(new Setter(TextBox.FontStretchProperty, fontStretch));
213+
style.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily));
214+
style.Setters.Add(new Setter(Control.FontStyleProperty, fontStyle));
215+
style.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight));
216+
style.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch));
219217

220218
// Set caret brush (retain existing logic)
221219
var caretBrushPropertyValue = style.Setters.OfType<Setter>().Any(x => x.Property.Name == "CaretBrush");
222220
var foregroundPropertyValue = style.Setters.OfType<Setter>().Where(x => x.Property.Name == "Foreground")
223221
.Select(x => x.Value).FirstOrDefault();
224222
if (!caretBrushPropertyValue && foregroundPropertyValue != null)
225-
style.Setters.Add(new Setter(TextBox.CaretBrushProperty, foregroundPropertyValue));
223+
style.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue));
226224
}
227225
else
228226
{
@@ -246,6 +244,7 @@ private void SetFontProperties(Style style, FontFamily fontFamily, FontStyle fon
246244
style.Setters.Add(new Setter(TextBlock.FontStretchProperty, fontStretch));
247245
}
248246
}
247+
249248
private ResourceDictionary GetThemeResourceDictionary(string theme)
250249
{
251250
var uri = GetThemePath(theme);
@@ -269,22 +268,22 @@ private ResourceDictionary GetResourceDictionary(string theme)
269268
var fontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.QueryBoxFontWeight);
270269
var fontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.QueryBoxFontStretch);
271270

272-
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, fontFamily));
273-
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, fontStyle));
274-
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, fontWeight));
275-
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, fontStretch));
271+
queryBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily));
272+
queryBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, fontStyle));
273+
queryBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight));
274+
queryBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch));
276275

277276
var caretBrushPropertyValue = queryBoxStyle.Setters.OfType<Setter>().Any(x => x.Property.Name == "CaretBrush");
278277
var foregroundPropertyValue = queryBoxStyle.Setters.OfType<Setter>().Where(x => x.Property.Name == "Foreground")
279278
.Select(x => x.Value).FirstOrDefault();
280279
if (!caretBrushPropertyValue && foregroundPropertyValue != null) //otherwise BaseQueryBoxStyle will handle styling
281-
queryBoxStyle.Setters.Add(new Setter(TextBox.CaretBrushProperty, foregroundPropertyValue));
280+
queryBoxStyle.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue));
282281

283282
// Query suggestion box's font style is aligned with query box
284-
querySuggestionBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, fontFamily));
285-
querySuggestionBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, fontStyle));
286-
querySuggestionBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, fontWeight));
287-
querySuggestionBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, fontStretch));
283+
querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily));
284+
querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, fontStyle));
285+
querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight));
286+
querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch));
288287
}
289288

290289
if (dict["ItemTitleStyle"] is Style resultItemStyle &&
@@ -321,7 +320,7 @@ private ResourceDictionary GetResourceDictionary(string theme)
321320
/* Ignore Theme Window Width and use setting */
322321
var windowStyle = dict["WindowStyle"] as Style;
323322
var width = _settings.WindowSize;
324-
windowStyle.Setters.Add(new Setter(Window.WidthProperty, width));
323+
windowStyle.Setters.Add(new Setter(FrameworkElement.WidthProperty, width));
325324
return dict;
326325
}
327326

@@ -423,7 +422,7 @@ public bool ChangeTheme(string theme = null)
423422

424423
BlurEnabled = IsBlurTheme();
425424

426-
// 블러 및 그림자 효과 적용을 위한 비동기 처리
425+
// Apply blur and drop shadow effects
427426
_ = RefreshFrameAsync();
428427

429428
return true;
@@ -623,17 +622,14 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
623622

624623
private void SetBlurForWindow(string theme, BackdropTypes backdropType)
625624
{
626-
var dict = GetResourceDictionary(theme); // GetThemeResourceDictionary 대신 GetResourceDictionary 사용
627-
if (dict == null)
628-
return;
625+
var dict = GetResourceDictionary(theme);
626+
if (dict == null) return;
629627

630628
var windowBorderStyle = dict.Contains("WindowBorderStyle") ? dict["WindowBorderStyle"] as Style : null;
631-
if (windowBorderStyle == null)
632-
return;
629+
if (windowBorderStyle == null) return;
633630

634-
Window mainWindow = Application.Current.MainWindow;
635-
if (mainWindow == null)
636-
return;
631+
var mainWindow = Application.Current.MainWindow;
632+
if (mainWindow == null) return;
637633

638634
// Check if the theme supports blur
639635
bool hasBlur = dict.Contains("ThemeBlurEnabled") && dict["ThemeBlurEnabled"] is bool b && b;

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public FontFamily SelectedQueryBoxFont
342342
set
343343
{
344344
Settings.QueryBoxFont = value.ToString();
345-
_theme.UpdateFonts();
345+
_theme.UpdateFonts();
346346
}
347347
}
348348

@@ -364,7 +364,7 @@ public FamilyTypeface SelectedQueryBoxFontFaces
364364
Settings.QueryBoxFontStretch = value.Stretch.ToString();
365365
Settings.QueryBoxFontWeight = value.Weight.ToString();
366366
Settings.QueryBoxFontStyle = value.Style.ToString();
367-
_theme.UpdateFonts();
367+
_theme.UpdateFonts();
368368
}
369369
}
370370

@@ -386,7 +386,7 @@ public FontFamily SelectedResultFont
386386
set
387387
{
388388
Settings.ResultFont = value.ToString();
389-
_theme.UpdateFonts();
389+
_theme.UpdateFonts();
390390
}
391391
}
392392

@@ -408,7 +408,7 @@ public FamilyTypeface SelectedResultFontFaces
408408
Settings.ResultFontStretch = value.Stretch.ToString();
409409
Settings.ResultFontWeight = value.Weight.ToString();
410410
Settings.ResultFontStyle = value.Style.ToString();
411-
_theme.UpdateFonts();
411+
_theme.UpdateFonts();
412412
}
413413
}
414414

@@ -432,7 +432,7 @@ public FontFamily SelectedResultSubFont
432432
set
433433
{
434434
Settings.ResultSubFont = value.ToString();
435-
_theme.UpdateFonts();
435+
_theme.UpdateFonts();
436436
}
437437
}
438438

@@ -453,7 +453,7 @@ public FamilyTypeface SelectedResultSubFontFaces
453453
Settings.ResultSubFontStretch = value.Stretch.ToString();
454454
Settings.ResultSubFontWeight = value.Weight.ToString();
455455
Settings.ResultSubFontStyle = value.Style.ToString();
456-
_theme.UpdateFonts();
456+
_theme.UpdateFonts();
457457
}
458458
}
459459

0 commit comments

Comments
 (0)