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

View File

@ -20,7 +20,8 @@ interface
uses
Classes, SysUtils,
// LCL
Forms, Dialogs, Buttons, Controls, StdCtrls, ComCtrls, ImgList, Spin,
LCLType, Forms, Dialogs, Buttons, Controls, StdCtrls, ComCtrls, ImgList, Spin,
ButtonPanel,
// IdeIntf
PropEdits, ComponentEditors, ObjInspStrConsts, IDEImagesIntf, IDEWindowIntf;
@ -30,14 +31,12 @@ type
TTreeViewItemsEditorForm = class(TForm)
btnApply: TBitBtn;
btnCancel: TBitBtn;
btnHelp: TBitBtn;
btnOK: TBitBtn;
btnSave: TButton;
btnNewItem: TButton;
btnNewSubItem: TButton;
btnDelete: TButton;
btnLoad: TButton;
ButtonPanel: TButtonPanel;
edtNodeText: TEdit;
grpTreeEditor: TGroupBox;
grpNodeEditor: TGroupBox;
@ -57,8 +56,9 @@ type
procedure Edit1Change(Sender: TObject);
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure btnMoveUpClick(Sender: TObject);
procedure btnMoveClick(Sender: TObject);
procedure btnMoveDownClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure treEditorSelectionChanged(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
@ -115,6 +115,7 @@ end;
procedure TTreeViewItemsEditorForm.FormCreate(Sender: TObject);
begin
// Captions
Caption := sccsTrEdtCaption;
grpTreeEditor.Caption := sccsTrEdtGrpLCaption;
@ -137,6 +138,12 @@ begin
dlgOpen.Title := sccsTrEdtOpenDialog;
dlgSave.Title := sccsTrEdtSaveDialog;
// Button panel
ButtonPanel.ShowHint := true;
btnApply.LoadGlyphFromResource(idButtonRetry);
// Layout
IDEDialogLayoutList.ApplyLayout(Self);
end;
@ -146,6 +153,89 @@ begin
IDEDialogLayoutList.SaveLayout(Self);
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);
var
lNewName: String;
@ -171,14 +261,27 @@ begin
treEditor.Selected.Text := edtNodeText.Text;
end;
procedure TTreeViewItemsEditorForm.btnMoveUpClick(Sender: TObject);
procedure TTreeViewItemsEditorForm.btnMoveClick(Sender: TObject);
var
CurNode, PrevNode: TTreeNode;
lCurNode: TTreeNode;
begin
CurNode := treEditor.Selected; Assert(Assigned(CurNode));
PrevNode := CurNode.GetPrevSibling; Assert(Assigned(PrevNode));
CurNode.MoveTo(PrevNode, naInsert);
lCurNode := treEditor.Selected;
if lCurNode = nil then exit;
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;
treEditor.SetFocus; // return focus after button click
end;
procedure TTreeViewItemsEditorForm.btnMoveDownClick(Sender: TObject);