symlist, allow typing to editor after selecting a node and refresh style

This commit is contained in:
Basile Burg 2018-05-14 15:27:36 +02:00
parent c33b16518b
commit 28ba843430
1 changed files with 131 additions and 119 deletions

View File

@ -70,7 +70,6 @@ type
public public
constructor create(aOwner: TCOmponent); override; constructor create(aOwner: TCOmponent); override;
destructor destroy; override; destructor destroy; override;
//
procedure LoadFromTool(str: TStream); procedure LoadFromTool(str: TStream);
end; end;
@ -103,8 +102,6 @@ type
procedure AssignTo(Dest: TPersistent); override; procedure AssignTo(Dest: TPersistent); override;
end; end;
{ TCESymbolListWidget }
TCESymbolListWidget = class(TCEWidget, ICEDocumentObserver, ICEEditableOptions) TCESymbolListWidget = class(TCEWidget, ICEDocumentObserver, ICEEditableOptions)
btnRefresh: TCEToolButton; btnRefresh: TCEToolButton;
Tree: TTreeView; Tree: TTreeView;
@ -151,16 +148,16 @@ type
procedure updateVisibleCat; procedure updateVisibleCat;
procedure clearTree; procedure clearTree;
procedure smartExpand; procedure smartExpand;
//
procedure checkIfHasToolExe; procedure checkIfHasToolExe;
procedure callToolProc; procedure callToolProc;
procedure toolTerminated(sender: TObject); procedure toolTerminated(sender: TObject);
//
procedure docNew(document: TCESynMemo); procedure docNew(document: TCESynMemo);
procedure docClosing(document: TCESynMemo); procedure docClosing(document: TCESynMemo);
procedure docFocused(document: TCESynMemo); procedure docFocused(document: TCESynMemo);
procedure docChanged(document: TCESynMemo); procedure docChanged(document: TCESynMemo);
//
function optionedWantCategory(): string; function optionedWantCategory(): string;
function optionedWantEditorKind: TOptionEditorKind; function optionedWantEditorKind: TOptionEditorKind;
function optionedWantContainer: TPersistent; function optionedWantContainer: TPersistent;
@ -168,11 +165,11 @@ type
function optionedOptionsModified: boolean; function optionedOptionsModified: boolean;
protected protected
procedure updateDelayed; override; procedure updateDelayed; override;
//
function contextName: string; override; function contextName: string; override;
function contextActionCount: integer; override; function contextActionCount: integer; override;
function contextAction(index: integer): TAction; override; function contextAction(index: integer): TAction; override;
//
procedure SetVisible(value: boolean); override; procedure SetVisible(value: boolean); override;
procedure setToolBarFlat(value: boolean); override; procedure setToolBarFlat(value: boolean); override;
published published
@ -277,7 +274,7 @@ begin
if Source is TCESymbolListWidget then if Source is TCESymbolListWidget then
begin begin
widg := TCESymbolListWidget(Source); widg := TCESymbolListWidget(Source);
//
fDeep := widg.fDeep; fDeep := widg.fDeep;
fAutoRefreshDelay := widg.updaterByDelayDuration; fAutoRefreshDelay := widg.updaterByDelayDuration;
fRefreshOnFocus := widg.fRefreshOnFocus; fRefreshOnFocus := widg.fRefreshOnFocus;
@ -499,7 +496,8 @@ end;
procedure TCESymbolListWidget.actRefreshExecute(Sender: TObject); procedure TCESymbolListWidget.actRefreshExecute(Sender: TObject);
begin begin
if Updating then exit; if Updating then
exit;
callToolProc; callToolProc;
end; end;
@ -547,7 +545,8 @@ end;
procedure TCESymbolListWidget.optionedEvent(event: TOptionEditorEvent); procedure TCESymbolListWidget.optionedEvent(event: TOptionEditorEvent);
begin begin
if event <> oeeAccept then exit; if event <> oeeAccept then
exit;
fOptions.AssignTo(self); fOptions.AssignTo(self);
callToolProc; callToolProc;
end; end;
@ -567,7 +566,9 @@ end;
procedure TCESymbolListWidget.docClosing(document: TCESynMemo); procedure TCESymbolListWidget.docClosing(document: TCESynMemo);
begin begin
if fDoc <> document then exit; if fDoc <> document then
exit;
fDoc := nil; fDoc := nil;
clearTree; clearTree;
updateVisibleCat; updateVisibleCat;
@ -575,22 +576,26 @@ end;
procedure TCESymbolListWidget.docFocused(document: TCESynMemo); procedure TCESymbolListWidget.docFocused(document: TCESynMemo);
begin begin
if fDoc = document then exit; if fDoc = document then
exit;
fDoc := document; fDoc := document;
if not Visible then exit; if not Visible then
// exit;
if fAutoRefresh then beginDelayedUpdate if fAutoRefresh then beginDelayedUpdate
else if fRefreshOnFocus then callToolProc; else if fRefreshOnFocus then callToolProc;
end; end;
procedure TCESymbolListWidget.docChanged(document: TCESynMemo); procedure TCESymbolListWidget.docChanged(document: TCESynMemo);
begin begin
if fDoc <> document then exit; if (fDoc <> document) or not Visible then
if not Visible then exit; exit;
//
if fAutoRefresh then beginDelayedUpdate if fAutoRefresh then
else if fRefreshOnChange then callToolProc; beginDelayedUpdate
// else if fRefreshOnChange then
callToolProc;
if fSmartExpander then if fSmartExpander then
smartExpand; smartExpand;
end; end;
@ -679,8 +684,9 @@ end;
function TCESymbolListWidget.TreeFilterEdit1FilterItem(Item: TObject; out function TCESymbolListWidget.TreeFilterEdit1FilterItem(Item: TObject; out
Done: Boolean): Boolean; Done: Boolean): Boolean;
begin begin
if not fSmartFilter then exit(false); if not fSmartFilter then
// exit(false);
if TreeFilterEdit1.Filter.isNotEmpty then if TreeFilterEdit1.Filter.isNotEmpty then
tree.FullExpand tree.FullExpand
else if tree.Selected.isNil then else if tree.Selected.isNil then
@ -691,27 +697,29 @@ end;
procedure TCESymbolListWidget.TreeFilterEdit1MouseEnter(Sender: TObject); procedure TCESymbolListWidget.TreeFilterEdit1MouseEnter(Sender: TObject);
begin begin
if not fSmartFilter then exit; if not fSmartFilter then
// exit;
tree.Selected := nil; tree.Selected := nil;
end; end;
procedure TCESymbolListWidget.TreeKeyPress(Sender: TObject; var Key: char); procedure TCESymbolListWidget.TreeKeyPress(Sender: TObject; var Key: char);
begin begin
if Key = #13 then TreeDblClick(nil); if Key = #13 then
TreeDblClick(nil);
end; end;
procedure TCESymbolListWidget.TreeDblClick(Sender: TObject); procedure TCESymbolListWidget.TreeDblClick(Sender: TObject);
var var
line: NativeUint; line: PtrUInt;
begin begin
if fDoc.isNil then exit; if fDoc.isNil or Tree.Selected.isNil or Tree.Selected.Data.isNil then
if Tree.Selected.isNil then exit; exit;
if Tree.Selected.Data.isNil then exit;
//
{$PUSH}{$WARNINGS OFF}{$HINTS OFF} {$PUSH}{$WARNINGS OFF}{$HINTS OFF}
line := NativeUInt(Tree.Selected.Data); line := NativeUInt(Tree.Selected.Data);
{$POP} {$POP}
fDoc.setFocus;
fDoc.CaretY := line; fDoc.CaretY := line;
fDoc.SelectLine; fDoc.SelectLine;
end; end;
@ -726,15 +734,16 @@ procedure TCESymbolListWidget.callToolProc;
var var
str: string; str: string;
begin begin
if not fHasToolExe then exit; if not fHasToolExe or fDoc.isNil then
if fDoc.isNil then exit; exit;
if (fDoc.Lines.Count = 0) or not fDoc.isDSource then if (fDoc.Lines.Count = 0) or not fDoc.isDSource then
begin begin
clearTree; clearTree;
updateVisibleCat; updateVisibleCat;
exit; exit;
end; end;
//
killProcess(fToolProc); killProcess(fToolProc);
fToolProc := TCEProcess.Create(nil); fToolProc := TCEProcess.Create(nil);
fToolProc.ShowWindow := swoHIDE; fToolProc.ShowWindow := swoHIDE;
@ -752,101 +761,103 @@ begin
end; end;
procedure TCESymbolListWidget.toolTerminated(sender: TObject); procedure TCESymbolListWidget.toolTerminated(sender: TObject);
//
function getCatNode(node: TTreeNode; stype: TSymbolType ): TTreeNode; function getCatNode(node: TTreeNode; stype: TSymbolType ): TTreeNode;
// function newCat(const aCat: string): TTreeNode;
function newCat(const aCat: string): TTreeNode; begin
result := node.FindNode(aCat);
if result.isNil then
result := node.TreeNodes.AddChild(node, aCat);
case stype of
_alias : begin result.ImageIndex:=0; result.SelectedIndex:=0; end;
_class : begin result.ImageIndex:=1; result.SelectedIndex:=1; end;
_enum : begin result.ImageIndex:=2; result.SelectedIndex:=2; end;
_function : begin result.ImageIndex:=3; result.SelectedIndex:=3; end;
_import : begin result.ImageIndex:=4; result.SelectedIndex:=4; end;
_interface: begin result.ImageIndex:=5; result.SelectedIndex:=5; end;
_mixin : begin result.ImageIndex:=6; result.SelectedIndex:=6; end;
_struct : begin result.ImageIndex:=7; result.SelectedIndex:=7; end;
_template : begin result.ImageIndex:=0; result.SelectedIndex:=0; end;
_union : begin result.ImageIndex:=1; result.SelectedIndex:=1; end;
_unittest : begin result.ImageIndex:=2; result.SelectedIndex:=2; end;
_variable : begin result.ImageIndex:=3; result.SelectedIndex:=3; end;
_warning : begin result.ImageIndex:=8; result.SelectedIndex:=8; end;
_error : begin result.ImageIndex:=9; result.SelectedIndex:=9; end;
end;
end;
begin begin
result := node.FindNode(aCat); result := nil;
if result.isNil then if node.isNil then case stype of
result := node.TreeNodes.AddChild(node, aCat); _alias : exit(ndAlias);
case stype of _class : exit(ndClass);
_alias : begin result.ImageIndex:=0; result.SelectedIndex:=0; end; _enum : exit(ndEnum);
_class : begin result.ImageIndex:=1; result.SelectedIndex:=1; end; _function : exit(ndFunc);
_enum : begin result.ImageIndex:=2; result.SelectedIndex:=2; end; _import : exit(ndImp);
_function : begin result.ImageIndex:=3; result.SelectedIndex:=3; end; _interface: exit(ndIntf);
_import : begin result.ImageIndex:=4; result.SelectedIndex:=4; end; _mixin : exit(ndMix);
_interface: begin result.ImageIndex:=5; result.SelectedIndex:=5; end; _struct : exit(ndStruct);
_mixin : begin result.ImageIndex:=6; result.SelectedIndex:=6; end; _template : exit(ndTmp);
_struct : begin result.ImageIndex:=7; result.SelectedIndex:=7; end; _union : exit(ndUni);
_template : begin result.ImageIndex:=0; result.SelectedIndex:=0; end; _unittest : exit(ndUt);
_union : begin result.ImageIndex:=1; result.SelectedIndex:=1; end; _variable : exit(ndVar);
_unittest : begin result.ImageIndex:=2; result.SelectedIndex:=2; end; _warning : exit(ndWarn);
_variable : begin result.ImageIndex:=3; result.SelectedIndex:=3; end; _error : exit(ndErr);
_warning : begin result.ImageIndex:=8; result.SelectedIndex:=8; end; end else case stype of
_error : begin result.ImageIndex:=9; result.SelectedIndex:=9; end; _alias: exit(newCat('Alias'));
end; _class: exit(newCat('Class'));
_enum: exit(newCat('Enum'));
_function: exit(newCat('Function'));
_import: exit(newCat('Import'));
_interface: exit(newCat('Interface'));
_mixin: exit(newCat('Mixin'));
_struct: exit(newCat('Struct'));
_template: exit(newCat('Template'));
_union: exit(newCat('Union'));
_unittest: exit(newCat('Unittest'));
_variable: exit(newCat('Variable'));
_warning: exit(ndWarn);
_error: exit(ndErr);
end;
end; end;
//
begin procedure symbolToTreeNode(origin: TTreenode; sym: TSymbol);
result := nil; var
if node.isNil then case stype of cat: TTreeNode;
_alias : exit(ndAlias); node: TTreeNode;
_class : exit(ndClass); i: Integer;
_enum : exit(ndEnum); begin
_function : exit(ndFunc); cat := getCatNode(origin, sym.symType);
_import : exit(ndImp); {$PUSH}{$WARNINGS OFF}{$HINTS OFF}
_interface: exit(ndIntf); node := tree.Items.AddChildObject(cat, sym.name, Pointer(sym.fline));
_mixin : exit(ndMix); {$POP}
_struct : exit(ndStruct); node.SelectedIndex:= cat.SelectedIndex;
_template : exit(ndTmp); node.ImageIndex:= cat.ImageIndex;
_union : exit(ndUni); if not fShowChildCategories then
_unittest : exit(ndUt); node := nil;
_variable : exit(ndVar); cat.Visible:=true;
_warning : exit(ndWarn); for i := 0 to sym.subs.Count-1 do
_error : exit(ndErr); symbolToTreeNode(node, sym.subs[i]);
end else case stype of end;
_alias: exit(newCat('Alias'));
_class: exit(newCat('Class'));
_enum: exit(newCat('Enum'));
_function: exit(newCat('Function'));
_import: exit(newCat('Import'));
_interface: exit(newCat('Interface'));
_mixin: exit(newCat('Mixin'));
_struct: exit(newCat('Struct'));
_template: exit(newCat('Template'));
_union: exit(newCat('Union'));
_unittest: exit(newCat('Unittest'));
_variable: exit(newCat('Variable'));
_warning: exit(ndWarn);
_error: exit(ndErr);
end;
end;
//
procedure symbolToTreeNode(origin: TTreenode; sym: TSymbol);
var
cat: TTreeNode;
node: TTreeNode;
i: Integer;
begin
cat := getCatNode(origin, sym.symType);
{$PUSH}{$WARNINGS OFF}{$HINTS OFF}
node := tree.Items.AddChildObject(cat, sym.name, Pointer(sym.fline));
{$POP}
node.SelectedIndex:= cat.SelectedIndex;
node.ImageIndex:= cat.ImageIndex;
if not fShowChildCategories then
node := nil;
cat.Visible:=true;
for i := 0 to sym.subs.Count-1 do
symbolToTreeNode(node, sym.subs[i]);
end;
//
var var
i: Integer; i: Integer;
flt: string; flt: string;
begin begin
if ndAlias.isNil then exit; if ndAlias.isNil then
exit;
clearTree; clearTree;
updateVisibleCat; updateVisibleCat;
if fDoc.isNil then exit; if fDoc.isNil then
// exit;
fToolProc.OnTerminate := nil; fToolProc.OnTerminate := nil;
fToolProc.OnReadData := nil; fToolProc.OnReadData := nil;
fToolProc.OutputStack.Position:=0; fToolProc.OutputStack.Position:=0;
if fToolProc.OutputStack.Size = 0 then exit; if fToolProc.OutputStack.Size = 0 then
exit;
fSyms.LoadFromTool(fToolProc.OutputStack); fSyms.LoadFromTool(fToolProc.OutputStack);
//
flt := TreeFilterEdit1.Filter; flt := TreeFilterEdit1.Filter;
TreeFilterEdit1.Text := ''; TreeFilterEdit1.Text := '';
tree.BeginUpdate; tree.BeginUpdate;
@ -906,8 +917,9 @@ var
end; end;
begin begin
if fDoc.isNil then exit; if fDoc.isNil then
// exit;
target := fDoc.CaretY; target := fDoc.CaretY;
for i := 0 to tree.Items.Count-1 do for i := 0 to tree.Items.Count-1 do
look(tree.Items[i]); look(tree.Items[i]);