1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-12-24 00:08:52 -05:00

First code for Simba with only one script thread.

This commit is contained in:
Merlijn Wajer 2010-07-22 23:32:32 +02:00
parent 88604e8845
commit f38da4bc8c
3 changed files with 41 additions and 28 deletions

View File

@ -78,13 +78,12 @@ type
ScriptName : string;//The name of the currently opened/saved file.
ScriptDefault : string;//The default script e.g. program new; begin end.
ScriptChanged : boolean;//We need this for that little * (edited star).
ScriptThread : TMThread;//Just one thread for now..
FScriptState : TScriptState;//Stores the ScriptState, if you want the Run/Pause/Start buttons to change accordingly, acces through Form1
// ScriptThread : TMThread;//Just one thread for now..
// FScriptState : TScriptState;//Stores the ScriptState, if you want the Run/Pause/Start buttons to change accordingly, acces through Form1
procedure undo;
procedure redo;
procedure HandleErrorData;
procedure MakeActiveScriptFrame;
procedure ScriptThreadTerminate(Sender: TObject);
constructor Create(TheOwner: TComponent); override;
{ public declarations }
end;
@ -582,11 +581,6 @@ begin
end;
end;
procedure TScriptFrame.ScriptThreadTerminate(Sender: TObject);
begin
FScriptState:= ss_None;
SimbaForm.RefreshTab;
end;
procedure AddKey(const SynEdit : TSynEdit; const ACmd: TSynEditorCommand; const AKey: word;const AShift: TShiftState);
begin
with SynEdit.KeyStrokes.Add do
@ -612,7 +606,7 @@ begin
ScriptDefault:= StartText;
ScriptName:= 'Untitled';
ScriptChanged := false;
FScriptState:= ss_None;
ScriptErrorLine:= -1;
OwnerSheet.Caption:= ScriptName;
SynEdit.Highlighter := SimbaForm.CurrHighlighter;

View File

@ -396,6 +396,7 @@ type
Picker: TMColorPicker;
Selector: TMWindowSelector;
OnScriptStart : TScriptStartEvent;
FScriptState: TScriptState;
{$ifdef mswindows}
ConsoleVisible : boolean;
procedure ShowConsole( ShowIt : boolean);
@ -410,6 +411,7 @@ type
function SaveCurrentScriptAsDefault : boolean;
function CanExitOrOpen : boolean;
function ClearScript : boolean;
procedure ScriptThreadTerminate(Sender: TObject);
procedure RunScript;
procedure PauseScript;
procedure StopScript;
@ -852,13 +854,24 @@ end;
//{$ENDIF}
procedure TSimbaForm.ScriptThreadTerminate(Sender: TObject);
begin
mDebugLn('Thread terminated');
ScriptState := ss_None;
CurrThread := nil;
end;
procedure TSimbaForm.RunScript;
begin
if CurrThread <> nil then
exit;
with CurrScript do
begin
if ScriptState = ss_Paused then
begin;
ScriptThread.Resume;
CurrThread.Resume;
// ScriptThread.Resume;
ScriptState := ss_Running;
Exit;
end else
@ -867,13 +880,13 @@ begin
FormWritelnEx('The script hasn''t stopped yet, so we cannot start a new one.');
exit;
end;
InitalizeTMThread(scriptthread);
ScriptThread.CompileOnly:= false;
ScriptThread.OnTerminate:=@ScriptThreadTerminate;
InitalizeTMThread(CurrThread);
CurrThread.CompileOnly:= false;
CurrThread.OnTerminate:=@ScriptThreadTerminate;
ScriptState:= ss_Running;
FirstRun := false;
//Lets run it!
ScriptThread.Resume;
CurrThread.Resume;
end;
end;
@ -884,14 +897,14 @@ begin
if ScriptState = ss_Running then
begin;
{$ifdef MSWindows}
ScriptThread.Suspended:= True;
CurrThread.Suspended:= True;
ScriptState:= ss_Paused;
{$else}
mDebugLn('Linux users are screwed, no pause button for u!');
{$endif}
end else if ScriptState = ss_Paused then
begin;
ScriptThread.Resume;
CurrThread.Resume;
ScriptState := ss_Running;
end;
end;
@ -905,20 +918,20 @@ begin
ss_Stopping:
begin //Terminate the thread the tough way.
mDebugLn('Terminating the Scriptthread');
mDebugLn('Exit code terminate: ' +inttostr(KillThread(ScriptThread.Handle)));
WaitForThreadTerminate(ScriptThread.Handle, 0);
ScriptThread.Free;
mDebugLn('Exit code terminate: ' +inttostr(KillThread(CurrThread.Handle)));
WaitForThreadTerminate(CurrThread.Handle, 0);
CurrThread.Free;
ScriptState := ss_None;
end;
ss_Running:
begin
ScriptThread.Terminate;
CurrThread.Terminate;
ScriptState := ss_Stopping;
end;
ss_Paused:
begin
ScriptThread.Resume;
ScriptThread.Terminate;
CurrThread.Resume;
CurrThread.Terminate;
ScriptState:= ss_Stopping;
end;
end;
@ -1136,7 +1149,11 @@ begin
end;
StatusBar.Panels[Panel_ScriptName].Text:= Script.ScriptName;
StatusBar.Panels[Panel_ScriptPath].text:= Script.ScriptFile;
SetScriptState(Tab.ScriptFrame.FScriptState);//To set the buttons right
{ XXX: No longer update buttons }
// SetScriptState(Tab.ScriptFrame.FScriptState);//To set the buttons right
if Self.Showing then
if Tab.TabSheet.TabIndex = Self.PageControl1.TabIndex then
if CurrScript.SynEdit.CanFocus then
@ -2622,7 +2639,7 @@ end;
function TSimbaForm.GetScriptState: TScriptState;
begin
result := CurrScript.FScriptState;
result := FScriptState;
end;
function TSimbaForm.GetShowParamHintAuto: boolean;
@ -2685,7 +2702,7 @@ end;
procedure TSimbaForm.SetScriptState(const State: TScriptState);
begin
CurrScript.FScriptState:= State;
FScriptState:= State;
with Self.StatusBar.panels[Panel_State] do
case state of
ss_Running : begin Text := 'Running'; TB_Run.Enabled:= False; {$ifdef MSWindows}TB_Pause.Enabled:= True; {$endif}
@ -2878,7 +2895,7 @@ begin
LocalCopy := CurrentSyncInfo;
mDebugLn('Executing : ' + LocalCopy.MethodName);
thread:= TMThread(LocalCopy.OldThread);
mmlpsthread.CurrThread:= thread;
//mmlpsthread.CurrThread:= thread;
try
if thread is TPSThread then
begin
@ -2893,7 +2910,7 @@ begin
raise Exception.Create('ThreadSafeCall not implemented on this client');
end;
finally
mmlpsthread.CurrThread:= nil;
//mmlpsthread.CurrThread:= nil;
end;
end;

View File

@ -188,8 +188,10 @@ type
procedure AddMethod(meth: TExpMethod); override;
end;
threadvar
var
CurrThread : TMThread;
var
PluginsGlob: TMPlugins;