@@ -72,7 +72,7 @@ public Theme(IPublicAPI publicAPI, Settings settings)
7272 }
7373 else
7474 {
75- Log . Error ( "현재 테마 리소스를 찾을 수 없습니다. 기본 테마로 초기화합니다 ." ) ;
75+ Log . Error ( "Current theme resource not found. Initializing with default theme ." ) ;
7676 _oldTheme = Constant . DefaultTheme ;
7777 } ;
7878 _oldTheme = Path . GetFileNameWithoutExtension ( _oldResource . Source . AbsolutePath ) ;
@@ -104,26 +104,149 @@ private void MakeSureThemeDirectoriesExist()
104104
105105 private void UpdateResourceDictionary ( ResourceDictionary dictionaryToUpdate )
106106 {
107- // 새 테마 리소스를 먼저 추가하고
107+ // Add the new theme resource first
108108 if ( ! Application . Current . Resources . MergedDictionaries . Contains ( dictionaryToUpdate ) )
109109 {
110110 Application . Current . Resources . MergedDictionaries . Add ( dictionaryToUpdate ) ;
111111 }
112112
113- // 그 다음 이전 테마 리소스 제거
113+ // Then remove the old theme resource
114114 if ( _oldResource != null &&
115115 _oldResource != dictionaryToUpdate &&
116116 Application . Current . Resources . MergedDictionaries . Contains ( _oldResource ) )
117117 {
118118 Application . Current . Resources . MergedDictionaries . Remove ( _oldResource ) ;
119119 }
120-
121120 _oldResource = dictionaryToUpdate ;
122-
123- // 리소스 변경 후 문제가 없는지 검증
124- Debug . WriteLine ( $ "테마 변경 후 리소스 딕셔너리 수: { Application . Current . Resources . MergedDictionaries . Count } ") ;
125121 }
126122
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+ }
127250 private ResourceDictionary GetThemeResourceDictionary ( string theme )
128251 {
129252 var uri = GetThemePath ( theme ) ;
@@ -286,9 +409,10 @@ public bool ChangeTheme(string theme = null)
286409 if ( string . IsNullOrEmpty ( path ) )
287410 throw new DirectoryNotFoundException ( "Theme path can't be found <{path}>" ) ;
288411
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 ) ;
292416
293417 _settings . Theme = theme ;
294418
@@ -299,10 +423,11 @@ public bool ChangeTheme(string theme = null)
299423 }
300424
301425 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 ;
306431 }
307432 catch ( DirectoryNotFoundException )
308433 {
@@ -324,7 +449,6 @@ public bool ChangeTheme(string theme = null)
324449 }
325450 return false ;
326451 }
327- return true ;
328452 }
329453
330454 #endregion
@@ -500,7 +624,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
500624
501625 private void SetBlurForWindow ( string theme , BackdropTypes backdropType )
502626 {
503- var dict = GetThemeResourceDictionary ( theme ) ;
627+ var dict = GetResourceDictionary ( theme ) ; // GetThemeResourceDictionary 대신 GetResourceDictionary 사용
504628 if ( dict == null )
505629 return ;
506630
0 commit comments