@@ -72,7 +72,7 @@ public Theme(IPublicAPI publicAPI, Settings settings)
72
72
}
73
73
else
74
74
{
75
- Log . Error ( "현재 테마 리소스를 찾을 수 없습니다. 기본 테마로 초기화합니다 ." ) ;
75
+ Log . Error ( "Current theme resource not found. Initializing with default theme ." ) ;
76
76
_oldTheme = Constant . DefaultTheme ;
77
77
} ;
78
78
_oldTheme = Path . GetFileNameWithoutExtension ( _oldResource . Source . AbsolutePath ) ;
@@ -104,26 +104,149 @@ private void MakeSureThemeDirectoriesExist()
104
104
105
105
private void UpdateResourceDictionary ( ResourceDictionary dictionaryToUpdate )
106
106
{
107
- // 새 테마 리소스를 먼저 추가하고
107
+ // Add the new theme resource first
108
108
if ( ! Application . Current . Resources . MergedDictionaries . Contains ( dictionaryToUpdate ) )
109
109
{
110
110
Application . Current . Resources . MergedDictionaries . Add ( dictionaryToUpdate ) ;
111
111
}
112
112
113
- // 그 다음 이전 테마 리소스 제거
113
+ // Then remove the old theme resource
114
114
if ( _oldResource != null &&
115
115
_oldResource != dictionaryToUpdate &&
116
116
Application . Current . Resources . MergedDictionaries . Contains ( _oldResource ) )
117
117
{
118
118
Application . Current . Resources . MergedDictionaries . Remove ( _oldResource ) ;
119
119
}
120
-
121
120
_oldResource = dictionaryToUpdate ;
122
-
123
- // 리소스 변경 후 문제가 없는지 검증
124
- Debug . WriteLine ( $ "테마 변경 후 리소스 딕셔너리 수: { Application . Current . Resources . MergedDictionaries . Count } ") ;
125
121
}
126
122
123
+ /// <summary>
124
+ /// Updates only the font settings and refreshes the UI.
125
+ /// </summary>
126
+ public void UpdateFonts ( )
127
+ {
128
+ try
129
+ {
130
+ // Loads a ResourceDictionary for the specified theme.
131
+ var themeName = GetCurrentTheme ( ) ;
132
+ var dict = GetThemeResourceDictionary ( themeName ) ;
133
+
134
+ // Applies font settings to the theme resource.
135
+ ApplyFontSettings ( dict ) ;
136
+ UpdateResourceDictionary ( dict ) ;
137
+ _ = RefreshFrameAsync ( ) ;
138
+ }
139
+ catch ( Exception e )
140
+ {
141
+ Log . Exception ( "Error occurred while updating theme fonts" , e ) ;
142
+ }
143
+ }
144
+
145
+ /// <summary>
146
+ /// Loads and applies font settings to the theme resource.
147
+ /// </summary>
148
+ private void ApplyFontSettings ( ResourceDictionary dict )
149
+ {
150
+ if ( dict [ "QueryBoxStyle" ] is Style queryBoxStyle &&
151
+ dict [ "QuerySuggestionBoxStyle" ] is Style querySuggestionBoxStyle )
152
+ {
153
+ var fontFamily = new FontFamily ( _settings . QueryBoxFont ) ;
154
+ var fontStyle = FontHelper . GetFontStyleFromInvariantStringOrNormal ( _settings . QueryBoxFontStyle ) ;
155
+ var fontWeight = FontHelper . GetFontWeightFromInvariantStringOrNormal ( _settings . QueryBoxFontWeight ) ;
156
+ var fontStretch = FontHelper . GetFontStretchFromInvariantStringOrNormal ( _settings . QueryBoxFontStretch ) ;
157
+
158
+ SetFontProperties ( queryBoxStyle , fontFamily , fontStyle , fontWeight , fontStretch , true ) ;
159
+ SetFontProperties ( querySuggestionBoxStyle , fontFamily , fontStyle , fontWeight , fontStretch , false ) ;
160
+ }
161
+
162
+ if ( dict [ "ItemTitleStyle" ] is Style resultItemStyle &&
163
+ dict [ "ItemTitleSelectedStyle" ] is Style resultItemSelectedStyle &&
164
+ dict [ "ItemHotkeyStyle" ] is Style resultHotkeyItemStyle &&
165
+ dict [ "ItemHotkeySelectedStyle" ] is Style resultHotkeyItemSelectedStyle )
166
+ {
167
+ var fontFamily = new FontFamily ( _settings . ResultFont ) ;
168
+ var fontStyle = FontHelper . GetFontStyleFromInvariantStringOrNormal ( _settings . ResultFontStyle ) ;
169
+ var fontWeight = FontHelper . GetFontWeightFromInvariantStringOrNormal ( _settings . ResultFontWeight ) ;
170
+ var fontStretch = FontHelper . GetFontStretchFromInvariantStringOrNormal ( _settings . ResultFontStretch ) ;
171
+
172
+ SetFontProperties ( resultItemStyle , fontFamily , fontStyle , fontWeight , fontStretch , false ) ;
173
+ SetFontProperties ( resultItemSelectedStyle , fontFamily , fontStyle , fontWeight , fontStretch , false ) ;
174
+ SetFontProperties ( resultHotkeyItemStyle , fontFamily , fontStyle , fontWeight , fontStretch , false ) ;
175
+ SetFontProperties ( resultHotkeyItemSelectedStyle , fontFamily , fontStyle , fontWeight , fontStretch , false ) ;
176
+ }
177
+
178
+ if ( dict [ "ItemSubTitleStyle" ] is Style resultSubItemStyle &&
179
+ dict [ "ItemSubTitleSelectedStyle" ] is Style resultSubItemSelectedStyle )
180
+ {
181
+ var fontFamily = new FontFamily ( _settings . ResultSubFont ) ;
182
+ var fontStyle = FontHelper . GetFontStyleFromInvariantStringOrNormal ( _settings . ResultSubFontStyle ) ;
183
+ var fontWeight = FontHelper . GetFontWeightFromInvariantStringOrNormal ( _settings . ResultSubFontWeight ) ;
184
+ var fontStretch = FontHelper . GetFontStretchFromInvariantStringOrNormal ( _settings . ResultSubFontStretch ) ;
185
+
186
+ SetFontProperties ( resultSubItemStyle , fontFamily , fontStyle , fontWeight , fontStretch , false ) ;
187
+ SetFontProperties ( resultSubItemSelectedStyle , fontFamily , fontStyle , fontWeight , fontStretch , false ) ;
188
+ }
189
+ }
190
+
191
+ /// <summary>
192
+ /// Applies font properties to a Style.
193
+ /// </summary>
194
+ private void SetFontProperties ( Style style , FontFamily fontFamily , FontStyle fontStyle , FontWeight fontWeight , FontStretch fontStretch , bool isTextBox )
195
+ {
196
+ // Remove existing font-related setters
197
+ if ( isTextBox )
198
+ {
199
+ // First, find the setters to remove and store them in a list
200
+ var settersToRemove = style . Setters
201
+ . OfType < Setter > ( )
202
+ . Where ( setter =>
203
+ setter . Property == TextBox . FontFamilyProperty ||
204
+ setter . Property == TextBox . FontStyleProperty ||
205
+ setter . Property == TextBox . FontWeightProperty ||
206
+ setter . Property == TextBox . FontStretchProperty )
207
+ . ToList ( ) ;
208
+
209
+ // Remove each found setter one by one
210
+ foreach ( var setter in settersToRemove )
211
+ {
212
+ style . Setters . Remove ( setter ) ;
213
+ }
214
+
215
+ // Add New font setter
216
+ style . Setters . Add ( new Setter ( TextBox . FontFamilyProperty , fontFamily ) ) ;
217
+ style . Setters . Add ( new Setter ( TextBox . FontStyleProperty , fontStyle ) ) ;
218
+ style . Setters . Add ( new Setter ( TextBox . FontWeightProperty , fontWeight ) ) ;
219
+ style . Setters . Add ( new Setter ( TextBox . FontStretchProperty , fontStretch ) ) ;
220
+
221
+ // Set caret brush (retain existing logic)
222
+ var caretBrushPropertyValue = style . Setters . OfType < Setter > ( ) . Any ( x => x . Property . Name == "CaretBrush" ) ;
223
+ var foregroundPropertyValue = style . Setters . OfType < Setter > ( ) . Where ( x => x . Property . Name == "Foreground" )
224
+ . Select ( x => x . Value ) . FirstOrDefault ( ) ;
225
+ if ( ! caretBrushPropertyValue && foregroundPropertyValue != null )
226
+ style . Setters . Add ( new Setter ( TextBox . CaretBrushProperty , foregroundPropertyValue ) ) ;
227
+ }
228
+ else
229
+ {
230
+ var settersToRemove = style . Setters
231
+ . OfType < Setter > ( )
232
+ . Where ( setter =>
233
+ setter . Property == TextBlock . FontFamilyProperty ||
234
+ setter . Property == TextBlock . FontStyleProperty ||
235
+ setter . Property == TextBlock . FontWeightProperty ||
236
+ setter . Property == TextBlock . FontStretchProperty )
237
+ . ToList ( ) ;
238
+
239
+ foreach ( var setter in settersToRemove )
240
+ {
241
+ style . Setters . Remove ( setter ) ;
242
+ }
243
+
244
+ style . Setters . Add ( new Setter ( TextBlock . FontFamilyProperty , fontFamily ) ) ;
245
+ style . Setters . Add ( new Setter ( TextBlock . FontStyleProperty , fontStyle ) ) ;
246
+ style . Setters . Add ( new Setter ( TextBlock . FontWeightProperty , fontWeight ) ) ;
247
+ style . Setters . Add ( new Setter ( TextBlock . FontStretchProperty , fontStretch ) ) ;
248
+ }
249
+ }
127
250
private ResourceDictionary GetThemeResourceDictionary ( string theme )
128
251
{
129
252
var uri = GetThemePath ( theme ) ;
@@ -286,9 +409,10 @@ public bool ChangeTheme(string theme = null)
286
409
if ( string . IsNullOrEmpty ( path ) )
287
410
throw new DirectoryNotFoundException ( "Theme path can't be found <{path}>" ) ;
288
411
289
- // reload all resources even if the theme itself hasn't changed in order to pickup changes
290
- // to things like fonts
291
- UpdateResourceDictionary ( GetResourceDictionary ( theme ) ) ;
412
+ // Retrieve theme resource – always use the resource with font settings applied.
413
+ var resourceDict = GetResourceDictionary ( theme ) ;
414
+
415
+ UpdateResourceDictionary ( resourceDict ) ;
292
416
293
417
_settings . Theme = theme ;
294
418
@@ -299,10 +423,11 @@ public bool ChangeTheme(string theme = null)
299
423
}
300
424
301
425
BlurEnabled = IsBlurTheme ( ) ;
302
- //if (_settings.UseDropShadowEffect)
303
- // AddDropShadowEffectToCurrentTheme();
304
- //Win32Helper.SetBlurForWindow(Application.Current.MainWindow, BlurEnabled);
305
- _ = SetBlurForWindowAsync ( ) ;
426
+
427
+ // 블러 및 그림자 효과 적용을 위한 비동기 처리
428
+ _ = RefreshFrameAsync ( ) ;
429
+
430
+ return true ;
306
431
}
307
432
catch ( DirectoryNotFoundException )
308
433
{
@@ -324,7 +449,6 @@ public bool ChangeTheme(string theme = null)
324
449
}
325
450
return false ;
326
451
}
327
- return true ;
328
452
}
329
453
330
454
#endregion
@@ -500,7 +624,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
500
624
501
625
private void SetBlurForWindow ( string theme , BackdropTypes backdropType )
502
626
{
503
- var dict = GetThemeResourceDictionary ( theme ) ;
627
+ var dict = GetResourceDictionary ( theme ) ; // GetThemeResourceDictionary 대신 GetResourceDictionary 사용
504
628
if ( dict == null )
505
629
return ;
506
630
0 commit comments