11using System . Diagnostics ;
2- using SourcepawnCondenser ;
3- using SourcepawnCondenser . SourcemodDefinition ;
2+ using System . IO ;
43using System . Threading ;
54using System . Timers ;
6- using System . IO ;
5+ using SourcepawnCondenser ;
6+ using SourcepawnCondenser . SourcemodDefinition ;
77using Spedit . UI . Components ;
8+ using Timer = System . Timers . Timer ;
89
910namespace Spedit . UI
1011{
11- public partial class MainWindow
12- {
13- private ulong currentSMDefUID ;
14- Thread backgroundParserThread ;
15- SMDefinition currentSMDef ;
16- System . Timers . Timer parseDistributorTimer ;
12+ public partial class MainWindow
13+ {
14+ private Thread backgroundParserThread ;
15+ private ACNode [ ] currentACNodes ;
16+ private ISNode [ ] currentISNodes ;
17+ private SMDefinition currentSMDef ;
18+ private ulong currentSMDefUID ;
19+
20+ private SMFunction [ ] currentSMFunctions ;
21+ private Timer parseDistributorTimer ;
22+
23+ private void StartBackgroundParserThread ( )
24+ {
25+ backgroundParserThread = new Thread ( BackgroundParser_Worker ) ;
26+ backgroundParserThread . Start ( ) ;
27+ parseDistributorTimer = new Timer ( 500.0 ) ;
28+ parseDistributorTimer . Elapsed += ParseDistributorTimer_Elapsed ;
29+ parseDistributorTimer . Start ( ) ;
30+ }
31+
32+ private void ParseDistributorTimer_Elapsed ( object sender , ElapsedEventArgs args )
33+ {
34+ if ( currentSMDefUID == 0 ) return ;
35+
36+ EditorElement [ ] ee = null ;
37+ EditorElement ce = null ;
38+ Dispatcher ? . Invoke ( ( ) =>
39+ {
40+ ee = GetAllEditorElements ( ) ;
41+ ce = GetCurrentEditorElement ( ) ;
42+ } ) ;
43+ if ( ee == null || ce == null ) return ;
1744
18- private void StartBackgroundParserThread ( )
19- {
20- backgroundParserThread = new Thread ( BackgroundParser_Worker ) ;
21- backgroundParserThread . Start ( ) ;
22- parseDistributorTimer = new System . Timers . Timer ( 500.0 ) ;
23- parseDistributorTimer . Elapsed += ParseDistributorTimer_Elapsed ;
24- parseDistributorTimer . Start ( ) ;
25- }
45+ Debug . Assert ( ee != null , nameof ( ee ) + " != null" ) ;
46+ foreach ( var e in ee )
47+ if ( e . LastSMDefUpdateUID < currentSMDefUID ) //wants an update of the SMDefinition
48+ {
49+ if ( e == ce )
50+ {
51+ Debug . Assert ( ce != null , nameof ( ce ) + " != null" ) ;
52+ if ( ce . ISAC_Open ) continue ;
53+ }
2654
27- private void ParseDistributorTimer_Elapsed ( object sender , ElapsedEventArgs args )
28- {
29- if ( currentSMDefUID == 0 ) { return ; }
30- EditorElement [ ] ee = null ;
31- EditorElement ce = null ;
32- Dispatcher ? . Invoke ( ( ) =>
33- {
34- ee = GetAllEditorElements ( ) ;
35- ce = GetCurrentEditorElement ( ) ;
36- } ) ;
37- if ( ee == null || ce == null ) { return ; } //this can happen!
55+ e . InterruptLoadAutoCompletes ( currentSMDef . FunctionStrings , currentSMFunctions , currentACNodes ,
56+ currentISNodes ) ;
57+ e . LastSMDefUpdateUID = currentSMDefUID ;
58+ }
59+ }
3860
39- Debug . Assert ( ee != null , nameof ( ee ) + " != null" ) ;
40- foreach ( var e in ee )
41- {
42- if ( e . LastSMDefUpdateUID < currentSMDefUID ) //wants an update of the SMDefinition
43- {
44- if ( e == ce )
45- {
46- Debug . Assert ( ce != null , nameof ( ce ) + " != null" ) ;
47- if ( ce . ISAC_Open )
48- {
49- continue ;
50- }
51- }
52- e . InterruptLoadAutoCompletes ( currentSMDef . FunctionStrings , currentSMFunctions , currentACNodes , currentISNodes ) ;
53- e . LastSMDefUpdateUID = currentSMDefUID ;
54- }
55- }
56- }
61+ private void BackgroundParser_Worker ( )
62+ {
63+ while ( true )
64+ while ( Program . OptionsObject . Program_DynamicISAC )
65+ {
66+ Thread . Sleep ( 5000 ) ;
67+ var ee = GetAllEditorElements ( ) ;
68+ if ( ee != null )
69+ {
70+ var definitions = new SMDefinition [ ee . Length ] ;
71+ for ( var i = 0 ; i < ee . Length ; ++ i )
72+ {
73+ var fInfo = new FileInfo ( ee [ i ] . FullFilePath ) ;
74+ if ( fInfo . Extension . Trim ( '.' ) . ToLowerInvariant ( ) == "inc" )
75+ definitions [ i ] =
76+ new Condenser ( File . ReadAllText ( fInfo . FullName ) , fInfo . Name ) . Condense ( ) ;
5777
58- private SMFunction [ ] currentSMFunctions ;
59- private ACNode [ ] currentACNodes ;
60- private ISNode [ ] currentISNodes ;
78+ if ( fInfo . Extension . Trim ( '.' ) . ToLowerInvariant ( ) == "sp" )
79+ {
80+ var i1 = i ;
81+ Dispatcher . Invoke ( ( ) =>
82+ {
83+ if ( ee [ i1 ] . IsLoaded )
84+ definitions [ i1 ] =
85+ new Condenser ( File . ReadAllText ( fInfo . FullName ) , fInfo . Name )
86+ . Condense ( ) ;
87+ } ) ;
88+ }
89+ }
6190
62- private void BackgroundParser_Worker ( )
63- {
64- while ( true )
65- {
66- while ( Program . OptionsObject . Program_DynamicISAC )
67- {
68- Thread . Sleep ( 5000 ) ;
69- var ee = GetAllEditorElements ( ) ;
70- if ( ee != null )
71- {
72- SMDefinition [ ] definitions = new SMDefinition [ ee . Length ] ;
73- for ( int i = 0 ; i < ee . Length ; ++ i )
74- {
75- FileInfo fInfo = new FileInfo ( ee [ i ] . FullFilePath ) ;
76- if ( fInfo . Extension . Trim ( '.' ) . ToLowerInvariant ( ) == "inc" )
77- {
78- definitions [ i ] = ( new Condenser ( File . ReadAllText ( fInfo . FullName ) , fInfo . Name ) . Condense ( ) ) ;
79- }
91+ currentSMDef = Program . Configs [ Program . SelectedConfig ] . GetSMDef ( )
92+ . ProduceTemporaryExpandedDefinition ( definitions ) ;
93+ currentSMFunctions = currentSMDef . Functions . ToArray ( ) ;
94+ currentACNodes = currentSMDef . ProduceACNodes ( ) ;
95+ currentISNodes = currentSMDef . ProduceISNodes ( ) ;
96+ ++ currentSMDefUID ;
97+ }
98+ }
8099
81- if ( fInfo . Extension . Trim ( '.' ) . ToLowerInvariant ( ) == "sp" )
82- {
83- definitions [ i ] = ( new Condenser ( File . ReadAllText ( fInfo . FullName ) , fInfo . Name , true ) . Condense ( ) ) ;
84- }
85- }
86- currentSMDef = Program . Configs [ Program . SelectedConfig ] . GetSMDef ( ) . ProduceTemporaryExpandedDefinition ( definitions ) ;
87- currentSMFunctions = currentSMDef . Functions . ToArray ( ) ;
88- currentACNodes = currentSMDef . ProduceACNodes ( ) ;
89- currentISNodes = currentSMDef . ProduceISNodes ( ) ;
90- ++ currentSMDefUID ;
91- }
92- }
93- Thread . Sleep ( 5000 ) ;
94- }
95- // ReSharper disable once FunctionNeverReturns
96- }
97- }
98- }
100+ // ReSharper disable once FunctionNeverReturns
101+ }
102+ }
103+ }
0 commit comments