View Issue Details

IDProjectCategoryView StatusLast Update
0030459LazarusPatchpublic2016-10-29 11:59
ReporterMarkusAssigned ToOndrej Pokorny 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformAllOSAllOS VersionAll
Product Version1.7 (SVN)Product Build 
Target Version1.8Fixed in Version1.7 (SVN) 
Summary0030459: [Enhancement] ComponentList: On Enter the selected component is added to the Designer
DescriptionWhen you filter/search for a component and you press ENTER the current selected component is added to the designer. So you don't have to switch to the mouse every time you want to add a component. Just add all components at once, and afterwards place it where you need it.
This behaviour is similar as in Delphi, which is very pleasant.
TagsNo tags attached.
Fixed in Revision53259, 53260
LazTarget1.8
Widgetset
Attached Files
  • componentlist.patch (8,962 bytes)
    Index: componentlist.lfm
    ===================================================================
    --- componentlist.lfm	(revision 52792)
    +++ componentlist.lfm	(working copy)
    @@ -11,12 +11,11 @@
       OnClose = FormClose
       OnKeyDown = FormKeyDown
       OnShow = FormShow
    -  LCLVersion = '1.7'
       Visible = False
       object PageControl: TPageControl
         Left = 0
    -    Height = 394
    -    Top = 31
    +    Height = 402
    +    Top = 27
         Width = 300
         ActivePage = TabSheetList
         Align = alClient
    @@ -25,24 +24,24 @@
         OnChange = PageControlChange
         object TabSheetList: TTabSheet
           Caption = 'List'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel7: TPanel
             Left = 0
    -        Height = 361
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 2
    -        ClientHeight = 361
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object ListTree: TTreeView
               Left = 2
    -          Height = 357
    +          Height = 370
               Top = 2
    -          Width = 292
    +          Width = 288
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -55,7 +54,6 @@
               ShowRoot = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
             end
    @@ -63,24 +61,24 @@
         end
         object TabSheetPaletteTree: TTabSheet
           Caption = 'Palette'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object pnPaletteTree: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object PalletteTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -92,7 +90,6 @@
               ShowLines = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
             end
    @@ -100,24 +97,24 @@
         end
         object TabSheetInheritance: TTabSheet
           Caption = 'Inheritance'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel6: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object InheritanceTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -129,7 +126,6 @@
               ScrollBars = ssAutoBoth
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
             end
    @@ -138,22 +134,22 @@
       end
       object FilterPanel: TPanel
         Left = 0
    -    Height = 31
    +    Height = 27
         Top = 0
         Width = 300
         Align = alTop
         AutoSize = True
         BevelOuter = bvNone
    -    ClientHeight = 31
    +    ClientHeight = 27
         ClientWidth = 300
         TabOrder = 0
         object LabelSearch: TLabel
           AnchorSideLeft.Control = FilterPanel
           AnchorSideTop.Control = FilterPanel
           Left = 6
    -      Height = 19
    +      Height = 15
           Top = 6
    -      Width = 86
    +      Width = 63
           BorderSpacing.Around = 6
           Caption = 'LabelSearch'
           ParentColor = False
    @@ -163,10 +159,10 @@
           AnchorSideLeft.Side = asrBottom
           AnchorSideTop.Control = LabelSearch
           AnchorSideTop.Side = asrCenter
    -      Left = 98
    -      Height = 29
    -      Top = 1
    -      Width = 198
    +      Left = 75
    +      Height = 23
    +      Top = 2
    +      Width = 221
           OnAfterFilter = TreeFilterEdAfterFilter
           ButtonWidth = 23
           NumGlyphs = 1
    @@ -179,8 +175,8 @@
       end
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 30
    -    Top = 431
    +    Height = 26
    +    Top = 435
         Width = 288
         OKButton.Name = 'OKButton'
         OKButton.DefaultCaption = True
    Index: componentlist.pas
    ===================================================================
    --- componentlist.pas	(revision 52792)
    +++ componentlist.pas	(working copy)
    @@ -34,7 +34,7 @@
     uses
       Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
       ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
    -  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
    +  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits;
     
     type
     
    @@ -78,7 +78,6 @@
         procedure tmDeselectTimer(Sender: TObject);
         procedure TreeFilterEdAfterFilter(Sender: TObject);
         procedure PageControlChange(Sender: TObject);
    -    procedure TreeKeyPress(Sender: TObject; var Key: char);
         procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
       private
         PrevPageIndex: Integer;
    @@ -97,6 +96,8 @@
         procedure DoComponentInheritence(Comp: TRegisteredComponent);
         procedure UpdateComponents;
         procedure UpdateButtonState;
    +
    +    procedure CreateComponentOnDesigner;
       protected
         procedure UpdateShowing; override;
       public
    @@ -243,6 +244,50 @@
       ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
     end;
     
    +procedure TComponentListForm.CreateComponentOnDesigner;
    +var
    +  TypeClass: TComponentClass;
    +  ParentComp: TComponent;
    +  X, Y: integer;
    +  AComponent: TComponent;
    +  DisableAutoSize: Boolean;
    +  selComponent: TRegisteredComponent;
    +begin
    +  selComponent := GetSelectedComponent;
    +
    +  if FormEditingHook<>nil then
    +  begin
    +    TypeClass:=selComponent.ComponentClass;
    +    if assigned(selComponent.OnGetCreationClass) then
    +      selComponent.OnGetCreationClass(Self,TypeClass);
    +    if TypeClass=nil then
    +      exit;
    +
    +    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
    +    if ParentComp=nil then
    +      Exit;
    +    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
    +      exit;
    +    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
    +    DisableAutoSize:=true;
    +    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
    +      DisableAutoSize);
    +    if AComponent<>nil then
    +    begin
    +      if DisableAutoSize and (AComponent is TControl) then
    +        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
    +      GlobalDesignHook.PersistentAdded(AComponent,true);
    +    end;
    +
    +    ClearSelection;
    +    TreeFilterEd.SelectAll;
    +    TreeFilterEd.SetFocus;
    +
    +    if Assigned(IDEComponentPalette.OnClassSelected) then
    +      IDEComponentPalette.OnClassSelected(Self);
    +  end;
    +end;
    +
     procedure TComponentListForm.UpdateShowing;
     begin
       if (ButtonPanel<>nil) and ButtonPanel.Visible then
    @@ -383,7 +428,7 @@
     procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
     // This is used for all 3 treeviews
     begin
    -  OKButtonClick(nil);       // Select and close this form
    +  CreateComponentOnDesigner;
     end;
     
     procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
    @@ -415,13 +460,6 @@
       end
     end;
     
    -procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
    -// This is used for all 3 treeviews
    -begin
    -  if Key = Char(VK_RETURN) then
    -    ComponentsDblClick(Sender);
    -end;
    -
     procedure TComponentListForm.PageControlChange(Sender: TObject);
     begin
       FPageControlChange := True;
    @@ -488,6 +526,10 @@
           Close
         else
           ClearSelection; //unselect if component is selected
    +  end
    +  else if Key = VK_RETURN then
    +  begin
    +    CreateComponentOnDesigner;
       end;
     end;
     
    
    componentlist.patch (8,962 bytes)
  • componentlist2.patch (8,899 bytes)
    Index: componentlist.lfm
    ===================================================================
    --- componentlist.lfm	(revision 52792)
    +++ componentlist.lfm	(working copy)
    @@ -15,8 +15,8 @@
       Visible = False
       object PageControl: TPageControl
         Left = 0
    -    Height = 394
    -    Top = 31
    +    Height = 402
    +    Top = 27
         Width = 300
         ActivePage = TabSheetList
         Align = alClient
    @@ -25,24 +25,24 @@
         OnChange = PageControlChange
         object TabSheetList: TTabSheet
           Caption = 'List'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel7: TPanel
             Left = 0
    -        Height = 361
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 2
    -        ClientHeight = 361
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object ListTree: TTreeView
               Left = 2
    -          Height = 357
    +          Height = 370
               Top = 2
    -          Width = 292
    +          Width = 288
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -55,7 +55,6 @@
               ShowRoot = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
             end
    @@ -63,24 +62,24 @@
         end
         object TabSheetPaletteTree: TTabSheet
           Caption = 'Palette'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object pnPaletteTree: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object PalletteTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -92,7 +91,6 @@
               ShowLines = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
             end
    @@ -100,24 +98,24 @@
         end
         object TabSheetInheritance: TTabSheet
           Caption = 'Inheritance'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel6: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object InheritanceTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -129,7 +127,6 @@
               ScrollBars = ssAutoBoth
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
             end
    @@ -138,22 +135,22 @@
       end
       object FilterPanel: TPanel
         Left = 0
    -    Height = 31
    +    Height = 27
         Top = 0
         Width = 300
         Align = alTop
         AutoSize = True
         BevelOuter = bvNone
    -    ClientHeight = 31
    +    ClientHeight = 27
         ClientWidth = 300
         TabOrder = 0
         object LabelSearch: TLabel
           AnchorSideLeft.Control = FilterPanel
           AnchorSideTop.Control = FilterPanel
           Left = 6
    -      Height = 19
    +      Height = 15
           Top = 6
    -      Width = 86
    +      Width = 63
           BorderSpacing.Around = 6
           Caption = 'LabelSearch'
           ParentColor = False
    @@ -163,10 +160,10 @@
           AnchorSideLeft.Side = asrBottom
           AnchorSideTop.Control = LabelSearch
           AnchorSideTop.Side = asrCenter
    -      Left = 98
    -      Height = 29
    -      Top = 1
    -      Width = 198
    +      Left = 75
    +      Height = 23
    +      Top = 2
    +      Width = 221
           OnAfterFilter = TreeFilterEdAfterFilter
           ButtonWidth = 23
           NumGlyphs = 1
    @@ -179,8 +176,8 @@
       end
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 30
    -    Top = 431
    +    Height = 26
    +    Top = 435
         Width = 288
         OKButton.Name = 'OKButton'
         OKButton.DefaultCaption = True
    Index: componentlist.pas
    ===================================================================
    --- componentlist.pas	(revision 52792)
    +++ componentlist.pas	(working copy)
    @@ -34,7 +34,7 @@
     uses
       Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
       ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
    -  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
    +  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits;
     
     type
     
    @@ -78,7 +78,6 @@
         procedure tmDeselectTimer(Sender: TObject);
         procedure TreeFilterEdAfterFilter(Sender: TObject);
         procedure PageControlChange(Sender: TObject);
    -    procedure TreeKeyPress(Sender: TObject; var Key: char);
         procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
       private
         PrevPageIndex: Integer;
    @@ -97,6 +96,8 @@
         procedure DoComponentInheritence(Comp: TRegisteredComponent);
         procedure UpdateComponents;
         procedure UpdateButtonState;
    +
    +    procedure CreateComponentOnDesigner;
       protected
         procedure UpdateShowing; override;
       public
    @@ -243,6 +244,50 @@
       ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
     end;
     
    +procedure TComponentListForm.CreateComponentOnDesigner;
    +var
    +  TypeClass: TComponentClass;
    +  ParentComp: TComponent;
    +  X, Y: integer;
    +  AComponent: TComponent;
    +  DisableAutoSize: Boolean;
    +  selComponent: TRegisteredComponent;
    +begin
    +  selComponent := GetSelectedComponent;
    +
    +  if Assigned(FormEditingHook) and Assigned(selComponent) then
    +  begin
    +    TypeClass:=selComponent.ComponentClass;
    +    if assigned(selComponent.OnGetCreationClass) then
    +      selComponent.OnGetCreationClass(Self,TypeClass);
    +    if TypeClass=nil then
    +      exit;
    +
    +    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
    +    if ParentComp=nil then
    +      Exit;
    +    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
    +      exit;
    +    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
    +    DisableAutoSize:=true;
    +    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
    +      DisableAutoSize);
    +    if AComponent<>nil then
    +    begin
    +      if DisableAutoSize and (AComponent is TControl) then
    +        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
    +      GlobalDesignHook.PersistentAdded(AComponent,true);
    +    end;
    +
    +    ClearSelection;
    +    TreeFilterEd.SelectAll;
    +    TreeFilterEd.SetFocus;
    +
    +    if Assigned(IDEComponentPalette.OnClassSelected) then
    +      IDEComponentPalette.OnClassSelected(Self);
    +  end;
    +end;
    +
     procedure TComponentListForm.UpdateShowing;
     begin
       if (ButtonPanel<>nil) and ButtonPanel.Visible then
    @@ -383,7 +428,7 @@
     procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
     // This is used for all 3 treeviews
     begin
    -  OKButtonClick(nil);       // Select and close this form
    +  CreateComponentOnDesigner;
     end;
     
     procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
    @@ -415,13 +460,6 @@
       end
     end;
     
    -procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
    -// This is used for all 3 treeviews
    -begin
    -  if Key = Char(VK_RETURN) then
    -    ComponentsDblClick(Sender);
    -end;
    -
     procedure TComponentListForm.PageControlChange(Sender: TObject);
     begin
       FPageControlChange := True;
    @@ -488,6 +526,10 @@
           Close
         else
           ClearSelection; //unselect if component is selected
    +  end
    +  else if Key = VK_RETURN then
    +  begin
    +    CreateComponentOnDesigner;
       end;
     end;
     
    
    componentlist2.patch (8,899 bytes)
  • componentlist3.patch (9,158 bytes)
    Index: componentlist.lfm
    ===================================================================
    --- componentlist.lfm	(revision 52792)
    +++ componentlist.lfm	(working copy)
    @@ -15,8 +15,8 @@
       Visible = False
       object PageControl: TPageControl
         Left = 0
    -    Height = 394
    -    Top = 31
    +    Height = 402
    +    Top = 27
         Width = 300
         ActivePage = TabSheetList
         Align = alClient
    @@ -25,24 +25,24 @@
         OnChange = PageControlChange
         object TabSheetList: TTabSheet
           Caption = 'List'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel7: TPanel
             Left = 0
    -        Height = 361
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 2
    -        ClientHeight = 361
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object ListTree: TTreeView
               Left = 2
    -          Height = 357
    +          Height = 370
               Top = 2
    -          Width = 292
    +          Width = 288
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -55,7 +55,6 @@
               ShowRoot = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
             end
    @@ -63,24 +62,24 @@
         end
         object TabSheetPaletteTree: TTabSheet
           Caption = 'Palette'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object pnPaletteTree: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object PalletteTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -92,7 +91,6 @@
               ShowLines = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
             end
    @@ -100,24 +98,24 @@
         end
         object TabSheetInheritance: TTabSheet
           Caption = 'Inheritance'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel6: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object InheritanceTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -129,7 +127,6 @@
               ScrollBars = ssAutoBoth
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
             end
    @@ -138,22 +135,22 @@
       end
       object FilterPanel: TPanel
         Left = 0
    -    Height = 31
    +    Height = 27
         Top = 0
         Width = 300
         Align = alTop
         AutoSize = True
         BevelOuter = bvNone
    -    ClientHeight = 31
    +    ClientHeight = 27
         ClientWidth = 300
         TabOrder = 0
         object LabelSearch: TLabel
           AnchorSideLeft.Control = FilterPanel
           AnchorSideTop.Control = FilterPanel
           Left = 6
    -      Height = 19
    +      Height = 15
           Top = 6
    -      Width = 86
    +      Width = 63
           BorderSpacing.Around = 6
           Caption = 'LabelSearch'
           ParentColor = False
    @@ -163,10 +160,10 @@
           AnchorSideLeft.Side = asrBottom
           AnchorSideTop.Control = LabelSearch
           AnchorSideTop.Side = asrCenter
    -      Left = 98
    -      Height = 29
    -      Top = 1
    -      Width = 198
    +      Left = 75
    +      Height = 23
    +      Top = 2
    +      Width = 221
           OnAfterFilter = TreeFilterEdAfterFilter
           ButtonWidth = 23
           NumGlyphs = 1
    @@ -179,8 +176,8 @@
       end
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 30
    -    Top = 431
    +    Height = 26
    +    Top = 435
         Width = 288
         OKButton.Name = 'OKButton'
         OKButton.DefaultCaption = True
    Index: componentlist.pas
    ===================================================================
    --- componentlist.pas	(revision 52792)
    +++ componentlist.pas	(working copy)
    @@ -34,7 +34,7 @@
     uses
       Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
       ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
    -  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
    +  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits;
     
     type
     
    @@ -78,7 +78,6 @@
         procedure tmDeselectTimer(Sender: TObject);
         procedure TreeFilterEdAfterFilter(Sender: TObject);
         procedure PageControlChange(Sender: TObject);
    -    procedure TreeKeyPress(Sender: TObject; var Key: char);
         procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
       private
         PrevPageIndex: Integer;
    @@ -97,6 +96,8 @@
         procedure DoComponentInheritence(Comp: TRegisteredComponent);
         procedure UpdateComponents;
         procedure UpdateButtonState;
    +
    +    procedure CreateComponentOnDesigner;
       protected
         procedure UpdateShowing; override;
       public
    @@ -145,6 +146,8 @@
         IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
         IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
       end;
    +
    +  ActiveControl := TreeFilterEd;
     end;
     
     destructor TComponentListForm.Destroy;
    @@ -243,6 +246,50 @@
       ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
     end;
     
    +procedure TComponentListForm.CreateComponentOnDesigner;
    +var
    +  TypeClass: TComponentClass;
    +  ParentComp: TComponent;
    +  X, Y: integer;
    +  AComponent: TComponent;
    +  DisableAutoSize: Boolean;
    +  selComponent: TRegisteredComponent;
    +begin
    +  selComponent := GetSelectedComponent;
    +
    +  if Assigned(FormEditingHook) and Assigned(selComponent) then
    +  begin
    +    TypeClass:=selComponent.ComponentClass;
    +    if assigned(selComponent.OnGetCreationClass) then
    +      selComponent.OnGetCreationClass(Self,TypeClass);
    +    if TypeClass=nil then
    +      exit;
    +
    +    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
    +    if ParentComp=nil then
    +      Exit;
    +    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
    +      exit;
    +    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
    +    DisableAutoSize:=true;
    +    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
    +      DisableAutoSize);
    +    if AComponent<>nil then
    +    begin
    +      if DisableAutoSize and (AComponent is TControl) then
    +        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
    +      GlobalDesignHook.PersistentAdded(AComponent,true);
    +    end;
    +
    +    ClearSelection;
    +    TreeFilterEd.SelectAll;
    +    TreeFilterEd.SetFocus;
    +
    +    if Assigned(IDEComponentPalette.OnClassSelected) then
    +      IDEComponentPalette.OnClassSelected(Self);
    +  end;
    +end;
    +
     procedure TComponentListForm.UpdateShowing;
     begin
       if (ButtonPanel<>nil) and ButtonPanel.Visible then
    @@ -383,7 +430,7 @@
     procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
     // This is used for all 3 treeviews
     begin
    -  OKButtonClick(nil);       // Select and close this form
    +  CreateComponentOnDesigner;
     end;
     
     procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
    @@ -415,13 +462,6 @@
       end
     end;
     
    -procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
    -// This is used for all 3 treeviews
    -begin
    -  if Key = Char(VK_RETURN) then
    -    ComponentsDblClick(Sender);
    -end;
    -
     procedure TComponentListForm.PageControlChange(Sender: TObject);
     begin
       FPageControlChange := True;
    @@ -488,6 +528,10 @@
           Close
         else
           ClearSelection; //unselect if component is selected
    +  end
    +  else if Key = VK_RETURN then
    +  begin
    +    CreateComponentOnDesigner;
       end;
     end;
     
    
    componentlist3.patch (9,158 bytes)
  • componentlist.jpg (62,049 bytes)
    componentlist.jpg (62,049 bytes)
  • componentlist4.patch (10,334 bytes)
    Index: componentlist.lfm
    ===================================================================
    --- componentlist.lfm	(revision 52792)
    +++ componentlist.lfm	(working copy)
    @@ -15,8 +15,8 @@
       Visible = False
       object PageControl: TPageControl
         Left = 0
    -    Height = 394
    -    Top = 31
    +    Height = 402
    +    Top = 27
         Width = 300
         ActivePage = TabSheetList
         Align = alClient
    @@ -25,24 +25,24 @@
         OnChange = PageControlChange
         object TabSheetList: TTabSheet
           Caption = 'List'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel7: TPanel
             Left = 0
    -        Height = 361
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 2
    -        ClientHeight = 361
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object ListTree: TTreeView
               Left = 2
    -          Height = 357
    +          Height = 370
               Top = 2
    -          Width = 292
    +          Width = 288
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -55,7 +55,6 @@
               ShowRoot = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
             end
    @@ -63,24 +62,24 @@
         end
         object TabSheetPaletteTree: TTabSheet
           Caption = 'Palette'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object pnPaletteTree: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object PalletteTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -92,7 +91,6 @@
               ShowLines = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
             end
    @@ -100,24 +98,24 @@
         end
         object TabSheetInheritance: TTabSheet
           Caption = 'Inheritance'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel6: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object InheritanceTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -129,7 +127,6 @@
               ScrollBars = ssAutoBoth
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
             end
    @@ -138,22 +135,22 @@
       end
       object FilterPanel: TPanel
         Left = 0
    -    Height = 31
    +    Height = 27
         Top = 0
         Width = 300
         Align = alTop
         AutoSize = True
         BevelOuter = bvNone
    -    ClientHeight = 31
    +    ClientHeight = 27
         ClientWidth = 300
         TabOrder = 0
         object LabelSearch: TLabel
           AnchorSideLeft.Control = FilterPanel
           AnchorSideTop.Control = FilterPanel
           Left = 6
    -      Height = 19
    +      Height = 15
           Top = 6
    -      Width = 86
    +      Width = 63
           BorderSpacing.Around = 6
           Caption = 'LabelSearch'
           ParentColor = False
    @@ -163,10 +160,10 @@
           AnchorSideLeft.Side = asrBottom
           AnchorSideTop.Control = LabelSearch
           AnchorSideTop.Side = asrCenter
    -      Left = 98
    -      Height = 29
    -      Top = 1
    -      Width = 198
    +      Left = 75
    +      Height = 23
    +      Top = 2
    +      Width = 221
           OnAfterFilter = TreeFilterEdAfterFilter
           ButtonWidth = 23
           NumGlyphs = 1
    @@ -179,8 +176,8 @@
       end
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 30
    -    Top = 431
    +    Height = 26
    +    Top = 435
         Width = 288
         OKButton.Name = 'OKButton'
         OKButton.DefaultCaption = True
    Index: componentlist.pas
    ===================================================================
    --- componentlist.pas	(revision 52792)
    +++ componentlist.pas	(working copy)
    @@ -34,7 +34,7 @@
     uses
       Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
       ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
    -  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
    +  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits;
     
     type
     
    @@ -78,7 +78,6 @@
         procedure tmDeselectTimer(Sender: TObject);
         procedure TreeFilterEdAfterFilter(Sender: TObject);
         procedure PageControlChange(Sender: TObject);
    -    procedure TreeKeyPress(Sender: TObject; var Key: char);
         procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
       private
         PrevPageIndex: Integer;
    @@ -97,6 +96,9 @@
         procedure DoComponentInheritence(Comp: TRegisteredComponent);
         procedure UpdateComponents;
         procedure UpdateButtonState;
    +    function IsUndocked: Boolean;
    +
    +    procedure CreateComponentOnDesigner;
       protected
         procedure UpdateShowing; override;
       public
    @@ -145,6 +147,8 @@
         IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
         IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
       end;
    +
    +  ActiveControl := TreeFilterEd;
     end;
     
     destructor TComponentListForm.Destroy;
    @@ -158,7 +162,7 @@
     procedure TComponentListForm.FormShow(Sender: TObject);
     begin
       //DebugLn(['*** TComponentListForm.FormShow, Parent=', Parent, ', Parent.Parent=', ParentParent]);
    -  ButtonPanel.Visible := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
    +  ButtonPanel.Visible := IsUndocked;
       if ButtonPanel.Visible then
       begin                              // ComponentList is undocked
         PageControl.AnchorSideBottom.Side := asrTop;
    @@ -175,6 +179,7 @@
     begin
       if Assigned(IDEComponentPalette) and (IDEComponentPalette.ChangeStamp<>PrevChangeStamp) then
         UpdateComponents;
    +
     end;
     
     procedure TComponentListForm.ClearSelection;
    @@ -243,6 +248,55 @@
       ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
     end;
     
    +function TComponentListForm.IsUndocked: Boolean;
    +begin
    +  Result := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
    +end;
    +
    +procedure TComponentListForm.CreateComponentOnDesigner;
    +var
    +  TypeClass: TComponentClass;
    +  ParentComp: TComponent;
    +  X, Y: integer;
    +  AComponent: TComponent;
    +  DisableAutoSize: Boolean;
    +  selComponent: TRegisteredComponent;
    +begin
    +  selComponent := GetSelectedComponent;
    +
    +  if Assigned(FormEditingHook) and Assigned(selComponent) then
    +  begin
    +    TypeClass:=selComponent.ComponentClass;
    +    if assigned(selComponent.OnGetCreationClass) then
    +      selComponent.OnGetCreationClass(Self,TypeClass);
    +    if TypeClass=nil then
    +      exit;
    +
    +    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
    +    if ParentComp=nil then
    +      Exit;
    +    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
    +      exit;
    +    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
    +    DisableAutoSize:=true;
    +    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
    +      DisableAutoSize);
    +    if AComponent<>nil then
    +    begin
    +      if DisableAutoSize and (AComponent is TControl) then
    +        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
    +      GlobalDesignHook.PersistentAdded(AComponent,true);
    +    end;
    +
    +    ClearSelection;
    +    TreeFilterEd.SelectAll;
    +    TreeFilterEd.SetFocus;
    +
    +    if Assigned(IDEComponentPalette.OnClassSelected) then
    +      IDEComponentPalette.OnClassSelected(Self);
    +  end;
    +end;
    +
     procedure TComponentListForm.UpdateShowing;
     begin
       if (ButtonPanel<>nil) and ButtonPanel.Visible then
    @@ -383,7 +437,10 @@
     procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
     // This is used for all 3 treeviews
     begin
    -  OKButtonClick(nil);       // Select and close this form
    +  if IsUndocked then
    +    OKButtonClick(nil)
    +  else
    +    CreateComponentOnDesigner;
     end;
     
     procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
    @@ -415,13 +472,6 @@
       end
     end;
     
    -procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
    -// This is used for all 3 treeviews
    -begin
    -  if Key = Char(VK_RETURN) then
    -    ComponentsDblClick(Sender);
    -end;
    -
     procedure TComponentListForm.PageControlChange(Sender: TObject);
     begin
       FPageControlChange := True;
    @@ -488,6 +538,13 @@
           Close
         else
           ClearSelection; //unselect if component is selected
    +  end
    +  else if Key = VK_RETURN then
    +  begin
    +    if IsUndocked then
    +      OKButtonClick(nil) //Only in undocked mode
    +    else
    +      CreateComponentOnDesigner;
       end;
     end;
     
    @@ -498,7 +555,6 @@
     begin
       AComponent := GetSelectedComponent;
       if AComponent<>nil then begin
    -    FPageControlChange:=True;
         IDEComponentPalette.Selected := AComponent;
         FKeepSelected := True;
         Close;
    
    componentlist4.patch (10,334 bytes)
  • componentlist5.patch (10,792 bytes)
    Index: componentlist.lfm
    ===================================================================
    --- componentlist.lfm	(revision 52792)
    +++ componentlist.lfm	(working copy)
    @@ -15,8 +15,8 @@
       Visible = False
       object PageControl: TPageControl
         Left = 0
    -    Height = 394
    -    Top = 31
    +    Height = 402
    +    Top = 27
         Width = 300
         ActivePage = TabSheetList
         Align = alClient
    @@ -25,24 +25,24 @@
         OnChange = PageControlChange
         object TabSheetList: TTabSheet
           Caption = 'List'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel7: TPanel
             Left = 0
    -        Height = 361
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 2
    -        ClientHeight = 361
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object ListTree: TTreeView
               Left = 2
    -          Height = 357
    +          Height = 370
               Top = 2
    -          Width = 292
    +          Width = 288
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -55,7 +55,6 @@
               ShowRoot = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
             end
    @@ -63,24 +62,24 @@
         end
         object TabSheetPaletteTree: TTabSheet
           Caption = 'Palette'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object pnPaletteTree: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object PalletteTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -92,7 +91,6 @@
               ShowLines = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
             end
    @@ -100,24 +98,24 @@
         end
         object TabSheetInheritance: TTabSheet
           Caption = 'Inheritance'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel6: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object InheritanceTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -129,7 +127,6 @@
               ScrollBars = ssAutoBoth
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
             end
    @@ -138,22 +135,22 @@
       end
       object FilterPanel: TPanel
         Left = 0
    -    Height = 31
    +    Height = 27
         Top = 0
         Width = 300
         Align = alTop
         AutoSize = True
         BevelOuter = bvNone
    -    ClientHeight = 31
    +    ClientHeight = 27
         ClientWidth = 300
         TabOrder = 0
         object LabelSearch: TLabel
           AnchorSideLeft.Control = FilterPanel
           AnchorSideTop.Control = FilterPanel
           Left = 6
    -      Height = 19
    +      Height = 15
           Top = 6
    -      Width = 86
    +      Width = 63
           BorderSpacing.Around = 6
           Caption = 'LabelSearch'
           ParentColor = False
    @@ -163,10 +160,10 @@
           AnchorSideLeft.Side = asrBottom
           AnchorSideTop.Control = LabelSearch
           AnchorSideTop.Side = asrCenter
    -      Left = 98
    -      Height = 29
    -      Top = 1
    -      Width = 198
    +      Left = 75
    +      Height = 23
    +      Top = 2
    +      Width = 221
           OnAfterFilter = TreeFilterEdAfterFilter
           ButtonWidth = 23
           NumGlyphs = 1
    @@ -179,8 +176,8 @@
       end
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 30
    -    Top = 431
    +    Height = 26
    +    Top = 435
         Width = 288
         OKButton.Name = 'OKButton'
         OKButton.DefaultCaption = True
    Index: componentlist.pas
    ===================================================================
    --- componentlist.pas	(revision 52792)
    +++ componentlist.pas	(working copy)
    @@ -34,7 +34,8 @@
     uses
       Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
       ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
    -  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
    +  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits,
    +  EnvironmentOpts, AskCompNameDlg;
     
     type
     
    @@ -78,7 +79,6 @@
         procedure tmDeselectTimer(Sender: TObject);
         procedure TreeFilterEdAfterFilter(Sender: TObject);
         procedure PageControlChange(Sender: TObject);
    -    procedure TreeKeyPress(Sender: TObject; var Key: char);
         procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
       private
         PrevPageIndex: Integer;
    @@ -97,6 +97,9 @@
         procedure DoComponentInheritence(Comp: TRegisteredComponent);
         procedure UpdateComponents;
         procedure UpdateButtonState;
    +    function IsUndocked: Boolean;
    +
    +    procedure CreateComponentOnDesigner;
       protected
         procedure UpdateShowing; override;
       public
    @@ -145,6 +148,8 @@
         IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
         IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
       end;
    +
    +  ActiveControl := TreeFilterEd;
     end;
     
     destructor TComponentListForm.Destroy;
    @@ -158,7 +163,7 @@
     procedure TComponentListForm.FormShow(Sender: TObject);
     begin
       //DebugLn(['*** TComponentListForm.FormShow, Parent=', Parent, ', Parent.Parent=', ParentParent]);
    -  ButtonPanel.Visible := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
    +  ButtonPanel.Visible := IsUndocked;
       if ButtonPanel.Visible then
       begin                              // ComponentList is undocked
         PageControl.AnchorSideBottom.Side := asrTop;
    @@ -175,6 +180,7 @@
     begin
       if Assigned(IDEComponentPalette) and (IDEComponentPalette.ChangeStamp<>PrevChangeStamp) then
         UpdateComponents;
    +
     end;
     
     procedure TComponentListForm.ClearSelection;
    @@ -243,6 +249,68 @@
       ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
     end;
     
    +function TComponentListForm.IsUndocked: Boolean;
    +begin
    +  Result := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
    +end;
    +
    +procedure TComponentListForm.CreateComponentOnDesigner;
    +var
    +  TypeClass: TComponentClass;
    +  ParentComp: TComponent;
    +  X, Y: integer;
    +  AComponent, LookupRoot: TComponent;
    +  DisableAutoSize: Boolean;
    +  selComponent: TRegisteredComponent;
    +begin
    +  selComponent := GetSelectedComponent;
    +
    +  if Assigned(FormEditingHook) and Assigned(selComponent) then
    +  begin
    +    TypeClass:=selComponent.ComponentClass;
    +    if assigned(selComponent.OnGetCreationClass) then
    +      selComponent.OnGetCreationClass(Self,TypeClass);
    +    if TypeClass=nil then
    +      exit;
    +
    +    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
    +    if ParentComp=nil then
    +      Exit;
    +    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
    +      exit;
    +    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
    +    DisableAutoSize:=true;
    +    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
    +      DisableAutoSize);
    +    if AComponent<>nil then
    +    begin
    +      if DisableAutoSize and (AComponent is TControl) then
    +        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
    +      GlobalDesignHook.PersistentAdded(AComponent,true);
    +
    +      if EnvironmentOptions.CreateComponentFocusNameProperty then
    +      begin
    +        // ask user for name
    +        if GlobalDesignHook.LookupRoot is TComponent then
    +        begin
    +          LookupRoot := TComponent(GlobalDesignHook.LookupRoot);
    +          AComponent.Name:=ShowComponentNameDialog(LookupRoot,AComponent);
    +        end;
    +      end;
    +
    +      GlobalDesignHook.SelectOnlyThis(AComponent);
    +    end;
    +
    +    ClearSelection;
    +    TreeFilterEd.SelectAll;
    +    TreeFilterEd.SetFocus;
    +
    +    if Assigned(IDEComponentPalette.OnClassSelected) then
    +      IDEComponentPalette.OnClassSelected(Self);
    +
    +  end;
    +end;
    +
     procedure TComponentListForm.UpdateShowing;
     begin
       if (ButtonPanel<>nil) and ButtonPanel.Visible then
    @@ -383,7 +451,10 @@
     procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
     // This is used for all 3 treeviews
     begin
    -  OKButtonClick(nil);       // Select and close this form
    +  if IsUndocked then
    +    OKButtonClick(nil)
    +  else
    +    CreateComponentOnDesigner;
     end;
     
     procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
    @@ -415,13 +486,6 @@
       end
     end;
     
    -procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
    -// This is used for all 3 treeviews
    -begin
    -  if Key = Char(VK_RETURN) then
    -    ComponentsDblClick(Sender);
    -end;
    -
     procedure TComponentListForm.PageControlChange(Sender: TObject);
     begin
       FPageControlChange := True;
    @@ -488,6 +552,13 @@
           Close
         else
           ClearSelection; //unselect if component is selected
    +  end
    +  else if Key = VK_RETURN then
    +  begin
    +    if IsUndocked then
    +      OKButtonClick(nil) //Only in undocked mode
    +    else
    +      CreateComponentOnDesigner;
       end;
     end;
     
    @@ -498,7 +569,6 @@
     begin
       AComponent := GetSelectedComponent;
       if AComponent<>nil then begin
    -    FPageControlChange:=True;
         IDEComponentPalette.Selected := AComponent;
         FKeepSelected := True;
         Close;
    
    componentlist5.patch (10,792 bytes)
  • componentlist6.patch (17,332 bytes)
    Index: components/ideintf/componentreg.pas
    ===================================================================
    --- components/ideintf/componentreg.pas	(revision 53017)
    +++ components/ideintf/componentreg.pas	(working copy)
    @@ -28,7 +28,7 @@
       {$IFDEF CustomIDEComps}
       CustomIDEComps,
       {$ENDIF}
    -  Controls, Laz2_XMLCfg, LCLProc;
    +  Controls, Laz2_XMLCfg, LCLProc, FormEditingIntf, PropEdits;
     
     type
       TComponentPriorityCategory = (
    @@ -234,6 +234,8 @@
         function GetMultiSelect: boolean;
         procedure SetSelected(const AValue: TRegisteredComponent);
         procedure SetMultiSelect(AValue: boolean);
    +  protected
    +    procedure AskForComponentNameOnDemand(AComponent: TComponent); virtual;
       public
         constructor Create(EnvPaletteOptions: TCompPaletteOptions);
         destructor Destroy; override;
    @@ -254,6 +256,7 @@
         procedure Update({%H-}ForceUpdateAll: Boolean); virtual;
         procedure IterateRegisteredClasses(Proc: TGetComponentClassEvent);
         procedure SetSelectedComp(AComponent: TRegisteredComponent; AMulti: Boolean);
    +    function CreateComponentOnDesigner(aSelectedComp: TRegisteredComponent): Boolean;
         // Registered handlers
         procedure DoAfterComponentAdded(ALookupRoot, AComponent: TComponent;
                                 ARegisteredComponent: TRegisteredComponent); virtual;
    @@ -890,6 +893,11 @@
         FSelectionMode := csmSingle;
     end;
     
    +procedure TBaseComponentPalette.AskForComponentNameOnDemand(AComponent: TComponent);
    +begin
    +  //Do due dependecies cycle, this function needs to be implemented on the derived class.
    +end;
    +
     procedure TBaseComponentPalette.AddHandler(HandlerType: TComponentPaletteHandlerType;
       const AMethod: TMethod; AsLast: boolean);
     begin
    @@ -1068,6 +1076,50 @@
       Selected := AComponent;
     end;
     
    +function TBaseComponentPalette.CreateComponentOnDesigner(
    +  aSelectedComp: TRegisteredComponent): Boolean;
    +var
    +  TypeClass: TComponentClass;
    +  ParentComp: TComponent;
    +  X, Y: integer;
    +  AComponent: TComponent;
    +  DisableAutoSize: Boolean;
    +begin
    +  Result := false;
    +
    +  if Assigned(FormEditingHook) and Assigned(aSelectedComp) then
    +  begin
    +    TypeClass:=aSelectedComp.ComponentClass;
    +    if assigned(aSelectedComp.OnGetCreationClass) then
    +      aSelectedComp.OnGetCreationClass(Self,TypeClass);
    +    if TypeClass=nil then
    +      Exit(false);
    +
    +    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
    +    if ParentComp=nil then
    +      Exit(false);
    +
    +    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
    +      Exit(false);
    +
    +    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
    +    DisableAutoSize:=true;
    +    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
    +      DisableAutoSize);
    +    if AComponent<>nil then
    +    begin
    +      if DisableAutoSize and (AComponent is TControl) then
    +        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
    +      GlobalDesignHook.PersistentAdded(AComponent,true);
    +
    +      AskForComponentNameOnDemand(AComponent);
    +
    +      GlobalDesignHook.SelectOnlyThis(AComponent);
    +    end;
    +    Result := true;
    +  end;
    +end;
    +
     // Execute handlers
     
     function TBaseComponentPalette.VoteCompVisibility(AComponent: TRegisteredComponent): Boolean;
    Index: ide/componentlist.lfm
    ===================================================================
    --- ide/componentlist.lfm	(revision 53017)
    +++ ide/componentlist.lfm	(working copy)
    @@ -12,11 +12,10 @@
       OnKeyDown = FormKeyDown
       OnShow = FormShow
       LCLVersion = '1.7'
    -  Visible = False
       object PageControl: TPageControl
         Left = 0
    -    Height = 394
    -    Top = 31
    +    Height = 402
    +    Top = 27
         Width = 300
         ActivePage = TabSheetList
         Align = alClient
    @@ -25,24 +24,24 @@
         OnChange = PageControlChange
         object TabSheetList: TTabSheet
           Caption = 'List'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel7: TPanel
             Left = 0
    -        Height = 361
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 2
    -        ClientHeight = 361
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object ListTree: TTreeView
               Left = 2
    -          Height = 357
    +          Height = 370
               Top = 2
    -          Width = 292
    +          Width = 288
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -55,7 +54,6 @@
               ShowRoot = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
             end
    @@ -63,24 +61,24 @@
         end
         object TabSheetPaletteTree: TTabSheet
           Caption = 'Palette'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object pnPaletteTree: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object PalletteTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -92,7 +90,6 @@
               ShowLines = False
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
             end
    @@ -100,24 +97,24 @@
         end
         object TabSheetInheritance: TTabSheet
           Caption = 'Inheritance'
    -      ClientHeight = 361
    -      ClientWidth = 296
    +      ClientHeight = 374
    +      ClientWidth = 292
           object Panel6: TPanel
             Left = 0
    -        Height = 375
    +        Height = 374
             Top = 0
    -        Width = 296
    +        Width = 292
             Align = alClient
             BevelOuter = bvNone
             BorderWidth = 5
    -        ClientHeight = 375
    -        ClientWidth = 296
    +        ClientHeight = 374
    +        ClientWidth = 292
             TabOrder = 0
             object InheritanceTree: TTreeView
               Left = 5
    -          Height = 365
    +          Height = 364
               Top = 5
    -          Width = 286
    +          Width = 282
               Align = alClient
               DefaultItemHeight = 26
               Images = imListPalette
    @@ -129,7 +126,6 @@
               ScrollBars = ssAutoBoth
               TabOrder = 0
               OnDblClick = ComponentsDblClick
    -          OnKeyPress = TreeKeyPress
               OnSelectionChanged = ListTreeSelectionChanged
               Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
             end
    @@ -138,22 +134,22 @@
       end
       object FilterPanel: TPanel
         Left = 0
    -    Height = 31
    +    Height = 27
         Top = 0
         Width = 300
         Align = alTop
         AutoSize = True
         BevelOuter = bvNone
    -    ClientHeight = 31
    +    ClientHeight = 27
         ClientWidth = 300
         TabOrder = 0
         object LabelSearch: TLabel
           AnchorSideLeft.Control = FilterPanel
           AnchorSideTop.Control = FilterPanel
           Left = 6
    -      Height = 19
    +      Height = 15
           Top = 6
    -      Width = 86
    +      Width = 63
           BorderSpacing.Around = 6
           Caption = 'LabelSearch'
           ParentColor = False
    @@ -163,10 +159,10 @@
           AnchorSideLeft.Side = asrBottom
           AnchorSideTop.Control = LabelSearch
           AnchorSideTop.Side = asrCenter
    -      Left = 98
    -      Height = 29
    -      Top = 1
    -      Width = 198
    +      Left = 75
    +      Height = 23
    +      Top = 2
    +      Width = 221
           OnAfterFilter = TreeFilterEdAfterFilter
           ButtonWidth = 23
           NumGlyphs = 1
    @@ -179,8 +175,8 @@
       end
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 30
    -    Top = 431
    +    Height = 26
    +    Top = 435
         Width = 288
         OKButton.Name = 'OKButton'
         OKButton.DefaultCaption = True
    Index: ide/componentlist.pas
    ===================================================================
    --- ide/componentlist.pas	(revision 53017)
    +++ ide/componentlist.pas	(working copy)
    @@ -78,7 +78,6 @@
         procedure tmDeselectTimer(Sender: TObject);
         procedure TreeFilterEdAfterFilter(Sender: TObject);
         procedure PageControlChange(Sender: TObject);
    -    procedure TreeKeyPress(Sender: TObject; var Key: char);
         procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
       private
         PrevPageIndex: Integer;
    @@ -97,12 +96,16 @@
         procedure DoComponentInheritence(Comp: TRegisteredComponent);
         procedure UpdateComponents;
         procedure UpdateButtonState;
    +    function IsUndocked: Boolean;
    +
    +    procedure CreateComponentOnDesigner;
       protected
         procedure UpdateShowing; override;
       public
         constructor Create(AOwner: TComponent); override;
         destructor Destroy; override;
         function GetSelectedComponent: TRegisteredComponent;
    +    procedure ExpliciteActivate;
       end;
       
     var
    @@ -145,6 +148,8 @@
         IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
         IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
       end;
    +
    +  ActiveControl := TreeFilterEd;
     end;
     
     destructor TComponentListForm.Destroy;
    @@ -158,7 +163,7 @@
     procedure TComponentListForm.FormShow(Sender: TObject);
     begin
       //DebugLn(['*** TComponentListForm.FormShow, Parent=', Parent, ', Parent.Parent=', ParentParent]);
    -  ButtonPanel.Visible := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
    +  ButtonPanel.Visible := IsUndocked;
       if ButtonPanel.Visible then
       begin                              // ComponentList is undocked
         PageControl.AnchorSideBottom.Side := asrTop;
    @@ -175,6 +180,7 @@
     begin
       if Assigned(IDEComponentPalette) and (IDEComponentPalette.ChangeStamp<>PrevChangeStamp) then
         UpdateComponents;
    +
     end;
     
     procedure TComponentListForm.ClearSelection;
    @@ -231,6 +237,13 @@
         Result := GetSelectedTreeComp(InheritanceTree)
     end;
     
    +procedure TComponentListForm.ExpliciteActivate;
    +begin
    +  //In docked mode, the Active event is not fired, and the TreeFilter gets not selected.
    +  if TreeFilterEd.CanSetFocus then
    +    TreeFilterEd.SetFocus;
    +end;
    +
     procedure TComponentListForm.ComponentWasAdded(ALookupRoot, AComponent: TComponent;
       ARegisteredComponent: TRegisteredComponent);
     begin
    @@ -243,6 +256,28 @@
       ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
     end;
     
    +function TComponentListForm.IsUndocked: Boolean;
    +begin
    +  Result := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
    +end;
    +
    +procedure TComponentListForm.CreateComponentOnDesigner;
    +var
    +  selComponent: TRegisteredComponent;
    +begin
    +  selComponent := GetSelectedComponent;
    +
    +  if IDEComponentPalette.CreateComponentOnDesigner(selComponent) then
    +  begin
    +    ClearSelection;
    +    TreeFilterEd.SelectAll;
    +    TreeFilterEd.SetFocus;
    +
    +    if Assigned(IDEComponentPalette.OnClassSelected) then
    +      IDEComponentPalette.OnClassSelected(Self);
    +  end;
    +end;
    +
     procedure TComponentListForm.UpdateShowing;
     begin
       if (ButtonPanel<>nil) and ButtonPanel.Visible then
    @@ -383,17 +418,19 @@
     procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
     // This is used for all 3 treeviews
     begin
    -  OKButtonClick(nil);       // Select and close this form
    +  if IsUndocked then
    +    OKButtonClick(nil)
    +  else
    +    CreateComponentOnDesigner;
     end;
     
     procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
     var
       AComponent: TRegisteredComponent;
     begin
    -  UpdateButtonState;
       if FInitialized then
       begin
    -    if FPageControlChange then
    +    if FPageControlChange or FKeepSelected then
           Exit;
         AComponent:=GetSelectedComponent;
         if AComponent<>nil then
    @@ -404,6 +441,7 @@
           IDEComponentPalette.SetSelectedComp(nil, False);
           FIgnoreSelection := False;
         end;
    +    UpdateButtonState;
       end
       else begin
         // Only run once when the IDE starts.
    @@ -415,13 +453,6 @@
       end
     end;
     
    -procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
    -// This is used for all 3 treeviews
    -begin
    -  if Key = Char(VK_RETURN) then
    -    ComponentsDblClick(Sender);
    -end;
    -
     procedure TComponentListForm.PageControlChange(Sender: TObject);
     begin
       FPageControlChange := True;
    @@ -461,8 +492,6 @@
     begin
       if Parent=nil then begin
         ClearSelection;
    -    if not fKeepSelected then
    -      IDEComponentPalette.Selected := Nil;
       end
       else begin
         // Using a dock manager...
    @@ -488,6 +517,13 @@
           Close
         else
           ClearSelection; //unselect if component is selected
    +  end
    +  else if Key = VK_RETURN then
    +  begin
    +    if IsUndocked then
    +      OKButtonClick(nil) //Only in undocked mode
    +    else
    +      CreateComponentOnDesigner;
       end;
     end;
     
    @@ -498,7 +534,6 @@
     begin
       AComponent := GetSelectedComponent;
       if AComponent<>nil then begin
    -    FPageControlChange:=True;
         IDEComponentPalette.Selected := AComponent;
         FKeepSelected := True;
         Close;
    Index: ide/componentpalette.pas
    ===================================================================
    --- ide/componentpalette.pas	(revision 53017)
    +++ ide/componentpalette.pas	(working copy)
    @@ -42,7 +42,7 @@
       Controls, Forms, Graphics, ComCtrls, Buttons, Menus, ExtCtrls,
       LazFileUtils, LazFileCache, PropEdits, LCLProc, MainBase, LazarusIDEStrConsts,
       FormEditingIntf, LazIDEIntf, IDEImagesIntf,
    -  ComponentReg, DesignerProcs, PackageDefs, EnvironmentOpts;
    +  ComponentReg, DesignerProcs, PackageDefs, EnvironmentOpts, AskCompNameDlg;
     
     const
       CompPalSelectionToolBtnPrefix = 'PaletteSelectBtn';
    @@ -129,6 +129,8 @@
         procedure ComponentWasAdded({%H-}ALookupRoot, {%H-}AComponent: TComponent;
                                     {%H-}ARegisteredComponent: TRegisteredComponent);
         procedure CheckComponentDesignerVisible(AComponent: TComponent; var Invisible: boolean);
    +  protected
    +    procedure AskForComponentNameOnDemand(AComponent: TComponent); override;
       public
         constructor Create;
         destructor Destroy; override;
    @@ -677,27 +679,11 @@
       DisableAutoSize: Boolean;
     begin
       //debugln('TComponentPalette.ComponentBtnDblClick ',TComponent(Sender).Name);
    -  if SelectAButton(TSpeedButton(Sender)) and (Selected<>nil) then begin
    -    if FormEditingHook<>nil then begin
    -      TypeClass:=Selected.ComponentClass;
    -      if assigned(Selected.OnGetCreationClass) then
    -        Selected.OnGetCreationClass(Self,TypeClass);
    -      if TypeClass=nil then exit;
    -      ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
    -      if ParentComp=nil then exit;
    -      if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y)
    -      then exit;
    -      //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
    -      DisableAutoSize:=true;
    -      AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
    -        DisableAutoSize);
    -      if AComponent<>nil then begin
    -        if DisableAutoSize and (AComponent is TControl) then
    -          TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
    -        GlobalDesignHook.PersistentAdded(AComponent,true);
    -      end;
    -    end;
    +  if SelectAButton(TSpeedButton(Sender)) and (Selected<>nil) then
    +  begin
    +    CreateComponentOnDesigner(Selected);
       end;
    +
       Selected:=nil;
       if Assigned(OnClassSelected) then
         OnClassSelected(Self);
    @@ -827,6 +813,21 @@
       end;
     end;
     
    +procedure TComponentPalette.AskForComponentNameOnDemand(AComponent: TComponent);
    +var
    +  lookupRoot: TComponent;
    +begin
    +  if EnvironmentOptions.CreateComponentFocusNameProperty then
    +  begin
    +    // ask user for name
    +    if GlobalDesignHook.LookupRoot is TComponent then
    +    begin
    +      lookupRoot := TComponent(GlobalDesignHook.LookupRoot);
    +      AComponent.Name:=ShowComponentNameDialog(lookupRoot,AComponent);
    +    end;
    +  end;
    +end;
    +
     constructor TComponentPalette.Create;
     begin
       inherited Create(EnvironmentOptions.Desktop.ComponentPaletteOptions);
    Index: ide/main.pp
    ===================================================================
    --- ide/main.pp	(revision 53017)
    +++ ide/main.pp	(working copy)
    @@ -5883,7 +5883,10 @@
       end else if State=iwgfDisabled then
         ComponentListForm.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TMainIDE.DoShowComponentList'){$ENDIF};
       if State>=iwgfShow then
    +  begin
         IDEWindowCreators.ShowForm(ComponentListForm,State=iwgfShowOnTop);
    +    ComponentListForm.ExpliciteActivate;
    +  end;
     end;
     
     procedure TMainIDE.DoShowJumpHistory(State: TIWGetFormState);
    
    componentlist6.patch (17,332 bytes)

Activities

Markus

2016-08-10 18:27

reporter  

componentlist.patch (8,962 bytes)
Index: componentlist.lfm
===================================================================
--- componentlist.lfm	(revision 52792)
+++ componentlist.lfm	(working copy)
@@ -11,12 +11,11 @@
   OnClose = FormClose
   OnKeyDown = FormKeyDown
   OnShow = FormShow
-  LCLVersion = '1.7'
   Visible = False
   object PageControl: TPageControl
     Left = 0
-    Height = 394
-    Top = 31
+    Height = 402
+    Top = 27
     Width = 300
     ActivePage = TabSheetList
     Align = alClient
@@ -25,24 +24,24 @@
     OnChange = PageControlChange
     object TabSheetList: TTabSheet
       Caption = 'List'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel7: TPanel
         Left = 0
-        Height = 361
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 2
-        ClientHeight = 361
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object ListTree: TTreeView
           Left = 2
-          Height = 357
+          Height = 370
           Top = 2
-          Width = 292
+          Width = 288
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -55,7 +54,6 @@
           ShowRoot = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
         end
@@ -63,24 +61,24 @@
     end
     object TabSheetPaletteTree: TTabSheet
       Caption = 'Palette'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object pnPaletteTree: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object PalletteTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -92,7 +90,6 @@
           ShowLines = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
         end
@@ -100,24 +97,24 @@
     end
     object TabSheetInheritance: TTabSheet
       Caption = 'Inheritance'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel6: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object InheritanceTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -129,7 +126,6 @@
           ScrollBars = ssAutoBoth
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
         end
@@ -138,22 +134,22 @@
   end
   object FilterPanel: TPanel
     Left = 0
-    Height = 31
+    Height = 27
     Top = 0
     Width = 300
     Align = alTop
     AutoSize = True
     BevelOuter = bvNone
-    ClientHeight = 31
+    ClientHeight = 27
     ClientWidth = 300
     TabOrder = 0
     object LabelSearch: TLabel
       AnchorSideLeft.Control = FilterPanel
       AnchorSideTop.Control = FilterPanel
       Left = 6
-      Height = 19
+      Height = 15
       Top = 6
-      Width = 86
+      Width = 63
       BorderSpacing.Around = 6
       Caption = 'LabelSearch'
       ParentColor = False
@@ -163,10 +159,10 @@
       AnchorSideLeft.Side = asrBottom
       AnchorSideTop.Control = LabelSearch
       AnchorSideTop.Side = asrCenter
-      Left = 98
-      Height = 29
-      Top = 1
-      Width = 198
+      Left = 75
+      Height = 23
+      Top = 2
+      Width = 221
       OnAfterFilter = TreeFilterEdAfterFilter
       ButtonWidth = 23
       NumGlyphs = 1
@@ -179,8 +175,8 @@
   end
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 30
-    Top = 431
+    Height = 26
+    Top = 435
     Width = 288
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
Index: componentlist.pas
===================================================================
--- componentlist.pas	(revision 52792)
+++ componentlist.pas	(working copy)
@@ -34,7 +34,7 @@
 uses
   Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
   ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
-  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
+  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits;
 
 type
 
@@ -78,7 +78,6 @@
     procedure tmDeselectTimer(Sender: TObject);
     procedure TreeFilterEdAfterFilter(Sender: TObject);
     procedure PageControlChange(Sender: TObject);
-    procedure TreeKeyPress(Sender: TObject; var Key: char);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
   private
     PrevPageIndex: Integer;
@@ -97,6 +96,8 @@
     procedure DoComponentInheritence(Comp: TRegisteredComponent);
     procedure UpdateComponents;
     procedure UpdateButtonState;
+
+    procedure CreateComponentOnDesigner;
   protected
     procedure UpdateShowing; override;
   public
@@ -243,6 +244,50 @@
   ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
 end;
 
+procedure TComponentListForm.CreateComponentOnDesigner;
+var
+  TypeClass: TComponentClass;
+  ParentComp: TComponent;
+  X, Y: integer;
+  AComponent: TComponent;
+  DisableAutoSize: Boolean;
+  selComponent: TRegisteredComponent;
+begin
+  selComponent := GetSelectedComponent;
+
+  if FormEditingHook<>nil then
+  begin
+    TypeClass:=selComponent.ComponentClass;
+    if assigned(selComponent.OnGetCreationClass) then
+      selComponent.OnGetCreationClass(Self,TypeClass);
+    if TypeClass=nil then
+      exit;
+
+    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
+    if ParentComp=nil then
+      Exit;
+    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
+      exit;
+    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
+    DisableAutoSize:=true;
+    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
+      DisableAutoSize);
+    if AComponent<>nil then
+    begin
+      if DisableAutoSize and (AComponent is TControl) then
+        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
+      GlobalDesignHook.PersistentAdded(AComponent,true);
+    end;
+
+    ClearSelection;
+    TreeFilterEd.SelectAll;
+    TreeFilterEd.SetFocus;
+
+    if Assigned(IDEComponentPalette.OnClassSelected) then
+      IDEComponentPalette.OnClassSelected(Self);
+  end;
+end;
+
 procedure TComponentListForm.UpdateShowing;
 begin
   if (ButtonPanel<>nil) and ButtonPanel.Visible then
@@ -383,7 +428,7 @@
 procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
 // This is used for all 3 treeviews
 begin
-  OKButtonClick(nil);       // Select and close this form
+  CreateComponentOnDesigner;
 end;
 
 procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
@@ -415,13 +460,6 @@
   end
 end;
 
-procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
-// This is used for all 3 treeviews
-begin
-  if Key = Char(VK_RETURN) then
-    ComponentsDblClick(Sender);
-end;
-
 procedure TComponentListForm.PageControlChange(Sender: TObject);
 begin
   FPageControlChange := True;
@@ -488,6 +526,10 @@
       Close
     else
       ClearSelection; //unselect if component is selected
+  end
+  else if Key = VK_RETURN then
+  begin
+    CreateComponentOnDesigner;
   end;
 end;
 
componentlist.patch (8,962 bytes)

Markus

2016-08-10 18:36

reporter  

componentlist2.patch (8,899 bytes)
Index: componentlist.lfm
===================================================================
--- componentlist.lfm	(revision 52792)
+++ componentlist.lfm	(working copy)
@@ -15,8 +15,8 @@
   Visible = False
   object PageControl: TPageControl
     Left = 0
-    Height = 394
-    Top = 31
+    Height = 402
+    Top = 27
     Width = 300
     ActivePage = TabSheetList
     Align = alClient
@@ -25,24 +25,24 @@
     OnChange = PageControlChange
     object TabSheetList: TTabSheet
       Caption = 'List'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel7: TPanel
         Left = 0
-        Height = 361
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 2
-        ClientHeight = 361
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object ListTree: TTreeView
           Left = 2
-          Height = 357
+          Height = 370
           Top = 2
-          Width = 292
+          Width = 288
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -55,7 +55,6 @@
           ShowRoot = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
         end
@@ -63,24 +62,24 @@
     end
     object TabSheetPaletteTree: TTabSheet
       Caption = 'Palette'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object pnPaletteTree: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object PalletteTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -92,7 +91,6 @@
           ShowLines = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
         end
@@ -100,24 +98,24 @@
     end
     object TabSheetInheritance: TTabSheet
       Caption = 'Inheritance'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel6: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object InheritanceTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -129,7 +127,6 @@
           ScrollBars = ssAutoBoth
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
         end
@@ -138,22 +135,22 @@
   end
   object FilterPanel: TPanel
     Left = 0
-    Height = 31
+    Height = 27
     Top = 0
     Width = 300
     Align = alTop
     AutoSize = True
     BevelOuter = bvNone
-    ClientHeight = 31
+    ClientHeight = 27
     ClientWidth = 300
     TabOrder = 0
     object LabelSearch: TLabel
       AnchorSideLeft.Control = FilterPanel
       AnchorSideTop.Control = FilterPanel
       Left = 6
-      Height = 19
+      Height = 15
       Top = 6
-      Width = 86
+      Width = 63
       BorderSpacing.Around = 6
       Caption = 'LabelSearch'
       ParentColor = False
@@ -163,10 +160,10 @@
       AnchorSideLeft.Side = asrBottom
       AnchorSideTop.Control = LabelSearch
       AnchorSideTop.Side = asrCenter
-      Left = 98
-      Height = 29
-      Top = 1
-      Width = 198
+      Left = 75
+      Height = 23
+      Top = 2
+      Width = 221
       OnAfterFilter = TreeFilterEdAfterFilter
       ButtonWidth = 23
       NumGlyphs = 1
@@ -179,8 +176,8 @@
   end
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 30
-    Top = 431
+    Height = 26
+    Top = 435
     Width = 288
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
Index: componentlist.pas
===================================================================
--- componentlist.pas	(revision 52792)
+++ componentlist.pas	(working copy)
@@ -34,7 +34,7 @@
 uses
   Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
   ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
-  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
+  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits;
 
 type
 
@@ -78,7 +78,6 @@
     procedure tmDeselectTimer(Sender: TObject);
     procedure TreeFilterEdAfterFilter(Sender: TObject);
     procedure PageControlChange(Sender: TObject);
-    procedure TreeKeyPress(Sender: TObject; var Key: char);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
   private
     PrevPageIndex: Integer;
@@ -97,6 +96,8 @@
     procedure DoComponentInheritence(Comp: TRegisteredComponent);
     procedure UpdateComponents;
     procedure UpdateButtonState;
+
+    procedure CreateComponentOnDesigner;
   protected
     procedure UpdateShowing; override;
   public
@@ -243,6 +244,50 @@
   ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
 end;
 
+procedure TComponentListForm.CreateComponentOnDesigner;
+var
+  TypeClass: TComponentClass;
+  ParentComp: TComponent;
+  X, Y: integer;
+  AComponent: TComponent;
+  DisableAutoSize: Boolean;
+  selComponent: TRegisteredComponent;
+begin
+  selComponent := GetSelectedComponent;
+
+  if Assigned(FormEditingHook) and Assigned(selComponent) then
+  begin
+    TypeClass:=selComponent.ComponentClass;
+    if assigned(selComponent.OnGetCreationClass) then
+      selComponent.OnGetCreationClass(Self,TypeClass);
+    if TypeClass=nil then
+      exit;
+
+    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
+    if ParentComp=nil then
+      Exit;
+    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
+      exit;
+    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
+    DisableAutoSize:=true;
+    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
+      DisableAutoSize);
+    if AComponent<>nil then
+    begin
+      if DisableAutoSize and (AComponent is TControl) then
+        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
+      GlobalDesignHook.PersistentAdded(AComponent,true);
+    end;
+
+    ClearSelection;
+    TreeFilterEd.SelectAll;
+    TreeFilterEd.SetFocus;
+
+    if Assigned(IDEComponentPalette.OnClassSelected) then
+      IDEComponentPalette.OnClassSelected(Self);
+  end;
+end;
+
 procedure TComponentListForm.UpdateShowing;
 begin
   if (ButtonPanel<>nil) and ButtonPanel.Visible then
@@ -383,7 +428,7 @@
 procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
 // This is used for all 3 treeviews
 begin
-  OKButtonClick(nil);       // Select and close this form
+  CreateComponentOnDesigner;
 end;
 
 procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
@@ -415,13 +460,6 @@
   end
 end;
 
-procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
-// This is used for all 3 treeviews
-begin
-  if Key = Char(VK_RETURN) then
-    ComponentsDblClick(Sender);
-end;
-
 procedure TComponentListForm.PageControlChange(Sender: TObject);
 begin
   FPageControlChange := True;
@@ -488,6 +526,10 @@
       Close
     else
       ClearSelection; //unselect if component is selected
+  end
+  else if Key = VK_RETURN then
+  begin
+    CreateComponentOnDesigner;
   end;
 end;
 
componentlist2.patch (8,899 bytes)

Markus

2016-08-10 18:37

reporter   ~0094082

Added check, if the selected component is not nil.
componentlist2.patch

Markus

2016-08-10 18:43

reporter  

componentlist3.patch (9,158 bytes)
Index: componentlist.lfm
===================================================================
--- componentlist.lfm	(revision 52792)
+++ componentlist.lfm	(working copy)
@@ -15,8 +15,8 @@
   Visible = False
   object PageControl: TPageControl
     Left = 0
-    Height = 394
-    Top = 31
+    Height = 402
+    Top = 27
     Width = 300
     ActivePage = TabSheetList
     Align = alClient
@@ -25,24 +25,24 @@
     OnChange = PageControlChange
     object TabSheetList: TTabSheet
       Caption = 'List'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel7: TPanel
         Left = 0
-        Height = 361
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 2
-        ClientHeight = 361
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object ListTree: TTreeView
           Left = 2
-          Height = 357
+          Height = 370
           Top = 2
-          Width = 292
+          Width = 288
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -55,7 +55,6 @@
           ShowRoot = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
         end
@@ -63,24 +62,24 @@
     end
     object TabSheetPaletteTree: TTabSheet
       Caption = 'Palette'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object pnPaletteTree: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object PalletteTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -92,7 +91,6 @@
           ShowLines = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
         end
@@ -100,24 +98,24 @@
     end
     object TabSheetInheritance: TTabSheet
       Caption = 'Inheritance'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel6: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object InheritanceTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -129,7 +127,6 @@
           ScrollBars = ssAutoBoth
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
         end
@@ -138,22 +135,22 @@
   end
   object FilterPanel: TPanel
     Left = 0
-    Height = 31
+    Height = 27
     Top = 0
     Width = 300
     Align = alTop
     AutoSize = True
     BevelOuter = bvNone
-    ClientHeight = 31
+    ClientHeight = 27
     ClientWidth = 300
     TabOrder = 0
     object LabelSearch: TLabel
       AnchorSideLeft.Control = FilterPanel
       AnchorSideTop.Control = FilterPanel
       Left = 6
-      Height = 19
+      Height = 15
       Top = 6
-      Width = 86
+      Width = 63
       BorderSpacing.Around = 6
       Caption = 'LabelSearch'
       ParentColor = False
@@ -163,10 +160,10 @@
       AnchorSideLeft.Side = asrBottom
       AnchorSideTop.Control = LabelSearch
       AnchorSideTop.Side = asrCenter
-      Left = 98
-      Height = 29
-      Top = 1
-      Width = 198
+      Left = 75
+      Height = 23
+      Top = 2
+      Width = 221
       OnAfterFilter = TreeFilterEdAfterFilter
       ButtonWidth = 23
       NumGlyphs = 1
@@ -179,8 +176,8 @@
   end
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 30
-    Top = 431
+    Height = 26
+    Top = 435
     Width = 288
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
Index: componentlist.pas
===================================================================
--- componentlist.pas	(revision 52792)
+++ componentlist.pas	(working copy)
@@ -34,7 +34,7 @@
 uses
   Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
   ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
-  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
+  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits;
 
 type
 
@@ -78,7 +78,6 @@
     procedure tmDeselectTimer(Sender: TObject);
     procedure TreeFilterEdAfterFilter(Sender: TObject);
     procedure PageControlChange(Sender: TObject);
-    procedure TreeKeyPress(Sender: TObject; var Key: char);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
   private
     PrevPageIndex: Integer;
@@ -97,6 +96,8 @@
     procedure DoComponentInheritence(Comp: TRegisteredComponent);
     procedure UpdateComponents;
     procedure UpdateButtonState;
+
+    procedure CreateComponentOnDesigner;
   protected
     procedure UpdateShowing; override;
   public
@@ -145,6 +146,8 @@
     IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
     IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
   end;
+
+  ActiveControl := TreeFilterEd;
 end;
 
 destructor TComponentListForm.Destroy;
@@ -243,6 +246,50 @@
   ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
 end;
 
+procedure TComponentListForm.CreateComponentOnDesigner;
+var
+  TypeClass: TComponentClass;
+  ParentComp: TComponent;
+  X, Y: integer;
+  AComponent: TComponent;
+  DisableAutoSize: Boolean;
+  selComponent: TRegisteredComponent;
+begin
+  selComponent := GetSelectedComponent;
+
+  if Assigned(FormEditingHook) and Assigned(selComponent) then
+  begin
+    TypeClass:=selComponent.ComponentClass;
+    if assigned(selComponent.OnGetCreationClass) then
+      selComponent.OnGetCreationClass(Self,TypeClass);
+    if TypeClass=nil then
+      exit;
+
+    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
+    if ParentComp=nil then
+      Exit;
+    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
+      exit;
+    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
+    DisableAutoSize:=true;
+    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
+      DisableAutoSize);
+    if AComponent<>nil then
+    begin
+      if DisableAutoSize and (AComponent is TControl) then
+        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
+      GlobalDesignHook.PersistentAdded(AComponent,true);
+    end;
+
+    ClearSelection;
+    TreeFilterEd.SelectAll;
+    TreeFilterEd.SetFocus;
+
+    if Assigned(IDEComponentPalette.OnClassSelected) then
+      IDEComponentPalette.OnClassSelected(Self);
+  end;
+end;
+
 procedure TComponentListForm.UpdateShowing;
 begin
   if (ButtonPanel<>nil) and ButtonPanel.Visible then
@@ -383,7 +430,7 @@
 procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
 // This is used for all 3 treeviews
 begin
-  OKButtonClick(nil);       // Select and close this form
+  CreateComponentOnDesigner;
 end;
 
 procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
@@ -415,13 +462,6 @@
   end
 end;
 
-procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
-// This is used for all 3 treeviews
-begin
-  if Key = Char(VK_RETURN) then
-    ComponentsDblClick(Sender);
-end;
-
 procedure TComponentListForm.PageControlChange(Sender: TObject);
 begin
   FPageControlChange := True;
@@ -488,6 +528,10 @@
       Close
     else
       ClearSelection; //unselect if component is selected
+  end
+  else if Key = VK_RETURN then
+  begin
+    CreateComponentOnDesigner;
   end;
 end;
 
componentlist3.patch (9,158 bytes)

Markus

2016-08-10 18:46

reporter   ~0094083

Unfortunatelly, I cannot delete attached files. So I uploaded a 3rd one.
+ When the componentlist is invoked with the shortcut, the treefilter editbox is already selected. So you can add all component at once without using the mouse.
+ Double click does also create the component.

componentlist3.patch

Markus

2016-08-16 15:15

reporter  

componentlist.jpg (62,049 bytes)
componentlist.jpg (62,049 bytes)

Ondrej Pokorny

2016-08-16 22:36

developer   ~0094148

How it works now:
a1.) Hit Ctrl+Alt+P to show component window
a2.) Select the component
a3.) Hit Enter. The component window is hidden if undocked.
a4.) Click with mouse where you want to add the component

If you want this behavior to be changed you must achieve:

b1.) Hit Ctrl+Alt+P to show component window
b2.) Select the component (without Enter)
b3.) Click with mouse where you want to add the component. The component window is hidden if undocked.
AND
c1.) Hit Ctrl+Alt+P to show component window
c2.) Hit enter to add the component into the current control (if component is a control) or in the form (if it's a component). The component window is hidden if undocked.

Both (b) and (c) must be implemented if you want the patch to be applied to trunk.

Markus

2016-08-18 17:00

reporter   ~0094175

Last edited: 2016-08-18 17:02

View 2 revisions

@Ondrej: Why should the component window hide, when you place a component on the form? Maybe somebody want to place more then one component before the window hides. Why not using the ESC key to hide the window if somebody is finished? This behaviour is more intuitive for me. You can add all components without using the mouse!

Using both hands to press Ctrl+Alt+P to invoke the component window, then switching a hand back to the mouse to place a component, then again moving the hand away from the mouse to the keyboard to press Ctrl+Alt+P to start the process again is not very elegant.

By the way b3) also doesn't hide the component window in v1.6

In my patch all steps are achieved (b and c), besides to hide the undocked window.
ESC is closing the window by the first press. It doesn't need to clear the filter edit anymore, since the filter text is focused and selected, by adding a component with ENTER, double click or by showing the window. So you can just type (override) the next filter text.

Markus

2016-08-24 10:21

reporter  

componentlist4.patch (10,334 bytes)
Index: componentlist.lfm
===================================================================
--- componentlist.lfm	(revision 52792)
+++ componentlist.lfm	(working copy)
@@ -15,8 +15,8 @@
   Visible = False
   object PageControl: TPageControl
     Left = 0
-    Height = 394
-    Top = 31
+    Height = 402
+    Top = 27
     Width = 300
     ActivePage = TabSheetList
     Align = alClient
@@ -25,24 +25,24 @@
     OnChange = PageControlChange
     object TabSheetList: TTabSheet
       Caption = 'List'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel7: TPanel
         Left = 0
-        Height = 361
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 2
-        ClientHeight = 361
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object ListTree: TTreeView
           Left = 2
-          Height = 357
+          Height = 370
           Top = 2
-          Width = 292
+          Width = 288
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -55,7 +55,6 @@
           ShowRoot = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
         end
@@ -63,24 +62,24 @@
     end
     object TabSheetPaletteTree: TTabSheet
       Caption = 'Palette'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object pnPaletteTree: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object PalletteTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -92,7 +91,6 @@
           ShowLines = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
         end
@@ -100,24 +98,24 @@
     end
     object TabSheetInheritance: TTabSheet
       Caption = 'Inheritance'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel6: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object InheritanceTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -129,7 +127,6 @@
           ScrollBars = ssAutoBoth
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
         end
@@ -138,22 +135,22 @@
   end
   object FilterPanel: TPanel
     Left = 0
-    Height = 31
+    Height = 27
     Top = 0
     Width = 300
     Align = alTop
     AutoSize = True
     BevelOuter = bvNone
-    ClientHeight = 31
+    ClientHeight = 27
     ClientWidth = 300
     TabOrder = 0
     object LabelSearch: TLabel
       AnchorSideLeft.Control = FilterPanel
       AnchorSideTop.Control = FilterPanel
       Left = 6
-      Height = 19
+      Height = 15
       Top = 6
-      Width = 86
+      Width = 63
       BorderSpacing.Around = 6
       Caption = 'LabelSearch'
       ParentColor = False
@@ -163,10 +160,10 @@
       AnchorSideLeft.Side = asrBottom
       AnchorSideTop.Control = LabelSearch
       AnchorSideTop.Side = asrCenter
-      Left = 98
-      Height = 29
-      Top = 1
-      Width = 198
+      Left = 75
+      Height = 23
+      Top = 2
+      Width = 221
       OnAfterFilter = TreeFilterEdAfterFilter
       ButtonWidth = 23
       NumGlyphs = 1
@@ -179,8 +176,8 @@
   end
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 30
-    Top = 431
+    Height = 26
+    Top = 435
     Width = 288
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
Index: componentlist.pas
===================================================================
--- componentlist.pas	(revision 52792)
+++ componentlist.pas	(working copy)
@@ -34,7 +34,7 @@
 uses
   Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
   ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
-  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
+  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits;
 
 type
 
@@ -78,7 +78,6 @@
     procedure tmDeselectTimer(Sender: TObject);
     procedure TreeFilterEdAfterFilter(Sender: TObject);
     procedure PageControlChange(Sender: TObject);
-    procedure TreeKeyPress(Sender: TObject; var Key: char);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
   private
     PrevPageIndex: Integer;
@@ -97,6 +96,9 @@
     procedure DoComponentInheritence(Comp: TRegisteredComponent);
     procedure UpdateComponents;
     procedure UpdateButtonState;
+    function IsUndocked: Boolean;
+
+    procedure CreateComponentOnDesigner;
   protected
     procedure UpdateShowing; override;
   public
@@ -145,6 +147,8 @@
     IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
     IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
   end;
+
+  ActiveControl := TreeFilterEd;
 end;
 
 destructor TComponentListForm.Destroy;
@@ -158,7 +162,7 @@
 procedure TComponentListForm.FormShow(Sender: TObject);
 begin
   //DebugLn(['*** TComponentListForm.FormShow, Parent=', Parent, ', Parent.Parent=', ParentParent]);
-  ButtonPanel.Visible := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
+  ButtonPanel.Visible := IsUndocked;
   if ButtonPanel.Visible then
   begin                              // ComponentList is undocked
     PageControl.AnchorSideBottom.Side := asrTop;
@@ -175,6 +179,7 @@
 begin
   if Assigned(IDEComponentPalette) and (IDEComponentPalette.ChangeStamp<>PrevChangeStamp) then
     UpdateComponents;
+
 end;
 
 procedure TComponentListForm.ClearSelection;
@@ -243,6 +248,55 @@
   ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
 end;
 
+function TComponentListForm.IsUndocked: Boolean;
+begin
+  Result := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
+end;
+
+procedure TComponentListForm.CreateComponentOnDesigner;
+var
+  TypeClass: TComponentClass;
+  ParentComp: TComponent;
+  X, Y: integer;
+  AComponent: TComponent;
+  DisableAutoSize: Boolean;
+  selComponent: TRegisteredComponent;
+begin
+  selComponent := GetSelectedComponent;
+
+  if Assigned(FormEditingHook) and Assigned(selComponent) then
+  begin
+    TypeClass:=selComponent.ComponentClass;
+    if assigned(selComponent.OnGetCreationClass) then
+      selComponent.OnGetCreationClass(Self,TypeClass);
+    if TypeClass=nil then
+      exit;
+
+    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
+    if ParentComp=nil then
+      Exit;
+    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
+      exit;
+    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
+    DisableAutoSize:=true;
+    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
+      DisableAutoSize);
+    if AComponent<>nil then
+    begin
+      if DisableAutoSize and (AComponent is TControl) then
+        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
+      GlobalDesignHook.PersistentAdded(AComponent,true);
+    end;
+
+    ClearSelection;
+    TreeFilterEd.SelectAll;
+    TreeFilterEd.SetFocus;
+
+    if Assigned(IDEComponentPalette.OnClassSelected) then
+      IDEComponentPalette.OnClassSelected(Self);
+  end;
+end;
+
 procedure TComponentListForm.UpdateShowing;
 begin
   if (ButtonPanel<>nil) and ButtonPanel.Visible then
@@ -383,7 +437,10 @@
 procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
 // This is used for all 3 treeviews
 begin
-  OKButtonClick(nil);       // Select and close this form
+  if IsUndocked then
+    OKButtonClick(nil)
+  else
+    CreateComponentOnDesigner;
 end;
 
 procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
@@ -415,13 +472,6 @@
   end
 end;
 
-procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
-// This is used for all 3 treeviews
-begin
-  if Key = Char(VK_RETURN) then
-    ComponentsDblClick(Sender);
-end;
-
 procedure TComponentListForm.PageControlChange(Sender: TObject);
 begin
   FPageControlChange := True;
@@ -488,6 +538,13 @@
       Close
     else
       ClearSelection; //unselect if component is selected
+  end
+  else if Key = VK_RETURN then
+  begin
+    if IsUndocked then
+      OKButtonClick(nil) //Only in undocked mode
+    else
+      CreateComponentOnDesigner;
   end;
 end;
 
@@ -498,7 +555,6 @@
 begin
   AComponent := GetSelectedComponent;
   if AComponent<>nil then begin
-    FPageControlChange:=True;
     IDEComponentPalette.Selected := AComponent;
     FKeepSelected := True;
     Close;
componentlist4.patch (10,334 bytes)

Markus

2016-08-24 10:27

reporter   ~0094299

Last edited: 2016-08-24 10:37

View 2 revisions

@Ondrej: I added a patch (componentlist4.patch), where all your points b and c are fullfilled, if it is in undocked mode (current behaviour). When in docked mode, ENTER and double click will create the component on the form.

I really would like to see that feature in lazarus, since I am a delphi developer and want to move to lazarus, and want to help to improve it in order to make switching from delphi to lazarus more comfortable.

Markus

2016-08-25 09:43

reporter   ~0094307

Question:
With the latest patch 4 (in docked mode), when a component is created on the form (by double click or ENTER), afterwards the selection/focus goes to the form. That means if you want to create components in a container like TGroupBox or TPanel, you always have to re-select that container first (by mouse). This is the default behaviour by the ComponentPalette (double click).

In contrast to Delphi, when a component is created on the form, that component gains the focus.

1) Should I also implement the Delphi behaviour? So that the last created component gets the focus? Drawback: If you want to add a panel and a button, on the form, the button is created in the panel, when the panel is added first.
2) Or should the container of the last created component gain the focus? Drawback: Not so intuitive, the added component is not selected. You need to select the component in order it's properties are shown in the property inspector.
3) Or should it be the same way as by the ComponentPalette (no changes)? Drawback: I always need to re-select the container where I want to put the components.

Ondrej Pokorny

2016-08-26 08:57

developer   ~0094321

Sorry I didn't answer - I am on vacation until the end of september, I'll get back then. The component list has been reworked several times the last year. I'm sure we find a good solution, thanks a lot for the patches!

Markus

2016-08-28 09:13

reporter  

componentlist5.patch (10,792 bytes)
Index: componentlist.lfm
===================================================================
--- componentlist.lfm	(revision 52792)
+++ componentlist.lfm	(working copy)
@@ -15,8 +15,8 @@
   Visible = False
   object PageControl: TPageControl
     Left = 0
-    Height = 394
-    Top = 31
+    Height = 402
+    Top = 27
     Width = 300
     ActivePage = TabSheetList
     Align = alClient
@@ -25,24 +25,24 @@
     OnChange = PageControlChange
     object TabSheetList: TTabSheet
       Caption = 'List'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel7: TPanel
         Left = 0
-        Height = 361
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 2
-        ClientHeight = 361
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object ListTree: TTreeView
           Left = 2
-          Height = 357
+          Height = 370
           Top = 2
-          Width = 292
+          Width = 288
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -55,7 +55,6 @@
           ShowRoot = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
         end
@@ -63,24 +62,24 @@
     end
     object TabSheetPaletteTree: TTabSheet
       Caption = 'Palette'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object pnPaletteTree: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object PalletteTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -92,7 +91,6 @@
           ShowLines = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
         end
@@ -100,24 +98,24 @@
     end
     object TabSheetInheritance: TTabSheet
       Caption = 'Inheritance'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel6: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object InheritanceTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -129,7 +127,6 @@
           ScrollBars = ssAutoBoth
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
         end
@@ -138,22 +135,22 @@
   end
   object FilterPanel: TPanel
     Left = 0
-    Height = 31
+    Height = 27
     Top = 0
     Width = 300
     Align = alTop
     AutoSize = True
     BevelOuter = bvNone
-    ClientHeight = 31
+    ClientHeight = 27
     ClientWidth = 300
     TabOrder = 0
     object LabelSearch: TLabel
       AnchorSideLeft.Control = FilterPanel
       AnchorSideTop.Control = FilterPanel
       Left = 6
-      Height = 19
+      Height = 15
       Top = 6
-      Width = 86
+      Width = 63
       BorderSpacing.Around = 6
       Caption = 'LabelSearch'
       ParentColor = False
@@ -163,10 +160,10 @@
       AnchorSideLeft.Side = asrBottom
       AnchorSideTop.Control = LabelSearch
       AnchorSideTop.Side = asrCenter
-      Left = 98
-      Height = 29
-      Top = 1
-      Width = 198
+      Left = 75
+      Height = 23
+      Top = 2
+      Width = 221
       OnAfterFilter = TreeFilterEdAfterFilter
       ButtonWidth = 23
       NumGlyphs = 1
@@ -179,8 +176,8 @@
   end
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 30
-    Top = 431
+    Height = 26
+    Top = 435
     Width = 288
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
Index: componentlist.pas
===================================================================
--- componentlist.pas	(revision 52792)
+++ componentlist.pas	(working copy)
@@ -34,7 +34,8 @@
 uses
   Classes, SysUtils, LCLType, Forms, Controls, Graphics, StdCtrls, ExtCtrls,
   ComCtrls, ButtonPanel, Menus, LazarusIDEStrConsts, ComponentReg, PackageDefs,
-  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs;
+  IDEImagesIntf, TreeFilterEdit, FormEditingIntf, IDEOptionDefs, PropEdits,
+  EnvironmentOpts, AskCompNameDlg;
 
 type
 
@@ -78,7 +79,6 @@
     procedure tmDeselectTimer(Sender: TObject);
     procedure TreeFilterEdAfterFilter(Sender: TObject);
     procedure PageControlChange(Sender: TObject);
-    procedure TreeKeyPress(Sender: TObject; var Key: char);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
   private
     PrevPageIndex: Integer;
@@ -97,6 +97,9 @@
     procedure DoComponentInheritence(Comp: TRegisteredComponent);
     procedure UpdateComponents;
     procedure UpdateButtonState;
+    function IsUndocked: Boolean;
+
+    procedure CreateComponentOnDesigner;
   protected
     procedure UpdateShowing; override;
   public
@@ -145,6 +148,8 @@
     IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
     IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
   end;
+
+  ActiveControl := TreeFilterEd;
 end;
 
 destructor TComponentListForm.Destroy;
@@ -158,7 +163,7 @@
 procedure TComponentListForm.FormShow(Sender: TObject);
 begin
   //DebugLn(['*** TComponentListForm.FormShow, Parent=', Parent, ', Parent.Parent=', ParentParent]);
-  ButtonPanel.Visible := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
+  ButtonPanel.Visible := IsUndocked;
   if ButtonPanel.Visible then
   begin                              // ComponentList is undocked
     PageControl.AnchorSideBottom.Side := asrTop;
@@ -175,6 +180,7 @@
 begin
   if Assigned(IDEComponentPalette) and (IDEComponentPalette.ChangeStamp<>PrevChangeStamp) then
     UpdateComponents;
+
 end;
 
 procedure TComponentListForm.ClearSelection;
@@ -243,6 +249,68 @@
   ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
 end;
 
+function TComponentListForm.IsUndocked: Boolean;
+begin
+  Result := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
+end;
+
+procedure TComponentListForm.CreateComponentOnDesigner;
+var
+  TypeClass: TComponentClass;
+  ParentComp: TComponent;
+  X, Y: integer;
+  AComponent, LookupRoot: TComponent;
+  DisableAutoSize: Boolean;
+  selComponent: TRegisteredComponent;
+begin
+  selComponent := GetSelectedComponent;
+
+  if Assigned(FormEditingHook) and Assigned(selComponent) then
+  begin
+    TypeClass:=selComponent.ComponentClass;
+    if assigned(selComponent.OnGetCreationClass) then
+      selComponent.OnGetCreationClass(Self,TypeClass);
+    if TypeClass=nil then
+      exit;
+
+    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
+    if ParentComp=nil then
+      Exit;
+    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
+      exit;
+    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
+    DisableAutoSize:=true;
+    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
+      DisableAutoSize);
+    if AComponent<>nil then
+    begin
+      if DisableAutoSize and (AComponent is TControl) then
+        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
+      GlobalDesignHook.PersistentAdded(AComponent,true);
+
+      if EnvironmentOptions.CreateComponentFocusNameProperty then
+      begin
+        // ask user for name
+        if GlobalDesignHook.LookupRoot is TComponent then
+        begin
+          LookupRoot := TComponent(GlobalDesignHook.LookupRoot);
+          AComponent.Name:=ShowComponentNameDialog(LookupRoot,AComponent);
+        end;
+      end;
+
+      GlobalDesignHook.SelectOnlyThis(AComponent);
+    end;
+
+    ClearSelection;
+    TreeFilterEd.SelectAll;
+    TreeFilterEd.SetFocus;
+
+    if Assigned(IDEComponentPalette.OnClassSelected) then
+      IDEComponentPalette.OnClassSelected(Self);
+
+  end;
+end;
+
 procedure TComponentListForm.UpdateShowing;
 begin
   if (ButtonPanel<>nil) and ButtonPanel.Visible then
@@ -383,7 +451,10 @@
 procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
 // This is used for all 3 treeviews
 begin
-  OKButtonClick(nil);       // Select and close this form
+  if IsUndocked then
+    OKButtonClick(nil)
+  else
+    CreateComponentOnDesigner;
 end;
 
 procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
@@ -415,13 +486,6 @@
   end
 end;
 
-procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
-// This is used for all 3 treeviews
-begin
-  if Key = Char(VK_RETURN) then
-    ComponentsDblClick(Sender);
-end;
-
 procedure TComponentListForm.PageControlChange(Sender: TObject);
 begin
   FPageControlChange := True;
@@ -488,6 +552,13 @@
       Close
     else
       ClearSelection; //unselect if component is selected
+  end
+  else if Key = VK_RETURN then
+  begin
+    if IsUndocked then
+      OKButtonClick(nil) //Only in undocked mode
+    else
+      CreateComponentOnDesigner;
   end;
 end;
 
@@ -498,7 +569,6 @@
 begin
   AComponent := GetSelectedComponent;
   if AComponent<>nil then begin
-    FPageControlChange:=True;
     IDEComponentPalette.Selected := AComponent;
     FKeepSelected := True;
     Close;
componentlist5.patch (10,792 bytes)

Markus

2016-08-28 09:19

reporter   ~0094331

Changes in patch 5:
When a component is added by ENTER or double click:
1) the environmental option "ask for component name" is considert.
2) the currently added component is selected. This feels most natural to me. But I am open if another solution is used as stated above.

Ondrej Pokorny

2016-09-22 06:31

developer   ~0094761

I tested both 3 a 5 patch and they are both not good.

3 patch: doesn't work a second time for me.
5 patch: the component is not added any more when I select it and hit enter. The dialog is closed, though.

Your approach is very wrong, you use duplicate functionality when introducing CreateComponentOnDesigner. Don't do that. Use the original approach to add component to the form.

+ Why not to make it easy and create a "Close" check box next to the "Use and close" button (that has to be renamed to "Use")?

Markus

2016-09-22 11:18

reporter  

componentlist6.patch (17,332 bytes)
Index: components/ideintf/componentreg.pas
===================================================================
--- components/ideintf/componentreg.pas	(revision 53017)
+++ components/ideintf/componentreg.pas	(working copy)
@@ -28,7 +28,7 @@
   {$IFDEF CustomIDEComps}
   CustomIDEComps,
   {$ENDIF}
-  Controls, Laz2_XMLCfg, LCLProc;
+  Controls, Laz2_XMLCfg, LCLProc, FormEditingIntf, PropEdits;
 
 type
   TComponentPriorityCategory = (
@@ -234,6 +234,8 @@
     function GetMultiSelect: boolean;
     procedure SetSelected(const AValue: TRegisteredComponent);
     procedure SetMultiSelect(AValue: boolean);
+  protected
+    procedure AskForComponentNameOnDemand(AComponent: TComponent); virtual;
   public
     constructor Create(EnvPaletteOptions: TCompPaletteOptions);
     destructor Destroy; override;
@@ -254,6 +256,7 @@
     procedure Update({%H-}ForceUpdateAll: Boolean); virtual;
     procedure IterateRegisteredClasses(Proc: TGetComponentClassEvent);
     procedure SetSelectedComp(AComponent: TRegisteredComponent; AMulti: Boolean);
+    function CreateComponentOnDesigner(aSelectedComp: TRegisteredComponent): Boolean;
     // Registered handlers
     procedure DoAfterComponentAdded(ALookupRoot, AComponent: TComponent;
                             ARegisteredComponent: TRegisteredComponent); virtual;
@@ -890,6 +893,11 @@
     FSelectionMode := csmSingle;
 end;
 
+procedure TBaseComponentPalette.AskForComponentNameOnDemand(AComponent: TComponent);
+begin
+  //Do due dependecies cycle, this function needs to be implemented on the derived class.
+end;
+
 procedure TBaseComponentPalette.AddHandler(HandlerType: TComponentPaletteHandlerType;
   const AMethod: TMethod; AsLast: boolean);
 begin
@@ -1068,6 +1076,50 @@
   Selected := AComponent;
 end;
 
+function TBaseComponentPalette.CreateComponentOnDesigner(
+  aSelectedComp: TRegisteredComponent): Boolean;
+var
+  TypeClass: TComponentClass;
+  ParentComp: TComponent;
+  X, Y: integer;
+  AComponent: TComponent;
+  DisableAutoSize: Boolean;
+begin
+  Result := false;
+
+  if Assigned(FormEditingHook) and Assigned(aSelectedComp) then
+  begin
+    TypeClass:=aSelectedComp.ComponentClass;
+    if assigned(aSelectedComp.OnGetCreationClass) then
+      aSelectedComp.OnGetCreationClass(Self,TypeClass);
+    if TypeClass=nil then
+      Exit(false);
+
+    ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
+    if ParentComp=nil then
+      Exit(false);
+
+    if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y) then
+      Exit(false);
+
+    //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
+    DisableAutoSize:=true;
+    AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
+      DisableAutoSize);
+    if AComponent<>nil then
+    begin
+      if DisableAutoSize and (AComponent is TControl) then
+        TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
+      GlobalDesignHook.PersistentAdded(AComponent,true);
+
+      AskForComponentNameOnDemand(AComponent);
+
+      GlobalDesignHook.SelectOnlyThis(AComponent);
+    end;
+    Result := true;
+  end;
+end;
+
 // Execute handlers
 
 function TBaseComponentPalette.VoteCompVisibility(AComponent: TRegisteredComponent): Boolean;
Index: ide/componentlist.lfm
===================================================================
--- ide/componentlist.lfm	(revision 53017)
+++ ide/componentlist.lfm	(working copy)
@@ -12,11 +12,10 @@
   OnKeyDown = FormKeyDown
   OnShow = FormShow
   LCLVersion = '1.7'
-  Visible = False
   object PageControl: TPageControl
     Left = 0
-    Height = 394
-    Top = 31
+    Height = 402
+    Top = 27
     Width = 300
     ActivePage = TabSheetList
     Align = alClient
@@ -25,24 +24,24 @@
     OnChange = PageControlChange
     object TabSheetList: TTabSheet
       Caption = 'List'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel7: TPanel
         Left = 0
-        Height = 361
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 2
-        ClientHeight = 361
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object ListTree: TTreeView
           Left = 2
-          Height = 357
+          Height = 370
           Top = 2
-          Width = 292
+          Width = 288
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -55,7 +54,6 @@
           ShowRoot = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoToolTips]
         end
@@ -63,24 +61,24 @@
     end
     object TabSheetPaletteTree: TTabSheet
       Caption = 'Palette'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object pnPaletteTree: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object PalletteTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -92,7 +90,6 @@
           ShowLines = False
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowRoot, tvoToolTips]
         end
@@ -100,24 +97,24 @@
     end
     object TabSheetInheritance: TTabSheet
       Caption = 'Inheritance'
-      ClientHeight = 361
-      ClientWidth = 296
+      ClientHeight = 374
+      ClientWidth = 292
       object Panel6: TPanel
         Left = 0
-        Height = 375
+        Height = 374
         Top = 0
-        Width = 296
+        Width = 292
         Align = alClient
         BevelOuter = bvNone
         BorderWidth = 5
-        ClientHeight = 375
-        ClientWidth = 296
+        ClientHeight = 374
+        ClientWidth = 292
         TabOrder = 0
         object InheritanceTree: TTreeView
           Left = 5
-          Height = 365
+          Height = 364
           Top = 5
-          Width = 286
+          Width = 282
           Align = alClient
           DefaultItemHeight = 26
           Images = imListPalette
@@ -129,7 +126,6 @@
           ScrollBars = ssAutoBoth
           TabOrder = 0
           OnDblClick = ComponentsDblClick
-          OnKeyPress = TreeKeyPress
           OnSelectionChanged = ListTreeSelectionChanged
           Options = [tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRightClickSelect, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
         end
@@ -138,22 +134,22 @@
   end
   object FilterPanel: TPanel
     Left = 0
-    Height = 31
+    Height = 27
     Top = 0
     Width = 300
     Align = alTop
     AutoSize = True
     BevelOuter = bvNone
-    ClientHeight = 31
+    ClientHeight = 27
     ClientWidth = 300
     TabOrder = 0
     object LabelSearch: TLabel
       AnchorSideLeft.Control = FilterPanel
       AnchorSideTop.Control = FilterPanel
       Left = 6
-      Height = 19
+      Height = 15
       Top = 6
-      Width = 86
+      Width = 63
       BorderSpacing.Around = 6
       Caption = 'LabelSearch'
       ParentColor = False
@@ -163,10 +159,10 @@
       AnchorSideLeft.Side = asrBottom
       AnchorSideTop.Control = LabelSearch
       AnchorSideTop.Side = asrCenter
-      Left = 98
-      Height = 29
-      Top = 1
-      Width = 198
+      Left = 75
+      Height = 23
+      Top = 2
+      Width = 221
       OnAfterFilter = TreeFilterEdAfterFilter
       ButtonWidth = 23
       NumGlyphs = 1
@@ -179,8 +175,8 @@
   end
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 30
-    Top = 431
+    Height = 26
+    Top = 435
     Width = 288
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
Index: ide/componentlist.pas
===================================================================
--- ide/componentlist.pas	(revision 53017)
+++ ide/componentlist.pas	(working copy)
@@ -78,7 +78,6 @@
     procedure tmDeselectTimer(Sender: TObject);
     procedure TreeFilterEdAfterFilter(Sender: TObject);
     procedure PageControlChange(Sender: TObject);
-    procedure TreeKeyPress(Sender: TObject; var Key: char);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
   private
     PrevPageIndex: Integer;
@@ -97,12 +96,16 @@
     procedure DoComponentInheritence(Comp: TRegisteredComponent);
     procedure UpdateComponents;
     procedure UpdateButtonState;
+    function IsUndocked: Boolean;
+
+    procedure CreateComponentOnDesigner;
   protected
     procedure UpdateShowing; override;
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
     function GetSelectedComponent: TRegisteredComponent;
+    procedure ExpliciteActivate;
   end;
   
 var
@@ -145,6 +148,8 @@
     IDEComponentPalette.AddHandlerSelectionChanged(@SelectionWasChanged);
     IDEComponentPalette.AddHandlerComponentAdded(@ComponentWasAdded);
   end;
+
+  ActiveControl := TreeFilterEd;
 end;
 
 destructor TComponentListForm.Destroy;
@@ -158,7 +163,7 @@
 procedure TComponentListForm.FormShow(Sender: TObject);
 begin
   //DebugLn(['*** TComponentListForm.FormShow, Parent=', Parent, ', Parent.Parent=', ParentParent]);
-  ButtonPanel.Visible := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
+  ButtonPanel.Visible := IsUndocked;
   if ButtonPanel.Visible then
   begin                              // ComponentList is undocked
     PageControl.AnchorSideBottom.Side := asrTop;
@@ -175,6 +180,7 @@
 begin
   if Assigned(IDEComponentPalette) and (IDEComponentPalette.ChangeStamp<>PrevChangeStamp) then
     UpdateComponents;
+
 end;
 
 procedure TComponentListForm.ClearSelection;
@@ -231,6 +237,13 @@
     Result := GetSelectedTreeComp(InheritanceTree)
 end;
 
+procedure TComponentListForm.ExpliciteActivate;
+begin
+  //In docked mode, the Active event is not fired, and the TreeFilter gets not selected.
+  if TreeFilterEd.CanSetFocus then
+    TreeFilterEd.SetFocus;
+end;
+
 procedure TComponentListForm.ComponentWasAdded(ALookupRoot, AComponent: TComponent;
   ARegisteredComponent: TRegisteredComponent);
 begin
@@ -243,6 +256,28 @@
   ButtonPanel.OKButton.Enabled := Assigned(GetSelectedComponent);
 end;
 
+function TComponentListForm.IsUndocked: Boolean;
+begin
+  Result := (HostDockSite=Nil) or (HostDockSite.Parent=Nil);
+end;
+
+procedure TComponentListForm.CreateComponentOnDesigner;
+var
+  selComponent: TRegisteredComponent;
+begin
+  selComponent := GetSelectedComponent;
+
+  if IDEComponentPalette.CreateComponentOnDesigner(selComponent) then
+  begin
+    ClearSelection;
+    TreeFilterEd.SelectAll;
+    TreeFilterEd.SetFocus;
+
+    if Assigned(IDEComponentPalette.OnClassSelected) then
+      IDEComponentPalette.OnClassSelected(Self);
+  end;
+end;
+
 procedure TComponentListForm.UpdateShowing;
 begin
   if (ButtonPanel<>nil) and ButtonPanel.Visible then
@@ -383,17 +418,19 @@
 procedure TComponentListForm.ComponentsDblClick(Sender: TObject);
 // This is used for all 3 treeviews
 begin
-  OKButtonClick(nil);       // Select and close this form
+  if IsUndocked then
+    OKButtonClick(nil)
+  else
+    CreateComponentOnDesigner;
 end;
 
 procedure TComponentListForm.ListTreeSelectionChanged(Sender: TObject);
 var
   AComponent: TRegisteredComponent;
 begin
-  UpdateButtonState;
   if FInitialized then
   begin
-    if FPageControlChange then
+    if FPageControlChange or FKeepSelected then
       Exit;
     AComponent:=GetSelectedComponent;
     if AComponent<>nil then
@@ -404,6 +441,7 @@
       IDEComponentPalette.SetSelectedComp(nil, False);
       FIgnoreSelection := False;
     end;
+    UpdateButtonState;
   end
   else begin
     // Only run once when the IDE starts.
@@ -415,13 +453,6 @@
   end
 end;
 
-procedure TComponentListForm.TreeKeyPress(Sender: TObject; var Key: char);
-// This is used for all 3 treeviews
-begin
-  if Key = Char(VK_RETURN) then
-    ComponentsDblClick(Sender);
-end;
-
 procedure TComponentListForm.PageControlChange(Sender: TObject);
 begin
   FPageControlChange := True;
@@ -461,8 +492,6 @@
 begin
   if Parent=nil then begin
     ClearSelection;
-    if not fKeepSelected then
-      IDEComponentPalette.Selected := Nil;
   end
   else begin
     // Using a dock manager...
@@ -488,6 +517,13 @@
       Close
     else
       ClearSelection; //unselect if component is selected
+  end
+  else if Key = VK_RETURN then
+  begin
+    if IsUndocked then
+      OKButtonClick(nil) //Only in undocked mode
+    else
+      CreateComponentOnDesigner;
   end;
 end;
 
@@ -498,7 +534,6 @@
 begin
   AComponent := GetSelectedComponent;
   if AComponent<>nil then begin
-    FPageControlChange:=True;
     IDEComponentPalette.Selected := AComponent;
     FKeepSelected := True;
     Close;
Index: ide/componentpalette.pas
===================================================================
--- ide/componentpalette.pas	(revision 53017)
+++ ide/componentpalette.pas	(working copy)
@@ -42,7 +42,7 @@
   Controls, Forms, Graphics, ComCtrls, Buttons, Menus, ExtCtrls,
   LazFileUtils, LazFileCache, PropEdits, LCLProc, MainBase, LazarusIDEStrConsts,
   FormEditingIntf, LazIDEIntf, IDEImagesIntf,
-  ComponentReg, DesignerProcs, PackageDefs, EnvironmentOpts;
+  ComponentReg, DesignerProcs, PackageDefs, EnvironmentOpts, AskCompNameDlg;
 
 const
   CompPalSelectionToolBtnPrefix = 'PaletteSelectBtn';
@@ -129,6 +129,8 @@
     procedure ComponentWasAdded({%H-}ALookupRoot, {%H-}AComponent: TComponent;
                                 {%H-}ARegisteredComponent: TRegisteredComponent);
     procedure CheckComponentDesignerVisible(AComponent: TComponent; var Invisible: boolean);
+  protected
+    procedure AskForComponentNameOnDemand(AComponent: TComponent); override;
   public
     constructor Create;
     destructor Destroy; override;
@@ -677,27 +679,11 @@
   DisableAutoSize: Boolean;
 begin
   //debugln('TComponentPalette.ComponentBtnDblClick ',TComponent(Sender).Name);
-  if SelectAButton(TSpeedButton(Sender)) and (Selected<>nil) then begin
-    if FormEditingHook<>nil then begin
-      TypeClass:=Selected.ComponentClass;
-      if assigned(Selected.OnGetCreationClass) then
-        Selected.OnGetCreationClass(Self,TypeClass);
-      if TypeClass=nil then exit;
-      ParentComp:=FormEditingHook.GetDefaultComponentParent(TypeClass);
-      if ParentComp=nil then exit;
-      if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentComp,X,Y)
-      then exit;
-      //debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
-      DisableAutoSize:=true;
-      AComponent:=FormEditingHook.CreateComponent(ParentComp,TypeClass,'',X,Y,0,0,
-        DisableAutoSize);
-      if AComponent<>nil then begin
-        if DisableAutoSize and (AComponent is TControl) then
-          TControl(AComponent).EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TComponentPalette.ComponentBtnDblClick'){$ENDIF};
-        GlobalDesignHook.PersistentAdded(AComponent,true);
-      end;
-    end;
+  if SelectAButton(TSpeedButton(Sender)) and (Selected<>nil) then
+  begin
+    CreateComponentOnDesigner(Selected);
   end;
+
   Selected:=nil;
   if Assigned(OnClassSelected) then
     OnClassSelected(Self);
@@ -827,6 +813,21 @@
   end;
 end;
 
+procedure TComponentPalette.AskForComponentNameOnDemand(AComponent: TComponent);
+var
+  lookupRoot: TComponent;
+begin
+  if EnvironmentOptions.CreateComponentFocusNameProperty then
+  begin
+    // ask user for name
+    if GlobalDesignHook.LookupRoot is TComponent then
+    begin
+      lookupRoot := TComponent(GlobalDesignHook.LookupRoot);
+      AComponent.Name:=ShowComponentNameDialog(lookupRoot,AComponent);
+    end;
+  end;
+end;
+
 constructor TComponentPalette.Create;
 begin
   inherited Create(EnvironmentOptions.Desktop.ComponentPaletteOptions);
Index: ide/main.pp
===================================================================
--- ide/main.pp	(revision 53017)
+++ ide/main.pp	(working copy)
@@ -5883,7 +5883,10 @@
   end else if State=iwgfDisabled then
     ComponentListForm.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TMainIDE.DoShowComponentList'){$ENDIF};
   if State>=iwgfShow then
+  begin
     IDEWindowCreators.ShowForm(ComponentListForm,State=iwgfShowOnTop);
+    ComponentListForm.ExpliciteActivate;
+  end;
 end;
 
 procedure TMainIDE.DoShowJumpHistory(State: TIWGetFormState);
componentlist6.patch (17,332 bytes)

Markus

2016-09-22 11:32

reporter   ~0094768

Fixed it in patch 6.
Reason: The window had a different behaviour in undocked mode and in classic mode. I thought undocked (anchoredocking) is the same as classic view (undocked). There was also some glitches in the original code, which are also now fixed by that patch.

I also transfered the CreateComponentOnDesigner into the TBaseComponentPalette base class in order TComponentPalette and TComponentList are using the same function. I was not able to use the orignal function since that functionality was implemented in the TComponentPalette.ComponentBtnDblClick event, and specific to that class behaviour.

I also had to extend the code in main.pp where the componentlist is invoked. In docked mode, I have to make an explicite call to give a specific component the focus.

>> Why not to make it easy and create a "Close" check box ...
Here a custom control is used PanelButton, which needs more action to be done, to add a checkbox. I can investigate it after that patch is applied in order I don't get out of sync with the other files, since there are a lot of check ins ever day.

Let me now, if that patch is OK.

Ondrej Pokorny

2016-10-29 11:59

developer   ~0095390

The patch was not OK at all. You still introduced the function CreateComponentOnDesigner instead of using procedure AddComponent from designer.pp - I talked about it in my previous comment. See r53259. Moving CreateComponentOnDesigner somewhere else doesn't solve anything.

I also said to use a checkbox for the different modes.

Please test. If you check "keep open" the palette will behave like in Delphi. The "keep open" mode is always used when docked - for obvious reasons.

Issue History

Date Modified Username Field Change
2016-08-10 18:27 Markus New Issue
2016-08-10 18:27 Markus File Added: componentlist.patch
2016-08-10 18:36 Markus File Added: componentlist2.patch
2016-08-10 18:37 Markus Note Added: 0094082
2016-08-10 18:43 Markus File Added: componentlist3.patch
2016-08-10 18:46 Markus Note Added: 0094083
2016-08-16 15:15 Markus File Added: componentlist.jpg
2016-08-16 22:36 Ondrej Pokorny Note Added: 0094148
2016-08-18 17:00 Markus Note Added: 0094175
2016-08-18 17:02 Markus Note Edited: 0094175 View Revisions
2016-08-24 10:21 Markus File Added: componentlist4.patch
2016-08-24 10:27 Markus Note Added: 0094299
2016-08-24 10:37 Markus Note Edited: 0094299 View Revisions
2016-08-24 10:42 Juha Manninen Assigned To => Ondrej Pokorny
2016-08-24 10:42 Juha Manninen Status new => assigned
2016-08-25 09:43 Markus Note Added: 0094307
2016-08-26 08:57 Ondrej Pokorny Note Added: 0094321
2016-08-28 09:13 Markus File Added: componentlist5.patch
2016-08-28 09:19 Markus Note Added: 0094331
2016-09-22 06:31 Ondrej Pokorny Note Added: 0094761
2016-09-22 11:18 Markus File Added: componentlist6.patch
2016-09-22 11:32 Markus Note Added: 0094768
2016-10-29 11:59 Ondrej Pokorny Fixed in Revision => 53259, 53260
2016-10-29 11:59 Ondrej Pokorny LazTarget => 1.8
2016-10-29 11:59 Ondrej Pokorny Note Added: 0095390
2016-10-29 11:59 Ondrej Pokorny Status assigned => resolved
2016-10-29 11:59 Ondrej Pokorny Fixed in Version => 1.7 (SVN)
2016-10-29 11:59 Ondrej Pokorny Resolution open => fixed
2016-10-29 11:59 Ondrej Pokorny Target Version => 1.8