1- using System ;
1+ using Microsoft . Win32 ;
2+ using System ;
23using System . Collections ;
34using System . Collections . Generic ;
45using System . Collections . ObjectModel ;
@@ -28,18 +29,27 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
2829 {
2930 themeColors . Clear ( ) ;
3031
32+ //foreach (KeyValuePair<string, SolidColorBrush> item in origResourceColors)
33+ //{
34+ // Application.Current.Resources[item.Key] = item.Value;
35+ //}
36+
3137 // get original colors to collection
3238 foreach ( DictionaryEntry item in Application . Current . Resources . MergedDictionaries [ 0 ] )
39+ //foreach (DictionaryEntry item in Application.Current.Resources[themeColors[i].Key])
3340 {
41+ // take currently used colors
42+ var currentColor = Application . Current . Resources [ item . Key ] ;
43+
3444 var themeColorPair = new ThemeColor ( ) ;
3545 themeColorPair . Key = item . Key . ToString ( ) ;
36- themeColorPair . Brush = ( SolidColorBrush ) item . Value ;
46+ themeColorPair . Brush = ( SolidColorBrush ) currentColor ; // (SolidColorBrush) item.Value;
3747 themeColors . Add ( themeColorPair ) ;
3848
3949 // take backup copy
4050 var themeColorPair2 = new ThemeColor ( ) ;
4151 themeColorPair2 . Key = item . Key . ToString ( ) ;
42- themeColorPair2 . Brush = ( SolidColorBrush ) item . Value ;
52+ themeColorPair2 . Brush = ( SolidColorBrush ) currentColor ; // item.Value;
4353 themeColorsOrig . Add ( themeColorPair2 ) ;
4454 }
4555
@@ -54,6 +64,8 @@ private void GridThemeColors_SelectionChanged(object sender, System.Windows.Cont
5464 //Console.WriteLine(gridThemeColors.SelectedItem);
5565 var item = gridThemeColors . SelectedItem as ThemeColor ;
5666
67+ if ( item == null ) return ;
68+
5769 //selectedRow = gridThemeColors.SelectedIndex;
5870
5971 //selectedKey = k.Value.Key;
@@ -69,12 +81,16 @@ private void GridThemeColors_SelectionChanged(object sender, System.Windows.Cont
6981
7082 forceValue = true ;
7183 sliderRed . Value = item . Brush . Color . R ;
84+ txtRed . Text = sliderRed . Value . ToString ( ) ;
7285 forceValue = true ;
7386 sliderGreen . Value = item . Brush . Color . G ;
87+ txtGreen . Text = sliderGreen . Value . ToString ( ) ;
7488 forceValue = true ;
7589 sliderBlue . Value = item . Brush . Color . B ;
90+ txtBlue . Text = sliderBlue . Value . ToString ( ) ;
7691 forceValue = true ;
7792 sliderAlpha . Value = item . Brush . Color . A ;
93+ txtAlpha . Text = sliderAlpha . Value . ToString ( ) ;
7894 forceValue = false ;
7995 }
8096
@@ -150,18 +166,32 @@ private void SliderAlpha_ValueChanged(object sender, RoutedPropertyChangedEventA
150166
151167 private void BtnSaveTheme_Click ( object sender , RoutedEventArgs e )
152168 {
153- // NOTE for now its application root folder, would be nicer to have fixed themes/ folder
154- var rootFolder = Path . GetDirectoryName ( Process . GetCurrentProcess ( ) . MainModule . FileName ) ;
155- List < string > iniRows = new List < string > ( ) ;
156- iniRows . Add ( "# Created with UnityLauncherPro built-in theme editor " + DateTime . Now . ToString ( "dd/MM/YYYY" ) ) ;
157- for ( int i = 0 ; i < themeColors . Count ; i ++ )
169+ var themeFolder = Path . Combine ( Path . GetDirectoryName ( Process . GetCurrentProcess ( ) . MainModule . FileName ) , "Themes" ) ;
170+
171+ if ( Directory . Exists ( themeFolder ) == false ) Directory . CreateDirectory ( themeFolder ) ;
172+
173+ SaveFileDialog saveFileDialog = new SaveFileDialog ( ) ;
174+ saveFileDialog . FileName = "custom" ;
175+ saveFileDialog . DefaultExt = ".ini" ;
176+ saveFileDialog . Filter = "Theme files (.ini)|*.ini" ;
177+ saveFileDialog . InitialDirectory = themeFolder ;
178+ saveFileDialog . RestoreDirectory = true ;
179+
180+ if ( saveFileDialog . ShowDialog ( ) == true )
158181 {
159- iniRows . Add ( themeColors [ i ] . Key + "=" + themeColors [ i ] . Brush . ToString ( ) ) ;
182+ List < string > iniRows = new List < string > ( ) ;
183+ iniRows . Add ( "# Created with UnityLauncherPro built-in theme editor " + DateTime . Now . ToString ( "dd/MM/YYYY" ) ) ;
184+ for ( int i = 0 ; i < themeColors . Count ; i ++ )
185+ {
186+ iniRows . Add ( themeColors [ i ] . Key + "=" + themeColors [ i ] . Brush . ToString ( ) ) ;
187+ }
188+
189+ var themePath = saveFileDialog . FileName ;
190+ File . WriteAllLines ( themePath , iniRows ) ;
191+ Console . WriteLine ( "Saved theme: " + themePath ) ;
192+
193+ // TODO close theme editor window?
160194 }
161- // TODO ask for output filename
162- var themePath = Path . Combine ( rootFolder , "custom.ini" ) ;
163- File . WriteAllLines ( themePath , iniRows ) ;
164- Console . WriteLine ( "Saved theme: " + themePath ) ;
165195 }
166196
167197 private void BtnResetTheme_Click ( object sender , RoutedEventArgs e )
0 commit comments