1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-28 20:12:16 -05:00

Ctrl click now works better, goes to new files etc.. Tree is now generated using Niels' parser (has an include tree to, not sure if its too slow). And fixed some other stuff..

This commit is contained in:
Raymond 2010-03-28 22:11:12 +02:00
parent 9235a38b95
commit 7b3b694b09
4 changed files with 131 additions and 52 deletions

View File

@ -49,17 +49,16 @@ type
{ public declarations } { public declarations }
end; end;
TMethodInfo = record TMethodInfo = packed record
MethodStr : PChar; MethodStr,Filename : PChar;
BeginPos : integer; BeginPos,endpos : integer;
// FileName : PChar;
end; end;
PMethodInfo = ^TMethodInfo; PMethodInfo = ^TMethodInfo;
implementation implementation
uses uses
TestUnit, Graphics, stringutil, simpleanalyzer,v_ideCodeInsight,v_ideCodeParser; TestUnit, Graphics, stringutil, simpleanalyzer,v_ideCodeInsight,v_ideCodeParser,lclintf;
{ TFunctionListFrame } { TFunctionListFrame }
@ -112,8 +111,8 @@ begin
MethodInfo := PMethodInfo(Node.data); MethodInfo := PMethodInfo(Node.data);
if MethodInfo^.MethodStr <> nil then if MethodInfo^.MethodStr <> nil then
StrDispose(MethodInfo^.MethodStr); StrDispose(MethodInfo^.MethodStr);
{ if MethodInfo^.FileName <> nil then if MethodInfo^.FileName <> nil then
StrDispose(MethodInfo^.filename);} StrDispose(MethodInfo^.filename);
Freemem(node.data,sizeof(TMethodInfo)); Freemem(node.data,sizeof(TMethodInfo));
end; end;
end; end;
@ -184,7 +183,7 @@ begin
end; end;
procedure TFunctionListFrame.LoadScriptTree(Script: String); procedure TFunctionListFrame.LoadScriptTree(Script: String);
procedure AddProcsTree(Node : TTreeNode; Procs : TDeclarationList; FileName : string); procedure AddProcsTree(Node : TTreeNode; Procs : TDeclarationList; Path : string);
var var
i : integer; i : integer;
tmpNode : TTreeNode; tmpNode : TTreeNode;
@ -193,19 +192,20 @@ begin;
if (Procs[i] is TciProcedureDeclaration) then if (Procs[i] is TciProcedureDeclaration) then
with Procs[i] as TciProcedureDeclaration do with Procs[i] as TciProcedureDeclaration do
begin begin
tmpNode := FunctionList.Items.AddChild(Node,name); tmpNode := FunctionList.Items.AddChild(Node,name.ShortText);
tmpNode.Data := GetMem(SizeOf(TMethodInfo)); tmpNode.Data := GetMem(SizeOf(TMethodInfo));
with PMethodInfo(tmpNode.Data)^ do with PMethodInfo(tmpNode.Data)^ do
begin begin
MethodStr := strnew(Pchar(CleanDeclaration)); MethodStr := strnew(Pchar(CleanDeclaration));
BeginPos:= StartPos; Filename:= strnew(pchar(path));
BeginPos:= name.StartPos ;
EndPos := name.StartPos + Length(TrimRight(name.RawText));
end; end;
end; end;
end; end;
procedure AddIncludes(Include : TCodeInsight); procedure AddIncludes(ParentNode : TTreeNode; Include : TCodeInsight);
var var
parentNode : TTreeNode;
i : integer; i : integer;
begin; begin;
parentNode := FunctionList.Items.AddChild( parentNode := FunctionList.Items.AddChild(
@ -213,19 +213,25 @@ begin;
Include.FileName)); Include.FileName));
AddProcsTree(parentNode,Include.Items,Include.FileName); AddProcsTree(parentNode,Include.Items,Include.FileName);
for i := 0 to high(Include.Includes) do for i := 0 to high(Include.Includes) do
AddIncludes(Include.Includes[i]) AddIncludes(ParentNode,Include.Includes[i])
end; end;
var var
I : integer; I : integer;
Analyzing : TCodeInsight; Analyzing : TCodeInsight;
MS : TMemoryStream; MS : TMemoryStream;
time : longword;
begin begin
Time := GetTickCount;
if script = '' then if script = '' then
exit; exit;
if ScriptNode = nil then if ScriptNode = nil then
exit; exit;
if FilterTree.Visible then if FilterTree.Visible then
begin
mDebugLn('Might get some acces violations now..'); mDebugLn('Might get some acces violations now..');
exit;
end;
FunctionList.BeginUpdate;
ScriptNode.DeleteChildren; ScriptNode.DeleteChildren;
Analyzing := TCodeInsight.Create(); Analyzing := TCodeInsight.Create();
Analyzing.OnFindInclude:= @Form1.OnCCFindInclude; Analyzing.OnFindInclude:= @Form1.OnCCFindInclude;
@ -241,20 +247,21 @@ begin
begin; begin;
IncludesNode.DeleteChildren; IncludesNode.DeleteChildren;
for i := 0 to high(Analyzing.Includes) do for i := 0 to high(Analyzing.Includes) do
AddIncludes(Analyzing.Includes[i]); AddIncludes(IncludesNode, Analyzing.Includes[i]);
end; end;
ScriptNode.Expand(true); ScriptNode.Expand(true);
FunctionList.EndUpdate;
Analyzing.Free; Analyzing.Free;
end; end;
function TFunctionListFrame.Find(Next : boolean; backwards : boolean = false) : boolean; function TFunctionListFrame.Find(Next : boolean; backwards : boolean = false) : boolean;
var var
Start,Len,i,index,posi,c: Integer; Start,Len,i,ii,index,posi,c: Integer;
FoundFunction : boolean; FoundFunction : boolean;
LastSection : string; LastSection : Array[1..2] of String;
str : string; str : string;
RootNode : TTreeNode; RootNode : TTreeNode;
NormalNode : TTreeNode; NormalNode,tmpNode : TTreeNode;
Node : TTreeNode; Node : TTreeNode;
InsertStr : string; InsertStr : string;
begin begin
@ -301,7 +308,7 @@ begin
c := 0; c := 0;
while c < (len ) do while c < (len ) do
begin; begin;
if FilterTree.Items[i mod len].Level = 1 then if (FilterTree.Items[i mod len].HasChildren = false) then
begin begin
FilterTree.Items[i mod len].Selected:= true; FilterTree.Items[i mod len].Selected:= true;
InsertStr := FilterTree.Items[i mod len].Text; InsertStr := FilterTree.Items[i mod len].Text;
@ -316,18 +323,21 @@ begin
end; end;
end else end else
begin begin
FilterTree.BeginUpdate;
FilterTree.Items.Clear; FilterTree.Items.Clear;
FoundFunction := False; FoundFunction := False;
if FunctionList.Selected <> nil then if FunctionList.Selected <> nil then
Start := FunctionList.Selected.AbsoluteIndex Start := FunctionList.Selected.AbsoluteIndex
else else
Start := 0; Start := 0;
Len := FunctionList.Items.Count; Len := FunctionList.Items.Count;
LastSection := ''; LastSection[1] := '';
LastSection[2] := '';
for i := start to start + FunctionList.Items.Count - 1 do for i := start to start + FunctionList.Items.Count - 1 do
begin; begin;
Node := FunctionList.Items[i mod FunctionList.Items.Count]; Node := FunctionList.Items[i mod FunctionList.Items.Count];
if(Node.Level = 1)then if(Node.Level >= 1) and (node.HasChildren = false) then
if(pos(lowercase(editSearchList.Text), lowercase(Node.Text)) > 0)then if(pos(lowercase(editSearchList.Text), lowercase(Node.Text)) > 0)then
begin begin
if not FoundFunction then if not FoundFunction then
@ -336,10 +346,31 @@ begin
index := i mod FunctionList.Items.Count; index := i mod FunctionList.Items.Count;
InsertStr:= node.Text; InsertStr:= node.Text;
end; end;
if LastSection <> Node.Parent.Text then //We enter a new section, add it to the filter tree! if node.level = 2 then
RootNode := FilterTree.Items.AddChild(nil,Node.Parent.Text); begin;
if node.Parent.text <> lastsection[2] then
begin
if node.parent.parent.text <> lastsection[1] then
begin;
rootnode := FilterTree.Items.AddChild(nil,node.parent.parent.text);
lastsection[1] := rootnode.text;
rootnode := FilterTree.Items.AddChild(Rootnode,node.parent.text);
lastsection[2] := rootnode.text;
end else
begin
rootnode := FilterTree.Items.AddChild(rootnode.parent,node.parent.text);
lastsection[2] := rootnode.text;
end;
end;
end else
begin
if node.parent.text <> lastsection[1] then
begin
rootnode := FilterTree.Items.AddChild(nil,node.parent.text);
lastsection[1] := Rootnode.text;
end;
end;
FilterTree.Items.AddChild(RootNode,Node.Text).Data := Node.Data; FilterTree.Items.AddChild(RootNode,Node.Text).Data := Node.Data;
LastSection:= RootNode.Text;
// break; // break;
end; end;
end; end;
@ -349,7 +380,10 @@ begin
begin; begin;
FilterTreeVis(True); FilterTreeVis(True);
FilterTree.FullExpand; FilterTree.FullExpand;
FilterTree.Items[1].Selected:= True; c := 0;
while FilterTree.Items[c].HasChildren do
inc(c);
FilterTree.Items[c].Selected:= True;
mDebugLn(FunctionList.Items[Index].Text); mDebugLn(FunctionList.Items[Index].Text);
FunctionList.FullCollapse; FunctionList.FullCollapse;
FunctionList.Items[Index].Selected := true; FunctionList.Items[Index].Selected := true;
@ -364,6 +398,7 @@ begin
if InCodeCompletion then if InCodeCompletion then
Form1.CurrScript.SynEdit.Lines[CompletionCaret.y - 1] := CompletionStart; Form1.CurrScript.SynEdit.Lines[CompletionCaret.y - 1] := CompletionStart;
end; end;
FilterTree.EndUpdate;
end; end;
if result and InCodeCompletion then if result and InCodeCompletion then

View File

@ -162,8 +162,18 @@ begin
if (d <> nil) then if (d <> nil) then
begin begin
if (TCodeInsight(d.Parser).FileName <> mp.FileName) then if (TCodeInsight(d.Parser).FileName <> mp.FileName) then
mDebugLn('Declared in "' + TCodeInsight(d.Parser).FileName + '" at ' + IntToStr(d.StartPos)) begin
if FileExists(TCodeInsight(d.Parser).FileName) then
begin;
if Form1.LoadScriptFile(TCodeInsight(d.Parser).FileName,true,true) then
begin;
Form1.CurrScript.SynEdit.SelStart:= d.StartPos + 1;
Form1.CurrScript.SynEdit.SelEnd := d.StartPos + Length(TrimRight(d.RawText)) + 1;
end;
end
else else
mDebugLn('Declared in "' + TCodeInsight(d.Parser).FileName + '" at ' + IntToStr(d.StartPos));
end else
begin begin
SynEdit.SelStart := d.StartPos + 1; SynEdit.SelStart := d.StartPos + 1;
SynEdit.SelEnd := d.StartPos + Length(TrimRight(d.RawText)) + 1; SynEdit.SelEnd := d.StartPos + Length(TrimRight(d.RawText)) + 1;
@ -429,15 +439,7 @@ begin
else else
begin begin
ErrorData.Module:= SetDirSeparators(ErrorData.Module);// Set it right ;-) ErrorData.Module:= SetDirSeparators(ErrorData.Module);// Set it right ;-)
for i := 0 to Form1.Tabs.Count - 1 do Form1.LoadScriptFile(ErrorData.Module,true,true);//Checks if the file is already open!
if lowercase(TMufasaTab(Form1.Tabs[i]).ScriptFrame.ScriptFile) = lowercase(ErrorData.Module) then
begin;
ErrorData.Module:= '';
TMufasaTab(Form1.Tabs[i]).ScriptFrame.ErrorData := Self.ErrorData;
TMufasaTab(Form1.Tabs[i]).ScriptFrame.HandleErrorData;
Exit;
end;
Form1.LoadScriptFile(ErrorData.Module,true);
ErrorData.Module:= ''; ErrorData.Module:= '';
Form1.CurrScript.ErrorData := Self.ErrorData; Form1.CurrScript.ErrorData := Self.ErrorData;
Form1.CurrScript.HandleErrorData; Form1.CurrScript.HandleErrorData;

View File

@ -352,7 +352,7 @@ type
property ScriptState : TScriptState read GetScriptState write SetScriptState; property ScriptState : TScriptState read GetScriptState write SetScriptState;
procedure SafeCallThread; procedure SafeCallThread;
function OpenScript : boolean; function OpenScript : boolean;
function LoadScriptFile(filename : string; AlwaysOpenInNewTab : boolean = false) : 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 CanExitOrOpen : boolean; function CanExitOrOpen : boolean;
@ -362,6 +362,7 @@ type
procedure StopScript; procedure StopScript;
procedure AddTab; procedure AddTab;
procedure StopCodeCompletion; procedure StopCodeCompletion;
function FindTab(filename : string) : integer;
function DeleteTab( TabIndex : integer; CloseLast : boolean; Silent : boolean = false) : boolean; function DeleteTab( TabIndex : integer; CloseLast : boolean; Silent : boolean = false) : boolean;
procedure ClearTab( TabIndex : integer); procedure ClearTab( TabIndex : integer);
procedure CloseTabs(Exclude: integer = -1; Silent : boolean = false); //-1 for no exclusion procedure CloseTabs(Exclude: integer = -1; Silent : boolean = false); //-1 for no exclusion
@ -965,6 +966,7 @@ begin
CreateSetting('Settings/Fonts/LoadOnStartUp', 'True'); CreateSetting('Settings/Fonts/LoadOnStartUp', 'True');
CreateSetting('Settings/Tabs/OpenNextOnClose','False'); CreateSetting('Settings/Tabs/OpenNextOnClose','False');
CreateSetting('Settings/Tabs/OpenScriptInNewTab','True'); CreateSetting('Settings/Tabs/OpenScriptInNewTab','True');
CreateSetting('Settings/Tabs/CheckTabsBeforeOpen','True');
CreateSetting('Settings/ColourPicker/ShowHistoryOnPick', 'True'); CreateSetting('Settings/ColourPicker/ShowHistoryOnPick', 'True');
CreateSetting('Settings/General/MaxRecentFiles','10'); CreateSetting('Settings/General/MaxRecentFiles','10');
CreateSetting('Settings/MainForm/NormalSize','739:555'); CreateSetting('Settings/MainForm/NormalSize','739:555');
@ -1259,7 +1261,7 @@ procedure TForm1.OnSaveScript(const Filename: string);
begin begin
with CurrScript do with CurrScript do
begin begin
ScriptFile:= Filename; ScriptFile:= SetDirSeparators(Filename);
ScriptName:= ExtractFileNameOnly(Filename); ScriptName:= ExtractFileNameOnly(Filename);
mDebugLn('Script name will be: ' + ScriptName); mDebugLn('Script name will be: ' + ScriptName);
FormWritelnEx('Succesfully saved: ' + Filename); FormWritelnEx('Succesfully saved: ' + Filename);
@ -1551,6 +1553,21 @@ begin
end; end;
end; end;
function TForm1.FindTab(filename: string): integer;
var
i : integer;
begin
FileName := SetDirSeparators(filename);
for i := 0 to Form1.Tabs.Count - 1 do
{$ifdef MSWindows} //Case insensitive
if lowercase(TMufasaTab(Tabs[i]).ScriptFrame.ScriptFile) = lowercase(filename) then
{$else}
if TMufasaTab(Tabs[i]).ScriptFrame.ScriptFile = filename then
{$endif}
exit(i);
result := -1;
end;
procedure TForm1.editSearchListExit(Sender: TObject); procedure TForm1.editSearchListExit(Sender: TObject);
begin begin
frmFunctionList.editSearchList.Color := clWhite; frmFunctionList.editSearchList.Color := clWhite;
@ -1639,16 +1656,25 @@ var
begin begin
if node = nil then if node = nil then
exit; exit;
if Node.level = 0 then
StatusBar.Panels[Panel_ScriptPath].Text := 'Section: ' + Node.Text;
if (Node.Level > 0) and (Node.Data <> nil) then if (Node.Level > 0) and (Node.Data <> nil) then
begin begin
MethodInfo := PMethodInfo(node.Data)^; MethodInfo := PMethodInfo(node.Data)^;
StatusBar.Panels[Panel_ScriptPath].Text := MethodInfo.MethodStr; StatusBar.Panels[Panel_ScriptPath].Text := MethodInfo.MethodStr;
if frmFunctionList.DraggingNode = node then if frmFunctionList.DraggingNode = node then
if (MethodInfo.BeginPos > 0) then if (MethodInfo.BeginPos > 0) then
CurrScript.SynEdit.SelStart := MethodInfo.BeginPos + 1; begin;
if MethodInfo.Filename <> nil then
if MethodInfo.Filename <> '' then
begin;
Writeln(MethodInfo.filename);
LoadScriptFile(MethodInfo.Filename,true,true);
end;
CurrScript.SynEdit.SelStart := MethodInfo.BeginPos + 1;
CurrScript.SynEdit.SelEnd := MethodInfo.EndPos + 1;
end;
end; end;
if Node.level = 0 then
StatusBar.Panels[Panel_ScriptPath].Text := 'Section: ' + Node.Text;
end; end;
procedure TForm1.FunctionListEnter(Sender: TObject); procedure TForm1.FunctionListEnter(Sender: TObject);
@ -2401,17 +2427,32 @@ begin
end; end;
end; end;
function TForm1.LoadScriptFile(filename: string; AlwaysOpenInNewTab: boolean function TForm1.LoadScriptFile(filename: string; AlwaysOpenInNewTab: boolean; CheckOtherTabs : boolean
): boolean; ): boolean;
var var
OpenInNewTab : boolean; OpenInNewTab : boolean;
CheckTabsFirst : boolean;
Tab : integer;
begin begin
if AlwaysOpenInNewTab then if AlwaysOpenInNewTab then
OpenInNewTab := true OpenInNewTab := true
else else
OpenInNewTab:= (LowerCase(LoadSettingDef('Settings/Tabs/OpenScriptInNewTab','True')) = 'true'); OpenInNewTab:= (LowerCase(LoadSettingDef('Settings/Tabs/OpenScriptInNewTab','True')) = 'true');
if CheckOtherTabs then
CheckTabsFirst := True
else
CheckTabsFirst := (Lowercase(LoadSettingDef('Settings/Tabs/CheckTabsBeforeOpen','True')) = 'true');
if FileExists(FileName) then if FileExists(FileName) then
begin; begin;
if CheckTabsFirst then
begin;
Tab := FindTab(filename);
if tab <> -1 then
begin
TMufasaTab(Tabs[tab]).ScriptFrame.MakeActiveScriptFrame;
exit(true);
end;
end;
if OpenInNewTab and (CurrScript.SynEdit.Text <> CurrScript.ScriptDefault) then //Add la tab! if OpenInNewTab and (CurrScript.SynEdit.Text <> CurrScript.ScriptDefault) then //Add la tab!
self.addtab; self.addtab;
with CurrScript do with CurrScript do
@ -2421,7 +2462,7 @@ begin
StartText := SynEdit.Lines.text; StartText := SynEdit.Lines.text;
ScriptName:= ExtractFileNameOnly(filename); ScriptName:= ExtractFileNameOnly(filename);
mDebugLn('Script name will be: ' + ScriptName); mDebugLn('Script name will be: ' + ScriptName);
ScriptFile:= FileName; ScriptFile:= SetDirSeparators(FileName);
ScriptChanged := false; ScriptChanged := false;
AddRecentFile(filename); AddRecentFile(filename);
RefreshTab(); RefreshTab();

View File

@ -104,18 +104,19 @@ type
function GetRealType: TDeclaration; overload; function GetRealType: TDeclaration; overload;
end; end;
{ TciProcedureDeclaration } TciProcedureName = class(TDeclaration);
{ TciProcedureDeclaration }
TciProcedureDeclaration = class(TDeclaration) TciProcedureDeclaration = class(TDeclaration)
private private
fProcType: string; fProcType: string;
fParams: string; fParams: string;
fSynParams: string; fSynParams: string;
fName : string; fName : TciProcedureName;
fCleanDecl : string; fCleanDecl : string;
function GetCleanDeclaration: string; function GetCleanDeclaration: string;
function GetName: string; function GetName: TciProcedureName;
function GetProcType: string; function GetProcType: string;
function GetParams: string; function GetParams: string;
function GetSynParams: string; function GetSynParams: string;
@ -125,7 +126,7 @@ type
function GetParamDeclarations: TDeclarationArray; function GetParamDeclarations: TDeclarationArray;
property CleanDeclaration : string read GetCleanDeclaration; property CleanDeclaration : string read GetCleanDeclaration;
property Name : string read GetName; property Name : TciProcedureName read GetName;
property ProcType: string read GetProcType; property ProcType: string read GetProcType;
property Params: string read GetParams; property Params: string read GetParams;
property SynParams: string read GetSynParams; property SynParams: string read GetSynParams;
@ -158,7 +159,7 @@ type
TciLabelName = class(TDeclaration); //Label TciLabelName = class(TDeclaration); //Label
//TciProcedureDeclaration = class(TDeclaration); //Procedure/Function //TciProcedureDeclaration = class(TDeclaration); //Procedure/Function
TciProcedureName = class(TDeclaration); //Procedure/Function //TciProcedureName = class(TDeclaration); //Procedure/Function
TciProcedureClassName = class(TDeclaration); //Class Procedure/Function TciProcedureClassName = class(TDeclaration); //Class Procedure/Function
TciReturnType = class(TciTypeKind); //Function Result TciReturnType = class(TciTypeKind); //Function Result
TciForward = class(TciTypeKind); //Forwarding TciForward = class(TciTypeKind); //Forwarding
@ -788,19 +789,19 @@ begin
Result := fProcType; Result := fProcType;
end; end;
function TciProcedureDeclaration.GetName: string; function TciProcedureDeclaration.GetName: TciProcedureName;
var var
ProcedureName : TciProcedureName; ProcedureName : TciProcedureName;
begin begin
if (fName <> '') then if (fName <> nil) then
result := fName result := fName
else else
begin begin
ProcedureName := TciProcedureName(fItems.GetFirstItemOfClass(TciProcedureName)); ProcedureName := TciProcedureName(fItems.GetFirstItemOfClass(TciProcedureName));
if ProcedureName <> nil then if ProcedureName <> nil then
result := ProcedureName.ShortText result := ProcedureName
else else
Result := ''; Result := nil;
fName := result; fName := result;
end; end;
end; end;
@ -814,9 +815,9 @@ begin
else else
begin begin
result := ''; result := '';
if Name = '' then if Name = nil then
exit; exit;
result := proctype + ' ' + Name; result := proctype + ' ' + Name.ShortText;
if Params <> '' then if Params <> '' then
result := result + '(' + params + ')'; result := result + '(' + params + ')';
Return := fItems.GetFirstItemOfClass(TciReturnType) as TciReturnType; Return := fItems.GetFirstItemOfClass(TciReturnType) as TciReturnType;