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
|
{
fpGUI - Free Pascal GUI Toolkit
Copyright (C) 2006 - 2010 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
for details about redistributing fpGUI.
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.
Description:
This unit contains the dialog to manage bookmarks from the
File Open/Save dialog.
}
{%mainunit fpg_dialogs.pas}
{$IFDEF read_interface}
TConfigureBookmarksForm = class(TfpgForm)
private
{@VFD_HEAD_BEGIN: ConfigureBookmarksForm}
grdBookmarks: TfpgStringGrid;
btnChangeTitle: TfpgButton;
btnDelete: TfpgButton;
btnClose: TfpgButton;
btnMoveUp: TfpgButton;
btnMoveDown: TfpgButton;
{@VFD_HEAD_END: ConfigureBookmarksForm}
FIni: TfpgIniFile;
procedure SetupCaptions;
procedure PopulateGrid;
procedure UpdateINIFile;
procedure btnChangeTitleClicked(Sender: TObject);
procedure btnDeleteClicked(Sender: TObject);
public
constructor Create(var AIniFile: TfpgIniFile); reintroduce;
destructor Destroy; override;
procedure AfterCreate; override;
end;
{$ENDIF read_interface}
{$IFDEF read_implementation}
procedure TConfigureBookmarksForm.SetupCaptions;
begin
WindowTitle := rsConfigureBookmarks;
btnClose.Text := rsClose;
btnMoveUp.Text := rsMoveUp;
btnMoveDown.Text := rsMoveDown;
btnChangeTitle.Text := rsChangeTitle;
btnDelete.Text := rsDelete;
grdBookmarks.ColumnTitle[0] := rsName;
grdBookmarks.ColumnTitle[1] := rsDirectory;
end;
procedure TConfigureBookmarksForm.PopulateGrid;
var
i: integer;
lst: TStringList;
begin
lst := TStringList.Create;
FIni.ReadSection(FPG_BOOKMARK_SECTION, lst);
grdBookmarks.RowCount := lst.Count;
grdBookmarks.BeginUpdate;
for i := 0 to lst.Count-1 do
begin
grdBookmarks.Cells[0, i] := lst[i];
grdBookmarks.Cells[1, i] := FIni.ReadString(FPG_BOOKMARK_SECTION, lst[i], '');
end;
grdBookmarks.EndUpdate;
lst.Free;
end;
procedure TConfigureBookmarksForm.UpdateINIFile;
var
i: integer;
begin
FIni.EraseSection(FPG_BOOKMARK_SECTION);
for i := 0 to grdBookmarks.RowCount-1 do
begin
FIni.WriteString(FPG_BOOKMARK_SECTION, grdBookmarks.Cells[0, i], grdBookmarks.Cells[1, i]);
end;
end;
procedure TConfigureBookmarksForm.btnChangeTitleClicked(Sender: TObject);
var
s: TfpgString;
begin
if (grdBookmarks.RowCount = 0) or (grdBookmarks.FocusRow = -1) then
Exit;
s := grdBookmarks.Cells[0, grdBookmarks.FocusRow];
if fpgInputQuery('Bookmark', 'Enter new bookmark name', s) then
begin
s := StringReplace(s, '=', '-', [rfReplaceAll]); // don't allow '=' sign in name (ini file requirement)
grdBookmarks.Cells[0, grdBookmarks.FocusRow] := s;
end;
end;
procedure TConfigureBookmarksForm.btnDeleteClicked(Sender: TObject);
begin
if (grdBookmarks.RowCount = 0) or (grdBookmarks.FocusRow = -1) then
Exit;
grdBookmarks.DeleteRow(grdBookmarks.FocusRow);
end;
constructor TConfigureBookmarksForm.Create(var AIniFile: TfpgIniFile);
begin
inherited Create(nil);
FIni := AIniFile;
end;
destructor TConfigureBookmarksForm.Destroy;
begin
UpdateINIFile;
inherited Destroy;
end;
procedure TConfigureBookmarksForm.AfterCreate;
begin
{%region 'Auto-generated GUI code' -fold}
{@VFD_BODY_BEGIN: ConfigureBookmarksForm}
Name := 'ConfigureBookmarksForm';
SetPosition(331, 184, 596, 237);
WindowTitle := 'Configure Bookmarks';
Hint := '';
ShowHint := True;
WindowPosition := wpOneThirdDown;
grdBookmarks := TfpgStringGrid.Create(self);
with grdBookmarks do
begin
Name := 'grdBookmarks';
SetPosition(8, 8, 473, 218);
Anchors := [anLeft,anRight,anTop,anBottom];
AddColumn('Title', 150, taLeftJustify);
AddColumn('Directory', 300, taLeftJustify);
FontDesc := '#Grid';
HeaderFontDesc := '#GridHeader';
Hint := '';
RowCount := 0;
RowSelect := True;
TabOrder := 1;
Options := [go_SmoothScroll, go_AlternativeColor]
end;
btnChangeTitle := TfpgButton.Create(self);
with btnChangeTitle do
begin
Name := 'btnChangeTitle';
SetPosition(489, 8, 100, 24);
Anchors := [anRight,anTop];
Text := 'btnChangeTitle';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 2;
OnClick := @btnChangeTitleClicked;
end;
btnDelete := TfpgButton.Create(self);
with btnDelete do
begin
Name := 'btnDelete';
SetPosition(489, 36, 100, 24);
Anchors := [anRight,anTop];
Text := 'btnDelete';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 3;
OnClick := @btnDeleteClicked;
end;
btnMoveUp := TfpgButton.Create(self);
with btnMoveUp do
begin
Name := 'btnMoveUp';
SetPosition(489, 80, 100, 24);
Anchors := [anRight,anTop];
Text := 'btnMoveUp';
FontDesc := '#Label1';
Hint := '';
ImageName := 'sys.sb.up';
TabOrder := 4;
end;
btnMoveDown := TfpgButton.Create(self);
with btnMoveDown do
begin
Name := 'btnMoveDown';
SetPosition(489, 108, 100, 24);
Anchors := [anRight,anTop];
Text := 'btnMoveDown';
FontDesc := '#Label1';
Hint := '';
ImageName := 'sys.sb.down';
TabOrder := 5;
end;
btnClose := TfpgButton.Create(self);
with btnClose do
begin
Name := 'btnClose';
SetPosition(489, 204, 100, 24);
Anchors := [anRight,anBottom];
Text := 'btnClose';
FontDesc := '#Label1';
Hint := '';
ImageName := 'stdimg.close';
ModalResult := mrOK;
TabOrder := 6;
end;
{@VFD_BODY_END: ConfigureBookmarksForm}
{%endregion}
SetupCaptions;
PopulateGrid;
end;
{$ENDIF read_implementation}
|