6
6
using System . Threading . Tasks ;
7
7
using System . Windows ;
8
8
using System . Windows . Controls ;
9
+ using System . Windows . Controls . Primitives ;
9
10
using System . Windows . Markup ;
10
11
using System . Windows . Media ;
11
12
using System . Windows . Media . Effects ;
16
17
using Flow . Launcher . Infrastructure . UserSettings ;
17
18
using Flow . Launcher . Plugin ;
18
19
using Microsoft . Win32 ;
19
- using TextBox = System . Windows . Controls . TextBox ;
20
- using System . Diagnostics ;
21
20
22
21
namespace Flow . Launcher . Core . Resource
23
22
{
@@ -59,8 +58,7 @@ public Theme(IPublicAPI publicAPI, Settings settings)
59
58
var dicts = Application . Current . Resources . MergedDictionaries ;
60
59
_oldResource = dicts . FirstOrDefault ( d =>
61
60
{
62
- if ( d . Source == null )
63
- return false ;
61
+ if ( d . Source == null ) return false ;
64
62
65
63
var p = d . Source . AbsolutePath ;
66
64
return p . Contains ( Folder ) && Path . GetExtension ( p ) == Extension ;
@@ -103,19 +101,19 @@ private void MakeSureThemeDirectoriesExist()
103
101
104
102
private void UpdateResourceDictionary ( ResourceDictionary dictionaryToUpdate )
105
103
{
106
- // Add the new theme resource first
104
+ // Add new resources
107
105
if ( ! Application . Current . Resources . MergedDictionaries . Contains ( dictionaryToUpdate ) )
108
106
{
109
107
Application . Current . Resources . MergedDictionaries . Add ( dictionaryToUpdate ) ;
110
108
}
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 &&
115
112
Application . Current . Resources . MergedDictionaries . Contains ( _oldResource ) )
116
113
{
117
114
Application . Current . Resources . MergedDictionaries . Remove ( _oldResource ) ;
118
115
}
116
+
119
117
_oldResource = dictionaryToUpdate ;
120
118
}
121
119
@@ -190,7 +188,7 @@ private void ApplyFontSettings(ResourceDictionary dict)
190
188
/// <summary>
191
189
/// Applies font properties to a Style.
192
190
/// </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 )
194
192
{
195
193
// Remove existing font-related setters
196
194
if ( isTextBox )
@@ -199,10 +197,10 @@ private void SetFontProperties(Style style, FontFamily fontFamily, FontStyle fon
199
197
var settersToRemove = style . Setters
200
198
. OfType < Setter > ( )
201
199
. 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 )
206
204
. ToList ( ) ;
207
205
208
206
// Remove each found setter one by one
@@ -212,17 +210,17 @@ private void SetFontProperties(Style style, FontFamily fontFamily, FontStyle fon
212
210
}
213
211
214
212
// 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 ) ) ;
219
217
220
218
// Set caret brush (retain existing logic)
221
219
var caretBrushPropertyValue = style . Setters . OfType < Setter > ( ) . Any ( x => x . Property . Name == "CaretBrush" ) ;
222
220
var foregroundPropertyValue = style . Setters . OfType < Setter > ( ) . Where ( x => x . Property . Name == "Foreground" )
223
221
. Select ( x => x . Value ) . FirstOrDefault ( ) ;
224
222
if ( ! caretBrushPropertyValue && foregroundPropertyValue != null )
225
- style . Setters . Add ( new Setter ( TextBox . CaretBrushProperty , foregroundPropertyValue ) ) ;
223
+ style . Setters . Add ( new Setter ( TextBoxBase . CaretBrushProperty , foregroundPropertyValue ) ) ;
226
224
}
227
225
else
228
226
{
@@ -246,6 +244,7 @@ private void SetFontProperties(Style style, FontFamily fontFamily, FontStyle fon
246
244
style . Setters . Add ( new Setter ( TextBlock . FontStretchProperty , fontStretch ) ) ;
247
245
}
248
246
}
247
+
249
248
private ResourceDictionary GetThemeResourceDictionary ( string theme )
250
249
{
251
250
var uri = GetThemePath ( theme ) ;
@@ -269,22 +268,22 @@ private ResourceDictionary GetResourceDictionary(string theme)
269
268
var fontWeight = FontHelper . GetFontWeightFromInvariantStringOrNormal ( _settings . QueryBoxFontWeight ) ;
270
269
var fontStretch = FontHelper . GetFontStretchFromInvariantStringOrNormal ( _settings . QueryBoxFontStretch ) ;
271
270
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 ) ) ;
276
275
277
276
var caretBrushPropertyValue = queryBoxStyle . Setters . OfType < Setter > ( ) . Any ( x => x . Property . Name == "CaretBrush" ) ;
278
277
var foregroundPropertyValue = queryBoxStyle . Setters . OfType < Setter > ( ) . Where ( x => x . Property . Name == "Foreground" )
279
278
. Select ( x => x . Value ) . FirstOrDefault ( ) ;
280
279
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 ) ) ;
282
281
283
282
// 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 ) ) ;
288
287
}
289
288
290
289
if ( dict [ "ItemTitleStyle" ] is Style resultItemStyle &&
@@ -321,7 +320,7 @@ private ResourceDictionary GetResourceDictionary(string theme)
321
320
/* Ignore Theme Window Width and use setting */
322
321
var windowStyle = dict [ "WindowStyle" ] as Style ;
323
322
var width = _settings . WindowSize ;
324
- windowStyle . Setters . Add ( new Setter ( Window . WidthProperty , width ) ) ;
323
+ windowStyle . Setters . Add ( new Setter ( FrameworkElement . WidthProperty , width ) ) ;
325
324
return dict ;
326
325
}
327
326
@@ -423,7 +422,7 @@ public bool ChangeTheme(string theme = null)
423
422
424
423
BlurEnabled = IsBlurTheme ( ) ;
425
424
426
- // 블러 및 그림자 효과 적용을 위한 비동기 처리
425
+ // Apply blur and drop shadow effects
427
426
_ = RefreshFrameAsync ( ) ;
428
427
429
428
return true ;
@@ -623,17 +622,14 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
623
622
624
623
private void SetBlurForWindow ( string theme , BackdropTypes backdropType )
625
624
{
626
- var dict = GetResourceDictionary ( theme ) ; // GetThemeResourceDictionary 대신 GetResourceDictionary 사용
627
- if ( dict == null )
628
- return ;
625
+ var dict = GetResourceDictionary ( theme ) ;
626
+ if ( dict == null ) return ;
629
627
630
628
var windowBorderStyle = dict . Contains ( "WindowBorderStyle" ) ? dict [ "WindowBorderStyle" ] as Style : null ;
631
- if ( windowBorderStyle == null )
632
- return ;
629
+ if ( windowBorderStyle == null ) return ;
633
630
634
- Window mainWindow = Application . Current . MainWindow ;
635
- if ( mainWindow == null )
636
- return ;
631
+ var mainWindow = Application . Current . MainWindow ;
632
+ if ( mainWindow == null ) return ;
637
633
638
634
// Check if the theme supports blur
639
635
bool hasBlur = dict . Contains ( "ThemeBlurEnabled" ) && dict [ "ThemeBlurEnabled" ] is bool b && b ;
0 commit comments