source: branches/2.20_branch/NewView/SearchDirectoriesFormUnit.pas

Last change on this file was 228, checked in by RBRi, 18 years ago

refactoring for language handling

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1Unit SearchDirectoriesFormUnit;
2
3Interface
4
5Uses
6 Classes,
7 Forms,
8 Buttons,
9 StdCtrls,
10 ACLLanguageUnit,
11 CustomFileControls;
12
13Type
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
48Var
49 SearchDirectoriesForm: TSearchDirectoriesForm;
50
51Implementation
52
53Uses
54 ControlsUtility,
55 DebugUnit,
56 StringUtilsUnit;
57
58Procedure TSearchDirectoriesForm.SearchDirectoriesFormOnSetupShow (Sender: TObject);
59Begin
60 ScaleForm( self, 11, 16 );
61End;
62
63Procedure TSearchDirectoriesForm.AddDirectoryButtonOnClick (Sender: TObject);
64var
65 Dir: string;
66 i: longint;
67Begin
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;
83End;
84
85Procedure TSearchDirectoriesForm.SearchDirectoriesFormOnDestroy (Sender: TObject);
86Begin
87 SelectedFolders.Destroy;
88End;
89
90// Show or hide controls so they are in the tab order when appropriate
91Procedure TSearchDirectoriesForm.ShowBrowseControls( Show: boolean );
92Begin
93 DriveComboBox.Visible := Show;
94 DirectoryListBox.Visible := Show;
95 AddDirectoryButton.Visible := Show;
96 SubdirectoriesCheckBox.Visible := Show;
97End;
98
99Procedure TSearchDirectoriesForm.AddButtonOnClick (Sender: TObject);
100Begin
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;
109End;
110
111Procedure TSearchDirectoriesForm.OnLanguageEvent( Language: TLanguageFile;
112 const Apply: boolean );
113begin
114 // LogEvent(LogI18n, 'TSearchDirectoriesForm.OnLanguageEvent apply: "' + BoolToStr(Apply) + '"');
115 Language.LoadComponentLanguage( self, Apply );
116end;
117
118Procedure TSearchDirectoriesForm.SearchDirectoriesFormOnCreate (Sender: TObject);
119Begin
120 RegisterEventForLanguages( OnLanguageEvent );
121 ClientWidth := DirectoriesListBox.Left + DirectoriesListBox.Width + DirectoriesListBox.Left;
122
123 ShowBrowseControls( false );
124
125 SelectedFolders := TStringList.Create;
126End;
127
128Procedure TSearchDirectoriesForm.OKButtonOnClick (Sender: TObject);
129var
130 i: longint;
131begin
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;
142end;
143
144Procedure TSearchDirectoriesForm.SearchDirectoriesFormOnShow (Sender: TObject);
145var
146 i: longint;
147Begin
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;
159End;
160
161Initialization
162 RegisterClasses ([TSearchDirectoriesForm, TButton,
163 TLabel, TCustomDirectoryListBox, TCustomDriveComboBox, TListBox, TCheckBox]);
164End.
Note: See TracBrowser for help on using the repository browser.