@@ -26,6 +26,7 @@ namespace SPCode.UI.Windows
26
26
{
27
27
public partial class ConfigWindow
28
28
{
29
+ #region Properties
29
30
private bool AllowChange ;
30
31
private bool NeedsSMDefInvalidation ;
31
32
@@ -52,45 +53,26 @@ public partial class ConfigWindow
52
53
$ "{{plugins_unload}} { Translate ( "macro_plugins_unload" ) } "
53
54
} ;
54
55
55
- public ConfigWindow ( )
56
+ private class SimpleCommand : ICommand
56
57
{
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 )
61
62
{
62
- ThemeManager . ChangeAppStyle ( this , ThemeManager . GetAccent ( Program . OptionsObject . Program_AccentColor ) ,
63
- ThemeManager . GetAppTheme ( Program . OptionsObject . Program_Theme ) ) ;
63
+ return true ;
64
64
}
65
65
66
- foreach ( var config in Program . Configs )
66
+ public event EventHandler CanExecuteChanged
67
67
{
68
- ConfigListBox . Items . Add ( new ListBoxItem { Content = config . Name } ) ;
68
+ add => CommandManager . RequerySuggested += value ;
69
+ remove => CommandManager . RequerySuggested -= value ;
69
70
}
70
71
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 )
86
73
{
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
+ }
94
76
}
95
77
96
78
public ICommand TextBoxButtonFolderCmd
@@ -171,7 +153,52 @@ public ICommand TextBoxButtonFileCmd
171
153
return textBoxButtonFileCmd ;
172
154
}
173
155
}
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
174
200
201
+ #region Events
175
202
private void ConfigListBox_SelectionChanged ( object sender , SelectionChangedEventArgs e )
176
203
{
177
204
LoadConfigToUI ( ConfigListBox . SelectedIndex ) ;
@@ -220,41 +247,6 @@ private void BuildCommandsBoxes_OnFocus(object sender, RoutedEventArgs e)
220
247
SelectedBox = sender as TextBox ;
221
248
}
222
249
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
-
258
250
private void NewButton_Click ( object sender , RoutedEventArgs e )
259
251
{
260
252
var cfg = new Config
@@ -771,6 +763,63 @@ await this.ShowMessageAsync(Translate("ErrorSavingConfigs"),
771
763
} ) ;
772
764
}
773
765
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
+
774
823
/// <summary>
775
824
/// Creates the ListBoxItem that will be added to the SM Directories list of the selected config
776
825
/// </summary>
@@ -779,8 +828,10 @@ await this.ShowMessageAsync(Translate("ErrorSavingConfigs"),
779
828
private ListBoxItem CreateDirItem ( string path , bool canAccess = false )
780
829
{
781
830
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
+ } ;
784
835
stack . Children . Add ( new TextBlock
785
836
{
786
837
Text = path
@@ -809,22 +860,6 @@ private ListBoxItem CreateDirItem(string path, bool canAccess = false)
809
860
return item ;
810
861
}
811
862
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
-
828
863
private void Language_Translate ( )
829
864
{
830
865
Title = Translate ( "Configs" ) ;
@@ -869,27 +904,6 @@ private void EvaluateRTL()
869
904
C_OptimizationLevel . FlowDirection = FlowDirection . LeftToRight ;
870
905
C_VerboseLevel . FlowDirection = FlowDirection . LeftToRight ;
871
906
}
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
894
908
}
895
909
}
0 commit comments