amxmodx/editor/studio/UnitCodeExplorerUpdater.pas

366 lines
12 KiB
ObjectPascal
Raw Normal View History

2005-08-26 18:29:39 +00:00
unit UnitCodeExplorerUpdater;
interface
uses
Classes, Forms, SysUtils, ComCtrls, Windows, ScintillaLanguageManager,
2005-10-30 10:33:16 +00:00
Dialogs, CommCtrl;
2005-08-26 18:29:39 +00:00
type
TCodeExplorerUpdater = class(TThread)
private
eConstants: TStringList;
eDefined: TStringList;
eCVars: TStringList;
eIncluded: TStringList;
eMethodsDefault, eMethodsEvents, eStocks: TStringList;
eNatives: TStringList;
eForwards: TStringList;
eVariables: TStringList;
eCode: TStringList;
eAutoComplete, eCallTips, eKeywords: string;
eLastActive: Integer;
eActive: Integer;
2005-08-26 18:29:39 +00:00
protected
procedure Execute; override;
procedure GetCode;
procedure SetValuesPawn;
2005-08-26 18:29:39 +00:00
end;
function GetNode(eText: string): TTreeNode;
2005-08-26 18:29:39 +00:00
implementation
uses UnitfrmMain, UnitLanguages, UnitMainTools, UnitCodeUtils,
UnitTextAnalyze, UnitfrmSettings, UnitPlugins;
{ TCodeExplorerUpdater }
procedure TCodeExplorerUpdater.Execute;
function CheckAU: Boolean;
begin
Result := True;
if (eLastActive = eActive) and (frmSettings.chkAUDisable.Checked) then begin
if frmMain.sciEditor.Lines.Count > StrToIntDef(frmSettings.txtAUDisable.Text, 1500) then
Result := False;
end;
eLastActive := eActive;
end;
2005-08-26 18:29:39 +00:00
var eStr: TStringList;
begin
eCode := TStringList.Create;
eConstants := TStringList.Create;
eDefined := TStringList.Create;
eCVars := TStringList.Create;
eIncluded := TStringList.Create;
eMethodsDefault := TStringList.Create;
eMethodsEvents := TStringList.Create;
eStocks := TStringList.Create;
eNatives := TStringList.Create;
eForwards := TStringList.Create;
eVariables := TStringList.Create;
eStr := TStringList.Create;
repeat
Synchronize(GetCode);
eAutoComplete := '';
eCallTips := '';
eKeywords := '';
if (not Application.Terminated) and (Started) and (not frmMain.pnlLoading.Visible) and (frmMain.trvExplorer.Visible) and (Assigned(ActiveDoc)) then begin
if (Plugin_UpdateCodeExplorer(GetCurrLang.Name, ActiveDoc.FileName, frmMain.tbDocs.SelectedTab.Caption, True)) and (frmMain.stlIDEs.ItemIndex = 0) then begin
2005-08-26 18:29:39 +00:00
try
if CheckAU then begin
if Plugin_UpdateCodeExplorer(GetCurrLang.Name, ActiveDoc.FileName, frmMain.stlIDEs.Strings[frmMain.stlIDEs.ItemIndex], True) then begin
// analyze code
with ParseCodePawn(eCode, ExtractFileName(ActiveDoc.FileName)) do begin
eConstants.Assign(Constants);
eDefined.Assign(Defined);
eCVars.Assign(CVars);
eIncluded.Assign(Included);
eMethodsDefault.Assign(MethodsDefault);
eMethodsEvents.Assign(Events);
eStocks.Assign(Stocks);
eNatives.Assign(Natives);
eForwards.Assign(Forwards);
eVariables.Assign(Variables);
2005-08-26 18:29:39 +00:00
eAutoComplete := eAutoComplete + #13 + AutoComplete.Text;
eCallTips := eCallTips + #13 + CallTips.Text;
eKeywords := eKeywords + #13 + HighlightKeywords.Text;
2005-08-26 18:29:39 +00:00
DestroyResult;
end;
// apply changes
Synchronize(SetValuesPawn);
2005-08-26 18:29:39 +00:00
end;
end;
except
if FindWindow(nil, 'Delphi 7') <> 0 then // This is "Debug Mode"
2005-10-30 10:33:16 +00:00
//madExcept.HandleException;
2005-08-26 18:29:39 +00:00
end;
end;
Sleep(1000);
end
else
Sleep(50);
until not Started;
2005-08-26 18:29:39 +00:00
eCode.Free;
eConstants.Free;
eDefined.Free;
eCVars.Free;
eIncluded.Free;
eMethodsDefault.Free;
eMethodsEvents.Free;
eStocks.Free;
eNatives.Free;
eForwards.Free;
eVariables.Free;
eStr.Free;
end;
procedure TCodeExplorerUpdater.GetCode;
begin
eCode.Assign(frmMain.sciEditor.Lines);
eActive := ActiveDoc.Index;
2005-08-26 18:29:39 +00:00
end;
function GetNode(eText: string): TTreeNode;
2005-08-26 18:29:39 +00:00
var i: integer;
begin
Result := nil;
for i := 0 to frmMain.trvExplorer.Items.Count - 1 do begin
2005-08-26 18:29:39 +00:00
if (frmMain.trvExplorer.Items[i].Text = eText) then begin
if (frmMain.trvExplorer.Items[i].ImageIndex = 42) or (frmMain.trvExplorer.Items[i].ImageIndex = 43) then begin
Result := frmMain.trvExplorer.Items[i];
exit;
end;
end;
end;
end;
procedure TCodeExplorerUpdater.SetValuesPawn;
2005-08-26 18:29:39 +00:00
var exConstants, exDefined, exIncluded, exMethods, exDefault, exEvents,
exStocks, exNatives, exForwards, exVariables, exCVars: Boolean;
i, eSelStart, eSelLength: integer;
LineMaxSubord: integer;
eStr: TStringList;
eScrollPosX, eScrollPosY: Integer;
eTempNode: TTreeNode;
2005-08-26 18:29:39 +00:00
begin
if Application.Terminated then exit;
if (frmMain.trvExplorer.Items.Count = 0) or (eActive <> ActiveDoc.Index) then exit;
2005-08-26 18:29:39 +00:00
frmMain.trvExplorer.Items.BeginUpdate;
try
eScrollPosX := GetScrollPos(frmMain.trvExplorer.Handle, SB_HORZ);
eScrollPosY := GetScrollPos(frmMain.trvExplorer.Handle, SB_VERT);
2005-08-26 18:29:39 +00:00
// Get Expanded-State and delete children
with GetNode('Constants') do begin
2005-11-13 10:40:59 +00:00
exConstants := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('CVars') do begin
2005-11-13 10:40:59 +00:00
exCVars := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('Defined') do begin
2005-11-13 10:40:59 +00:00
exDefined := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('Included') do begin
2005-11-13 10:40:59 +00:00
exIncluded := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('Default') do begin
2005-11-13 10:40:59 +00:00
exDefault := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('Events') do begin
2005-11-13 10:40:59 +00:00
exEvents := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('Stocks') do begin
2005-11-13 10:40:59 +00:00
exStocks := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('Methods') do begin
2005-11-13 10:40:59 +00:00
exMethods := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('Natives') do begin
2005-11-13 10:40:59 +00:00
exNatives := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('Forwards') do begin
2005-11-13 10:40:59 +00:00
exForwards := (Expanded) and (Count <> 0);
DeleteChildren;
end;
with GetNode('Variables') do begin
2005-11-13 10:40:59 +00:00
exVariables := (Expanded) and (Count <> 0);
DeleteChildren;
end;
2005-08-26 18:29:39 +00:00
// Create new children
with frmMain.trvExplorer.Items.AddChild(GetNode('Defined'), 'CVars') do begin
ImageIndex := 42;
SelectedIndex := 42;
end;
with frmMain.trvExplorer.Items.AddChild(GetNode('Methods'), 'Default') do begin
ImageIndex := 42;
SelectedIndex := 42;
end;
with frmMain.trvExplorer.Items.AddChild(GetNode('Methods'), 'Events') do begin
ImageIndex := 42;
SelectedIndex := 42;
end;
with frmMain.trvExplorer.Items.AddChild(GetNode('Methods'), 'Stocks') do begin
ImageIndex := 42;
SelectedIndex := 42;
end;
2005-08-26 18:29:39 +00:00
eTempNode := GetNode('Constants');
for i := 0 to eConstants.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eConstants[i], Pointer(eConstants.Objects[i])) do begin
ImageIndex := 48;
SelectedIndex := 48;
end;
2005-08-26 18:29:39 +00:00
end;
eTempNode := GetNode('Defined');
for i := 0 to eDefined.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eDefined[i], Pointer(eDefined.Objects[i])) do begin
ImageIndex := 48;
SelectedIndex := 48;
end;
2005-08-26 18:29:39 +00:00
end;
eTempNode := GetNode('CVars');
for i := 0 to eCVars.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eCVars[i], Pointer(eCVars.Objects[i])) do begin
ImageIndex := 35;
SelectedIndex := 35;
end;
2005-08-26 18:29:39 +00:00
end;
// Sort items
eIncluded.Sort;
eMethodsDefault.Sort;
eMethodsEvents.Sort;
eStocks.Sort;
eNatives.Sort;
eForwards.Sort;
eVariables.Sort;
// Add items
eTempNode := GetNode('Included');
for i := 0 to eIncluded.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eIncluded[i], Pointer(eIncluded.Objects[i])) do begin
ImageIndex := 34;
SelectedIndex := 34;
end;
2005-08-26 18:29:39 +00:00
end;
eTempNode := GetNode('Default');
for i := 0 to eMethodsDefault.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eMethodsDefault[i], Pointer(eMethodsDefault.Objects[i])) do begin
ImageIndex := 12;
SelectedIndex := 12;
end;
2005-08-26 18:29:39 +00:00
end;
eTempNode := GetNode('Events');
for i := 0 to eMethodsEvents.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eMethodsEvents[i], Pointer(eMethodsEvents.Objects[i])) do begin
ImageIndex := 47;
SelectedIndex := 47;
end;
2005-08-26 18:29:39 +00:00
end;
eTempNode := GetNode('Stocks');
for i := 0 to eStocks.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eStocks[i], Pointer(eStocks.Objects[i])) do begin
ImageIndex := 12;
SelectedIndex := 12;
end;
2005-08-26 18:29:39 +00:00
end;
eTempNode := GetNode('Natives');
for i := 0 to eNatives.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eNatives[i], Pointer(eNatives.Objects[i])) do begin
ImageIndex := 47;
SelectedIndex := 47;
end;
2005-08-26 18:29:39 +00:00
end;
eTempNode := GetNode('Forwards');
for i := 0 to eForwards.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eForwards[i], Pointer(eForwards.Objects[i])) do begin
ImageIndex := 47;
SelectedIndex := 47;
end;
2005-08-26 18:29:39 +00:00
end;
eTempNode := GetNode('Variables');
for i := 0 to eVariables.Count - 1 do begin
with frmMain.trvExplorer.Items.AddChildObject(eTempNode, eVariables[i], Pointer(eVariables.Objects[i])) do begin
ImageIndex := 35;
SelectedIndex := 35;
end;
2005-08-26 18:29:39 +00:00
end;
GetNode('Constants').Expanded := exConstants;
GetNode('Defined').Expanded := exDefined;
GetNode('CVars').Expanded := exCVars;
GetNode('Included').Expanded := exIncluded;
GetNode('Methods').Expanded := exMethods;
GetNode('Default').Expanded := exDefault;
GetNode('Events').Expanded := exEvents;
GetNode('Stocks').Expanded := exStocks;
GetNode('Natives').Expanded := exNatives;
GetNode('Forwards').Expanded := exForwards;
GetNode('Variables').Expanded := exVariables;
SetScrollPos(frmMain.trvExplorer.Handle, SB_HORZ, eScrollPosX, False);
SetScrollPos(frmMain.trvExplorer.Handle, SB_VERT, eScrollPosY, False);
except
// well, yes.
end;
2005-08-26 18:29:39 +00:00
frmMain.trvExplorer.Items.EndUpdate;
if (not frmMain.pnlLoading.Visible) and (not frmMain.sciEditor.AutoCActive) and (not frmMain.sciEditor.CallTipActive) then begin
frmMain.sciAutoComplete.AStrings.Text := eAutoComplete;
for i := frmMain.sciAutoComplete.AStrings.Count - 1 downto 0 do begin
2005-08-26 18:29:39 +00:00
if Length(Trim(frmMain.sciAutoComplete.AStrings[i])) <= 1 then
frmMain.sciAutoComplete.AStrings.Delete(i);
end;
frmMain.sciCallTips.ApiStrings.Text := eCallTips;
for i := frmMain.sciCallTips.ApiStrings.Count - 1 downto 0 do begin
2005-08-26 18:29:39 +00:00
if Length(Trim(frmMain.sciCallTips.ApiStrings[i])) <= 1 then
frmMain.sciCallTips.ApiStrings.Delete(i);
end;
with TSciKeywords(TSciLangItem(frmMain.sciEditor.LanguageManager.LanguageList.Find('Pawn').Keywords.Items[1])) do begin
eStr := TStringList.Create;
for i := 0 to frmMain.sciEditor.Lines.Count - 1 do begin
2005-08-26 18:29:39 +00:00
if not frmMain.sciEditor.GetFoldExpanded(i) then
eStr.Add(IntToStr(i));
end;
2005-08-26 18:29:39 +00:00
Keywords.Text := eKeywords;
frmMain.sciEditor.LanguageManager.Update;
for i := 0 to frmMain.sciEditor.Lines.Count - 1 do begin
2005-08-26 18:29:39 +00:00
if eStr.IndexOf(IntToStr(i)) <> -1 then begin
LineMaxSubord := frmMain.sciEditor.GetLastChild(i, -1);
frmMain.sciEditor.SetFoldExpanded(i, False);
if LineMaxSubord > i then
frmMain.sciEditor.HideLines(i + 1, LineMaxSubord);
2005-08-26 18:29:39 +00:00
end;
end;
eStr.Free;
end;
end;
Plugin_UpdateCodeExplorer(GetCurrLang.Name, ActiveDoc.FileName, frmMain.stlIDEs.Strings[frmMain.stlIDEs.ItemIndex], False);
2005-08-26 18:29:39 +00:00
end;
end.