1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . IO ;
44using System . Linq ;
88using System . Windows . Interop ;
99using System . Windows . Markup ;
1010using System . Windows . Media ;
11+ using System . Windows . Media . Effects ;
1112using Flow . Launcher . Infrastructure ;
1213using Flow . Launcher . Infrastructure . Logger ;
1314using Flow . Launcher . Infrastructure . UserSettings ;
@@ -34,6 +35,9 @@ public Theme()
3435 var dicts = Application . Current . Resources . MergedDictionaries ;
3536 _oldResource = dicts . First ( d =>
3637 {
38+ if ( d . Source == null )
39+ return false ;
40+
3741 var p = d . Source . AbsolutePath ;
3842 var dir = Path . GetDirectoryName ( p ) . NonNull ( ) ;
3943 var info = new DirectoryInfo ( dir ) ;
@@ -65,7 +69,7 @@ private void MakesureThemeDirectoriesExist()
6569
6670 public bool ChangeTheme ( string theme )
6771 {
68- const string defaultTheme = "Dark" ;
72+ const string defaultTheme = Constant . DefaultTheme ;
6973
7074 string path = GetThemePath ( theme ) ;
7175 try
@@ -75,16 +79,15 @@ public bool ChangeTheme(string theme)
7579
7680 Settings . Theme = theme ;
7781
78- var dicts = Application . Current . Resources . MergedDictionaries ;
7982 //always allow re-loading default theme, in case of failure of switching to a new theme from default theme
8083 if ( _oldTheme != theme || theme == defaultTheme )
8184 {
82- dicts . Remove ( _oldResource ) ;
83- var newResource = GetResourceDictionary ( ) ;
84- dicts . Add ( newResource ) ;
85- _oldResource = newResource ;
85+ UpdateResourceDictionary ( GetResourceDictionary ( ) ) ;
8686 _oldTheme = Path . GetFileNameWithoutExtension ( _oldResource . Source . AbsolutePath ) ;
8787 }
88+
89+ if ( Settings . UseDropShadowEffect )
90+ AddDropShadowEffectToCurrentTheme ( ) ;
8891 }
8992 catch ( DirectoryNotFoundException e )
9093 {
@@ -109,14 +112,30 @@ public bool ChangeTheme(string theme)
109112 return true ;
110113 }
111114
112- public ResourceDictionary GetResourceDictionary ( )
115+ private void UpdateResourceDictionary ( ResourceDictionary dictionaryToUpdate )
116+ {
117+ var dicts = Application . Current . Resources . MergedDictionaries ;
118+
119+ dicts . Remove ( _oldResource ) ;
120+ dicts . Add ( dictionaryToUpdate ) ;
121+ _oldResource = dictionaryToUpdate ;
122+ }
123+
124+ private ResourceDictionary CurrentThemeResourceDictionary ( )
113125 {
114126 var uri = GetThemePath ( Settings . Theme ) ;
115127 var dict = new ResourceDictionary
116128 {
117129 Source = new Uri ( uri , UriKind . Absolute )
118130 } ;
119131
132+ return dict ;
133+ }
134+
135+ public ResourceDictionary GetResourceDictionary ( )
136+ {
137+ var dict = CurrentThemeResourceDictionary ( ) ;
138+
120139 Style queryBoxStyle = dict [ "QueryBoxStyle" ] as Style ;
121140 if ( queryBoxStyle != null )
122141 {
@@ -146,6 +165,7 @@ public ResourceDictionary GetResourceDictionary()
146165 Setter [ ] setters = { fontFamily , fontStyle , fontWeight , fontStretch } ;
147166 Array . ForEach ( new [ ] { resultItemStyle , resultSubItemStyle , resultItemSelectedStyle , resultSubItemSelectedStyle } , o => Array . ForEach ( setters , p => o . Setters . Add ( p ) ) ) ;
148167 }
168+
149169 return dict ;
150170 }
151171
@@ -176,6 +196,36 @@ private string GetThemePath(string themeName)
176196 return string . Empty ;
177197 }
178198
199+ public void AddDropShadowEffectToCurrentTheme ( )
200+ {
201+ var dict = CurrentThemeResourceDictionary ( ) ;
202+
203+ var windowBorderStyle = dict [ "WindowBorderStyle" ] as Style ;
204+
205+ var effectSetter = new Setter ( ) ;
206+ effectSetter . Property = Border . EffectProperty ;
207+ effectSetter . Value = new DropShadowEffect
208+ {
209+ Opacity = 0.9 ,
210+ ShadowDepth = 2 ,
211+ BlurRadius = 15
212+ } ;
213+
214+ windowBorderStyle . Setters . Add ( effectSetter ) ;
215+
216+ UpdateResourceDictionary ( dict ) ;
217+ }
218+
219+ public void RemoveDropShadowEffectToCurrentTheme ( )
220+ {
221+ var dict = CurrentThemeResourceDictionary ( ) ;
222+ var windowBorderStyle = dict [ "WindowBorderStyle" ] as Style ;
223+
224+ dict . Remove ( Border . EffectProperty ) ;
225+
226+ UpdateResourceDictionary ( dict ) ;
227+ }
228+
179229 #region Blur Handling
180230 /*
181231 Found on https://github.com/riverar/sample-win10-aeroglass
0 commit comments