LCL: Use ButtonPanel in TreeView component editor. Enable keyboard shortcuts. Part of patch by n7800, submitted for issue #40748

This commit is contained in:
wp_xyz 2024-02-18 00:48:01 +01:00
parent 8c636b64e7
commit d21d97c82a
2 changed files with 165 additions and 91 deletions

View File

@ -1,31 +1,32 @@
object TreeViewItemsEditorForm: TTreeViewItemsEditorForm object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
Left = 329 Left = 329
Height = 321 Height = 326
Top = 230 Top = 230
Width = 635 Width = 635
ActiveControl = btnNewItem ActiveControl = btnNewItem
BorderIcons = [biSystemMenu, biHelp] BorderIcons = [biSystemMenu, biHelp]
Caption = 'TreeView Items Editor' Caption = 'TreeView Items Editor'
ClientHeight = 321 ClientHeight = 326
ClientWidth = 635 ClientWidth = 635
Constraints.MinHeight = 240 Constraints.MinHeight = 240
Constraints.MinWidth = 400 Constraints.MinWidth = 400
KeyPreview = True
Position = poScreenCenter Position = poScreenCenter
LCLVersion = '3.99.0.0' LCLVersion = '3.99.0.0'
OnClose = FormClose OnClose = FormClose
OnCreate = FormCreate OnCreate = FormCreate
OnKeyDown = FormKeyDown
object grpTreeEditor: TGroupBox object grpTreeEditor: TGroupBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner AnchorSideTop.Control = Owner
AnchorSideBottom.Control = btnOK
Left = 6 Left = 6
Height = 277 Height = 282
Top = 6 Top = 6
Width = 420 Width = 420
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'Items' Caption = 'Items'
ClientHeight = 257 ClientHeight = 262
ClientWidth = 416 ClientWidth = 416
TabOrder = 0 TabOrder = 0
object treEditor: TTreeView object treEditor: TTreeView
@ -34,7 +35,7 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideBottom.Control = grpTreeEditor AnchorSideBottom.Control = grpTreeEditor
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 5 Left = 5
Height = 247 Height = 252
Top = 5 Top = 5
Width = 240 Width = 240
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
@ -56,13 +57,13 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 282 Left = 282
Height = 25 Height = 25
Hint = '[Ctrl+N]'
Top = 6 Top = 6
Width = 128 Width = 128
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 3 BorderSpacing.Left = 3
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = '&New Item' Caption = '&New Item'
Default = True
TabOrder = 1 TabOrder = 1
OnClick = btnNewItemClick OnClick = btnNewItemClick
end end
@ -74,6 +75,7 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 282 Left = 282
Height = 25 Height = 25
Hint = '[Ctrl+Shift+N]'
Top = 37 Top = 37
Width = 128 Width = 128
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
@ -90,6 +92,7 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 282 Left = 282
Height = 25 Height = 25
Hint = '[Del]'
Top = 68 Top = 68
Width = 128 Width = 128
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
@ -106,6 +109,7 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 282 Left = 282
Height = 25 Height = 25
Hint = '[Ctrl+O]; [Ctrl+L]'
Top = 99 Top = 99
Width = 128 Width = 128
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
@ -122,6 +126,7 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 282 Left = 282
Height = 25 Height = 25
Hint = '[Ctrl+S]'
Top = 130 Top = 130
Width = 128 Width = 128
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
@ -137,13 +142,14 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 251 Left = 251
Height = 26 Height = 26
Hint = '[Ctrl+Shift+Up]'
Top = 78 Top = 78
Width = 22 Width = 22
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Enabled = False Enabled = False
ShowHint = True ShowHint = True
ParentShowHint = False ParentShowHint = False
OnClick = btnMoveUpClick OnClick = btnMoveClick
end end
object btnMoveDown: TSpeedButton object btnMoveDown: TSpeedButton
AnchorSideLeft.Control = btnMoveUp AnchorSideLeft.Control = btnMoveUp
@ -151,13 +157,14 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 251 Left = 251
Height = 26 Height = 26
Hint = '[Ctrl+Shift+Down]'
Top = 111 Top = 111
Width = 22 Width = 22
BorderSpacing.Top = 7 BorderSpacing.Top = 7
Enabled = False Enabled = False
ShowHint = True ShowHint = True
ParentShowHint = False ParentShowHint = False
OnClick = btnMoveDownClick OnClick = btnMoveClick
end end
end end
object grpNodeEditor: TGroupBox object grpNodeEditor: TGroupBox
@ -166,15 +173,14 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideTop.Control = Owner AnchorSideTop.Control = Owner
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = btnOK
Left = 432 Left = 432
Height = 277 Height = 282
Top = 6 Top = 6
Width = 197 Width = 197
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'Item Properties' Caption = 'Item Properties'
ClientHeight = 257 ClientHeight = 262
ClientWidth = 193 ClientWidth = 193
TabOrder = 1 TabOrder = 1
object lblNodeText: TLabel object lblNodeText: TLabel
@ -291,77 +297,42 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
OnChange = spnIndexChange OnChange = spnIndexChange
end end
end end
object btnOK: TBitBtn object ButtonPanel: TButtonPanel
AnchorSideRight.Control = btnCancel Left = 6
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 304
Height = 26 Height = 26
Top = 289 Top = 294
Width = 75 Width = 623
Anchors = [akRight, akBottom] OKButton.Name = 'OKButton'
AutoSize = True OKButton.Hint = '[Ctrl+Enter]'
BorderSpacing.Around = 6 OKButton.DefaultCaption = True
Caption = '&OK' HelpButton.Name = 'HelpButton'
Constraints.MinHeight = 25 HelpButton.Hint = '[F1]'
Constraints.MinWidth = 75 HelpButton.DefaultCaption = True
Kind = bkOK CloseButton.Name = 'CloseButton'
ModalResult = 1 CloseButton.DefaultCaption = True
CancelButton.Name = 'CancelButton'
CancelButton.Hint = '[Esc]'
CancelButton.DefaultCaption = True
TabOrder = 2 TabOrder = 2
end ShowButtons = [pbOK, pbCancel, pbHelp]
object btnCancel: TBitBtn ShowBevel = False
AnchorSideRight.Control = btnApply object btnApply: TBitBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Side = asrBottom
AnchorSideBottom.Side = asrBottom Left = 357
Left = 385 Height = 26
Height = 26 Hint = '[Shift+Enter]'
Top = 289 Top = 0
Width = 82 Width = 75
Anchors = [akRight, akBottom] Align = alCustom
AutoSize = True Anchors = []
BorderSpacing.Around = 6 AutoSize = True
Cancel = True BorderSpacing.Around = 6
Caption = 'Cancel' Caption = '&Apply'
Constraints.MinHeight = 25 Constraints.MinHeight = 25
Constraints.MinWidth = 75 Constraints.MinWidth = 75
Kind = bkCancel TabOrder = 4
ModalResult = 2 OnClick = btnApplyClick
TabOrder = 3 end
end
object btnApply: TBitBtn
AnchorSideRight.Control = btnHelp
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 473
Height = 25
Top = 290
Width = 75
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Around = 6
Caption = '&Apply'
Constraints.MinHeight = 25
Constraints.MinWidth = 75
TabOrder = 4
OnClick = btnApplyClick
end
object btnHelp: TBitBtn
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 554
Height = 26
Top = 289
Width = 75
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Around = 6
Caption = '&Help'
Constraints.MinHeight = 25
Constraints.MinWidth = 75
Kind = bkHelp
TabOrder = 5
end end
object dlgOpen: TOpenDialog object dlgOpen: TOpenDialog
Title = 'Open' Title = 'Open'

View File

@ -20,7 +20,8 @@ interface
uses uses
Classes, SysUtils, Classes, SysUtils,
// LCL // LCL
Forms, Dialogs, Buttons, Controls, StdCtrls, ComCtrls, ImgList, Spin, LCLType, Forms, Dialogs, Buttons, Controls, StdCtrls, ComCtrls, ImgList, Spin,
ButtonPanel,
// IdeIntf // IdeIntf
PropEdits, ComponentEditors, ObjInspStrConsts, IDEImagesIntf, IDEWindowIntf; PropEdits, ComponentEditors, ObjInspStrConsts, IDEImagesIntf, IDEWindowIntf;
@ -30,14 +31,12 @@ type
TTreeViewItemsEditorForm = class(TForm) TTreeViewItemsEditorForm = class(TForm)
btnApply: TBitBtn; btnApply: TBitBtn;
btnCancel: TBitBtn;
btnHelp: TBitBtn;
btnOK: TBitBtn;
btnSave: TButton; btnSave: TButton;
btnNewItem: TButton; btnNewItem: TButton;
btnNewSubItem: TButton; btnNewSubItem: TButton;
btnDelete: TButton; btnDelete: TButton;
btnLoad: TButton; btnLoad: TButton;
ButtonPanel: TButtonPanel;
edtNodeText: TEdit; edtNodeText: TEdit;
grpTreeEditor: TGroupBox; grpTreeEditor: TGroupBox;
grpNodeEditor: TGroupBox; grpNodeEditor: TGroupBox;
@ -57,8 +56,9 @@ type
procedure Edit1Change(Sender: TObject); procedure Edit1Change(Sender: TObject);
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction); procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure btnMoveUpClick(Sender: TObject); procedure btnMoveClick(Sender: TObject);
procedure btnMoveDownClick(Sender: TObject); procedure btnMoveDownClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure treEditorSelectionChanged(Sender: TObject); procedure treEditorSelectionChanged(Sender: TObject);
procedure btnApplyClick(Sender: TObject); procedure btnApplyClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject); procedure btnDeleteClick(Sender: TObject);
@ -115,6 +115,7 @@ end;
procedure TTreeViewItemsEditorForm.FormCreate(Sender: TObject); procedure TTreeViewItemsEditorForm.FormCreate(Sender: TObject);
begin begin
// Captions
Caption := sccsTrEdtCaption; Caption := sccsTrEdtCaption;
grpTreeEditor.Caption := sccsTrEdtGrpLCaption; grpTreeEditor.Caption := sccsTrEdtGrpLCaption;
@ -137,6 +138,12 @@ begin
dlgOpen.Title := sccsTrEdtOpenDialog; dlgOpen.Title := sccsTrEdtOpenDialog;
dlgSave.Title := sccsTrEdtSaveDialog; dlgSave.Title := sccsTrEdtSaveDialog;
// Button panel
ButtonPanel.ShowHint := true;
btnApply.LoadGlyphFromResource(idButtonRetry);
// Layout
IDEDialogLayoutList.ApplyLayout(Self); IDEDialogLayoutList.ApplyLayout(Self);
end; end;
@ -146,6 +153,89 @@ begin
IDEDialogLayoutList.SaveLayout(Self); IDEDialogLayoutList.SaveLayout(Self);
end; end;
procedure TTreeViewItemsEditorForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
// form actions
VK_RETURN:
if (Shift = [ssCtrl]) then
begin
Key := 0;
ModalResult := mrOK;
end else
if (Shift = [ssShift]) then
begin
Key := 0;
btnApplyClick(Sender);
end;
VK_ESCAPE:
if (Shift = []) then
begin
if not treEditor.IsEditing then
begin
Key := 0;
ModalResult := mrCancel;
end;
end;
// create items
VK_N:
if (Shift = [ssCtrl]) then
begin
Key := 0;
btnNewItemClick(btnNewItem); // "Sender" is the pressed button
end else
if (Shift = [ssCtrl, ssShift]) then
begin
Key := 0;
btnNewItemClick(btnNewSubItem); // "Sender" is the pressed button
end;
// delete item
VK_DELETE:
if (Shift = []) then
begin
// check to prevent it from working in TEdit or TSpinEdit
// or when renaming node
if treEditor.Focused and not treEditor.IsEditing then
begin
Key := 0;
btnDeleteClick(Sender);
end;
end;
// move item
VK_DOWN:
if (Shift = [ssCtrl, ssShift]) then
begin
Key := 0;
btnMoveClick(btnMoveDown); // "Sender" is the pressed button
end;
VK_UP:
if (Shift = [ssCtrl, ssShift]) then
begin
Key := 0;
btnMoveClick(btnMoveUp); // "Sender" is the pressed button
end;
// save and load in/from file
VK_S:
if (Shift = [ssCtrl]) then
begin
Key := 0;
btnSaveClick(Sender);
end;
VK_L, VK_O:
if (Shift = [ssCtrl]) then
begin
Key := 0;
btnLoadClick(Sender);
end;
end;
end;
procedure TTreeViewItemsEditorForm.btnNewItemClick(Sender: TObject); procedure TTreeViewItemsEditorForm.btnNewItemClick(Sender: TObject);
var var
lNewName: String; lNewName: String;
@ -171,14 +261,27 @@ begin
treEditor.Selected.Text := edtNodeText.Text; treEditor.Selected.Text := edtNodeText.Text;
end; end;
procedure TTreeViewItemsEditorForm.btnMoveUpClick(Sender: TObject); procedure TTreeViewItemsEditorForm.btnMoveClick(Sender: TObject);
var var
CurNode, PrevNode: TTreeNode; lCurNode: TTreeNode;
begin begin
CurNode := treEditor.Selected; Assert(Assigned(CurNode)); lCurNode := treEditor.Selected;
PrevNode := CurNode.GetPrevSibling; Assert(Assigned(PrevNode)); if lCurNode = nil then exit;
CurNode.MoveTo(PrevNode, naInsert);
if Sender = btnMoveUp then
begin
if lCurNode.GetPrevSibling = nil then exit;
lCurNode.MoveTo(lCurNode.GetPrevSibling, naInsert);
end else
if Sender = btnMoveDown then
begin
if lCurNode.GetNextSibling = nil then exit;
lCurNode.MoveTo(lCurNode.GetNextSibling, naInsertBehind);
end else
raise Exception.Create('[btnMoveClick] Unknown Sender');
UpdateEnabledStates; UpdateEnabledStates;
treEditor.SetFocus; // return focus after button click
end; end;
procedure TTreeViewItemsEditorForm.btnMoveDownClick(Sender: TObject); procedure TTreeViewItemsEditorForm.btnMoveDownClick(Sender: TObject);