1 | Unit SearchDirectoriesFormUnit;
|
---|
2 |
|
---|
3 | Interface
|
---|
4 |
|
---|
5 | Uses
|
---|
6 | Classes,
|
---|
7 | Forms,
|
---|
8 | Buttons,
|
---|
9 | StdCtrls,
|
---|
10 | ACLLanguageUnit,
|
---|
11 | CustomFileControls;
|
---|
12 |
|
---|
13 | Type
|
---|
14 | TSearchDirectoriesForm = Class (TForm)
|
---|
15 | OKButton: TButton;
|
---|
16 | CancelButton: TButton;
|
---|
17 | DirectoriesLabel: TLabel;
|
---|
18 | HelpButton: TButton;
|
---|
19 | AddButton: TButton;
|
---|
20 | AddDirectoryButton: TButton;
|
---|
21 | SubdirectoriesCheckBox: TCheckBox;
|
---|
22 | DirectoryListBox: TCustomDirectoryListBox;
|
---|
23 | DriveComboBox: TCustomDriveComboBox;
|
---|
24 | DirectoriesListBox: TListBox;
|
---|
25 | DriveLabel: TLabel;
|
---|
26 | DirectoryLabel: TLabel;
|
---|
27 | Procedure SearchDirectoriesFormOnSetupShow (Sender: TObject);
|
---|
28 | Procedure AddDirectoryButtonOnClick (Sender: TObject);
|
---|
29 | Procedure SearchDirectoriesFormOnDestroy (Sender: TObject);
|
---|
30 | Procedure AddButtonOnClick (Sender: TObject);
|
---|
31 | Procedure SearchDirectoriesFormOnCreate (Sender: TObject);
|
---|
32 | Procedure OKButtonOnClick (Sender: TObject);
|
---|
33 | Procedure SearchDirectoriesFormOnShow (Sender: TObject);
|
---|
34 | Protected
|
---|
35 | Procedure ShowBrowseControls( Show: boolean );
|
---|
36 |
|
---|
37 | Public
|
---|
38 | {Insert public declarations here}
|
---|
39 | Procedure OnLanguageEvent( Language: TLanguageFile;
|
---|
40 | const Apply: boolean );
|
---|
41 |
|
---|
42 | SelectedFolders: TStringList; // input/output.
|
---|
43 | // On input; if the associated object is non-nil, then
|
---|
44 | // the folder will be displayed as non-selected.
|
---|
45 | CustomDirAdded: boolean; // output
|
---|
46 | End;
|
---|
47 |
|
---|
48 | Var
|
---|
49 | SearchDirectoriesForm: TSearchDirectoriesForm;
|
---|
50 |
|
---|
51 | Implementation
|
---|
52 |
|
---|
53 | Uses
|
---|
54 | ControlsUtility,
|
---|
55 | DebugUnit,
|
---|
56 | StringUtilsUnit;
|
---|
57 |
|
---|
58 | Procedure TSearchDirectoriesForm.SearchDirectoriesFormOnSetupShow (Sender: TObject);
|
---|
59 | Begin
|
---|
60 | ScaleForm( self, 11, 16 );
|
---|
61 | End;
|
---|
62 |
|
---|
63 | Procedure TSearchDirectoriesForm.AddDirectoryButtonOnClick (Sender: TObject);
|
---|
64 | var
|
---|
65 | Dir: string;
|
---|
66 | i: longint;
|
---|
67 | Begin
|
---|
68 | Dir := DirectoryListBox.Directory;
|
---|
69 | if SubdirectoriesCheckBox.Checked then
|
---|
70 | Dir := Dir + '...';
|
---|
71 |
|
---|
72 | i := DirectoriesListBox.Items.IndexOf( Dir );
|
---|
73 |
|
---|
74 | if i = -1 then
|
---|
75 | begin
|
---|
76 | // not already present...
|
---|
77 | i := DirectoriesListBox.Items.Add( Dir );
|
---|
78 | CustomDirAdded := true;
|
---|
79 | end;
|
---|
80 | DirectoriesListBox.Selected[ i ] := true;
|
---|
81 |
|
---|
82 | DirectoriesListBox.TopIndex := i;
|
---|
83 | End;
|
---|
84 |
|
---|
85 | Procedure TSearchDirectoriesForm.SearchDirectoriesFormOnDestroy (Sender: TObject);
|
---|
86 | Begin
|
---|
87 | SelectedFolders.Destroy;
|
---|
88 | End;
|
---|
89 |
|
---|
90 | // Show or hide controls so they are in the tab order when appropriate
|
---|
91 | Procedure TSearchDirectoriesForm.ShowBrowseControls( Show: boolean );
|
---|
92 | Begin
|
---|
93 | DriveComboBox.Visible := Show;
|
---|
94 | DirectoryListBox.Visible := Show;
|
---|
95 | AddDirectoryButton.Visible := Show;
|
---|
96 | SubdirectoriesCheckBox.Visible := Show;
|
---|
97 | End;
|
---|
98 |
|
---|
99 | Procedure TSearchDirectoriesForm.AddButtonOnClick (Sender: TObject);
|
---|
100 | Begin
|
---|
101 | ShowBrowseControls( true );
|
---|
102 |
|
---|
103 | ClientWidth := DirectoryListBox.Left
|
---|
104 | + DirectoryListBox.Width
|
---|
105 | + DirectoriesListBox.Left; // same margin as left
|
---|
106 | DriveComboBox.Focus;
|
---|
107 |
|
---|
108 | AddButton.Visible := false;
|
---|
109 | End;
|
---|
110 |
|
---|
111 | Procedure TSearchDirectoriesForm.OnLanguageEvent( Language: TLanguageFile;
|
---|
112 | const Apply: boolean );
|
---|
113 | begin
|
---|
114 | // LogEvent(LogI18n, 'TSearchDirectoriesForm.OnLanguageEvent apply: "' + BoolToStr(Apply) + '"');
|
---|
115 | Language.LoadComponentLanguage( self, Apply );
|
---|
116 | end;
|
---|
117 |
|
---|
118 | Procedure TSearchDirectoriesForm.SearchDirectoriesFormOnCreate (Sender: TObject);
|
---|
119 | Begin
|
---|
120 | RegisterEventForLanguages( OnLanguageEvent );
|
---|
121 | ClientWidth := DirectoriesListBox.Left + DirectoriesListBox.Width + DirectoriesListBox.Left;
|
---|
122 |
|
---|
123 | ShowBrowseControls( false );
|
---|
124 |
|
---|
125 | SelectedFolders := TStringList.Create;
|
---|
126 | End;
|
---|
127 |
|
---|
128 | Procedure TSearchDirectoriesForm.OKButtonOnClick (Sender: TObject);
|
---|
129 | var
|
---|
130 | i: longint;
|
---|
131 | begin
|
---|
132 | // SelectedDrives := '';
|
---|
133 | SelectedFolders.Clear;
|
---|
134 | for i := 0 to DirectoriesListBox.Items.Count -1 do
|
---|
135 | begin
|
---|
136 | if DirectoriesListBox.Selected[ i ] then
|
---|
137 | begin
|
---|
138 | LogEvent(LogDebug, 'Adding directory ' + DirectoriesListBox.Items[i]);
|
---|
139 | SelectedFolders.Add( DirectoriesListBox.Items[i] );
|
---|
140 | end;
|
---|
141 | end;
|
---|
142 | end;
|
---|
143 |
|
---|
144 | Procedure TSearchDirectoriesForm.SearchDirectoriesFormOnShow (Sender: TObject);
|
---|
145 | var
|
---|
146 | i: longint;
|
---|
147 | Begin
|
---|
148 | CustomDirAdded := false;
|
---|
149 | OKButton.Default := true;
|
---|
150 |
|
---|
151 | DirectoriesListBox.CLear;
|
---|
152 |
|
---|
153 | for i := 0 to SelectedFolders.Count - 1 do
|
---|
154 | begin
|
---|
155 | DirectoriesListBox.Items.Add( SelectedFolders[ i ] );
|
---|
156 | if SelectedFolders.Objects[ i ] = nil then
|
---|
157 | DirectoriesListBox.Selected[ i ] := true;
|
---|
158 | end;
|
---|
159 | End;
|
---|
160 |
|
---|
161 | Initialization
|
---|
162 | RegisterClasses ([TSearchDirectoriesForm, TButton,
|
---|
163 | TLabel, TCustomDirectoryListBox, TCustomDriveComboBox, TListBox, TCheckBox]);
|
---|
164 | End.
|
---|