/usr/lib/lazarus/0.9.30.4/ideintf/treeviewpropedit.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | { Copyright (C) 2005
*****************************************************************************
* *
* See the file COPYING.modifiedLGPL.txt, 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, Forms, Controls, Graphics, Dialogs, Buttons,
PropEdits, Componenteditors, StdCtrls, ComCtrls, ObjInspStrConsts, ExtCtrls;
type
{ TTreeViewItemsEditorForm }
TTreeViewItemsEditorForm = class(TForm)
BtnApply: TBitBtn;
BtnCancel: TBitBtn;
BtnHelp: TBitBtn;
BtnOK: TBitBtn;
BtnSave: TButton;
BtnNewItem: TButton;
BtnNewSubItem: TButton;
BtnDelete: TButton;
BtnLoad: TButton;
edtText: TEdit;
edtIndexImg: TEdit;
edtIndexSel: TEdit;
edtIndexState: TEdit;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
LabelText: TLabel;
LabelImageIndex: TLabel;
LabelSelectedIndex: TLabel;
LabelStateIndex: TLabel;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
TreeView1: TTreeView;
procedure BtnNewItemClick(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TreeView1SelectionChanged(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure btnLoadClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure edtIndexStateEditingDone(Sender: TObject);
private
FTreeView: TTreeView;
FModified: Boolean;
procedure LoadFromTree(ATreeView:TTreeView);
procedure SaveToTree;
public
end;
type
TTreeViewItemsProperty = class(TClassPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
end;
{ TTreeViewComponentEditor }
TTreeViewComponentEditor = class(TComponentEditor)
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
implementation
{$R *.lfm}
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 := sccsTrEdtItem + IntToStr(TreeView1.Items.Count);
if (Sender as TComponent).Tag = 1 then
TreeView1.Selected := TreeView1.Items.Add(TreeView1.Selected, S)
else
TreeView1.Selected := TreeView1.Items.AddChild(TreeView1.Selected, S);
GroupBox2.Enabled := TreeView1.Items.Count > 0;
edtText.SetFocus;
edtText.SelectAll;
end;
procedure TTreeViewItemsEditorForm.Edit1Change(Sender: TObject);
begin
if Assigned(TreeView1.Selected) then
TreeView1.Selected.Text := edtText.Text;
end;
procedure TTreeViewItemsEditorForm.FormCreate(Sender: TObject);
begin
Caption := sccsTrEdtCaption;
GroupBox1.Caption := sccsTrEdtGrpLCaption;
BtnNewItem.Caption := sccsTrEdtNewItem;
BtnNewSubItem.Caption := sccsTrEdtNewSubItem;
BtnDelete.Caption := sccsTrEdtDelete;
BtnLoad.Caption := sccsTrEdtLoad;
BtnSave.Caption := sccsTrEdtSave;
BtnApply.Caption := sccsTrEdtApply;
GroupBox2.Caption := sccsTrEdtGrpRCaption;
LabelText.Caption := sccsTrEdtLabelText;
LabelImageIndex.Caption := sccsTrEdtLabelImageIndex;
LabelSelectedIndex.Caption := sccsTrEdtLabelSelIndex;
LabelStateIndex.Caption := sccsTrEdtLabelStateIndex;
OpenDialog1.Title := sccsTrEdtOpenDialog;
SaveDialog1.Title := sccsTrEdtSaveDialog;
end;
procedure TTreeViewItemsEditorForm.TreeView1SelectionChanged(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);
var
TempNode: TTreeNode;
begin
if Assigned(TreeView1.Selected) then
begin
TempNode := TreeView1.Selected.GetNextSibling;
if TempNode = nil then
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;
TreeView1.SetFocus;
end;
end;
procedure TTreeViewItemsEditorForm.btnLoadClick(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
TreeView1.LoadFromFile(OpenDialog1.FileName);
GroupBox2.Enabled := TreeView1.Items.Count > 0;
end;
end;
procedure TTreeViewItemsEditorForm.btnSaveClick(Sender: TObject);
begin
if SaveDialog1.Execute then
TreeView1.SaveToFile(SaveDialog1.FileName);
end;
procedure TTreeViewItemsEditorForm.edtIndexStateEditingDone(Sender: TObject);
begin
if Assigned(TreeView1.Selected) then
begin
TreeView1.Selected.ImageIndex := StrToIntDef(edtIndexImg.Text, -1);
TreeView1.Selected.SelectedIndex := StrToIntDef(edtIndexSel.Text, -1);
TreeView1.Selected.StateIndex := StrToIntDef(edtIndexState.Text, -1);
edtIndexImg.Text := IntToStr(TreeView1.Selected.ImageIndex);
edtIndexSel.Text := IntToStr(TreeView1.Selected.SelectedIndex);
edtIndexState.Text := IntToStr(TreeView1.Selected.StateIndex);
end;
end;
procedure TTreeViewItemsEditorForm.LoadFromTree(ATreeView: TTreeView);
begin
FTreeView := ATreeView;
if Assigned(ATreeView) then
begin
TreeView1.Images := ATreeView.Images;
TreeView1.StateImages := ATreeView.StateImages;
TreeView1.Items.Assign(ATreeView.Items);
end;
GroupBox2.Enabled := TreeView1.Items.Count > 0;
end;
procedure TTreeViewItemsEditorForm.SaveToTree;
begin
if Assigned(FTreeView) then
begin
FTreeView.Items.Assign(TreeView1.Items);
FModified := True;
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 := sccsTrEdt;
end;
function TTreeViewComponentEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
initialization
RegisterPropertyEditor(ClassTypeInfo(TTreeNodes), TTreeView, 'Items', TTreeViewItemsProperty);
RegisterComponentEditor(TTreeView,TTreeViewComponentEditor);
end.
|