-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm_LNBrowse.pas
More file actions
385 lines (353 loc) · 11.1 KB
/
Form_LNBrowse.pas
File metadata and controls
385 lines (353 loc) · 11.1 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
{==============================================================================|
| Project : Notes/Delphi class library | 3.8 |
|==============================================================================|
| Content: |
|==============================================================================|
| The contents of this file are subject to the Mozilla Public License Ver. 1.0 |
| (the "License"); you may not use this file except in compliance with the |
| License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ |
| |
| Software distributed under the License is distributed on an "AS IS" basis, |
| WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for |
| the specific language governing rights and limitations under the License. |
|==============================================================================|
| Initial Developers of the Original Code are: |
| Sergey Kolchin (Russia) skolchin@usa.net ICQ#2292387 |
| Sergey Kucherov (Russia) |
| Sergey Okorochkov (Russia) |
| All Rights Reserved. |
| Last Modified: |
| 27.02.00, Sergey Kolchin |
|==============================================================================|
| Contributors and Bug Corrections: |
| Fujio Kurose |
| Noah Silva |
| Tibor Egressi |
| Andreas Pape |
| Anatoly Ivkov |
| Winalot |
| and others... |
|==============================================================================|
| History: see README.TXT |
|==============================================================================|
| This unit contains Open Database dialog and LnBrowse function |
| used to visually browse for a database on local or remote server |
| |
| In some configurations, Notes returns file names in OEM codepage rather than |
| in ANSI. If this happened (dialog displays incorrect characters), define |
| a symbol USE_OEM_CODEPAGE (see below)
|==============================================================================|}
unit Form_LNBrowse;
interface
{.$DEFINE USE_OEM_CODEPAGE}
// Delphi version
{$IFDEF VER130}
{$DEFINE D5}
{$DEFINE D4}
{$ELSE}
{$IFDEF VER120}
{$DEFINE D4}
{$ELSE}
{$DEFINE D3}
{$ENDIF}
{$ENDIF}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, Class_LotusNotes, ImgList
{$IFDEF D4}
, ImgList;
{$ELSE}
;
{$ENDIF}
type
// Browse form
TLnBrowseDlg = class(TForm)
Label1: TLabel;
CbServer: TComboBox;
TreeView: TTreeView;
Label2: TLabel;
Label3: TLabel;
EFileName: TEdit;
BtOpen: TButton;
BtCancel: TButton;
BtBrowse: TButton;
OpenDialog: TOpenDialog;
BtRefresh: TButton;
ImageList1: TImageList;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure CbServerDropDown(Sender: TObject);
procedure BtOpenClick(Sender: TObject);
procedure CbServerChange(Sender: TObject);
procedure TreeViewChange(Sender: TObject; Node: TTreeNode);
procedure TreeViewExpanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
procedure BtBrowseClick(Sender: TObject);
procedure BtRefreshClick(Sender: TObject);
procedure TreeViewGetImageIndex(Sender: TObject; Node: TTreeNode);
procedure TreeViewGetSelectedIndex(Sender: TObject; Node: TTreeNode);
procedure TreeViewDblClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
Directory: TNotesDirectory;
Port: string;
function GetPath (Item: TTreeNode): string;
procedure ListDir (Item: TTreeNode);
public
end;
var
LnBrowseDlg: TLnBrowseDlg;
SedFldr:string;
function LnBrowse (aPort: string; var aServer, aPath: string): boolean;
// Combines/divides LN path to be used in editors
// ! is a separator
const LN_EDIT_SEPARATOR = '!';
procedure ParseLnPath (const aPath: string; var Server, Path: string);
function CombineLnPath (const Server, Path: string): string;
implementation
{$R *.DFM}
procedure ParseLnPath;
var
n: integer;
begin
n := Pos (LN_EDIT_SEPARATOR, aPath);
if n = 0 then begin
Server := '';
Path := aPath;
end
else begin
Server := Trim(copy (aPath, 1, n-1));
Path := Trim(copy (aPath, n+1, length(aPath)-n));
end;
end;
function CombineLnPath;
begin
Result := Server;
if Result <> ''
then Result:= Result + LN_EDIT_SEPARATOR + Path //appendStr (Result, LN_EDIT_SEPARATOR + Path)
else Result := Path;
end;
function ChgOemToAnsi (aStr : string): string;
begin
{$IFDEF USE_OEM_CODEPAGE}
setLength(Result, length(aStr)+1);
OemToChar(pchar(aStr), pchar(Result));
Result := strPas(pchar(Result));
{$ELSE}
Result := aStr;
{$ENDIF}
end;
function ChgNotesSep (aStr : string): string;
const
NotesSeperator = '|';
var
i: integer;
begin
Result:= aStr;
repeat
i := Pos (#10, Result);
if i > 0 then Result[i]:= NotesSeperator;
until (I = 0);
end;
function LnBrowse;
begin
SedFldr:=aPath;
LnBrowseDlg := TLnBrowseDlg.create (nil);
with LnBrowseDlg do try
Port := aPort;
CbServer.text := aServer;
Result := False;
showModal;
if modalResult = mrOk then begin
aServer := CbServer.text;
if compareText (aServer,'Local') = 0 then aServer := '';
aPath := EFileName.Text;
Result := True;
end;
finally
LnBrowseDlg.free;
end;
end;
procedure TLnBrowseDlg.FormCreate(Sender: TObject);
begin
Directory := TNotesDirectory.create;
end;
procedure TLnBrowseDlg.FormDestroy(Sender: TObject);
begin
Directory.free;
end;
procedure TLnBrowseDlg.CbServerDropDown(Sender: TObject);
begin
if CbServer.Items.Count = 0 then begin
Screen.Cursor := crHourglass;
try
Directory.ListServers ('', CbServer.Items);
finally
Screen.Cursor := crDefault;
end;
end;
end;
procedure TLnBrowseDlg.BtOpenClick(Sender: TObject);
begin
try
if (TreeView.Items.count = 0) and (EFileName.text = '') then begin
// List root directory
ModalResult := mrNone;
ListDir (nil);
end
else begin
// Exiting
if TreeView.Items.Count <> 0 then
if (EFileName.text = '') or ((TreeView.Selected <> nil) and (TreeView.Selected.ImageIndex <> 0)) then
raise Exception.create ('Select a database to open');
ModalResult := mrOk;
end;
except
ModalResult := mrNone;
raise;
end;
end;
procedure TLnBrowseDlg.CbServerChange(Sender: TObject);
begin
TreeView.Items.BeginUpdate;
TreeView.Items.Clear;
TreeView.Items.EndUpdate;
EFileName.text := '';
end;
function TLnBrowseDlg.GetPath;
var
s: string;
n: integer;
begin
Result := '';
while Item <> nil do begin
s := Item.Text;
n := Pos ('[', s);
if n <> 0 then begin
delete (s, 1, n);
n := Pos (']', s);
if n <> 0 then delete (s, n, length(s)-n+1);
end;
Result := s + '\' + Result;
Item := Item.Parent;
end;
if (Result <> '') and (Result[length(Result)] = '\') then delete(Result,length(Result),1);
end;
procedure TLnBrowseDlg.ListDir;
var
Entry: TNotesDirEntry;
NotDone: boolean;
aPath: string;
Node: TTreeNode;
begin
Screen.Cursor := crHourglass;
try
if Item = nil then aPath := '' else aPath := GetPath (Item);
NotDone := Directory.FindFirst (cbServer.Text, aPath, [nfoFiles, nfoTemplates, nfoSubDirs], Entry);
while NotDone do begin
if Entry.EntryType then begin
Node := TreeView.Items.AddChild (Item, ChgOemToAnsi(Entry.FileName));
Node.HasChildren := True;
Node.ImageIndex := 1;
Node.SelectedIndex := 1;
Node.StateIndex := -1;
Node.Data := nil;
end
else begin
Node := TreeView.Items.AddChild (Item,
ChgNotesSep(ChgOemToAnsi(Entry.FileInfo))
+ ' [' + ChgOemToAnsi(Entry.fileName) + ']');
Node.HasChildren := False;
Node.ImageIndex := 0;
end;
NotDone := Directory.FindNext (Entry);
end;
Directory.FindClose;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TLnBrowseDlg.TreeViewChange(Sender: TObject; Node: TTreeNode);
begin
EFileName.text := GetPath (Node);
end;
procedure TLnBrowseDlg.TreeViewExpanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
begin
AllowExpansion := False;
if Node.ImageIndex = 0 then exit;
if Node.Data <> nil then AllowExpansion := Node.HasChildren
else begin
// Listing sub-directory
ListDir (Node);
AllowExpansion := Node.count > 0;
Node.HasChildren := AllowExpansion;
Node.Data := pointer(1);
end;
end;
procedure TLnBrowseDlg.BtBrowseClick(Sender: TObject);
begin
if OpenDialog.execute then begin
CbServer.Text := '';
TreeView.Items.Clear;
EFileName.text := OpenDialog.FileName;
end;
end;
procedure TLnBrowseDlg.BtRefreshClick(Sender: TObject);
begin
TreeView.Items.Clear;
ListDir(nil);
end;
procedure TLnBrowseDlg.TreeViewGetImageIndex(Sender: TObject;
Node: TTreeNode);
begin
if Node.ImageIndex <> 0 then
if Node.Expanded then Node.ImageIndex := 2 else Node.ImageIndex := 1;
end;
procedure TLnBrowseDlg.TreeViewGetSelectedIndex(Sender: TObject;
Node: TTreeNode);
begin
if Node.ImageIndex <> 0 then
if Node.Expanded then Node.SelectedIndex := 2 else Node.SelectedIndex := 1;
end;
procedure TLnBrowseDlg.TreeViewDblClick(Sender: TObject);
begin
if (TreeView.Selected <> nil) and (TreeView.Selected.ImageIndex = 0) then BtOpenClick(Sender);
end;
function GetNodeByText (ATree : TTreeView; AValue:String; AVisible: Boolean): TTreeNode;
var
Node: TTreeNode;
begin
Result := nil;
if ATree.Items.Count = 0 then Exit;
Node := ATree.Items[0];
while Node <> nil do
begin
if UpperCase(Node.Text) = UpperCase(AValue) then
begin
Result := Node;
if AVisible then
Result.MakeVisible;
Break;
end;
Node := Node.GetNext;
end;
end;
procedure TLnBrowseDlg.FormShow(Sender: TObject);
var
Node: TTreeNode;
begin
ListDir (nil);
if SedFldr <> '' then Node:=GetNodeByText(TreeView,SedFldr,true);
if Node <> nil then
begin
TreeView.SetFocus;
Node.Selected:=true;
if Node.HasChildren then
begin
ListDir (Node);
Node.Expand(true);
end;
end;
end;
end.