mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-15 02:16:11 +02:00
IdeInspector: Display unit name and file of selected Component
git-svn-id: trunk@28663 -
This commit is contained in:
parent
0596f52334
commit
d14fe5acfe
@ -1,7 +1,7 @@
|
||||
object IdeInspectForm: TIdeInspectForm
|
||||
Left = 2033
|
||||
Left = 2070
|
||||
Height = 479
|
||||
Top = 182
|
||||
Top = 157
|
||||
Width = 498
|
||||
Caption = 'IdeInspectForm'
|
||||
ClientHeight = 479
|
||||
@ -90,7 +90,7 @@ object IdeInspectForm: TIdeInspectForm
|
||||
end
|
||||
object TreeView1: TTreeView
|
||||
Left = 0
|
||||
Height = 453
|
||||
Height = 364
|
||||
Top = 26
|
||||
Width = 217
|
||||
Align = alLeft
|
||||
@ -105,10 +105,93 @@ object IdeInspectForm: TIdeInspectForm
|
||||
end
|
||||
object Splitter1: TSplitter
|
||||
Left = 217
|
||||
Height = 453
|
||||
Height = 364
|
||||
Top = 26
|
||||
Width = 5
|
||||
end
|
||||
object Panel1: TPanel
|
||||
Left = 0
|
||||
Height = 89
|
||||
Top = 390
|
||||
Width = 498
|
||||
Align = alBottom
|
||||
AutoSize = True
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 89
|
||||
ClientWidth = 498
|
||||
TabOrder = 3
|
||||
object ComboHistory: TComboBox
|
||||
AnchorSideLeft.Control = Panel1
|
||||
AnchorSideTop.Control = Panel1
|
||||
AnchorSideRight.Control = Panel1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 5
|
||||
Height = 23
|
||||
Top = 5
|
||||
Width = 488
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 5
|
||||
BorderSpacing.Top = 5
|
||||
BorderSpacing.Right = 5
|
||||
ItemHeight = 15
|
||||
OnChange = ComboHistoryChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 0
|
||||
end
|
||||
object EditFile: TEdit
|
||||
AnchorSideLeft.Control = ComboHistory
|
||||
AnchorSideTop.Control = EditUnit
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = btnOpenFile
|
||||
AnchorSideBottom.Control = Panel1
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 5
|
||||
Height = 23
|
||||
Top = 61
|
||||
Width = 454
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Top = 5
|
||||
BorderSpacing.Right = 5
|
||||
BorderSpacing.Bottom = 5
|
||||
ReadOnly = True
|
||||
TabOrder = 1
|
||||
end
|
||||
object EditUnit: TEdit
|
||||
AnchorSideLeft.Control = ComboHistory
|
||||
AnchorSideTop.Control = ComboHistory
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = btnOpenFile
|
||||
Left = 5
|
||||
Height = 23
|
||||
Top = 33
|
||||
Width = 454
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 5
|
||||
BorderSpacing.Right = 5
|
||||
ReadOnly = True
|
||||
TabOrder = 2
|
||||
end
|
||||
object btnOpenFile: TSpeedButton
|
||||
AnchorSideTop.Control = EditFile
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Control = Panel1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 464
|
||||
Height = 22
|
||||
Hint = 'Open File'
|
||||
Top = 61
|
||||
Width = 29
|
||||
Anchors = [akTop, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 5
|
||||
BorderSpacing.Right = 5
|
||||
Caption = '...'
|
||||
NumGlyphs = 0
|
||||
OnClick = btnOpenFileClick
|
||||
ShowHint = True
|
||||
ParentShowHint = False
|
||||
end
|
||||
end
|
||||
object popComponent: TPopupMenu
|
||||
OnPopup = popComponentPopup
|
||||
left = 80
|
||||
|
@ -6,20 +6,39 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, Buttons,
|
||||
ComCtrls, Menus, MenuIntf, ObjectInspector, types, typinfo;
|
||||
ComCtrls, Menus, StdCtrls, MenuIntf, ObjectInspector, types, LazIDEIntf;
|
||||
|
||||
type
|
||||
|
||||
{ THistoryEntry }
|
||||
|
||||
THistoryEntry = class
|
||||
private
|
||||
FBaseDisplay: string;
|
||||
public
|
||||
Comp: TComponent;
|
||||
Display: string;
|
||||
TheUnitName: string;
|
||||
FileName: string;
|
||||
procedure Assign(Other: THistoryEntry);
|
||||
procedure UpdateDisplayName;
|
||||
end;
|
||||
|
||||
{ TIdeInspectForm }
|
||||
|
||||
TIdeInspectForm = class(TForm)
|
||||
ComboHistory: TComboBox;
|
||||
EditUnit: TEdit;
|
||||
EditFile: TEdit;
|
||||
ImageList1: TImageList;
|
||||
menuFollowForm: TMenuItem;
|
||||
menuFollowFrame: TMenuItem;
|
||||
Panel1: TPanel;
|
||||
popComponent: TPopupMenu;
|
||||
popSubComponent: TPopupMenu;
|
||||
popControls: TPopupMenu;
|
||||
popFollowType: TPopupMenu;
|
||||
btnOpenFile: TSpeedButton;
|
||||
Splitter1: TSplitter;
|
||||
ToolBar1: TToolBar;
|
||||
btnComponent: TToolButton;
|
||||
@ -33,7 +52,9 @@ type
|
||||
ToolButtonFollowActive: TToolButton;
|
||||
TreeView1: TTreeView;
|
||||
procedure btnControlsClick(Sender: TObject);
|
||||
procedure btnOpenFileClick(Sender: TObject);
|
||||
procedure btnSubComponentClick(Sender: TObject);
|
||||
procedure ComboHistoryChange(Sender: TObject);
|
||||
procedure menuFollowFormClick(Sender: TObject);
|
||||
procedure menuFollowFrameClick(Sender: TObject);
|
||||
procedure MenuItem1Click(Sender: TObject);
|
||||
@ -48,15 +69,20 @@ type
|
||||
procedure TreeView1Click(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
protected
|
||||
FPropertiesGrid: TCustomPropertiesGrid;
|
||||
FSelected: TComponent;
|
||||
FFollowFrames: Boolean;
|
||||
FHistoryList: TList;
|
||||
FCurEntry: THistoryEntry;
|
||||
FIsUpdatingHistory: Boolean;
|
||||
protected
|
||||
FPropertiesGrid: TCustomPropertiesGrid;
|
||||
procedure SetSelected(AComp: TComponent);
|
||||
procedure UpdateTree;
|
||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||
procedure DoActiveFormChanged(Sender: TObject; Form: TCustomForm);
|
||||
procedure DoActiveControChanged(Sender: TObject; LastControl: TControl);
|
||||
procedure UpdateHistory;
|
||||
procedure UpdateCurrent;
|
||||
public
|
||||
{ public declarations }
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
@ -74,8 +100,7 @@ resourcestring
|
||||
ideinspComponentsOwned = 'Components (Owned)';
|
||||
ideinspRemoveSelectedItemSFromTree = 'Remove selected item(s) from tree';
|
||||
ideinspControlsChildren = 'Controls (Children)';
|
||||
ideinspInspectingNameClassUnit = 'Inspecting %s: %s (Unit: %s)';
|
||||
ideinspInspectingNameClass = 'Inspecting %s: %s';
|
||||
ideinspInspectingNameClass = 'Inspecting %s';
|
||||
ideinspIdeInspector = 'Ide Inspector';
|
||||
|
||||
procedure Register;
|
||||
@ -84,6 +109,9 @@ implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
const
|
||||
MAX_HIST_CNT = 25;
|
||||
|
||||
type
|
||||
|
||||
{ TExtMenuItem }
|
||||
@ -95,6 +123,26 @@ type
|
||||
property TheObject: TPersistent read FTheObject write FTheObject;
|
||||
end;
|
||||
|
||||
{ THistoryEntry }
|
||||
|
||||
procedure THistoryEntry.Assign(Other: THistoryEntry);
|
||||
begin
|
||||
Comp := Other.Comp;
|
||||
FBaseDisplay := Other.FBaseDisplay;
|
||||
Display := Other.Display;
|
||||
TheUnitName := Other.TheUnitName;
|
||||
FileName := Other.FileName;
|
||||
end;
|
||||
|
||||
procedure THistoryEntry.UpdateDisplayName;
|
||||
begin
|
||||
if Comp <> nil then begin
|
||||
FBaseDisplay := Comp.Name + ': ' + Comp.ClassName;
|
||||
Display := FBaseDisplay + ' (' + IntToHex(PtrUInt(Comp), SizeOf(Pointer)*2) + ')';
|
||||
end else
|
||||
Display := FBaseDisplay;
|
||||
end;
|
||||
|
||||
{ TIdeInspectForm }
|
||||
|
||||
procedure TIdeInspectForm.MenuItem1Click(Sender: TObject);
|
||||
@ -107,16 +155,41 @@ begin
|
||||
btnSubComponent.CheckMenuDropdown;
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.ComboHistoryChange(Sender: TObject);
|
||||
var
|
||||
i: LongInt;
|
||||
begin
|
||||
if FIsUpdatingHistory then exit;
|
||||
i := ComboHistory.ItemIndex;
|
||||
// ignore current entry re-select
|
||||
if i <= 0 then
|
||||
exit;
|
||||
if ComboHistory.Items.Count > FHistoryList.Count then begin
|
||||
ComboHistory.Items.Delete(0); // the none-history curent entry
|
||||
dec(i);
|
||||
end;
|
||||
FCurEntry.Assign(THistoryEntry(FHistoryList[i]));
|
||||
if i > 0 then begin
|
||||
FHistoryList.Move(i, 0);
|
||||
ComboHistory.Items.Move(i, 0);
|
||||
end;
|
||||
if FCurEntry.Comp <> nil then
|
||||
SetSelected(FCurEntry.Comp);
|
||||
UpdateCurrent;
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.menuFollowFormClick(Sender: TObject);
|
||||
begin
|
||||
FFollowFrames := False;
|
||||
ToolButtonActiveType.Caption := menuFollowForm.Caption;
|
||||
ToolButtonFollowActive.Down := True;
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.menuFollowFrameClick(Sender: TObject);
|
||||
begin
|
||||
FFollowFrames := True;
|
||||
ToolButtonActiveType.Caption := menuFollowFrame.Caption;
|
||||
ToolButtonFollowActive.Down := True;
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.btnControlsClick(Sender: TObject);
|
||||
@ -124,6 +197,11 @@ begin
|
||||
btnControls.CheckMenuDropdown;
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.btnOpenFileClick(Sender: TObject);
|
||||
begin
|
||||
LazarusIDE.DoOpenEditorFile(EditFile.Text, -1, -1, [ofOnlyIfExists, ofRegularFile]);
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.btnComponentClick(Sender: TObject);
|
||||
begin
|
||||
btnComponent.CheckMenuDropdown;
|
||||
@ -239,8 +317,6 @@ begin
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.SetSelected(AComp: TComponent);
|
||||
var
|
||||
TypeInfo: PTypeData;
|
||||
begin
|
||||
FSelected := AComp;
|
||||
FPropertiesGrid.TIObject := FSelected;
|
||||
@ -249,17 +325,14 @@ begin
|
||||
(FSelected is TWinControl) and (TWinControl(FSelected).ControlCount > 0);
|
||||
UpdateTree;
|
||||
|
||||
if FSelected <> nil then begin
|
||||
TypeInfo := GetTypeData(PTypeInfo(FSelected.ClassType.ClassInfo));
|
||||
if (TypeInfo <> nil) then begin
|
||||
Caption := Format(ideinspInspectingNameClassUnit, [FSelected.Name, FSelected.ClassName,
|
||||
TypeInfo ^ .UnitName]);
|
||||
end
|
||||
else
|
||||
Caption := Format(ideinspInspectingNameClass, [FSelected.Name, FSelected.ClassName]);
|
||||
end
|
||||
else
|
||||
Caption := ideinspIdeInspector
|
||||
// keep date, if the component gets destroyed
|
||||
if FCurEntry.Comp <> FSelected then begin
|
||||
FCurEntry.Comp := FSelected;
|
||||
FCurEntry.UpdateDisplayName;
|
||||
FCurEntry.TheUnitName := FSelected.UnitName;
|
||||
FCurEntry.FileName := LazarusIDE.FindUnitFile(FCurEntry.TheUnitName);
|
||||
UpdateHistory;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.UpdateTree;
|
||||
@ -291,7 +364,10 @@ procedure TIdeInspectForm.UpdateTree;
|
||||
var
|
||||
ANode: TTreeNode;
|
||||
begin
|
||||
if FSelected = nil then exit;
|
||||
if FSelected = nil then begin
|
||||
TreeView1.Selected := nil;
|
||||
exit;
|
||||
end;
|
||||
|
||||
ANode := FindNode(FSelected);
|
||||
ANode.Expanded := True;
|
||||
@ -301,7 +377,25 @@ end;
|
||||
procedure TIdeInspectForm.Notification(AComponent: TComponent; Operation: TOperation);
|
||||
var
|
||||
ANode: TTreeNode;
|
||||
i: Integer;
|
||||
f: Boolean;
|
||||
begin
|
||||
if (Operation = opRemove) and (FCurEntry <> nil) and (FCurEntry.Comp = AComponent) then begin
|
||||
FCurEntry.Comp := nil;
|
||||
FCurEntry.UpdateDisplayName;
|
||||
UpdateCurrent;
|
||||
end;
|
||||
if (Operation = opRemove) and (FHistoryList <> nil) then begin
|
||||
f := False;
|
||||
for i := 0 to FHistoryList.Count - 1 do
|
||||
if THistoryEntry(FHistoryList[i]).Comp = AComponent then begin
|
||||
THistoryEntry(FHistoryList[i]).Comp := nil;
|
||||
THistoryEntry(FHistoryList[i]).UpdateDisplayName;
|
||||
f := True;
|
||||
end;
|
||||
if f then
|
||||
UpdateHistory;
|
||||
end;
|
||||
if (Operation = opRemove) and (TreeView1 <> nil) then begin
|
||||
ANode := TreeView1.Items.FindNodeWithData(AComponent);
|
||||
if ANode <> nil then begin
|
||||
@ -342,8 +436,65 @@ begin
|
||||
SetSelected(Screen.ActiveControl.Owner);
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.UpdateHistory;
|
||||
var
|
||||
i: Integer;
|
||||
FNewHist: THistoryEntry;
|
||||
begin
|
||||
FIsUpdatingHistory := True;
|
||||
|
||||
i := -1;
|
||||
if (FCurEntry.Comp <> nil) and
|
||||
( (FCurEntry.Comp is TCustomForm) or (FCurEntry.Comp is TCustomFrame) )
|
||||
then begin
|
||||
i := FHistoryList.Count - 1;
|
||||
while (i >= 0) and (THistoryEntry(FHistoryList[i]).Comp <> FCurEntry.Comp) do
|
||||
dec(i);
|
||||
if i < 0 then begin
|
||||
FNewHist := THistoryEntry.Create;
|
||||
FNewHist.Assign(FCurEntry);
|
||||
FHistoryList.Insert(0, FNewHist);
|
||||
while FHistoryList.Count > MAX_HIST_CNT do begin
|
||||
THistoryEntry(FHistoryList[FHistoryList.Count - 1]).Free;
|
||||
FHistoryList.Delete(FHistoryList.Count - 1);
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
if i > 0 then
|
||||
FHistoryList.Move(i, 0);
|
||||
end;
|
||||
end;
|
||||
|
||||
ComboHistory.Clear;
|
||||
if (FHistoryList.Count = 0) or
|
||||
(THistoryEntry(FHistoryList[0]).Display <> FCurEntry.Display)
|
||||
then
|
||||
ComboHistory.Items.Add(FCurEntry.Display);
|
||||
for i := 0 to FHistoryList.Count - 1 do
|
||||
ComboHistory.Items.Add(THistoryEntry(FHistoryList[i]).Display);
|
||||
|
||||
FIsUpdatingHistory := False;
|
||||
UpdateCurrent;
|
||||
end;
|
||||
|
||||
procedure TIdeInspectForm.UpdateCurrent;
|
||||
begin
|
||||
FIsUpdatingHistory := True;
|
||||
ComboHistory.Text := FCurEntry.Display;
|
||||
EditUnit.Text := FCurEntry.TheUnitName;
|
||||
EditFile.Text := FCurEntry.FileName;
|
||||
if FCurEntry.Comp<> nil then
|
||||
Caption := Format(ideinspInspectingNameClass, [FCurEntry.Display])
|
||||
else
|
||||
Caption := ideinspIdeInspector;
|
||||
btnOpenFile.Enabled := EditFile.Text <> '';
|
||||
FIsUpdatingHistory := False;
|
||||
end;
|
||||
|
||||
constructor TIdeInspectForm.Create(TheOwner: TComponent);
|
||||
begin
|
||||
FHistoryList := TList.Create;
|
||||
FCurEntry := THistoryEntry.Create;
|
||||
Screen.AddHandlerActiveFormChanged(@DoActiveFormChanged);
|
||||
Screen.AddHandlerActiveControlChanged(@DoActiveControChanged);
|
||||
inherited Create(TheOwner);
|
||||
@ -360,16 +511,21 @@ begin
|
||||
btnControls.Caption := ideinspControlsChildren;
|
||||
btnRemoveSelected.Hint := ideinspRemoveSelectedItemSFromTree;
|
||||
|
||||
FFollowFrames := False;
|
||||
ToolButtonActiveType.Caption := menuFollowForm.Caption;
|
||||
|
||||
FFollowFrames := True;
|
||||
ToolButtonActiveType.Caption := menuFollowFrame.Caption;
|
||||
SetSelected(Application);
|
||||
end;
|
||||
|
||||
destructor TIdeInspectForm.Destroy;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Screen.RemoveHandlerActiveControlChanged(@DoActiveControChanged);
|
||||
Screen.RemoveHandlerActiveFormChanged(@DoActiveFormChanged);
|
||||
for i := 0 to FHistoryList.Count - 1 do
|
||||
THistoryEntry(FHistoryList[i]).Free;
|
||||
FreeAndNil(FHistoryList);
|
||||
FreeAndNil(FCurEntry);
|
||||
FreeAndNil(TreeView1);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user