11using System ;
2- using System . Collections . Generic ;
32using System . Drawing ;
43using System . IO ;
54using System . Linq ;
65using System . Reflection ;
76using System . Windows . Forms ;
8- using RT . Util ;
7+ using RT . Util . CommandLine ;
98using RT . Util . Controls ;
109using RT . Util . Dialogs ;
1110using RT . Util . ExtensionMethods ;
@@ -17,12 +16,34 @@ partial class Mainform : ManagedForm, IIde
1716 {
1817 private bool _splitterDistanceBugWorkaround ;
1918
20- public Mainform ( EsotericIDE . Settings settings )
19+ public Mainform ( EsotericIDE . Settings settings , string [ ] cmdArgs )
2120 : base ( settings . FormSettings )
2221 {
2322 InitializeComponent ( ) ;
2423 Icon = Resources . EsotericIDEIcon ;
2524 init ( ) ;
25+
26+ try
27+ {
28+ var cmd = CommandLineParser . Parse < CommandLine > ( cmdArgs ) ;
29+
30+ if ( cmd . Filename != null )
31+ openCore ( cmd . Filename ) ;
32+
33+ if ( cmd . Filename != null && cmd . LanguagePreselect == null )
34+ {
35+ // Try to guess language from file extension
36+ var ext = Path . GetExtension ( cmd . Filename ) . Substring ( 1 ) ;
37+ cmd . LanguagePreselect = Languages . FirstOrDefault ( pl => pl . DefaultFileExtension . Equals ( ext , StringComparison . InvariantCultureIgnoreCase ) ) ;
38+ }
39+
40+ if ( cmd . LanguagePreselect != null )
41+ cmbLanguage . SelectedItem = cmd . LanguagePreselect ;
42+ }
43+ catch ( CommandLineParseException px )
44+ {
45+ txtSource . Text = px . GetUsageInfo ( ) . ToString ( ) ;
46+ }
2647 }
2748
2849 private void init ( )
@@ -48,16 +69,16 @@ private void init()
4869 ctSplit . SplitterDistance = ( int ) ( ctSplit . Height * EsotericIDEProgram . Settings . SplitterPercent ) ;
4970 } ;
5071
51- _languages = Assembly . GetExecutingAssembly ( ) . GetTypes ( )
72+ Languages = Assembly . GetExecutingAssembly ( ) . GetTypes ( )
5273 . Where ( t => typeof ( ProgrammingLanguage ) . IsAssignableFrom ( t ) && ! t . IsAbstract )
5374 . Select ( t => ( ProgrammingLanguage ) Activator . CreateInstance ( t ) )
5475 . OrderBy ( t => t . LanguageName )
5576 . ToArray ( ) ;
5677 LanguageSettings settings ;
57- foreach ( var lang in _languages )
78+ foreach ( var lang in Languages )
5879 if ( EsotericIDEProgram . Settings . LanguageSettings . TryGetValue ( lang . LanguageName , out settings ) && settings != null )
5980 lang . Settings = settings ;
60- cmbLanguage . Items . AddRange ( _languages ) ;
81+ cmbLanguage . Items . AddRange ( Languages ) ;
6182
6283 ToolStripMenuItem [ ] currentLanguageSpecificMenus = null ;
6384 cmbLanguage . SelectedIndexChanged += ( _ , __ ) =>
@@ -72,11 +93,11 @@ private void init()
7293 currentLanguageSpecificMenus = _currentLanguage . CreateMenus ( this ) ;
7394 ctMenu . Items . AddRange ( currentLanguageSpecificMenus ) ;
7495 } ;
75- var ll = _languages . IndexOf ( lang => lang . LanguageName == EsotericIDEProgram . Settings . LastLanguageName ) ;
96+ var ll = Languages . IndexOf ( lang => lang . LanguageName == EsotericIDEProgram . Settings . LastLanguageName ) ;
7697 cmbLanguage . SelectedIndex = ll == - 1 ? 0 : ll ;
7798 }
7899
79- private ProgrammingLanguage [ ] _languages ;
100+ public static ProgrammingLanguage [ ] Languages ;
80101 private ProgrammingLanguage _currentLanguage ;
81102
82103 private string _input
@@ -255,7 +276,7 @@ private void open(object _, EventArgs __)
255276 if ( ! canDestroy ( ) )
256277 return ;
257278
258- var filter = _languages
279+ var filter = Languages
259280 . OrderByDescending ( lang => lang == _currentLanguage )
260281 . ThenBy ( lang => lang . LanguageName )
261282 . Select ( lang => "{1} (*.{0})|*.{0}" . Fmt ( lang . DefaultFileExtension , lang . LanguageName ) )
0 commit comments