1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-26 03:02:15 -05:00

Merge branch 'master' of ssh://villavu.com:54367/simba

This commit is contained in:
Raymond 2010-05-19 16:01:36 +02:00
commit ca34d1011c
3 changed files with 122 additions and 90 deletions

View File

@ -88,13 +88,13 @@ type
{ public declarations } { public declarations }
end; end;
function WordAtCaret(e: TSynEdit; var sp, ep: Integer; Start: Integer = -1): string; function WordAtCaret(e: TSynEdit; var sp, ep: Integer; Start: Integer = -1; Offset: Integer = 0): string;
implementation implementation
uses uses
SimbaUnit, SynEditTypes, LCLIntF, StrUtils,framefunctionlist; SimbaUnit, MufasaTypes, SynEditTypes, LCLIntF, StrUtils,framefunctionlist;
function WordAtCaret(e: TSynEdit; var sp, ep: Integer; Start: Integer = -1): string; function WordAtCaret(e: TSynEdit; var sp, ep: Integer; Start: Integer = -1; Offset: Integer = 0): string;
var var
s: string; s: string;
l: Integer; l: Integer;
@ -102,6 +102,7 @@ begin
Result := ''; Result := '';
if (Start = -1) then if (Start = -1) then
Start := e.CaretX; Start := e.CaretX;
Start := Start + Offset;
sp := Start - 1; sp := Start - 1;
ep := Start - 1; ep := Start - 1;
s := e.Lines[e.CaretY - 1]; s := e.Lines[e.CaretY - 1];
@ -222,11 +223,17 @@ var
s: string; s: string;
sp, ep: Integer; sp, ep: Integer;
begin begin
if (Command = ecChar) and (AChar = '(') and (SimbaForm.ParamHint.Visible = false) and (SimbaForm.ShowHintAuto) then if (Command = ecChar) then
begin if(AChar = '(') and (SimbaForm.ParamHint.Visible = False) and (SimbaForm.ShowParamHintAuto) then
Command2:= ecCodeHints; begin
SynEditProcessUserCommand(sender,command2,achar,nil); Command2:= ecCodeHints;
end; SynEditProcessUserCommand(sender,command2,achar,nil);
end
else if(AChar = '.') and (SimbaForm.CodeCompletionForm.Visible = False) and (SimbaForm.ShowCodeCompletionAuto) then
begin
Command2:= ecCodeCompletion;
SynEditProcessUserCommand(sender,command2,achar, Pointer(@s));
end;
if SimbaForm.CodeCompletionForm.Visible then if SimbaForm.CodeCompletionForm.Visible then
case Command of case Command of
@ -328,43 +335,6 @@ begin
if (Command = ecCodeCompletion) and ((not SynEdit.GetHighlighterAttriAtRowCol(SynEdit.CaretXY, s, Attri)) or if (Command = ecCodeCompletion) and ((not SynEdit.GetHighlighterAttriAtRowCol(SynEdit.CaretXY, s, Attri)) or
((Attri.Name <> SYNS_AttrComment) and (Attri.name <> SYNS_AttrString) and (Attri.name <> SYNS_AttrDirective))) then ((Attri.Name <> SYNS_AttrComment) and (Attri.name <> SYNS_AttrString) and (Attri.name <> SYNS_AttrDirective))) then
begin begin
{SimbaForm.FunctionListShown(True);
with SimbaForm.frmFunctionList do
if editSearchList.CanFocus then
begin;
editSearchList.SetFocus;
LineText := SynEdit.LineText;
Caret:=SynEdit.LogicalCaretXY;
i := Caret.X - 1;
endi := caret.x;
if (i > length(LineText)) or ((i = 0) and (length(lineText) = 0)) then
begin
SearchText:= '';
CompletionLine := PadRight(linetext,caret.x);
end
else begin
while (i > 0) and (LineText[i] in ['a'..'z','A'..'Z','0'..'9','_']) do
dec(i);
while LineText[endi] in ['a'..'z','A'..'Z','0'..'9','_'] do
inc(endi);
SearchText := Trim(copy(LineText, i + 1, Caret.X - i - 1));
CompletionLine := LineText;
end;
CompletionStart:= LineText;
Delete(CompletionLine,i+1,endi - i - 1);
Insert('%s',CompletionLine,i+1);
CompletionCaret := Point(endi,Caret.y);
StartWordCompletion:= Point(i+1,caret.y);
mDebugLn(CompletionLine);
mDebugLn(CompletionStart);
InCodeCompletion := true;
editSearchList.Text:= SearchText;
editSearchList.SelStart:= Length(searchText);
SynEdit.SelectedColor.Style:= [fsUnderline];
SynEdit.SelectedColor.Foreground:= clBlack;
SynEdit.SelectedColor.Background:= clWhite;
Synedit.MarkupByClass[TSynEditMarkupHighlightAllCaret].TempDisable;
end;}
mp := TCodeInsight.Create; mp := TCodeInsight.Create;
mp.FileName := ScriptFile; mp.FileName := ScriptFile;
mp.OnMessage := @SimbaForm.OnCCMessage; mp.OnMessage := @SimbaForm.OnCCMessage;
@ -399,10 +369,17 @@ begin
s := ''; s := '';
end; end;
mp.FillSynCompletionProposal(ItemList, InsertList, s); if (Data <> nil) then //If showing automatically
p := SynEdit.ClientToScreen(SynEdit.RowColumnToPixels(Point(ep, SynEdit.CaretY))); if (s <> '') and (((mp.DeclarationAtPos <> nil) and (mp.DeclarationAtPos is TciCompoundStatement)) or ((mp.DeclarationAtPos.Owner <> nil) and (mp.DeclarationAtPos.Owner is TciCompoundStatement))) then
p.y := p.y + SynEdit.LineHeight; Data := nil;
SimbaForm.CodeCompletionForm.Show(p, ItemList, InsertList, Filter, SynEdit);
if (Data = nil) then
begin
mp.FillSynCompletionProposal(ItemList, InsertList, s);
p := SynEdit.ClientToScreen(SynEdit.RowColumnToPixels(Point(ep, SynEdit.CaretY)));
p.y := p.y + SynEdit.LineHeight;
SimbaForm.CodeCompletionForm.Show(p, ItemList, InsertList, Filter, SynEdit);
end;
finally finally
FreeAndNil(ms); FreeAndNil(ms);
FreeAndNil(mp); FreeAndNil(mp);
@ -425,9 +402,9 @@ begin
Synedit.GetWordBoundsAtRowCol(Synedit.CaretXY, sp, ep); Synedit.GetWordBoundsAtRowCol(Synedit.CaretXY, sp, ep);
s := SynEdit.Lines[SynEdit.Carety-1]; s := SynEdit.Lines[SynEdit.Carety-1];
if ep > length(s) then //We are outside the real text, go back to the last char if ep > length(s) then //We are outside the real text, go back to the last char
mp.Run(ms, nil, Synedit.SelStart - ep + length(s),true) mp.Run(ms, nil, Synedit.SelStart - ep + length(s), True)
else else
mp.Run(ms, nil, Synedit.SelStart + (ep - Synedit.CaretX) - 1,true); mp.Run(ms, nil, Synedit.SelStart + (ep - Synedit.CaretX) - 1, True);
bcc := 1;bck := 0;cc := 0; bcc := 1;bck := 0;cc := 0;
s := mp.GetExpressionAtPos(bcc, bck, cc,posi, true); s := mp.GetExpressionAtPos(bcc, bck, cc,posi, true);
@ -463,7 +440,7 @@ begin
d := d.Owner; d := d.Owner;
if (TciProcedureDeclaration(d).Params <> '') then if (TciProcedureDeclaration(d).Params <> '') then
SimbaForm.ParamHint.Show(PosToCaretXY(synedit,posi + 1), PosToCaretXY(synedit,bracketpos), SimbaForm.ParamHint.Show(PosToCaretXY(synedit,posi + 1), PosToCaretXY(synedit,bracketpos),
TciProcedureDeclaration(d), synedit,mp) TciProcedureDeclaration(d), synedit,mp)
else else
FormWriteln('<no parameters expected>'); FormWriteln('<no parameters expected>');
end; end;
@ -544,8 +521,6 @@ begin
end; end;
procedure TScriptFrame.HandleErrorData; procedure TScriptFrame.HandleErrorData;
var
i : integer;
begin begin
if ErrorData.Module <> '' then if ErrorData.Module <> '' then
begin; begin;
@ -610,6 +585,9 @@ begin
inherited Create(TheOwner); inherited Create(TheOwner);
OwnerSheet := TTabSheet(TheOwner); OwnerSheet := TTabSheet(TheOwner);
OwnerPage := TPageControl(OwnerSheet.Owner); OwnerPage := TPageControl(OwnerSheet.Owner);
if FileExists(MainDir + DS + 'default.simba') then
SynEdit.Lines.LoadFromFile(MainDir + DS + 'default.simba');
StartText:= SynEdit.Lines.text; StartText:= SynEdit.Lines.text;
ScriptDefault:= StartText; ScriptDefault:= StartText;
ScriptName:= 'Untitled'; ScriptName:= 'Untitled';

View File

@ -592,6 +592,10 @@ object SimbaForm: TSimbaForm
Caption = 'Save as...' Caption = 'Save as...'
OnClick = ActionSaveAsExecute OnClick = ActionSaveAsExecute
end end
object MenuItemSaveDef: TMenuItem
Action = ActionSaveDef
OnClick = ActionSaveDefExecute
end
object MenuItemSaveAll: TMenuItem object MenuItemSaveAll: TMenuItem
Action = ActionSaveAll Action = ActionSaveAll
Enabled = False Enabled = False
@ -2693,6 +2697,16 @@ object SimbaForm: TSimbaForm
Caption = 'Save as..' Caption = 'Save as..'
OnExecute = ActionSaveAsExecute OnExecute = ActionSaveAsExecute
end end
object ActionSaveDef: TAction
Caption = 'Save as Default'
OnExecute = ActionSaveDefExecute
end
object ActionSaveAll: TAction
Caption = 'Save All'
ImageIndex = 21
OnExecute = ActionSaveAllExecute
ShortCut = 24659
end
object ActionRunScript: TAction object ActionRunScript: TAction
Caption = '&Run' Caption = '&Run'
OnExecute = ActionRunExecute OnExecute = ActionRunExecute
@ -2707,12 +2721,6 @@ object SimbaForm: TSimbaForm
OnExecute = ActionStopExecute OnExecute = ActionStopExecute
ShortCut = 113 ShortCut = 113
end end
object ActionSaveAll: TAction
Caption = 'Save All'
ImageIndex = 21
OnExecute = ActionSaveAllExecute
ShortCut = 24659
end
object ActionClearDebug: TAction object ActionClearDebug: TAction
Caption = 'Clear' Caption = 'Clear'
ImageIndex = 4 ImageIndex = 4
@ -3090,7 +3098,24 @@ object SimbaForm: TSimbaForm
left = 488 left = 488
top = 200 top = 200
end end
object LazHighlighter: TSynFreePascalSyn object FunctionListTimer: TTimer
Interval = 750
OnTimer = FunctionListTimerTimer
left = 608
top = 200
end
object SCARHighlighter: TSynPasSyn
Enabled = False
CommentAttri.Foreground = clGreen
CommentAttri.Style = []
NumberAttri.Foreground = clNavy
StringAttri.Foreground = clFuchsia
CompilerMode = pcmObjFPC
NestedComments = False
left = 568
top = 200
end
object LazHighlighter: TSynPasSyn
Enabled = False Enabled = False
CommentAttri.Foreground = clBlue CommentAttri.Foreground = clBlue
CommentAttri.Style = [fsBold] CommentAttri.Style = [fsBold]
@ -3106,21 +3131,4 @@ object SimbaForm: TSimbaForm
left = 528 left = 528
top = 200 top = 200
end end
object SCARHighlighter: TSynFreePascalSyn
Enabled = False
CommentAttri.Foreground = clGreen
CommentAttri.Style = []
NumberAttri.Foreground = clHotLight
StringAttri.Foreground = clFuchsia
CompilerMode = pcmObjFPC
NestedComments = False
left = 568
top = 200
end
object FunctionListTimer: TTimer
Interval = 750
OnTimer = FunctionListTimerTimer
left = 608
top = 200
end
end end

View File

@ -67,6 +67,7 @@ type
{ TSimbaForm } { TSimbaForm }
TSimbaForm = class(TForm) TSimbaForm = class(TForm)
ActionSaveDef: TAction;
ActionConsole: TAction; ActionConsole: TAction;
ActionNormalSize: TAction; ActionNormalSize: TAction;
ActionCompileScript: TAction; ActionCompileScript: TAction;
@ -96,14 +97,15 @@ type
ActionTabNext: TAction; ActionTabNext: TAction;
ActionList: TActionList; ActionList: TActionList;
CheckBoxMatchCase: TCheckBox; CheckBoxMatchCase: TCheckBox;
LazHighlighter: TSynFreePascalSyn;
frmFunctionList: TFunctionListFrame; frmFunctionList: TFunctionListFrame;
LabeledEditSearch: TLabeledEdit; LabeledEditSearch: TLabeledEdit;
LazHighlighter: TSynPasSyn;
MainMenu: TMainMenu; MainMenu: TMainMenu;
Memo1: TMemo; Memo1: TMemo;
MenuFile: TMenuItem; MenuFile: TMenuItem;
MenuEdit: TMenuItem; MenuEdit: TMenuItem;
MenuHelp: TMenuItem; MenuHelp: TMenuItem;
MenuItemSaveDef: TMenuItem;
MenuItemBitmapConv: TMenuItem; MenuItemBitmapConv: TMenuItem;
MenuItemExtensions: TMenuItem; MenuItemExtensions: TMenuItem;
MenuItemSettingsButton: TMenuItem; MenuItemSettingsButton: TMenuItem;
@ -118,8 +120,8 @@ type
MenuItemDivider9: TMenuItem; MenuItemDivider9: TMenuItem;
MouseTimer: TTimer; MouseTimer: TTimer;
NewsTimer: TTimer; NewsTimer: TTimer;
SCARHighlighter: TSynFreePascalSyn;
FunctionListTimer: TTimer; FunctionListTimer: TTimer;
SCARHighlighter: TSynPasSyn;
TT_Console: TToolButton; TT_Console: TToolButton;
TT_Cut: TToolButton; TT_Cut: TToolButton;
TT_Copy: TToolButton; TT_Copy: TToolButton;
@ -240,6 +242,7 @@ type
procedure ActionRunExecute(Sender: TObject); procedure ActionRunExecute(Sender: TObject);
procedure ActionSaveAllExecute(Sender: TObject); procedure ActionSaveAllExecute(Sender: TObject);
procedure ActionSaveAsExecute(Sender: TObject); procedure ActionSaveAsExecute(Sender: TObject);
procedure ActionSaveDefExecute(Sender: TObject);
procedure ActionSaveExecute(Sender: TObject); procedure ActionSaveExecute(Sender: TObject);
procedure ActionSelectAllExecute(Sender: TObject); procedure ActionSelectAllExecute(Sender: TObject);
procedure ActionStopExecute(Sender: TObject); procedure ActionStopExecute(Sender: TObject);
@ -359,14 +362,16 @@ type
function GetIncludePath: String; function GetIncludePath: String;
function GetPluginPath: string; function GetPluginPath: string;
function GetScriptState: TScriptState; function GetScriptState: TScriptState;
function GetShowHintAuto: boolean; function GetShowParamHintAuto: boolean;
function GetShowCodeCompletionAuto: Boolean;
function GetSimbaNews: String; function GetSimbaNews: String;
procedure SetExtPath(const AValue: string); procedure SetExtPath(const AValue: string);
procedure SetFontPath(const AValue: String); procedure SetFontPath(const AValue: String);
procedure SetIncludePath(const AValue: String); procedure SetIncludePath(const AValue: String);
procedure SetPluginPath(const AValue: string); procedure SetPluginPath(const AValue: string);
procedure SetScriptPath(const AValue: string); procedure SetScriptPath(const AValue: string);
procedure SetShowHintAuto(const AValue: boolean); procedure SetShowParamHintAuto(const AValue: boolean);
procedure SetShowCodeCompletionAuto(const AValue: boolean);
procedure SetScriptState(const State: TScriptState); procedure SetScriptState(const State: TScriptState);
function LoadSettingDef(const Key, Def : string) : string; function LoadSettingDef(const Key, Def : string) : string;
function CreateSetting(const Key, Value : string) : string; function CreateSetting(const Key, Value : string) : string;
@ -398,6 +403,7 @@ type
function LoadScriptFile(filename : string; AlwaysOpenInNewTab : boolean = false; CheckOtherTabs : boolean = true) : boolean; function LoadScriptFile(filename : string; AlwaysOpenInNewTab : boolean = false; CheckOtherTabs : boolean = true) : boolean;
function SaveCurrentScript : boolean; function SaveCurrentScript : boolean;
function SaveCurrentScriptAs : boolean; function SaveCurrentScriptAs : boolean;
function SaveCurrentScriptAsDefault : boolean;
function CanExitOrOpen : boolean; function CanExitOrOpen : boolean;
function ClearScript : boolean; function ClearScript : boolean;
procedure RunScript; procedure RunScript;
@ -421,7 +427,8 @@ type
procedure InitalizeTMThread(var Thread : TMThread); procedure InitalizeTMThread(var Thread : TMThread);
procedure HandleParameters; procedure HandleParameters;
procedure OnSaveScript(const Filename : string); procedure OnSaveScript(const Filename : string);
property ShowHintAuto : boolean read GetShowHintAuto write SetShowHintAuto; property ShowParamHintAuto : boolean read GetShowParamHintAuto write SetShowParamHintAuto;
property ShowCodeCompletionAuto: Boolean read GetShowCodeCompletionAuto write SetShowCodeCompletionAuto;
property IncludePath : String read GetIncludePath write SetIncludePath; property IncludePath : String read GetIncludePath write SetIncludePath;
property FontPath : String read GetFontPath write SetFontPath; property FontPath : String read GetFontPath write SetFontPath;
property PluginPath : string read GetPluginPath write SetPluginPath; property PluginPath : string read GetPluginPath write SetPluginPath;
@ -1163,6 +1170,7 @@ begin
CreateSetting('Settings/MainForm/NormalSize','739:555'); CreateSetting('Settings/MainForm/NormalSize','739:555');
CreateSetting('Settings/FunctionList/ShowOnStart','True'); CreateSetting('Settings/FunctionList/ShowOnStart','True');
CreateSetting('Settings/CodeHints/ShowAutomatically','True'); CreateSetting('Settings/CodeHints/ShowAutomatically','True');
CreateSetting('Settings/CodeCompletion/ShowAutomatically','True');
CreateSetting('Settings/SourceEditor/LazColors','True'); CreateSetting('Settings/SourceEditor/LazColors','True');
CreateSetting('Settings/Extensions/FileExtension','sex'); CreateSetting('Settings/Extensions/FileExtension','sex');
@ -1691,6 +1699,11 @@ begin
Self.SaveCurrentScriptAs; Self.SaveCurrentScriptAs;
end; end;
procedure TSimbaForm.ActionSaveDefExecute(Sender: TObject);
begin
Self.SaveCurrentScriptAsDefault;
end;
procedure TSimbaForm.ActionSaveExecute(Sender: TObject); procedure TSimbaForm.ActionSaveExecute(Sender: TObject);
begin begin
Self.SaveCurrentScript; Self.SaveCurrentScript;
@ -2093,7 +2106,6 @@ begin
//AutoCompletionStart := Point(-1, -1); //AutoCompletionStart := Point(-1, -1);
CodeCompletionForm := TAutoCompletePopup.Create(Self); CodeCompletionForm := TAutoCompletePopup.Create(Self);
CodeCompletionForm.InsertProc := @OnCompleteCode; CodeCompletionForm.InsertProc := @OnCompleteCode;
ParamHint := TParamHint.Create(self); ParamHint := TParamHint.Create(self);
{$ifdef MSWindows} {$ifdef MSWindows}
@ -2580,11 +2592,16 @@ begin
result := CurrScript.FScriptState; result := CurrScript.FScriptState;
end; end;
function TSimbaForm.GetShowHintAuto: boolean; function TSimbaForm.GetShowParamHintAuto: boolean;
begin begin
Result := LowerCase(LoadSettingDef('Settings/CodeHints/ShowAutomatically','True')) = 'true'; Result := LowerCase(LoadSettingDef('Settings/CodeHints/ShowAutomatically','True')) = 'true';
end; end;
function TSimbaForm.GetShowCodeCompletionAuto: boolean;
begin
Result := LowerCase(LoadSettingDef('Settings/CodeCompletion/ShowAutomatically','True')) = 'true';
end;
procedure TSimbaForm.SetFontPath(const AValue: String); procedure TSimbaForm.SetFontPath(const AValue: String);
begin begin
SetSetting('Settings/Fonts/Path',AValue,true); SetSetting('Settings/Fonts/Path',AValue,true);
@ -2755,9 +2772,14 @@ begin
TThread.Synchronize(nil,@HandleScriptStartData); TThread.Synchronize(nil,@HandleScriptStartData);
end; end;
procedure TSimbaForm.SetShowHintAuto(const AValue: boolean); procedure TSimbaForm.SetShowParamHintAuto(const AValue: boolean);
begin begin
SetSetting('Settings/CodeHints/ShowAutomatically',Booltostr(AValue,true)); SetSetting('Settings/CodeHints/ShowAutomatically', Booltostr(AValue,true));
end;
procedure TSimbaForm.SetShowCodeCompletionAuto(const AValue: boolean);
begin
SetSetting('Settings/CodeCompletion/ShowAutomatically', Booltostr(AValue,true));
end; end;
{$ifdef mswindows} {$ifdef mswindows}
@ -2844,6 +2866,7 @@ end;
function TSimbaForm.OpenScript: boolean; function TSimbaForm.OpenScript: boolean;
var var
i: Integer;
OpenInNewTab : boolean; OpenInNewTab : boolean;
begin begin
Result := False; Result := False;
@ -2853,11 +2876,19 @@ begin
Exit; Exit;
with TOpenDialog.Create(nil) do with TOpenDialog.Create(nil) do
try try
Filter:= 'Simba Files|*.Simba;*.simb;*.cogat;*.mufa;*.txt;*.' +LoadSettingDef('Settings/Extensions/FileExtension','sex')+ Options := [ofAllowMultiSelect, ofExtensionDifferent, ofPathMustExist, ofFileMustExist, ofEnableSizing, ofViewDetail];
Filter:= 'Simba Files|*.simba;*.simb;*.cogat;*.mufa;*.txt;*.' +LoadSettingDef('Settings/Extensions/FileExtension','sex')+
'|Any files|*.*'; '|Any files|*.*';
if Execute then if Execute then
if FileExistsUTF8(filename) then begin
result := LoadScriptFile(filename); Result := True;
for i := 0 to Files.Count - 1 do
if (not FileExistsUTF8(Files[i])) or (not LoadScriptFile(Files[i])) then
begin
Result := False;
Break;
end;
end;
finally finally
Free; Free;
end; end;
@ -2953,6 +2984,21 @@ begin
end; end;
end; end;
function TSimbaForm.SaveCurrentScriptAsDefault : boolean;
begin
with CurrScript do
begin
try
SynEdit.Lines.SaveToFile(MainDir + DS + 'default.simba');
mDebugLn('Script saved as default.');
Result := True;
except
mDebugLn('Cannot save script as default.');
Result := False;
end;
end;
end;
function TSimbaForm.CanExitOrOpen: boolean; function TSimbaForm.CanExitOrOpen: boolean;
begin; begin;
Self.Enabled := False;//We HAVE to answer the popup Self.Enabled := False;//We HAVE to answer the popup