1212namespace Spedit . UI . Windows
1313{
1414 /// <summary>
15- /// Interaction logic for AboutWindow.xaml
15+ /// Interaction logic for AboutWindow.xaml
1616 /// </summary>
1717 public partial class NewFileWindow
1818 {
19- string PathStr = "sourcepawn\\ scripts" ;
20- Dictionary < string , TemplateInfo > TemplateDictionary ;
19+ // From https://github.com/CrucialCoding/Spedit/commit/d2edde54385bb76eccdf13934ce33a8a7e3cc31e
20+ private readonly string PathStr = Program . Configs [ Program . SelectedConfig ] . SMDirectories [ 0 ] ;
21+ private Dictionary < string , TemplateInfo > TemplateDictionary ;
22+
23+ private ICommand textBoxButtonFileCmd ;
24+
2125 public NewFileWindow ( )
2226 {
2327 InitializeComponent ( ) ;
24- Language_Translate ( ) ;
25- if ( Program . OptionsObject . Program_AccentColor != "Red" || Program . OptionsObject . Program_Theme != "BaseDark" )
26- { ThemeManager . ChangeAppStyle ( this , ThemeManager . GetAccent ( Program . OptionsObject . Program_AccentColor ) , ThemeManager . GetAppTheme ( Program . OptionsObject . Program_Theme ) ) ; }
27- ParseTemplateFile ( ) ;
28+ Language_Translate ( ) ;
29+ if ( Program . OptionsObject . Program_AccentColor != "Red" || Program . OptionsObject . Program_Theme != "BaseDark" )
30+ ThemeManager . ChangeAppStyle ( this , ThemeManager . GetAccent ( Program . OptionsObject . Program_AccentColor ) ,
31+ ThemeManager . GetAppTheme ( Program . OptionsObject . Program_Theme ) ) ;
32+ ParseTemplateFile ( ) ;
2833 TemplateListBox . SelectedIndex = 0 ;
2934 }
3035
36+ public ICommand TextBoxButtonFileCmd
37+ {
38+ set { }
39+ get
40+ {
41+ if ( textBoxButtonFileCmd == null )
42+ {
43+ var cmd = new SimpleCommand
44+ {
45+ CanExecutePredicate = o => true ,
46+ ExecuteAction = o =>
47+ {
48+ if ( o is TextBox box )
49+ {
50+ var dialog = new SaveFileDialog
51+ {
52+ AddExtension = true ,
53+ Filter = "Sourcepawn Files (*.sp *.inc)|*.sp;*.inc|All Files (*.*)|*.*" ,
54+ OverwritePrompt = true ,
55+ Title = Program . Translations . GetLanguage ( "NewFile" )
56+ } ;
57+ var result = dialog . ShowDialog ( ) ;
58+
59+ Debug . Assert ( result != null , nameof ( result ) + " != null" ) ;
60+ if ( result . Value ) box . Text = dialog . FileName ;
61+ }
62+ }
63+ } ;
64+ textBoxButtonFileCmd = cmd ;
65+ return cmd ;
66+ }
67+
68+ return textBoxButtonFileCmd ;
69+ }
70+ }
71+
3172 private void ParseTemplateFile ( )
3273 {
3374 TemplateDictionary = new Dictionary < string , TemplateInfo > ( ) ;
3475 if ( File . Exists ( "sourcepawn\\ templates\\ Templates.xml" ) )
35- {
3676 using ( Stream stream = File . OpenRead ( "sourcepawn\\ templates\\ Templates.xml" ) )
3777 {
38- XmlDocument doc = new XmlDocument ( ) ;
78+ var doc = new XmlDocument ( ) ;
3979 doc . Load ( stream ) ;
4080 if ( doc . ChildNodes . Count <= 0 ) return ;
4181 if ( doc . ChildNodes [ 0 ] . Name != "Templates" ) return ;
42-
43- XmlNode mainNode = doc . ChildNodes [ 0 ] ;
44- for ( int i = 0 ; i < mainNode . ChildNodes . Count ; ++ i )
45- {
82+
83+ var mainNode = doc . ChildNodes [ 0 ] ;
84+ for ( var i = 0 ; i < mainNode . ChildNodes . Count ; ++ i )
4685 if ( mainNode . ChildNodes [ i ] . Name == "Template" )
4786 {
48- XmlAttributeCollection attributes = mainNode . ChildNodes [ i ] . Attributes ;
49- string NameStr = attributes ? [ "Name" ] . Value ;
50- string FileNameStr = attributes ? [ "File" ] . Value ;
51- string NewNameStr = attributes ? [ "NewName" ] . Value ;
52-
87+ var attributes = mainNode . ChildNodes [ i ] . Attributes ;
88+ var NameStr = attributes ? [ "Name" ] . Value ;
89+ var FileNameStr = attributes ? [ "File" ] . Value ;
90+ var NewNameStr = attributes ? [ "NewName" ] . Value ;
91+
5392 Debug . Assert ( FileNameStr != null , nameof ( FileNameStr ) + " != null" ) ;
54- string FilePathStr = Path . Combine ( "sourcepawn\\ templates\\ " , FileNameStr ) ;
93+ var FilePathStr = Path . Combine ( "sourcepawn\\ templates\\ " , FileNameStr ) ;
5594 if ( File . Exists ( FilePathStr ) )
5695 {
5796 Debug . Assert ( NameStr != null , nameof ( NameStr ) + " != null" ) ;
58- TemplateDictionary . Add ( NameStr , new TemplateInfo { Name = NameStr , FileName = FileNameStr , Path = FilePathStr , NewName = NewNameStr } ) ;
97+ TemplateDictionary . Add ( NameStr ,
98+ new TemplateInfo
99+ {
100+ Name = NameStr , FileName = FileNameStr , Path = FilePathStr , NewName = NewNameStr
101+ } ) ;
59102 TemplateListBox . Items . Add ( NameStr ) ;
60103 }
61104 }
62- }
63105 }
64- }
65106 }
66107
67108 private void TemplateListBox_SelectionChanged ( object sender , SelectionChangedEventArgs e )
68109 {
69- TemplateInfo templateInfo = TemplateDictionary [ ( string ) TemplateListBox . SelectedItem ] ;
110+ var templateInfo = TemplateDictionary [ ( string ) TemplateListBox . SelectedItem ] ;
70111 PrevieBox . Text = File . ReadAllText ( templateInfo . Path ) ;
71112 PathBox . Text = Path . Combine ( PathStr , templateInfo . NewName ) ;
72113 }
73114
74115 private void Button_Click ( object sender , RoutedEventArgs e )
75116 {
76- FileInfo destFile = new FileInfo ( PathBox . Text ) ;
77- TemplateInfo templateInfo = TemplateDictionary [ ( string ) TemplateListBox . SelectedItem ] ;
117+ var destFile = new FileInfo ( PathBox . Text ) ;
118+ var templateInfo = TemplateDictionary [ ( string ) TemplateListBox . SelectedItem ] ;
78119 File . Copy ( templateInfo . Path , destFile . FullName , true ) ;
79120 Program . MainWindow . TryLoadSourceFile ( destFile . FullName , true , true , true ) ;
80121 Close ( ) ;
81122 }
82123
83- private void Language_Translate ( )
84- {
85- if ( Program . Translations . IsDefault )
86- {
87- return ;
88- }
89- PreviewBlock . Text = $ "{ Program . Translations . GetLanguage ( "Preview" ) } :";
90- SaveButton . Content = Program . Translations . GetLanguage ( "Save" ) ;
91- }
92-
93- private ICommand textBoxButtonFileCmd ;
94-
95- public ICommand TextBoxButtonFileCmd
124+ private void Language_Translate ( )
96125 {
97- set { }
98- get
99- {
100- if ( textBoxButtonFileCmd == null )
101- {
102- var cmd = new SimpleCommand
103- {
104- CanExecutePredicate = o => true ,
105- ExecuteAction = o =>
106- {
107- if ( o is TextBox box )
108- {
109- var dialog = new SaveFileDialog
110- {
111- AddExtension = true ,
112- Filter = "Sourcepawn Files (*.sp *.inc)|*.sp;*.inc|All Files (*.*)|*.*" ,
113- OverwritePrompt = true ,
114- Title = Program . Translations . GetLanguage ( "NewFile" )
115- } ;
116- var result = dialog . ShowDialog ( ) ;
117-
118- Debug . Assert ( result != null , nameof ( result ) + " != null" ) ;
119- if ( result . Value )
120- {
121- box . Text = dialog . FileName ;
122- }
123- }
124- }
125- } ;
126- textBoxButtonFileCmd = cmd ;
127- return cmd ;
128- }
129-
130- return textBoxButtonFileCmd ;
131- }
126+ if ( Program . Translations . IsDefault ) return ;
127+ PreviewBlock . Text = $ "{ Program . Translations . GetLanguage ( "Preview" ) } :";
128+ SaveButton . Content = Program . Translations . GetLanguage ( "Save" ) ;
132129 }
133130
134131 private class SimpleCommand : ICommand
@@ -156,9 +153,9 @@ public void Execute(object parameter)
156153
157154 public class TemplateInfo
158155 {
159- public string Name ;
160156 public string FileName ;
161- public string Path ;
157+ public string Name ;
162158 public string NewName ;
159+ public string Path ;
163160 }
164- }
161+ }
0 commit comments