IDE: Add up/down move buttons to treeview item editor. Issue #9773.

git-svn-id: trunk@42755 -
This commit is contained in:
juha 2013-09-12 14:29:23 +00:00
parent 14a2fdcdd2
commit 085568141c
2 changed files with 145 additions and 91 deletions

View File

@ -1,31 +1,31 @@
object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
Left = 304
Height = 320
Top = 189
Width = 536
Left = 329
Height = 321
Top = 230
Width = 635
ActiveControl = BtnNewItem
BorderIcons = [biSystemMenu, biHelp]
Caption = 'TreeView Items Editor'
ClientHeight = 320
ClientWidth = 536
ClientHeight = 321
ClientWidth = 635
Constraints.MinHeight = 240
Constraints.MinWidth = 400
OnCreate = FormCreate
Position = poScreenCenter
LCLVersion = '0.9.27'
LCLVersion = '1.1'
object GroupBox1: TGroupBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
AnchorSideBottom.Control = BtnOK
Left = 6
Height = 266
Height = 273
Top = 6
Width = 321
Width = 420
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 6
Caption = 'Items'
ClientHeight = 247
ClientWidth = 317
ClientHeight = 253
ClientWidth = 416
TabOrder = 0
object TreeView1: TTreeView
AnchorSideLeft.Control = GroupBox1
@ -33,14 +33,13 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideBottom.Control = GroupBox1
AnchorSideBottom.Side = asrBottom
Left = 5
Height = 237
Height = 243
Top = 5
Width = 194
Width = 240
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 5
BorderSpacing.Top = 5
BorderSpacing.Bottom = 5
DefaultItemHeight = 19
HideSelection = False
ReadOnly = True
TabOrder = 0
@ -49,16 +48,17 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
end
object BtnNewItem: TButton
Tag = 1
AnchorSideLeft.Control = TreeView1
AnchorSideLeft.Control = MoveUpBtn
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = GroupBox1
AnchorSideRight.Control = GroupBox1
AnchorSideRight.Side = asrBottom
Left = 205
Left = 282
Height = 25
Top = 6
Width = 106
Width = 128
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 3
BorderSpacing.Around = 6
Caption = '&New Item'
Default = True
@ -66,73 +66,98 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
TabOrder = 1
end
object BtnNewSubItem: TButton
AnchorSideLeft.Control = TreeView1
AnchorSideLeft.Side = asrBottom
AnchorSideLeft.Control = BtnNewItem
AnchorSideTop.Control = BtnNewItem
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = GroupBox1
AnchorSideRight.Control = BtnNewItem
AnchorSideRight.Side = asrBottom
Left = 205
Left = 282
Height = 25
Top = 37
Width = 106
Width = 128
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6
BorderSpacing.Top = 6
Caption = 'N&ew SubItem'
OnClick = BtnNewItemClick
TabOrder = 2
end
object BtnDelete: TButton
AnchorSideLeft.Control = TreeView1
AnchorSideLeft.Side = asrBottom
AnchorSideLeft.Control = BtnNewSubItem
AnchorSideTop.Control = BtnNewSubItem
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = GroupBox1
AnchorSideRight.Control = BtnNewSubItem
AnchorSideRight.Side = asrBottom
Left = 205
Left = 282
Height = 25
Top = 68
Width = 106
Width = 128
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6
BorderSpacing.Top = 6
Caption = '&Delete'
OnClick = btnDeleteClick
TabOrder = 3
end
object BtnLoad: TButton
AnchorSideLeft.Control = TreeView1
AnchorSideLeft.Side = asrBottom
AnchorSideLeft.Control = BtnDelete
AnchorSideTop.Control = BtnDelete
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = GroupBox1
AnchorSideRight.Control = BtnDelete
AnchorSideRight.Side = asrBottom
Left = 205
Left = 282
Height = 25
Top = 99
Width = 106
Width = 128
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6
BorderSpacing.Top = 6
Caption = '&Load'
OnClick = btnLoadClick
TabOrder = 4
end
object BtnSave: TButton
AnchorSideLeft.Control = TreeView1
AnchorSideLeft.Side = asrBottom
AnchorSideLeft.Control = BtnLoad
AnchorSideTop.Control = BtnLoad
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = GroupBox1
AnchorSideRight.Control = BtnLoad
AnchorSideRight.Side = asrBottom
Left = 205
Left = 282
Height = 25
Top = 130
Width = 106
Width = 128
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6
BorderSpacing.Top = 6
Caption = '&Save'
OnClick = btnSaveClick
TabOrder = 5
end
object MoveUpBtn: TSpeedButton
AnchorSideLeft.Control = TreeView1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 251
Height = 26
Top = 78
Width = 22
BorderSpacing.Around = 6
Enabled = False
OnClick = MoveUpBtnClick
ShowHint = True
ParentShowHint = False
end
object MoveDownBtn: TSpeedButton
AnchorSideLeft.Control = MoveUpBtn
AnchorSideTop.Control = MoveUpBtn
AnchorSideTop.Side = asrBottom
Left = 251
Height = 26
Top = 111
Width = 22
BorderSpacing.Top = 7
Enabled = False
OnClick = MoveDownBtnClick
ShowHint = True
ParentShowHint = False
end
end
object GroupBox2: TGroupBox
AnchorSideLeft.Control = GroupBox1
@ -141,14 +166,14 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = BtnOK
Left = 333
Height = 266
Left = 432
Height = 273
Top = 6
Width = 197
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 6
Caption = 'Item Properties'
ClientHeight = 247
ClientHeight = 253
ClientWidth = 193
TabOrder = 1
object LabelText: TLabel
@ -157,7 +182,7 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
Left = 6
Height = 18
Top = 6
Width = 30
Width = 37
BorderSpacing.Left = 6
BorderSpacing.Top = 6
Caption = 'Text:'
@ -170,8 +195,8 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideTop.Side = asrBottom
Left = 6
Height = 18
Top = 59
Width = 83
Top = 58
Width = 95
BorderSpacing.Top = 6
Caption = 'Image Index:'
FocusControl = edtIndexImg
@ -183,8 +208,8 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideTop.Side = asrBottom
Left = 6
Height = 18
Top = 112
Width = 99
Top = 110
Width = 113
BorderSpacing.Top = 6
Caption = 'Selected index:'
FocusControl = edtIndexSel
@ -196,8 +221,8 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideTop.Side = asrBottom
Left = 6
Height = 18
Top = 165
Width = 78
Top = 162
Width = 90
BorderSpacing.Top = 6
Caption = 'State Index:'
FocusControl = edtIndexState
@ -210,11 +235,10 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Control = GroupBox2
AnchorSideRight.Side = asrBottom
Left = 6
Height = 27
Height = 26
Top = 26
Width = 182
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 2
BorderSpacing.Right = 5
OnChange = Edit1Change
@ -225,10 +249,9 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideTop.Control = LabelImageIndex
AnchorSideTop.Side = asrBottom
Left = 6
Height = 27
Top = 79
Height = 26
Top = 78
Width = 48
AutoSize = True
BorderSpacing.Top = 2
OnEditingDone = edtIndexStateEditingDone
TabOrder = 1
@ -238,10 +261,9 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideTop.Control = LabelSelectedIndex
AnchorSideTop.Side = asrBottom
Left = 6
Height = 27
Top = 132
Height = 26
Top = 130
Width = 48
AutoSize = True
BorderSpacing.Top = 2
OnEditingDone = edtIndexStateEditingDone
TabOrder = 2
@ -251,10 +273,9 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideTop.Control = LabelStateIndex
AnchorSideTop.Side = asrBottom
Left = 6
Height = 27
Top = 185
Height = 26
Top = 182
Width = 48
AutoSize = True
BorderSpacing.Top = 2
OnEditingDone = edtIndexStateEditingDone
TabOrder = 3
@ -264,9 +285,9 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Control = BtnCancel
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 209
Height = 36
Top = 278
Left = 304
Height = 30
Top = 285
Width = 75
Anchors = [akRight, akBottom]
AutoSize = True
@ -276,17 +297,16 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
Constraints.MinWidth = 75
Kind = bkOK
ModalResult = 1
NumGlyphs = 0
TabOrder = 2
end
object BtnCancel: TBitBtn
AnchorSideRight.Control = BtnApply
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 290
Height = 32
Top = 282
Width = 78
Left = 385
Height = 30
Top = 285
Width = 82
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Around = 6
@ -296,16 +316,15 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
Constraints.MinWidth = 75
Kind = bkCancel
ModalResult = 2
NumGlyphs = 0
TabOrder = 3
end
object BtnApply: TBitBtn
AnchorSideRight.Control = BtnHelp
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 374
Height = 29
Top = 285
Left = 473
Height = 28
Top = 287
Width = 75
Anchors = [akRight, akBottom]
AutoSize = True
@ -313,7 +332,6 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
Caption = '&Apply'
Constraints.MinHeight = 25
Constraints.MinWidth = 75
NumGlyphs = 0
OnClick = btnApplyClick
TabOrder = 4
end
@ -322,9 +340,9 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 455
Height = 36
Top = 278
Left = 554
Height = 32
Top = 283
Width = 75
Anchors = [akRight, akBottom]
AutoSize = True
@ -333,19 +351,18 @@ object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
Constraints.MinHeight = 25
Constraints.MinWidth = 75
Kind = bkHelp
NumGlyphs = 0
TabOrder = 5
end
object OpenDialog1: TOpenDialog
Title = 'Open'
FilterIndex = 0
left = 176
top = 234
left = 296
top = 208
end
object SaveDialog1: TSaveDialog
Title = 'Save'
FilterIndex = 0
left = 176
top = 234
left = 368
top = 232
end
end

View File

@ -46,11 +46,15 @@ type
LabelSelectedIndex: TLabel;
LabelStateIndex: TLabel;
OpenDialog1: TOpenDialog;
MoveDownBtn: TSpeedButton;
MoveUpBtn: TSpeedButton;
SaveDialog1: TSaveDialog;
TreeView1: TTreeView;
procedure BtnNewItemClick(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MoveUpBtnClick(Sender: TObject);
procedure MoveDownBtnClick(Sender: TObject);
procedure TreeView1SelectionChanged(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
@ -60,8 +64,9 @@ type
private
FTreeView: TTreeView;
FModified: Boolean;
procedure LoadFromTree(ATreeView:TTreeView);
procedure LoadFromTree(ATreeView: TTreeView);
procedure SaveToTree;
procedure UpdateEnabledStates;
public
end;
@ -136,6 +141,10 @@ begin
BtnLoad.Caption := sccsTrEdtLoad;
BtnSave.Caption := sccsTrEdtSave;
BtnApply.Caption := sccsTrEdtApply;
MoveUpBtn.LoadGlyphFromLazarusResource('arrow_up');
MoveDownBtn.LoadGlyphFromLazarusResource('arrow_down');
MoveUpBtn.Hint:=rscdMoveUp;
MoveDownBtn.Hint:=rscdMoveDown;
GroupBox2.Caption := sccsTrEdtGrpRCaption;
LabelText.Caption := sccsTrEdtLabelText;
@ -147,6 +156,26 @@ begin
SaveDialog1.Title := sccsTrEdtSaveDialog;
end;
procedure TTreeViewItemsEditorForm.MoveUpBtnClick(Sender: TObject);
var
CurNode, PrevNode: TTreeNode;
begin
CurNode := TreeView1.Selected; Assert(Assigned(CurNode));
PrevNode := CurNode.GetPrevSibling; Assert(Assigned(PrevNode));
CurNode.MoveTo(PrevNode, naInsert);
UpdateEnabledStates;
end;
procedure TTreeViewItemsEditorForm.MoveDownBtnClick(Sender: TObject);
var
CurNode, NextNode: TTreeNode;
begin
CurNode := TreeView1.Selected; Assert(Assigned(CurNode));
NextNode := CurNode.GetNextSibling; Assert(Assigned(NextNode));
CurNode.MoveTo(NextNode, naInsertBehind);
UpdateEnabledStates;
end;
procedure TTreeViewItemsEditorForm.TreeView1SelectionChanged(Sender: TObject);
begin
if Assigned(TreeView1.Selected) then
@ -156,6 +185,7 @@ begin
edtIndexSel.Text := IntToStr(TreeView1.Selected.SelectedIndex);
edtIndexState.Text := IntToStr(TreeView1.Selected.StateIndex);
end;
UpdateEnabledStates;
end;
procedure TTreeViewItemsEditorForm.btnApplyClick(Sender: TObject);
@ -174,13 +204,10 @@ begin
TempNode := TreeView1.Selected.GetPrevSibling;
if TempNode = nil then
TempNode := TreeView1.Selected.Parent;
TreeView1.Items.Delete(TreeView1.Selected);
if TempNode <> nil then
TreeView1.Selected := TempNode;
GroupBox2.Enabled := TreeView1.Items.Count > 0;
UpdateEnabledStates;
TreeView1.SetFocus;
end;
end;
@ -190,7 +217,7 @@ begin
if OpenDialog1.Execute then
begin
TreeView1.LoadFromFile(OpenDialog1.FileName);
GroupBox2.Enabled := TreeView1.Items.Count > 0;
UpdateEnabledStates;
end;
end;
@ -223,8 +250,7 @@ begin
TreeView1.StateImages := ATreeView.StateImages;
TreeView1.Items.Assign(ATreeView.Items);
end;
GroupBox2.Enabled := TreeView1.Items.Count > 0;
UpdateEnabledStates;
end;
procedure TTreeViewItemsEditorForm.SaveToTree;
@ -236,6 +262,17 @@ begin
end;
end;
procedure TTreeViewItemsEditorForm.UpdateEnabledStates;
var
CurNode: TTreeNode;
begin
CurNode := TreeView1.Selected;
MoveUpBtn.Enabled := Assigned(CurNode) and Assigned(CurNode.GetPrevSibling);
MoveDownBtn.Enabled:=Assigned(CurNode) and Assigned(CurNode.GetNextSibling);
GroupBox2.Enabled := Assigned(CurNode);
end;
{ TTreeViewItemsProperty }
procedure TTreeViewItemsProperty.Edit;