added TTreeView items editor from Lagunov Aleksey

git-svn-id: trunk@7680 -
This commit is contained in:
mattias 2005-09-12 22:22:28 +00:00
parent c2deb580ce
commit 6c4c6cdbd2
5 changed files with 543 additions and 1 deletions

3
.gitattributes vendored
View File

@ -993,6 +993,9 @@ ideintf/projectintf.pas svneol=native#text/pascal
ideintf/propedits.pp svneol=native#text/pascal
ideintf/srceditorintf.pas svneol=native#text/pascal
ideintf/texttools.pas svneol=native#text/pascal
ideintf/treeviewpropedit.lfm svneol=native#text/plain
ideintf/treeviewpropedit.lrs svneol=native#text/plain
ideintf/treeviewpropedit.pas svneol=native#text/plain
images/LazarusForm.bmp -text svneol=unset#image/bmp
images/LazarusForm.ico -text svneol=unset#image/x-icon
images/LazarusProject.ico -text svneol=unset#image/x-icon

View File

@ -49,7 +49,8 @@ uses
ProjectIntf,
PropEdits,
SrcEditorIntf,
TextTools;
TextTools,
TreeViewPropEdit;
implementation

View File

@ -0,0 +1,220 @@
object TreeViewItemsEditorForm: TTreeViewItemsEditorForm
BorderIcons = [biSystemMenu, biHelp]
Caption = 'TreeView Items Editor'
ClientHeight = 261
ClientWidth = 487
PixelsPerInch = 96
Position = poDesktopCenter
HorzScrollBar.Page = 486
VertScrollBar.Page = 260
Left = 313
Height = 261
Top = 194
Width = 487
object Button1: TButton
Anchors = [akRight, akBottom]
Caption = 'OK'
ModalResult = 1
TabOrder = 0
Left = 166
Height = 25
Top = 229
Width = 75
end
object Button2: TButton
Anchors = [akRight, akBottom]
Caption = 'Cancel'
ModalResult = 2
TabOrder = 1
Left = 246
Height = 25
Top = 229
Width = 75
end
object btnApply: TButton
Anchors = [akRight, akBottom]
Caption = '&Apply'
OnClick = btnApplyClick
TabOrder = 2
Left = 326
Height = 25
Top = 229
Width = 75
end
object Button4: TButton
Anchors = [akRight, akBottom]
Caption = 'Help'
TabOrder = 3
Left = 406
Height = 25
Top = 229
Width = 75
end
object GroupBox1: TGroupBox
Anchors = [akTop, akLeft, akRight, akBottom]
Caption = 'Items'
ClientHeight = 195
ClientWidth = 275
ParentColor = True
TabOrder = 4
Left = 8
Height = 213
Top = 8
Width = 279
object TreeView1: TTreeView
Anchors = [akTop, akLeft, akRight, akBottom]
DefaultItemHeight = 15
TabOrder = 0
OnClick = TreeView1Click
Left = 6
Height = 188
Width = 184
end
object BtnNewItem: TButton
Anchors = [akTop, akRight]
Caption = '&New Item'
OnClick = BtnNewItemClick
TabOrder = 1
Left = 197
Height = 25
Top = 4
Width = 75
Tag = 1
end
object Button6: TButton
Anchors = [akTop, akRight]
Caption = 'N&ew SubItem'
OnClick = BtnNewItemClick
TabOrder = 2
Left = 197
Height = 25
Top = 36
Width = 75
end
object btnDelete: TButton
Anchors = [akTop, akRight]
Caption = '&Delete'
OnClick = btnDeleteClick
TabOrder = 3
Left = 197
Height = 25
Top = 70
Width = 75
end
object btnLoad: TButton
Anchors = [akTop, akRight]
Caption = '&Load'
OnClick = btnLoadClick
TabOrder = 4
Left = 197
Height = 25
Top = 102
Width = 75
end
object btnSave: TButton
Anchors = [akTop, akRight]
BorderSpacing.OnChange = nil
Caption = '&Save'
OnClick = btnSaveClick
TabOrder = 5
Left = 197
Height = 25
Top = 136
Width = 75
end
end
object GroupBox2: TGroupBox
Anchors = [akTop, akRight, akBottom]
Caption = 'Item Properties'
ClientHeight = 195
ClientWidth = 181
ParentColor = True
TabOrder = 5
Left = 296
Height = 213
Top = 8
Width = 185
object Label1: TLabel
Caption = 'Text:'
Color = clNone
FocusControl = edtText
Left = 8
Height = 17
Top = 10
Width = 65
end
object Label2: TLabel
Caption = 'Image Index:'
Color = clNone
FocusControl = edtIndexImg
Left = 9
Height = 17
Top = 44
Width = 65
end
object Label3: TLabel
Caption = 'Selected index:'
Color = clNone
FocusControl = edtIndexSel
Left = 6
Height = 17
Top = 78
Width = 78
end
object Label4: TLabel
Caption = 'State Index:'
Color = clNone
FocusControl = edtIndexState
Left = 8
Height = 17
Top = 110
Width = 65
end
object edtText: TEdit
OnChange = Edit1Change
TabOrder = 0
Left = 86
Height = 23
Top = 4
Width = 91
end
object edtIndexImg: TEdit
OnChange = Edit1Change
TabOrder = 1
Left = 86
Height = 23
Top = 38
Width = 48
end
object edtIndexSel: TEdit
OnChange = Edit1Change
TabOrder = 2
Left = 86
Height = 23
Top = 72
Width = 48
end
object edtIndexState: TEdit
OnChange = Edit1Change
TabOrder = 3
Left = 86
Height = 23
Top = 104
Width = 48
end
end
object OpenDialog1: TOpenDialog
Title = 'Îòêðûòü ñóùåñòâóþùèé ôàéë'
FilterIndex = 0
Title = 'Îòêðûòü ñóùåñòâóþùèé ôàéë'
left = 5
top = 237
end
object SaveDialog1: TSaveDialog
Title = 'Ñîõðàíèòü ôàéë êàê'
FilterIndex = 0
Title = 'Ñîõðàíèòü ôàéë êàê'
left = 5
top = 272
end
end

View File

@ -0,0 +1,64 @@
{ Ýòî - ôàéë ðåñóðñîâ, àâòîìàòè÷åñêè ñîçäàííûé lazarus }
LazarusResources.Add('TTreeViewItemsEditorForm','FORMDATA',[
'TPF0'#24'TTreeViewItemsEditorForm'#23'TreeViewItemsEditorForm'#11'BorderIcon'
+'s'#11#12'biSystemMenu'#6'biHelp'#0#7'Caption'#6#21'TreeView Items Editor'#12
+'ClientHeight'#3#5#1#11'ClientWidth'#3#231#1#13'PixelsPerInch'#2'`'#8'Positi'
+'on'#7#15'poDesktopCenter'#18'HorzScrollBar.Page'#3#230#1#18'VertScrollBar.P'
+'age'#3#4#1#4'Left'#3'9'#1#6'Height'#3#5#1#3'Top'#3#194#0#5'Width'#3#231#1#0
+#7'TButton'#7'Button1'#7'Anchors'#11#7'akRight'#8'akBottom'#0#7'Caption'#6#2
+'OK'#11'ModalResult'#2#1#8'TabOrder'#2#0#4'Left'#3#166#0#6'Height'#2#25#3'To'
+'p'#3#229#0#5'Width'#2'K'#0#0#7'TButton'#7'Button2'#7'Anchors'#11#7'akRight'
+#8'akBottom'#0#7'Caption'#6#6'Cancel'#11'ModalResult'#2#2#8'TabOrder'#2#1#4
+'Left'#3#246#0#6'Height'#2#25#3'Top'#3#229#0#5'Width'#2'K'#0#0#7'TButton'#8
+'btnApply'#7'Anchors'#11#7'akRight'#8'akBottom'#0#7'Caption'#6#6'&Apply'#7'O'
+'nClick'#7#13'btnApplyClick'#8'TabOrder'#2#2#4'Left'#3'F'#1#6'Height'#2#25#3
+'Top'#3#229#0#5'Width'#2'K'#0#0#7'TButton'#7'Button4'#7'Anchors'#11#7'akRigh'
+'t'#8'akBottom'#0#7'Caption'#6#4'Help'#8'TabOrder'#2#3#4'Left'#3#150#1#6'Hei'
+'ght'#2#25#3'Top'#3#229#0#5'Width'#2'K'#0#0#9'TGroupBox'#9'GroupBox1'#7'Anch'
+'ors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#7'Caption'#6#5'Items'#12
+'ClientHeight'#3#195#0#11'ClientWidth'#3#19#1#11'ParentColor'#9#8'TabOrder'#2
+#4#4'Left'#2#8#6'Height'#3#213#0#3'Top'#2#8#5'Width'#3#23#1#0#9'TTreeView'#9
+'TreeView1'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#17'Def'
+'aultItemHeight'#2#15#8'TabOrder'#2#0#7'OnClick'#7#14'TreeView1Click'#4'Left'
+#2#6#6'Height'#3#188#0#5'Width'#3#184#0#0#0#7'TButton'#10'BtnNewItem'#7'Anch'
+'ors'#11#5'akTop'#7'akRight'#0#7'Caption'#6#9'&New Item'#7'OnClick'#7#15'Btn'
+'NewItemClick'#8'TabOrder'#2#1#4'Left'#3#197#0#6'Height'#2#25#3'Top'#2#4#5'W'
+'idth'#2'K'#3'Tag'#2#1#0#0#7'TButton'#7'Button6'#7'Anchors'#11#5'akTop'#7'ak'
+'Right'#0#7'Caption'#6#12'N&ew SubItem'#7'OnClick'#7#15'BtnNewItemClick'#8'T'
+'abOrder'#2#2#4'Left'#3#197#0#6'Height'#2#25#3'Top'#2'$'#5'Width'#2'K'#0#0#7
+'TButton'#9'btnDelete'#7'Anchors'#11#5'akTop'#7'akRight'#0#7'Caption'#6#7'&D'
+'elete'#7'OnClick'#7#14'btnDeleteClick'#8'TabOrder'#2#3#4'Left'#3#197#0#6'He'
+'ight'#2#25#3'Top'#2'F'#5'Width'#2'K'#0#0#7'TButton'#7'btnLoad'#7'Anchors'#11
+#5'akTop'#7'akRight'#0#7'Caption'#6#5'&Load'#7'OnClick'#7#12'btnLoadClick'#8
+'TabOrder'#2#4#4'Left'#3#197#0#6'Height'#2#25#3'Top'#2'f'#5'Width'#2'K'#0#0#7
+'TButton'#7'btnSave'#7'Anchors'#11#5'akTop'#7'akRight'#0#22'BorderSpacing.On'
+'Change'#13#7'Caption'#6#5'&Save'#7'OnClick'#7#12'btnSaveClick'#8'TabOrder'#2
+#5#4'Left'#3#197#0#6'Height'#2#25#3'Top'#3#136#0#5'Width'#2'K'#0#0#0#9'TGrou'
+'pBox'#9'GroupBox2'#7'Anchors'#11#5'akTop'#7'akRight'#8'akBottom'#0#7'Captio'
+'n'#6#15'Item Properties'#12'ClientHeight'#3#195#0#11'ClientWidth'#3#181#0#11
+'ParentColor'#9#8'TabOrder'#2#5#4'Left'#3'('#1#6'Height'#3#213#0#3'Top'#2#8#5
+'Width'#3#185#0#0#6'TLabel'#6'Label1'#7'Caption'#6#5'Text:'#5'Color'#7#6'clN'
+'one'#12'FocusControl'#7#7'edtText'#4'Left'#2#8#6'Height'#2#17#3'Top'#2#10#5
+'Width'#2'A'#0#0#6'TLabel'#6'Label2'#7'Caption'#6#12'Image Index:'#5'Color'#7
+#6'clNone'#12'FocusControl'#7#11'edtIndexImg'#4'Left'#2#9#6'Height'#2#17#3'T'
+'op'#2','#5'Width'#2'A'#0#0#6'TLabel'#6'Label3'#7'Caption'#6#15'Selected ind'
+'ex:'#5'Color'#7#6'clNone'#12'FocusControl'#7#11'edtIndexSel'#4'Left'#2#6#6
+'Height'#2#17#3'Top'#2'N'#5'Width'#2'N'#0#0#6'TLabel'#6'Label4'#7'Caption'#6
+#12'State Index:'#5'Color'#7#6'clNone'#12'FocusControl'#7#13'edtIndexState'#4
+'Left'#2#8#6'Height'#2#17#3'Top'#2'n'#5'Width'#2'A'#0#0#5'TEdit'#7'edtText'#8
+'OnChange'#7#11'Edit1Change'#8'TabOrder'#2#0#4'Left'#2'V'#6'Height'#2#23#3'T'
+'op'#2#4#5'Width'#2'['#0#0#5'TEdit'#11'edtIndexImg'#8'OnChange'#7#11'Edit1Ch'
+'ange'#8'TabOrder'#2#1#4'Left'#2'V'#6'Height'#2#23#3'Top'#2'&'#5'Width'#2'0'
+#0#0#5'TEdit'#11'edtIndexSel'#8'OnChange'#7#11'Edit1Change'#8'TabOrder'#2#2#4
+'Left'#2'V'#6'Height'#2#23#3'Top'#2'H'#5'Width'#2'0'#0#0#5'TEdit'#13'edtInde'
+'xState'#8'OnChange'#7#11'Edit1Change'#8'TabOrder'#2#3#4'Left'#2'V'#6'Height'
+#2#23#3'Top'#2'h'#5'Width'#2'0'#0#0#0#11'TOpenDialog'#11'OpenDialog1'#5'Titl'
+'e'#6#25#206#242#234#240#251#242#252' '#241#243#249#229#241#242#226#243#254
+#249#232#233' '#244#224#233#235#11'FilterIndex'#2#0#5'Title'#6#25#206#242#234
+#240#251#242#252' '#241#243#249#229#241#242#226#243#254#249#232#233' '#244
+#224#233#235#4'left'#2#5#3'top'#3#237#0#0#0#11'TSaveDialog'#11'SaveDialog1'#5
+'Title'#6#18#209#238#245#240#224#237#232#242#252' '#244#224#233#235' '#234
+#224#234#11'FilterIndex'#2#0#5'Title'#6#18#209#238#245#240#224#237#232#242
+#252' '#244#224#233#235' '#234#224#234#4'left'#2#5#3'top'#3#16#1#0#0#0
]);

View File

@ -0,0 +1,254 @@
{ Copyright (C) 2005
*****************************************************************************
* *
* See the file COPYING.modifiedLGPL, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
Author: Lagunov Aleksey
Abstract:
Property Editors for TTreeView.
}
unit TreeViewPropEdit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
PropEdits, Componenteditors, StdCtrls, ComCtrls;
type
{ TTreeViewItemsEditorForm }
TTreeViewItemsEditorForm = class(TForm)
btnSave: TButton;
Button1: TButton;
Button2: TButton;
btnApply: TButton;
Button4: TButton;
BtnNewItem: TButton;
Button6: TButton;
btnDelete: TButton;
btnLoad: TButton;
edtText: TEdit;
edtIndexImg: TEdit;
edtIndexSel: TEdit;
edtIndexState: TEdit;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
TreeView1: TTreeView;
procedure BtnNewItemClick(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure TreeView1Click(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure btnLoadClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
private
FTreeView:TTreeView;
FModified:boolean;
procedure UpdateState;
procedure LoadFromTree(ATreeView:TTreeView);
procedure SaveToTree;
public
{ public declarations }
end;
type
TTreeViewItemsProperty = class(TClassPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
end;
TTreeViewComponentEditor = class(TDefaultComponentEditor)
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
implementation
function EditTreeView(ATreeView: TTreeView):boolean;
var
TreeViewItemsEditorForm: TTreeViewItemsEditorForm;
begin
TreeViewItemsEditorForm:=TTreeViewItemsEditorForm.Create(Application);
try
TreeViewItemsEditorForm.LoadFromTree(ATreeView);
if TreeViewItemsEditorForm.ShowModal = mrOk then
TreeViewItemsEditorForm.SaveToTree;
Result:=TreeViewItemsEditorForm.FModified;
finally
TreeViewItemsEditorForm.Free;
end;
end;
{ TTreeViewItemsEditorForm }
procedure TTreeViewItemsEditorForm.BtnNewItemClick(Sender: TObject);
var
S:string;
begin
S:='Item_'+IntToStr(TreeView1.Items.Count);
if (Sender as TComponent).Tag = 1 then
TreeView1.Items.Add(TreeView1.Selected, S)
else
TreeView1.Items.AddChild(TreeView1.Selected, S);
end;
procedure TTreeViewItemsEditorForm.Edit1Change(Sender: TObject);
begin
UpdateState;
end;
procedure TTreeViewItemsEditorForm.TreeView1Click(Sender: TObject);
begin
if Assigned(TreeView1.Selected) then
begin
edtText.Text:=TreeView1.Selected.Text;
edtIndexImg.Text:=IntToStr(TreeView1.Selected.ImageIndex);
edtIndexSel.Text:=IntToStr(TreeView1.Selected.SelectedIndex);
edtIndexState.Text:=IntToStr(TreeView1.Selected.StateIndex);
end;
end;
procedure TTreeViewItemsEditorForm.btnApplyClick(Sender: TObject);
begin
SaveToTree;
end;
procedure TTreeViewItemsEditorForm.btnDeleteClick(Sender: TObject);
begin
if Assigned(TreeView1.Selected) then
TreeView1.Items.Delete(TreeView1.Selected);
end;
procedure TTreeViewItemsEditorForm.btnLoadClick(Sender: TObject);
begin
if OpenDialog1.Execute then
TreeView1.LoadFromFile(OpenDialog1.FileName);
end;
procedure TTreeViewItemsEditorForm.btnSaveClick(Sender: TObject);
begin
if SaveDialog1.Execute then
TreeView1.SaveToFile(SaveDialog1.FileName);
end;
procedure TTreeViewItemsEditorForm.UpdateState;
begin
if Assigned(TreeView1.Selected) then
begin
TreeView1.Selected.Text:=edtText.Text;
TreeView1.Selected.ImageIndex:=StrToIntDef(edtIndexImg.Text, -1);
TreeView1.Selected.SelectedIndex:=StrToIntDef(edtIndexSel.Text, -1);
TreeView1.Selected.StateIndex:=StrToIntDef(edtIndexState.Text, -1);
end;
end;
procedure TTreeViewItemsEditorForm.LoadFromTree(ATreeView: TTreeView);
var
S:TMemoryStream;
begin
FTreeView:=ATreeView;
if Assigned(ATreeView) then
begin
S:=TMemoryStream.Create;
try
TreeView1.Images:=ATreeView.Images;
TreeView1.StateImages:=ATreeView.StateImages;
ATreeView.SaveToStream(S);
S.Seek(0, soFromBeginning);
TreeView1.LoadFromStream(S);
finally
S.Free;
end;
end;
end;
procedure TTreeViewItemsEditorForm.SaveToTree;
var
S:TMemoryStream;
begin
if Assigned(FTreeView) then
begin
S:=TMemoryStream.Create;
try
TreeView1.SaveToStream(S);
S.Seek(0, soFromBeginning);
FTreeView.LoadFromStream(S);
FModified:=true;
finally
S.Free;
end;
end
end;
{ TTreeViewItemsProperty }
procedure TTreeViewItemsProperty.Edit;
begin
if EditTreeView(GetComponent(0) as TTreeView) then
Modified;
end;
function TTreeViewItemsProperty.GetAttributes: TPropertyAttributes;
begin
Result:=[paDialog,paReadOnly,paRevertable];
end;
{ TTreeViewComponentEditor }
procedure TTreeViewComponentEditor.ExecuteVerb(Index: Integer);
var
Hook : TPropertyEditorHook;
begin
If Index=0 then
begin
GetHook(Hook);
if EditTreeView(GetComponent as TTreeView) then
if Assigned(Hook) then
Hook.Modified(Self);
end;
end;
function TTreeViewComponentEditor.GetVerb(Index: Integer): string;
begin
Result:='';
If Index=0 then
Result:='Edit TreeView';
end;
function TTreeViewComponentEditor.GetVerbCount: Integer;
begin
Result:=1;
end;
initialization
{$I treeviewpropedit.lrs}
RegisterPropertyEditor(ClassTypeInfo(TTreeNodes), TTreeView, 'Items', TTreeViewItemsProperty);
RegisterComponentEditor(TTreeView,TTreeViewComponentEditor);
end.