@@ -26,6 +26,7 @@ namespace SPCode.UI.Windows
2626{
2727 public partial class ConfigWindow
2828 {
29+ #region Properties
2930 private bool AllowChange ;
3031 private bool NeedsSMDefInvalidation ;
3132
@@ -52,45 +53,26 @@ public partial class ConfigWindow
5253 $ "{{plugins_unload}} { Translate ( "macro_plugins_unload" ) } "
5354 } ;
5455
55- public ConfigWindow ( )
56+ private class SimpleCommand : ICommand
5657 {
57- InitializeComponent ( ) ;
58- Language_Translate ( ) ;
59- EvaluateRTL ( ) ;
60- if ( Program . OptionsObject . Program_AccentColor != "Red" || Program . OptionsObject . Program_Theme != "BaseDark" )
58+ public Predicate < object > CanExecutePredicate { get ; set ; }
59+ public Action < object > ExecuteAction { get ; set ; }
60+
61+ public bool CanExecute ( object parameter )
6162 {
62- ThemeManager . ChangeAppStyle ( this , ThemeManager . GetAccent ( Program . OptionsObject . Program_AccentColor ) ,
63- ThemeManager . GetAppTheme ( Program . OptionsObject . Program_Theme ) ) ;
63+ return true ;
6464 }
6565
66- foreach ( var config in Program . Configs )
66+ public event EventHandler CanExecuteChanged
6767 {
68- ConfigListBox . Items . Add ( new ListBoxItem { Content = config . Name } ) ;
68+ add => CommandManager . RequerySuggested += value ;
69+ remove => CommandManager . RequerySuggested -= value ;
6970 }
7071
71- SelectedBox = C_PreBuildCmd ;
72-
73- ConfigListBox . SelectedIndex = Program . SelectedConfig ;
74-
75- CompileMacros . ToList ( ) . ForEach ( x => CMD_ItemC . Items . Add ( x ) ) ;
76- CMD_ItemC . SelectionChanged += CompileMacros_OnClickedItem ;
77- CommandMacros . ToList ( ) . ForEach ( x => Rcon_MenuC . Items . Add ( x ) ) ;
78- Rcon_MenuC . SelectionChanged += CommandMacros_OnClickedItem ;
79-
80- var item1 = new ComboBoxItem ( )
81- {
82- Visibility = Visibility . Collapsed ,
83- Content = Translate ( "Macros" ) ,
84- } ;
85- var item2 = new ComboBoxItem ( )
72+ public void Execute ( object parameter )
8673 {
87- Visibility = Visibility . Collapsed ,
88- Content = Translate ( "Macros" ) ,
89- } ;
90- CMD_ItemC . Items . Insert ( 0 , item1 ) ;
91- Rcon_MenuC . Items . Insert ( 0 , item2 ) ;
92- CMD_ItemC . SelectedIndex = 0 ;
93- Rcon_MenuC . SelectedIndex = 0 ;
74+ ExecuteAction ? . Invoke ( parameter ) ;
75+ }
9476 }
9577
9678 public ICommand TextBoxButtonFolderCmd
@@ -171,7 +153,52 @@ public ICommand TextBoxButtonFileCmd
171153 return textBoxButtonFileCmd ;
172154 }
173155 }
156+ #endregion
157+
158+ #region Constructors
159+ public ConfigWindow ( )
160+ {
161+ InitializeComponent ( ) ;
162+ Language_Translate ( ) ;
163+ EvaluateRTL ( ) ;
164+ if ( Program . OptionsObject . Program_AccentColor != "Red" || Program . OptionsObject . Program_Theme != "BaseDark" )
165+ {
166+ ThemeManager . ChangeAppStyle ( this , ThemeManager . GetAccent ( Program . OptionsObject . Program_AccentColor ) ,
167+ ThemeManager . GetAppTheme ( Program . OptionsObject . Program_Theme ) ) ;
168+ }
169+
170+ foreach ( var config in Program . Configs )
171+ {
172+ ConfigListBox . Items . Add ( new ListBoxItem { Content = config . Name } ) ;
173+ }
174+
175+ SelectedBox = C_PreBuildCmd ;
176+
177+ ConfigListBox . SelectedIndex = Program . SelectedConfig ;
178+
179+ CompileMacros . ToList ( ) . ForEach ( x => CMD_ItemC . Items . Add ( x ) ) ;
180+ CMD_ItemC . SelectionChanged += CompileMacros_OnClickedItem ;
181+ CommandMacros . ToList ( ) . ForEach ( x => Rcon_MenuC . Items . Add ( x ) ) ;
182+ Rcon_MenuC . SelectionChanged += CommandMacros_OnClickedItem ;
183+
184+ var item1 = new ComboBoxItem ( )
185+ {
186+ Visibility = Visibility . Collapsed ,
187+ Content = Translate ( "Macros" ) ,
188+ } ;
189+ var item2 = new ComboBoxItem ( )
190+ {
191+ Visibility = Visibility . Collapsed ,
192+ Content = Translate ( "Macros" ) ,
193+ } ;
194+ CMD_ItemC . Items . Insert ( 0 , item1 ) ;
195+ Rcon_MenuC . Items . Insert ( 0 , item2 ) ;
196+ CMD_ItemC . SelectedIndex = 0 ;
197+ Rcon_MenuC . SelectedIndex = 0 ;
198+ }
199+ #endregion
174200
201+ #region Events
175202 private void ConfigListBox_SelectionChanged ( object sender , SelectionChangedEventArgs e )
176203 {
177204 LoadConfigToUI ( ConfigListBox . SelectedIndex ) ;
@@ -220,41 +247,6 @@ private void BuildCommandsBoxes_OnFocus(object sender, RoutedEventArgs e)
220247 SelectedBox = sender as TextBox ;
221248 }
222249
223- private void LoadConfigToUI ( int index )
224- {
225- if ( index < 0 || index >= Program . Configs . Count )
226- {
227- return ;
228- }
229-
230- AllowChange = false ;
231- var c = Program . Configs [ index ] ;
232-
233- C_SMDir . Items . Clear ( ) ;
234- c . SMDirectories . ForEach ( x => C_SMDir . Items . Add ( CreateDirItem ( x , DirUtils . CanAccess ( x ) ) ) ) ;
235- C_Name . Text = c . Name ;
236- C_AutoCopy . IsChecked = c . AutoCopy ;
237- C_AutoUpload . IsChecked = c . AutoUpload ;
238- C_AutoRCON . IsChecked = c . AutoRCON ;
239- C_CopyDir . Text = c . CopyDirectory ;
240- C_ServerFile . Text = c . ServerFile ;
241- C_ServerArgs . Text = c . ServerArgs ;
242- C_PreBuildCmd . Text = c . PreCmd ;
243- C_PostBuildCmd . Text = c . PostCmd ;
244- C_OptimizationLevel . Value = c . OptimizeLevel ;
245- C_VerboseLevel . Value = c . VerboseLevel ;
246- C_DeleteAfterCopy . IsChecked = c . DeleteAfterCopy ;
247- C_FTPHost . Text = c . FTPHost ;
248- C_FTPUser . Text = c . FTPUser ;
249- C_FTPPW . Password = c . FTPPassword ;
250- C_FTPDir . Text = c . FTPDir ;
251- C_RConIP . Text = c . RConIP ;
252- C_RConPort . Text = c . RConPort . ToString ( ) ;
253- C_RConPW . Password = c . RConPassword ;
254- C_RConCmds . Text = c . RConCommands ;
255- AllowChange = true ;
256- }
257-
258250 private void NewButton_Click ( object sender , RoutedEventArgs e )
259251 {
260252 var cfg = new Config
@@ -771,6 +763,63 @@ await this.ShowMessageAsync(Translate("ErrorSavingConfigs"),
771763 } ) ;
772764 }
773765
766+ private void SidebarColumn_SizeChanged ( object sender , SizeChangedEventArgs e )
767+ {
768+ if ( e . NewSize . Width < 200 )
769+ {
770+ NewButtonText . Visibility = Visibility . Collapsed ;
771+ CopyButtonText . Visibility = Visibility . Collapsed ;
772+ DeleteButtonText . Visibility = Visibility . Collapsed ;
773+ }
774+ else
775+ {
776+ NewButtonText . Visibility = Visibility . Visible ;
777+ CopyButtonText . Visibility = Visibility . Visible ;
778+ DeleteButtonText . Visibility = Visibility . Visible ;
779+ }
780+ }
781+ #endregion
782+
783+ #region Methods
784+ /// <summary>
785+ /// Loads the config preferences to the controls of the window
786+ /// </summary>
787+ /// <param name="index"></param>
788+ private void LoadConfigToUI ( int index )
789+ {
790+ if ( index < 0 || index >= Program . Configs . Count )
791+ {
792+ return ;
793+ }
794+
795+ AllowChange = false ;
796+ var c = Program . Configs [ index ] ;
797+
798+ C_SMDir . Items . Clear ( ) ;
799+ c . SMDirectories . ForEach ( x => C_SMDir . Items . Add ( CreateDirItem ( x , DirUtils . CanAccess ( x ) ) ) ) ;
800+ C_Name . Text = c . Name ;
801+ C_AutoCopy . IsChecked = c . AutoCopy ;
802+ C_AutoUpload . IsChecked = c . AutoUpload ;
803+ C_AutoRCON . IsChecked = c . AutoRCON ;
804+ C_CopyDir . Text = c . CopyDirectory ;
805+ C_ServerFile . Text = c . ServerFile ;
806+ C_ServerArgs . Text = c . ServerArgs ;
807+ C_PreBuildCmd . Text = c . PreCmd ;
808+ C_PostBuildCmd . Text = c . PostCmd ;
809+ C_OptimizationLevel . Value = c . OptimizeLevel ;
810+ C_VerboseLevel . Value = c . VerboseLevel ;
811+ C_DeleteAfterCopy . IsChecked = c . DeleteAfterCopy ;
812+ C_FTPHost . Text = c . FTPHost ;
813+ C_FTPUser . Text = c . FTPUser ;
814+ C_FTPPW . Password = c . FTPPassword ;
815+ C_FTPDir . Text = c . FTPDir ;
816+ C_RConIP . Text = c . RConIP ;
817+ C_RConPort . Text = c . RConPort . ToString ( ) ;
818+ C_RConPW . Password = c . RConPassword ;
819+ C_RConCmds . Text = c . RConCommands ;
820+ AllowChange = true ;
821+ }
822+
774823 /// <summary>
775824 /// Creates the ListBoxItem that will be added to the SM Directories list of the selected config
776825 /// </summary>
@@ -779,8 +828,10 @@ await this.ShowMessageAsync(Translate("ErrorSavingConfigs"),
779828 private ListBoxItem CreateDirItem ( string path , bool canAccess = false )
780829 {
781830 var item = new ListBoxItem ( ) ;
782- var stack = new StackPanel ( ) ;
783- stack . Orientation = Orientation . Horizontal ;
831+ var stack = new StackPanel
832+ {
833+ Orientation = Orientation . Horizontal
834+ } ;
784835 stack . Children . Add ( new TextBlock
785836 {
786837 Text = path
@@ -809,22 +860,6 @@ private ListBoxItem CreateDirItem(string path, bool canAccess = false)
809860 return item ;
810861 }
811862
812- private void SidebarColumn_SizeChanged ( object sender , SizeChangedEventArgs e )
813- {
814- if ( e . NewSize . Width < 200 )
815- {
816- AddButtonText . Visibility = Visibility . Collapsed ;
817- CopyButtonText . Visibility = Visibility . Collapsed ;
818- RemoveButtonText . Visibility = Visibility . Collapsed ;
819- }
820- else
821- {
822- AddButtonText . Visibility = Visibility . Visible ;
823- CopyButtonText . Visibility = Visibility . Visible ;
824- RemoveButtonText . Visibility = Visibility . Visible ;
825- }
826- }
827-
828863 private void Language_Translate ( )
829864 {
830865 Title = Translate ( "Configs" ) ;
@@ -869,27 +904,6 @@ private void EvaluateRTL()
869904 C_OptimizationLevel . FlowDirection = FlowDirection . LeftToRight ;
870905 C_VerboseLevel . FlowDirection = FlowDirection . LeftToRight ;
871906 }
872-
873- private class SimpleCommand : ICommand
874- {
875- public Predicate < object > CanExecutePredicate { get ; set ; }
876- public Action < object > ExecuteAction { get ; set ; }
877-
878- public bool CanExecute ( object parameter )
879- {
880- return true ;
881- }
882-
883- public event EventHandler CanExecuteChanged
884- {
885- add => CommandManager . RequerySuggested += value ;
886- remove => CommandManager . RequerySuggested -= value ;
887- }
888-
889- public void Execute ( object parameter )
890- {
891- ExecuteAction ? . Invoke ( parameter ) ;
892- }
893- }
907+ #endregion
894908 }
895909}
0 commit comments