IDE: component list: add "keep open" option for Delphi behavior. Issue #30459

git-svn-id: trunk@53260 -
This commit is contained in:
ondrej 2016-10-29 09:59:25 +00:00
parent f7daccaf3b
commit 6e6f2e7c16
4 changed files with 142 additions and 65 deletions

View File

@ -12,11 +12,10 @@ object ComponentListForm: TComponentListForm
OnKeyDown = FormKeyDown OnKeyDown = FormKeyDown
OnShow = FormShow OnShow = FormShow
LCLVersion = '1.7' LCLVersion = '1.7'
Visible = False
object PageControl: TPageControl object PageControl: TPageControl
Left = 0 Left = 0
Height = 394 Height = 397
Top = 31 Top = 27
Width = 300 Width = 300
ActivePage = TabSheetList ActivePage = TabSheetList
Align = alClient Align = alClient
@ -25,24 +24,24 @@ object ComponentListForm: TComponentListForm
OnChange = PageControlChange OnChange = PageControlChange
object TabSheetList: TTabSheet object TabSheetList: TTabSheet
Caption = 'List' Caption = 'List'
ClientHeight = 361 ClientHeight = 369
ClientWidth = 296 ClientWidth = 292
object Panel7: TPanel object Panel7: TPanel
Left = 0 Left = 0
Height = 361 Height = 369
Top = 0 Top = 0
Width = 296 Width = 292
Align = alClient Align = alClient
BevelOuter = bvNone BevelOuter = bvNone
BorderWidth = 2 BorderWidth = 2
ClientHeight = 361 ClientHeight = 369
ClientWidth = 296 ClientWidth = 292
TabOrder = 0 TabOrder = 0
object ListTree: TTreeView object ListTree: TTreeView
Left = 2 Left = 2
Height = 357 Height = 365
Top = 2 Top = 2
Width = 292 Width = 288
Align = alClient Align = alClient
DefaultItemHeight = 26 DefaultItemHeight = 26
Images = imListPalette Images = imListPalette
@ -138,22 +137,22 @@ object ComponentListForm: TComponentListForm
end end
object FilterPanel: TPanel object FilterPanel: TPanel
Left = 0 Left = 0
Height = 31 Height = 27
Top = 0 Top = 0
Width = 300 Width = 300
Align = alTop Align = alTop
AutoSize = True AutoSize = True
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 31 ClientHeight = 27
ClientWidth = 300 ClientWidth = 300
TabOrder = 0 TabOrder = 0
object LabelSearch: TLabel object LabelSearch: TLabel
AnchorSideLeft.Control = FilterPanel AnchorSideLeft.Control = FilterPanel
AnchorSideTop.Control = FilterPanel AnchorSideTop.Control = FilterPanel
Left = 6 Left = 6
Height = 19 Height = 15
Top = 6 Top = 6
Width = 86 Width = 63
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'LabelSearch' Caption = 'LabelSearch'
ParentColor = False ParentColor = False
@ -163,10 +162,10 @@ object ComponentListForm: TComponentListForm
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = LabelSearch AnchorSideTop.Control = LabelSearch
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 98 Left = 75
Height = 29 Height = 23
Top = 1 Top = 2
Width = 198 Width = 221
OnAfterFilter = TreeFilterEdAfterFilter OnAfterFilter = TreeFilterEdAfterFilter
ButtonWidth = 23 ButtonWidth = 23
NumGlyphs = 1 NumGlyphs = 1
@ -177,23 +176,37 @@ object ComponentListForm: TComponentListForm
FilteredTreeview = ListTree FilteredTreeview = ListTree
end end
end end
object ButtonPanel: TButtonPanel object ButtonPanel: TPanel
Left = 6 Left = 0
Height = 30 Height = 43
Top = 431 Top = 424
Width = 288 Width = 300
OKButton.Name = 'OKButton' Align = alBottom
OKButton.DefaultCaption = True BevelOuter = bvNone
OKButton.OnClick = OKButtonClick ClientHeight = 43
HelpButton.Name = 'HelpButton' ClientWidth = 300
HelpButton.DefaultCaption = True
CloseButton.Name = 'CloseButton'
CloseButton.DefaultCaption = True
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 2 TabOrder = 2
ShowButtons = [pbOK] object chbKeepOpen: TCheckBox
ShowBevel = False Left = 8
Height = 19
Top = 10
Width = 95
Caption = 'chbKeepOpen'
OnChange = chbKeepOpenChange
TabOrder = 0
end
object OKButton: TButton
Left = 208
Height = 25
Top = 8
Width = 85
Anchors = [akTop, akRight]
Caption = 'OKButton'
Default = True
ModalResult = 1
OnClick = OKButtonClick
TabOrder = 1
end
end end
object imListPalette: TImageList object imListPalette: TImageList
Height = 24 Height = 24

View File

@ -33,23 +33,25 @@ interface
uses uses
Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls, Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs, ComCtrls, Menus, Dialogs, LazarusIDEStrConsts, ComponentReg, PackageDefs,
IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs; IDEImagesIntf, TreeFilterEdit, FormEditingIntf, PropEdits, IDEOptionDefs,
EnvironmentOpts, Designer;
type type
{ TComponentListForm } { TComponentListForm }
TComponentListForm = class(TForm) TComponentListForm = class(TForm)
chbKeepOpen: TCheckBox;
imListPalette: TImageList; imListPalette: TImageList;
imInheritance: TImageList; imInheritance: TImageList;
ListTree: TTreeView; ListTree: TTreeView;
ButtonPanel: TButtonPanel; ButtonPanel: TPanel;
miCollapse: TMenuItem; miCollapse: TMenuItem;
miCollapseAll: TMenuItem; miCollapseAll: TMenuItem;
miExpand: TMenuItem; miExpand: TMenuItem;
miExpandAll: TMenuItem; miExpandAll: TMenuItem;
OKButton: TPanelBitBtn; OKButton: TButton;
LabelSearch: TLabel; LabelSearch: TLabel;
PageControl: TPageControl; PageControl: TPageControl;
FilterPanel: TPanel; FilterPanel: TPanel;
@ -64,6 +66,7 @@ type
TabSheetList: TTabSheet; TabSheetList: TTabSheet;
tmDeselect: TTimer; tmDeselect: TTimer;
TreeFilterEd: TTreeFilterEdit; TreeFilterEd: TTreeFilterEdit;
procedure chbKeepOpenChange(Sender: TObject);
procedure FormActivate(Sender: TObject); procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure ListTreeSelectionChanged(Sender: TObject); procedure ListTreeSelectionChanged(Sender: TObject);
@ -90,6 +93,8 @@ type
FIgnoreSelection: Boolean; FIgnoreSelection: Boolean;
FPageControlChange: Boolean; FPageControlChange: Boolean;
FActiveTree: TTreeView; FActiveTree: TTreeView;
FAddCompNewLeft, FAddCompNewTop: Integer;
FAddCompNewParent: TComponent;
procedure ClearSelection; procedure ClearSelection;
procedure SelectionWasChanged; procedure SelectionWasChanged;
procedure ComponentWasAdded({%H-}ALookupRoot, {%H-}AComponent: TComponent; procedure ComponentWasAdded({%H-}ALookupRoot, {%H-}AComponent: TComponent;
@ -97,6 +102,8 @@ type
procedure DoComponentInheritence(Comp: TRegisteredComponent); procedure DoComponentInheritence(Comp: TRegisteredComponent);
procedure UpdateComponents; procedure UpdateComponents;
procedure UpdateButtonState; procedure UpdateButtonState;
function IsDocked: Boolean;
procedure AddSelectedComponent;
protected protected
procedure UpdateShowing; override; procedure UpdateShowing; override;
public public
@ -126,7 +133,8 @@ begin
TabSheetList.Caption := lisCmpLstList; TabSheetList.Caption := lisCmpLstList;
TabSheetPaletteTree.Caption := lisCmpLstPalette; TabSheetPaletteTree.Caption := lisCmpLstPalette;
TabSheetInheritance.Caption := lisCmpLstInheritance; TabSheetInheritance.Caption := lisCmpLstInheritance;
ButtonPanel.OKButton.Caption := lisUseAndClose; OKButton.Caption := lisUse;
chbKeepOpen.Caption := lisKeepOpen;
imListPalette.Width := ComponentPaletteImageWidth; imListPalette.Width := ComponentPaletteImageWidth;
imListPalette.Height := ComponentPaletteImageHeight; imListPalette.Height := ComponentPaletteImageHeight;
@ -145,6 +153,56 @@ begin
IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged); IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded); IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
end; end;
chbKeepOpen.Checked := EnvironmentOptions.ComponentListKeepOpen;
end;
procedure TComponentListForm.AddSelectedComponent;
var
AComponent: TRegisteredComponent;
ASelections: TPersistentSelectionList;
NewParent: TComponent;
CurDesigner: TDesigner;
begin
AComponent := GetSelectedComponent;
ASelections := TPersistentSelectionList.Create;
try
GlobalDesignHook.GetSelection(ASelections);
if (ASelections.Count>0) and (ASelections[0] is TComponent) then
NewParent := TComponent(ASelections[0])
else if GlobalDesignHook.LookupRoot is TComponent then
NewParent := TComponent(GlobalDesignHook.LookupRoot)
else
NewParent := nil;
finally
ASelections.Free;
end;
if NewParent=nil then
Exit;
CurDesigner:=TDesigner(FindRootDesigner(NewParent));
if CurDesigner=nil then
Exit;
CurDesigner.AddComponentCheckParent(NewParent, NewParent, nil, AComponent.ComponentClass);
if NewParent=nil then
Exit;
if FAddCompNewParent<>NewParent then
begin
FAddCompNewLeft := 0;
FAddCompNewTop := 0;
FAddCompNewParent := NewParent;
end;
Inc(FAddCompNewLeft, 8);
Inc(FAddCompNewTop, 8);
CurDesigner.AddComponent(AComponent, AComponent.ComponentClass, NewParent, FAddCompNewLeft, FAddCompNewTop, 0, 0);
end;
procedure TComponentListForm.chbKeepOpenChange(Sender: TObject);
begin
EnvironmentOptions.ComponentListKeepOpen := chbKeepOpen.Checked;
end; end;
destructor TComponentListForm.Destroy; destructor TComponentListForm.Destroy;
@ -158,7 +216,7 @@ end;
procedure TComponentListForm.FormShow(Sender: TObject); procedure TComponentListForm.FormShow(Sender: TObject);
begin begin
//DebugLn(['*** TComponentListForm.FormShow, Parent=', Parent, ', Parent.Parent=', ParentParent]); //DebugLn(['*** TComponentListForm.FormShow, Parent=', Parent, ', Parent.Parent=', ParentParent]);
ButtonPanel.Visible := (HostDockSite=Nil) or (HostDockSite.Parent=Nil); ButtonPanel.Visible := not IsDocked;
if ButtonPanel.Visible then if ButtonPanel.Visible then
begin // ComponentList is undocked begin // ComponentList is undocked
PageControl.AnchorSideBottom.Side := asrTop; PageControl.AnchorSideBottom.Side := asrTop;
@ -231,6 +289,11 @@ begin
Result := GetSelectedTreeComp(InheritanceTree) Result := GetSelectedTreeComp(InheritanceTree)
end; end;
function TComponentListForm.IsDocked: Boolean;
begin
Result := (HostDockSite<>Nil) and (HostDockSite.Parent<>Nil);
end;
procedure TComponentListForm.ComponentWasAdded(ALookupRoot, AComponent: TComponent; procedure TComponentListForm.ComponentWasAdded(ALookupRoot, AComponent: TComponent;
ARegisteredComponent: TRegisteredComponent); ARegisteredComponent: TRegisteredComponent);
begin begin
@ -240,7 +303,7 @@ end;
procedure TComponentListForm.UpdateButtonState; procedure TComponentListForm.UpdateButtonState;
begin begin
ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent); OKButton.Enabled := Assigned(GetSelectedComponent);
end; end;
procedure TComponentListForm.UpdateShowing; procedure TComponentListForm.UpdateShowing;
@ -459,23 +522,10 @@ end;
procedure TComponentListForm.FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure TComponentListForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin begin
if Parent=nil then begin if not FKeepSelected then
begin
ClearSelection; ClearSelection;
if not fKeepSelected then IDEComponentPalette.Selected := Nil;
IDEComponentPalette.Selected := Nil;
end
else begin
// Using a dock manager...
CloseAction := caNone;
//todo: helper function in DockManager or IDEDockMaster for closing forms.
// Only close the window if it's floating.
// AnchorDocking doesn't seem to initialize 'FloatingDockSiteClass' so we can't just check 'Floating'.
// Also, AnchorDocking use nested forms, so the check for HostDockSite.Parent.
if Assigned(HostDockSite) and (HostDockSite.DockClientCount <= 1)
and (HostDockSite is TCustomForm) and (HostDockSite.Parent = nil) then
begin
TCustomForm(HostDockSite).Close;
end;
end; end;
FKeepSelected := False; FKeepSelected := False;
end; end;
@ -484,7 +534,7 @@ procedure TComponentListForm.FormKeyDown(Sender: TObject; var Key: Word; Shift:
begin begin
if Key=VK_ESCAPE then if Key=VK_ESCAPE then
begin begin
if IDEComponentPalette.Selected = nil then //close only if no component is selected if (IDEComponentPalette.Selected = nil) and not IsDocked then //close only if no component is selected
Close Close
else else
ClearSelection; //unselect if component is selected ClearSelection; //unselect if component is selected
@ -497,13 +547,15 @@ var
AComponent: TRegisteredComponent; AComponent: TRegisteredComponent;
begin begin
AComponent := GetSelectedComponent; AComponent := GetSelectedComponent;
if AComponent<>nil then begin if AComponent=nil then
FPageControlChange:=True; Exit;
IDEComponentPalette.Selected := AComponent;
if IsDocked or chbKeepOpen.Checked then
AddSelectedComponent
else
begin
FKeepSelected := True; FKeepSelected := True;
Close; Close;
if Assigned(IDEComponentPalette.OnClassSelected) then
IDEComponentPalette.OnClassSelected(Self);
end; end;
end; end;

View File

@ -552,6 +552,9 @@ type
FNewUnitTemplate: string; FNewUnitTemplate: string;
FFileDialogFilter: string; FFileDialogFilter: string;
//component list
FComponentListKeepOpen: Boolean;
// Desktop // Desktop
FDesktops: TDesktopOptList; FDesktops: TDesktopOptList;
FDesktop: TDesktopOpt; FDesktop: TDesktopOpt;
@ -850,6 +853,9 @@ type
property MsgColors[u: TMessageLineUrgency]: TColor read GetMsgColors write SetMsgColors; property MsgColors[u: TMessageLineUrgency]: TColor read GetMsgColors write SetMsgColors;
property MsgViewShowFPCMsgLinesCompiled: Boolean read FMsgViewShowFPCMsgLinesCompiled write FMsgViewShowFPCMsgLinesCompiled; property MsgViewShowFPCMsgLinesCompiled: Boolean read FMsgViewShowFPCMsgLinesCompiled write FMsgViewShowFPCMsgLinesCompiled;
//component list
property ComponentListKeepOpen: Boolean read FComponentListKeepOpen write FComponentListKeepOpen;
// glyphs // glyphs
property ShowButtonGlyphs: TApplicationShowGlyphs read FShowButtonGlyphs write FShowButtonGlyphs; property ShowButtonGlyphs: TApplicationShowGlyphs read FShowButtonGlyphs write FShowButtonGlyphs;
property ShowMenuGlyphs: TApplicationShowGlyphs read FShowMenuGlyphs write FShowMenuGlyphs; property ShowMenuGlyphs: TApplicationShowGlyphs read FShowMenuGlyphs write FShowMenuGlyphs;
@ -1828,6 +1834,9 @@ begin
MsgViewFilters.LoadFromXMLConfig(FXMLCfg,'MsgView/Filters/'); MsgViewFilters.LoadFromXMLConfig(FXMLCfg,'MsgView/Filters/');
FMsgViewShowFPCMsgLinesCompiled:=FXMLCfg.GetValue(Path+'MsgView/FPCMsg/ShowLinesCompiled',false); FMsgViewShowFPCMsgLinesCompiled:=FXMLCfg.GetValue(Path+'MsgView/FPCMsg/ShowLinesCompiled',false);
//component list
FComponentListKeepOpen:=FXMLCfg.GetValue(Path+'ComponentList/KeepOpen',false);
// glyphs // glyphs
FShowButtonGlyphs := TApplicationShowGlyphs(FXMLCfg.GetValue(Path+'ShowButtonGlyphs/Value', FShowButtonGlyphs := TApplicationShowGlyphs(FXMLCfg.GetValue(Path+'ShowButtonGlyphs/Value',
Ord(sbgSystem))); Ord(sbgSystem)));
@ -2175,6 +2184,9 @@ begin
MsgViewFilters.SaveToXMLConfig(FXMLCfg,'MsgView/Filters/'); MsgViewFilters.SaveToXMLConfig(FXMLCfg,'MsgView/Filters/');
FXMLCfg.SetDeleteValue(Path+'MsgView/FPCMsg/ShowLinesCompiled',FMsgViewShowFPCMsgLinesCompiled,false); FXMLCfg.SetDeleteValue(Path+'MsgView/FPCMsg/ShowLinesCompiled',FMsgViewShowFPCMsgLinesCompiled,false);
//component list
FXMLCfg.SetDeleteValue(Path+'ComponentList/KeepOpen',FComponentListKeepOpen,false);
// glyphs // glyphs
FXMLCfg.SetDeleteValue(Path+'ShowButtonGlyphs/Value',Ord(FShowButtonGlyphs), Ord(sbgSystem)); FXMLCfg.SetDeleteValue(Path+'ShowButtonGlyphs/Value',Ord(FShowButtonGlyphs), Ord(sbgSystem));
FXMLCfg.SetDeleteValue(Path+'ShowMenuGlyphs/Value',Ord(FShowMenuGlyphs), Ord(sbgSystem)); FXMLCfg.SetDeleteValue(Path+'ShowMenuGlyphs/Value',Ord(FShowMenuGlyphs), Ord(sbgSystem));

View File

@ -211,6 +211,7 @@ resourcestring
lisSelectionTool = 'Selection tool'; lisSelectionTool = 'Selection tool';
lisClickToSelectPalettePage = 'Click to Select Palette Page'; lisClickToSelectPalettePage = 'Click to Select Palette Page';
lisTotalPages = 'Total Pages: %s'; lisTotalPages = 'Total Pages: %s';
lisKeepOpen = 'keep open';
// macros // macros
lisCursorColumnInCurrentEditor = 'Cursor column in current editor'; lisCursorColumnInCurrentEditor = 'Cursor column in current editor';
@ -345,7 +346,6 @@ resourcestring
lisKMSelectLineEnd = 'Select Line End'; lisKMSelectLineEnd = 'Select Line End';
lisKMSelectPageTop = 'Select Page Top'; lisKMSelectPageTop = 'Select Page Top';
lisKMSelectPageBottom = 'Select Page Bottom'; lisKMSelectPageBottom = 'Select Page Bottom';
lisUseAndClose = 'Use and close';
lisMenuSelect = 'Select'; lisMenuSelect = 'Select';
lisMenuMultiPaste = 'MultiPaste ...'; lisMenuMultiPaste = 'MultiPaste ...';
lisMenuSelectAll = 'Select All'; lisMenuSelectAll = 'Select All';