added incremental search to category and notes list
@@ -5,6 +5,7 @@ | ||
5 | 5 | interface |
6 | 6 | |
7 | 7 | uses |
8 | + Windows, | |
8 | 9 | SysUtils, |
9 | 10 | Types, |
10 | 11 | Classes, |
@@ -17,12 +18,12 @@ | ||
17 | 18 | const |
18 | 19 | TRICOLON = #$E2#$81#$9D; // UTF-8 for #$205D tricolon unicode character |
19 | 20 | |
20 | -procedure EnumDirectories(const _Base: string; _Dirs: TStrings; | |
21 | - _Sorted: boolean = True; _FullName: boolean = True; const _Mask: string = '*'); | |
22 | -procedure EnumFiles(const _Base: string; const _Mask: string; _Files: TStrings; _Sorted: boolean = True; | |
23 | - _FullName: boolean = True; _AdditionalAttribs: integer = 0); overload; | |
24 | -procedure EnumFiles(const _FullMask: string; _Files: TStrings; _Sorted: boolean = True; | |
25 | - _FullName: boolean = True; _AdditionalAttribs: integer = 0); overload; | |
21 | +procedure EnumDirectories(const _Base: String; _Dirs: TStrings; | |
22 | + _Sorted: Boolean = True; _FullName: Boolean = True; const _Mask: String = '*'); | |
23 | +procedure EnumFiles(const _Base: String; const _Mask: String; _Files: TStrings; _Sorted: Boolean = True; | |
24 | + _FullName: Boolean = True; _AdditionalAttribs: Integer = 0); overload; | |
25 | +procedure EnumFiles(const _FullMask: String; _Files: TStrings; _Sorted: Boolean = True; | |
26 | + _FullName: Boolean = True; _AdditionalAttribs: Integer = 0); overload; | |
26 | 27 | ///<summary> |
27 | 28 | /// Find a file matching the mask and return its name. If there are more than one matches, return |
28 | 29 | /// the first. |
@@ -29,9 +30,9 @@ | ||
29 | 30 | /// @param Mask is the mask the filen name must match |
30 | 31 | /// @param fn is the first file that was found, if any. Only valid if Result >0 |
31 | 32 | /// @returns the number of matching files found. </summary> |
32 | -function FindMatchingFile(const _Mask: string; out _fn: string; _FullName: boolean = True): integer; | |
33 | +function FindMatchingFile(const _Mask: String; out _fn: String; _FullName: Boolean = True): Integer; | |
33 | 34 | |
34 | -function IsValidFileName(const _Filename: string): boolean; | |
35 | +function IsValidFileName(const _Filename: String): Boolean; | |
35 | 36 | |
36 | 37 | procedure TForm_CenterOn(_frm: TForm; _Owner: TWinControl); overload; |
37 | 38 | function TForm_GetCenter(_frm: TForm): TPoint; |
@@ -40,36 +41,57 @@ | ||
40 | 41 | |
41 | 42 | procedure TWinControl_SetFocus(_ctrl: TWinControl); |
42 | 43 | |
43 | -function TApplication_GetDefaultIniFile: string; | |
44 | -function TApplication_GetExeDir: string; | |
45 | -function TApplication_GetExeDirBS: string; | |
44 | +function TApplication_GetDefaultIniFile: String; | |
45 | +function TApplication_GetExeDir: String; | |
46 | +function TApplication_GetExeDirBS: String; | |
46 | 47 | |
47 | 48 | procedure TButton_DrowpdownMenu(_btn: TButton; _pm: TPopupMenu); |
48 | 49 | |
49 | -function MessageDlgCentered(_Owner: TWinControl; const aMsg: string; DlgType: TMsgDlgType; | |
50 | - Buttons: TMsgDlgButtons; HelpCtx: longint = 0): TModalResult; | |
50 | +function MessageDlgCentered(_Owner: TWinControl; const aMsg: String; DlgType: TMsgDlgType; | |
51 | + Buttons: TMsgDlgButtons; HelpCtx: Longint = 0): TModalResult; | |
51 | 52 | |
53 | +type | |
54 | + | |
55 | + { TIncLookupHelper } | |
56 | + | |
57 | + TIncLookupHelper = class(TComponent) | |
58 | + private | |
59 | + FEdit: TEdit; | |
60 | + FList: TListBox; | |
61 | + FOldEditChange: TNotifyEvent; | |
62 | + FOldEditKeyDown: TKeyEvent; | |
63 | + FOldListKeyDown: TKeyEvent; | |
64 | + FOldListKeyPress: TKeyPressEvent; | |
65 | + procedure HandleEditChange(Sender: TObject); | |
66 | + procedure HandleEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); | |
67 | + procedure HandleListKeyPress(Sender: TObject; var Key: Char); | |
68 | + procedure HandleListKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); | |
69 | + public | |
70 | + constructor Create(_ed: TEdit; _lb: TListBox); reintroduce; | |
71 | + destructor Destroy; override; | |
72 | + end; | |
73 | + | |
52 | 74 | implementation |
53 | 75 | |
54 | -function TApplication_GetDefaultIniFile: string; | |
76 | +function TApplication_GetDefaultIniFile: String; | |
55 | 77 | begin |
56 | 78 | Result := ChangeFileExt(Application.ExeName, '.ini'); |
57 | 79 | end; |
58 | 80 | |
59 | -function TApplication_GetExeDir: string; | |
81 | +function TApplication_GetExeDir: String; | |
60 | 82 | begin |
61 | 83 | Result := ExtractFileDir(Application.ExeName); |
62 | 84 | end; |
63 | 85 | |
64 | -function TApplication_GetExeDirBS: string; | |
86 | +function TApplication_GetExeDirBS: String; | |
65 | 87 | begin |
66 | 88 | Result := IncludeTrailingPathDelimiter(TApplication_GetExeDir); |
67 | 89 | end; |
68 | 90 | |
69 | -procedure EnumDirectories(const _Base: string; _Dirs: TStrings; | |
70 | - _Sorted: boolean = True; _FullName: boolean = True; const _Mask: string = '*'); | |
91 | +procedure EnumDirectories(const _Base: String; _Dirs: TStrings; | |
92 | + _Sorted: Boolean = True; _FullName: Boolean = True; const _Mask: String = '*'); | |
71 | 93 | var |
72 | - Base: string; | |
94 | + Base: String; | |
73 | 95 | SearchRec: TRawByteSearchRec; |
74 | 96 | Dirs: TStringList; |
75 | 97 | begin |
@@ -96,18 +118,18 @@ | ||
96 | 118 | end; |
97 | 119 | end; |
98 | 120 | |
99 | -procedure EnumFiles(const _Base: string; const _Mask: string; _Files: TStrings; _Sorted: boolean = True; | |
100 | - _FullName: boolean = True; _AdditionalAttribs: integer = 0); | |
121 | +procedure EnumFiles(const _Base: String; const _Mask: String; _Files: TStrings; _Sorted: Boolean = True; | |
122 | + _FullName: Boolean = True; _AdditionalAttribs: Integer = 0); | |
101 | 123 | begin |
102 | 124 | EnumFiles(IncludeTrailingPathDelimiter(_Base) + _Mask, _Files, _Sorted, _FullName, _AdditionalAttribs); |
103 | 125 | end; |
104 | 126 | |
105 | -procedure EnumFiles(const _FullMask: string; _Files: TStrings; _Sorted: boolean = True; | |
106 | - _FullName: boolean = True; _AdditionalAttribs: integer = 0); | |
127 | +procedure EnumFiles(const _FullMask: String; _Files: TStrings; _Sorted: Boolean = True; | |
128 | + _FullName: Boolean = True; _AdditionalAttribs: Integer = 0); | |
107 | 129 | var |
108 | 130 | SearchRec: TRawbyteSearchRec; |
109 | 131 | Files: TStringList; |
110 | - Base: string; | |
132 | + Base: String; | |
111 | 133 | begin |
112 | 134 | _Files.Clear; |
113 | 135 | if FindFirst(_FullMask, faArchive + _AdditionalAttribs, SearchRec) = 0 then begin |
@@ -133,7 +155,7 @@ | ||
133 | 155 | end; |
134 | 156 | end; |
135 | 157 | |
136 | -function FindMatchingFile(const _Mask: string; out _fn: string; _FullName: boolean = True): integer; | |
158 | +function FindMatchingFile(const _Mask: String; out _fn: String; _FullName: Boolean = True): Integer; | |
137 | 159 | var |
138 | 160 | Files: TStringList; |
139 | 161 | begin |
@@ -186,8 +208,8 @@ | ||
186 | 208 | _pm.PopUp(pnt.x, pnt.y); |
187 | 209 | end; |
188 | 210 | |
189 | -function MessageDlgCentered(_Owner: TWinControl; const aMsg: string; DlgType: TMsgDlgType; | |
190 | - Buttons: TMsgDlgButtons; HelpCtx: longint): TModalResult; | |
211 | +function MessageDlgCentered(_Owner: TWinControl; const aMsg: String; DlgType: TMsgDlgType; | |
212 | + Buttons: TMsgDlgButtons; HelpCtx: Longint): TModalResult; | |
191 | 213 | var |
192 | 214 | Center: TPoint; |
193 | 215 | begin |
@@ -195,11 +217,11 @@ | ||
195 | 217 | Result := MessageDlgPos(aMsg, DlgType, Buttons, HelpCtx, Center.x, Center.y); |
196 | 218 | end; |
197 | 219 | |
198 | -function IsValidFileName(const _Filename: string): boolean; | |
220 | +function IsValidFileName(const _Filename: String): Boolean; | |
199 | 221 | const |
200 | - InvalidCharacters: set of char = ['\', '/', ':', '*', '?', '"', '<', '>', '|', #9, #13, #10]; | |
222 | + InvalidCharacters: set of Char = ['\', '/', ':', '*', '?', '"', '<', '>', '|', #9, #13, #10]; | |
201 | 223 | var |
202 | - c: char; | |
224 | + c: Char; | |
203 | 225 | begin |
204 | 226 | Result := _Filename <> ''; |
205 | 227 |
@@ -211,6 +233,138 @@ | ||
211 | 233 | end; |
212 | 234 | end; |
213 | 235 | |
236 | +{ TIncLookupHelper } | |
237 | + | |
238 | +constructor TIncLookupHelper.Create(_ed: TEdit; _lb: TListBox); | |
239 | +begin | |
240 | + inherited Create(_ed); | |
241 | + FEdit := _ed; | |
242 | + FList := _lb; | |
243 | + | |
244 | + FOldEditKeyDown := FEdit.OnKeyDown; | |
245 | + FEdit.OnKeyDown := @HandleEditKeyDown; | |
246 | + | |
247 | + FOldEditChange := FEdit.OnChange; | |
248 | + FEdit.OnChange := @HandleEditChange; | |
249 | + | |
250 | + FOldListKeyDown := FList.OnKeyDown; | |
251 | + FList.OnKeyDown := @HandleListKeyDown; | |
252 | + | |
253 | + FOldListKeyPress := FList.OnKeyPress; | |
254 | + FList.OnKeyPress := @HandleListKeyPress; | |
255 | +end; | |
256 | + | |
257 | +destructor TIncLookupHelper.Destroy; | |
258 | +begin | |
259 | + if Assigned(FEdit) then begin | |
260 | + FEdit.OnKeyDown := FOldEditKeyDown; | |
261 | + FEdit.OnChange := FOldEditChange; | |
262 | + end; | |
263 | + if Assigned(FList) then begin | |
264 | + FList.OnKeyDown := FOldListKeyDown; | |
265 | + FList.OnKeyPress := FOldListKeyPress; | |
266 | + end; | |
267 | + inherited Destroy; | |
268 | +end; | |
269 | + | |
270 | +procedure TIncLookupHelper.HandleEditChange(Sender: TObject); | |
271 | +var | |
272 | + s: String; | |
273 | + i: Integer; | |
274 | +begin | |
275 | + s := FEdit.Text; | |
276 | + while s <> '' do begin | |
277 | + for i := 0 to FList.Items.Count - 1 do begin | |
278 | + if SameText(s, LeftStr(FList.Items[i], Length(s))) then begin | |
279 | + FList.ItemIndex := i; | |
280 | + Exit; //==> | |
281 | + end; | |
282 | + end; | |
283 | + s := LeftStr(s, Length(s) - 1); | |
284 | + end; | |
285 | + if Assigned(FOldEditChange) then | |
286 | + FOldEditChange(Sender); | |
287 | +end; | |
288 | + | |
289 | +procedure TIncLookupHelper.HandleEditKeyDown(Sender: TObject; var Key: Word; | |
290 | + Shift: TShiftState); | |
291 | +var | |
292 | + Idx: Integer; | |
293 | +begin | |
294 | + Idx := FList.ItemIndex; | |
295 | + case Key of | |
296 | + VK_UP: begin | |
297 | + Key := 0; | |
298 | + if Idx > 0 then | |
299 | + FList.ItemIndex := Idx - 1; | |
300 | + end; | |
301 | + VK_DOWN: begin | |
302 | + Key := 0; | |
303 | + if Idx < FList.Items.Count then | |
304 | + FList.ItemIndex := Idx + 1; | |
305 | + end; | |
306 | + VK_PRIOR: begin | |
307 | + Key := 0; | |
308 | + if Idx > 0 then begin | |
309 | + Dec(Idx, 10); | |
310 | + if Idx < 0 then | |
311 | + Idx := 0; | |
312 | + FList.ItemIndex := Idx; | |
313 | + end; | |
314 | + end; | |
315 | + VK_NEXT: begin | |
316 | + Key := 0; | |
317 | + if Idx < FList.Items.Count then | |
318 | + Inc(Idx, 10); | |
319 | + if Idx >= FList.Items.Count then | |
320 | + Idx := FList.Items.Count - 1; | |
321 | + FList.ItemIndex := Idx; | |
322 | + end; | |
323 | + VK_ESCAPE: begin | |
324 | + Key := 0; | |
325 | + FEdit.Text := ''; | |
326 | + FEdit.Visible := False; | |
327 | + end; | |
328 | + end; | |
329 | + if Assigned(FOldEditKeyDown) then | |
330 | + FOldEditKeyDown(Sender, Key, Shift); | |
331 | +end; | |
332 | + | |
333 | +procedure TIncLookupHelper.HandleListKeyDown(Sender: TObject; var Key: Word; | |
334 | + Shift: TShiftState); | |
335 | +var | |
336 | + s: TCaption; | |
337 | +begin | |
338 | + if Key = VK_F3 then begin | |
339 | + Key := 0; | |
340 | + FEdit.Visible := True; | |
341 | + FEdit.SetFocus; | |
342 | + end else if Key = VK_BACK then begin | |
343 | + Key := 0; | |
344 | + s := FEdit.Text; | |
345 | + if s <> '' then | |
346 | + FEdit.Text := LeftStr(s, Length(s) - 1); | |
347 | + end else if Key = VK_ESCAPE then begin | |
348 | + Key := 0; | |
349 | + FEdit.Text := ''; | |
350 | + FEdit.Visible := False; | |
351 | + end; | |
352 | + if Assigned(FOldListKeyDown) then | |
353 | + FOldListKeyDown(Sender, key, Shift); | |
354 | +end; | |
355 | + | |
356 | +procedure TIncLookupHelper.HandleListKeyPress(Sender: TObject; var Key: Char); | |
357 | +begin | |
358 | + if Key in ['a'..'z', 'A'..'Z', '0'..'1'] then begin | |
359 | + FEdit.Visible := True; | |
360 | + FEdit.SelText := Key; | |
361 | + FEdit.SetFocus; | |
362 | + FEdit.SelStart := Length(FEdit.Text); | |
363 | + Key := #0; | |
364 | + end; | |
365 | + if Assigned(FOldListKeyPress) then | |
366 | + FOldListKeyPress(Sender, key); | |
367 | +end; | |
368 | + | |
214 | 369 | end. |
215 | 370 | |
216 | - |
@@ -5,7 +5,9 @@ | ||
5 | 5 | interface |
6 | 6 | |
7 | 7 | uses |
8 | + Windows, | |
8 | 9 | Classes, |
10 | + Types, | |
9 | 11 | SysUtils, |
10 | 12 | FileUtil, |
11 | 13 | Forms, |
@@ -13,8 +15,7 @@ | ||
13 | 15 | StdCtrls, |
14 | 16 | ExtCtrls, |
15 | 17 | Menus, |
16 | - wf_Notes, | |
17 | - Types; | |
18 | + wf_Notes; | |
18 | 19 | |
19 | 20 | type |
20 | 21 |
@@ -23,7 +24,8 @@ | ||
23 | 24 | Tfr_Categories = class(TFrame) |
24 | 25 | b_Menu: TButton; |
25 | 26 | b_NewCategory: TButton; |
26 | - lb_Categories: TListBox; | |
27 | + ed_Filter: TEdit; | |
28 | + lb_Items: TListBox; | |
27 | 29 | l_NoNotes: TLabel; |
28 | 30 | mi_About: TMenuItem; |
29 | 31 | mi_Configure: TMenuItem; |
@@ -33,28 +35,29 @@ | ||
33 | 35 | p_Main: TPanel; |
34 | 36 | p_NoCategories: TPanel; |
35 | 37 | procedure b_MenuClick(Sender: TObject); |
38 | + procedure ed_FilterKeyPress(Sender: TObject; var Key: char); | |
36 | 39 | procedure FrameEnter(Sender: TObject); |
37 | 40 | procedure FrameResize(Sender: TObject); |
38 | - procedure lb_CategoriesDrawItem(Control: TWinControl; Index: integer; | |
41 | + procedure lb_ItemsDrawItem(Control: TWinControl; Index: Integer; | |
39 | 42 | ARect: TRect; State: TOwnerDrawState); |
40 | 43 | procedure mi_AboutClick(Sender: TObject); |
41 | 44 | procedure mi_NewCategoryClick(Sender: TObject); |
42 | 45 | procedure mi_ConfigureClick(Sender: TObject); |
43 | - procedure lb_CategoriesDblClick(Sender: TObject); | |
44 | - procedure lb_CategoriesKeyPress(Sender: TObject; var Key: char); | |
46 | + procedure lb_ItemsDblClick(Sender: TObject); | |
47 | + procedure lb_ItemsKeyPress(Sender: TObject; var Key: Char); | |
45 | 48 | private |
46 | - FBasePath: ^string; | |
49 | + FBasePath: ^String; | |
47 | 50 | FNotesFrame: Tfr_Notes; |
48 | - function BasePathBS: string; | |
49 | - function TryGetCategory(out _Category: string): boolean; | |
51 | + function BasePathBS: String; | |
52 | + function TryGetCategory(out _Category: String): Boolean; | |
50 | 53 | procedure OnCloseCategory(_Sender: TObject); |
51 | 54 | public |
52 | 55 | constructor Create(_Owner: TComponent); override; |
53 | - procedure Init(var _BasePath: string); | |
56 | + procedure Init(var _BasePath: String); | |
54 | 57 | procedure GoBack; |
55 | 58 | procedure OpenSelected; |
56 | 59 | procedure ShowMenu; |
57 | - procedure OnCloseQuery(_Sender: TObject; var _CanClose: boolean); | |
60 | + procedure OnCloseQuery(_Sender: TObject; var _CanClose: Boolean); | |
58 | 61 | end; |
59 | 62 | |
60 | 63 | implementation |
@@ -83,18 +86,20 @@ | ||
83 | 86 | FNotesFrame.Parent := Self; |
84 | 87 | FNotesFrame.Align := alClient; |
85 | 88 | FNotesFrame.OnClose := @OnCloseCategory; |
89 | + | |
90 | + TIncLookupHelper.Create(ed_Filter, lb_Items); | |
86 | 91 | end; |
87 | 92 | |
88 | -procedure Tfr_Categories.Init(var _BasePath: string); | |
93 | +procedure Tfr_Categories.Init(var _BasePath: String); | |
89 | 94 | begin |
90 | 95 | FBasePath := @_BasePath; |
91 | 96 | |
92 | - EnumDirectories(BasePathBS, lb_Categories.Items, True, False); | |
93 | - p_NoCategories.Visible := (lb_Categories.Count = 0); | |
94 | - TWinControl_SetFocus(lb_Categories); | |
97 | + EnumDirectories(BasePathBS, lb_Items.Items, True, False); | |
98 | + p_NoCategories.Visible := (lb_Items.Count = 0); | |
99 | + TWinControl_SetFocus(lb_Items); | |
95 | 100 | end; |
96 | 101 | |
97 | -procedure Tfr_Categories.OnCloseQuery(_Sender: TObject; var _CanClose: boolean); | |
102 | +procedure Tfr_Categories.OnCloseQuery(_Sender: TObject; var _CanClose: Boolean); | |
98 | 103 | begin |
99 | 104 | if not Assigned(FNotesFrame) or not FNotesFrame.Visible then |
100 | 105 | Exit; //==> |
@@ -103,7 +108,7 @@ | ||
103 | 108 | |
104 | 109 | procedure Tfr_Categories.OpenSelected; |
105 | 110 | var |
106 | - Category: string; | |
111 | + Category: String; | |
107 | 112 | begin |
108 | 113 | if not Assigned(FNotesFrame) then |
109 | 114 | Exit; //==> |
@@ -112,18 +117,18 @@ | ||
112 | 117 | else begin |
113 | 118 | if not TryGetCategory(Category) then |
114 | 119 | Exit; //==> |
115 | - FNotesFrame.Init(Category, BasePathBS + Category, lb_Categories.Items); | |
120 | + FNotesFrame.Init(Category, BasePathBS + Category, lb_Items.Items); | |
116 | 121 | FNotesFrame.Visible := True; |
117 | 122 | p_Main.Visible := False; |
118 | 123 | end; |
119 | 124 | end; |
120 | 125 | |
121 | -procedure Tfr_Categories.lb_CategoriesDblClick(Sender: TObject); | |
126 | +procedure Tfr_Categories.lb_ItemsDblClick(Sender: TObject); | |
122 | 127 | begin |
123 | 128 | OpenSelected; |
124 | 129 | end; |
125 | 130 | |
126 | -procedure Tfr_Categories.lb_CategoriesKeyPress(Sender: TObject; var Key: char); | |
131 | +procedure Tfr_Categories.lb_ItemsKeyPress(Sender: TObject; var Key: Char); | |
127 | 132 | begin |
128 | 133 | if Key in [#13, #10] then |
129 | 134 | OpenSelected; |
@@ -154,32 +159,38 @@ | ||
154 | 159 | ShowMenu; |
155 | 160 | end; |
156 | 161 | |
162 | +procedure Tfr_Categories.ed_FilterKeyPress(Sender: TObject; var Key: char); | |
163 | +begin | |
164 | + if Key in [#13, #10] then | |
165 | + OpenSelected; | |
166 | +end; | |
167 | + | |
157 | 168 | procedure Tfr_Categories.FrameEnter(Sender: TObject); |
158 | 169 | begin |
159 | - TWinControl_SetFocus(lb_Categories); | |
160 | - if lb_Categories.ItemIndex = -1 then | |
161 | - if lb_Categories.Items.Count > 0 then | |
162 | - lb_Categories.ItemIndex := 0; | |
170 | + TWinControl_SetFocus(lb_Items); | |
171 | + if lb_Items.ItemIndex = -1 then | |
172 | + if lb_Items.Items.Count > 0 then | |
173 | + lb_Items.ItemIndex := 0; | |
163 | 174 | end; |
164 | 175 | |
165 | 176 | procedure Tfr_Categories.FrameResize(Sender: TObject); |
166 | 177 | var |
167 | - w, h: integer; | |
178 | + w, h: Integer; | |
168 | 179 | begin |
169 | - w := lb_Categories.Width; | |
180 | + w := lb_Items.Width; | |
170 | 181 | w := w - p_NoCategories.Width; |
171 | - p_NoCategories.Left := lb_Categories.Left + w div 2; | |
172 | - h := lb_Categories.Height; | |
182 | + p_NoCategories.Left := lb_Items.Left + w div 2; | |
183 | + h := lb_Items.Height; | |
173 | 184 | h := h - p_NoCategories.Height; |
174 | - p_NoCategories.Top := lb_Categories.Top + h div 2; | |
185 | + p_NoCategories.Top := lb_Items.Top + h div 2; | |
175 | 186 | end; |
176 | 187 | |
177 | -procedure Tfr_Categories.lb_CategoriesDrawItem(Control: TWinControl; | |
178 | - Index: integer; ARect: TRect; State: TOwnerDrawState); | |
188 | +procedure Tfr_Categories.lb_ItemsDrawItem(Control: TWinControl; | |
189 | + Index: Integer; ARect: TRect; State: TOwnerDrawState); | |
179 | 190 | var |
180 | 191 | lb: TListBox absolute Control; |
181 | 192 | cnv: TCanvas; |
182 | - s: string; | |
193 | + s: String; | |
183 | 194 | begin |
184 | 195 | s := lb.Items[Index]; |
185 | 196 | cnv := lb.Canvas; |
@@ -195,7 +206,7 @@ | ||
195 | 206 | |
196 | 207 | procedure Tfr_Categories.mi_NewCategoryClick(Sender: TObject); |
197 | 208 | var |
198 | - NewCategory: string; | |
209 | + NewCategory: String; | |
199 | 210 | begin |
200 | 211 | if Tf_NewCategory.Execute(Self, BasePathBS, NewCategory) then |
201 | 212 | Init(FBasePath^); |
@@ -207,20 +218,20 @@ | ||
207 | 218 | Init(FBasePath^); |
208 | 219 | end; |
209 | 220 | |
210 | -function Tfr_Categories.BasePathBS: string; | |
221 | +function Tfr_Categories.BasePathBS: String; | |
211 | 222 | begin |
212 | 223 | Result := IncludeTrailingPathDelimiter(FBasePath^); |
213 | 224 | end; |
214 | 225 | |
215 | -function Tfr_Categories.TryGetCategory(out _Category: string): boolean; | |
226 | +function Tfr_Categories.TryGetCategory(out _Category: String): Boolean; | |
216 | 227 | var |
217 | - Idx: integer; | |
228 | + Idx: Integer; | |
218 | 229 | begin |
219 | 230 | Result := False; |
220 | - Idx := lb_Categories.ItemIndex; | |
231 | + Idx := lb_Items.ItemIndex; | |
221 | 232 | if Idx = -1 then |
222 | 233 | Exit; //==> |
223 | - _Category := lb_Categories.Items[Idx]; | |
234 | + _Category := lb_Items.Items[Idx]; | |
224 | 235 | Result := (_Category <> ''); |
225 | 236 | end; |
226 | 237 |
@@ -228,7 +239,7 @@ | ||
228 | 239 | begin |
229 | 240 | FNotesFrame.Visible := False; |
230 | 241 | p_Main.Visible := True; |
231 | - TWinControl_SetFocus(lb_Categories); | |
242 | + TWinControl_SetFocus(lb_Items); | |
232 | 243 | end; |
233 | 244 | |
234 | 245 | end. |
@@ -24,6 +24,7 @@ | ||
24 | 24 | b_NewChecklist: TButton; |
25 | 25 | b_NewNote: TButton; |
26 | 26 | b_Menu: TButton; |
27 | + ed_Filter: TEdit; | |
27 | 28 | l_NoNotes: TLabel; |
28 | 29 | mi_Move: TMenuItem; |
29 | 30 | mi_Delete: TMenuItem; |
@@ -33,13 +34,14 @@ | ||
33 | 34 | mi_About: TMenuItem; |
34 | 35 | mi_NewNote: TMenuItem; |
35 | 36 | b_Back: TButton; |
36 | - lb_Notes: TListBox; | |
37 | + lb_Items: TListBox; | |
37 | 38 | p_Main: TPanel; |
38 | 39 | p_Top: TPanel; |
40 | + procedure ed_FilterKeyPress(Sender: TObject; var Key: char); | |
39 | 41 | procedure FrameEnter(Sender: TObject); |
40 | 42 | procedure FrameResize(Sender: TObject); |
41 | - procedure lb_NotesDrawItem(Control: TWinControl; Index: integer; | |
42 | - ARect: TRect; State: TOwnerDrawState); | |
43 | + procedure lb_ItemsDrawItem(Control: TWinControl; Index: Integer; ARect: TRect; | |
44 | + State: TOwnerDrawState); | |
43 | 45 | procedure mi_AboutClick(Sender: TObject); |
44 | 46 | procedure b_BackClick(Sender: TObject); |
45 | 47 | procedure b_MenuClick(Sender: TObject); |
@@ -46,11 +48,11 @@ | ||
46 | 48 | procedure mi_DeleteClick(Sender: TObject); |
47 | 49 | procedure mi_NewChecklistClick(Sender: TObject); |
48 | 50 | procedure mi_NewNoteClick(Sender: TObject); |
49 | - procedure lb_NotesDblClick(Sender: TObject); | |
50 | - procedure lb_NotesKeyPress(Sender: TObject; var Key: char); | |
51 | + procedure lb_ItemsDblClick(Sender: TObject); | |
52 | + procedure lb_ItemsKeyPress(Sender: TObject; var Key: Char); | |
51 | 53 | private |
52 | - FCategory: string; | |
53 | - FCategoryPathBS: string; | |
54 | + FCategory: String; | |
55 | + FCategoryPathBS: String; | |
54 | 56 | FOnClose: TNotifyEvent; |
55 | 57 | FEditFrame: Tfr_NoteEditor; |
56 | 58 | FCategories: TStrings; |
@@ -57,12 +59,12 @@ | ||
57 | 59 | procedure doOnClose; |
58 | 60 | procedure mi_MoveToCategoryClick(_Sender: TObject); |
59 | 61 | procedure OnCloseNote(_Sender: TObject); |
60 | - function TryGetNoteFn(out _fn: string): boolean; | |
62 | + function TryGetNoteFn(out _fn: String): Boolean; | |
61 | 63 | public |
62 | 64 | constructor Create(_Owner: TComponent); override; |
63 | 65 | destructor Destroy; override; |
64 | - procedure Init(const _Category: string; const _CategoryPath: string; _Categories: TStrings); | |
65 | - procedure FormCloseQuery(_Sender: TObject; var _CanClose: boolean); | |
66 | + procedure Init(const _Category: String; const _CategoryPath: String; _Categories: TStrings); | |
67 | + procedure FormCloseQuery(_Sender: TObject; var _CanClose: Boolean); | |
66 | 68 | procedure GoBack; |
67 | 69 | procedure OpenSelected; |
68 | 70 | procedure ShowMenu; |
@@ -96,6 +98,8 @@ | ||
96 | 98 | FEditFrame.Parent := Self; |
97 | 99 | FEditFrame.Align := alClient; |
98 | 100 | FEditFrame.OnClose := @OnCloseNote; |
101 | + | |
102 | + TIncLookupHelper.Create(ed_Filter, lb_Items); | |
99 | 103 | end; |
100 | 104 | |
101 | 105 | destructor Tfr_Notes.Destroy; |
@@ -104,12 +108,12 @@ | ||
104 | 108 | inherited Destroy; |
105 | 109 | end; |
106 | 110 | |
107 | -procedure Tfr_Notes.Init(const _Category: string; const _CategoryPath: string; _Categories: TStrings); | |
111 | +procedure Tfr_Notes.Init(const _Category: String; const _CategoryPath: String; _Categories: TStrings); | |
108 | 112 | var |
109 | 113 | Files: TStringList; |
110 | - i: integer; | |
111 | - fn, Title: string; | |
112 | - IsChecklist: boolean; | |
114 | + i: Integer; | |
115 | + fn, Title: String; | |
116 | + IsChecklist: Boolean; | |
113 | 117 | NoteColor: TDenkzettelColor; |
114 | 118 | mi: TMenuItem; |
115 | 119 | begin |
@@ -129,7 +133,7 @@ | ||
129 | 133 | |
130 | 134 | p_Top.Caption := _Category; |
131 | 135 | |
132 | - lb_Notes.Items.Clear; | |
136 | + lb_Items.Items.Clear; | |
133 | 137 | Files := TStringList.Create; |
134 | 138 | try |
135 | 139 | EnumFiles(FCategoryPathBS, '*.txt', Files, True, False); |
@@ -137,13 +141,13 @@ | ||
137 | 141 | fn := files[i]; |
138 | 142 | if not DecodeFilename(fn, Title, IsChecklist, NoteColor) then |
139 | 143 | Title := fn; |
140 | - lb_Notes.Items.AddObject(Title, TObject(PropertiesToPointer(NoteColor, IsChecklist))); | |
144 | + lb_Items.Items.AddObject(Title, TObject(PropertiesToPointer(NoteColor, IsChecklist))); | |
141 | 145 | end; |
142 | 146 | p_NoNotes.Visible := (Files.Count = 0); |
143 | 147 | finally |
144 | 148 | FreeAndNil(Files); |
145 | 149 | end; |
146 | - TWinControl_SetFocus(lb_Notes); | |
150 | + TWinControl_SetFocus(lb_Items); | |
147 | 151 | end; |
148 | 152 | |
149 | 153 | procedure Tfr_Notes.OnCloseNote(_Sender: TObject); |
@@ -153,7 +157,7 @@ | ||
153 | 157 | Init(FCategory, FCategoryPathBS, nil); |
154 | 158 | end; |
155 | 159 | |
156 | -procedure Tfr_Notes.FormCloseQuery(_Sender: TObject; var _CanClose: boolean); | |
160 | +procedure Tfr_Notes.FormCloseQuery(_Sender: TObject; var _CanClose: Boolean); | |
157 | 161 | begin |
158 | 162 | if not Assigned(FEditFrame) or not FEditFrame.Visible then |
159 | 163 | Exit; //==> |
@@ -160,16 +164,16 @@ | ||
160 | 164 | FEditFrame.FormCloseQuery(_Sender, _CanClose); |
161 | 165 | end; |
162 | 166 | |
163 | -function Tfr_Notes.TryGetNoteFn(out _fn: string): boolean; | |
167 | +function Tfr_Notes.TryGetNoteFn(out _fn: String): Boolean; | |
164 | 168 | var |
165 | - Idx: integer; | |
166 | - s: string; | |
169 | + Idx: Integer; | |
170 | + s: String; | |
167 | 171 | begin |
168 | 172 | Result := False; |
169 | - Idx := lb_Notes.ItemIndex; | |
173 | + Idx := lb_Items.ItemIndex; | |
170 | 174 | if Idx = -1 then |
171 | 175 | Exit; //==> |
172 | - s := lb_Notes.Items[Idx]; | |
176 | + s := lb_Items.Items[Idx]; | |
173 | 177 | if s = '' then |
174 | 178 | Exit; //==> |
175 | 179 | Result := FindMatchingFile(FCategoryPathBS + s + '*.*', _fn, False) > 0; |
@@ -183,7 +187,7 @@ | ||
183 | 187 | |
184 | 188 | procedure Tfr_Notes.OpenSelected; |
185 | 189 | var |
186 | - fn: string; | |
190 | + fn: String; | |
187 | 191 | begin |
188 | 192 | if not Assigned(FEditFrame) then |
189 | 193 | Exit; //==> |
@@ -194,12 +198,12 @@ | ||
194 | 198 | p_Main.Visible := False; |
195 | 199 | end; |
196 | 200 | |
197 | -procedure Tfr_Notes.lb_NotesDblClick(Sender: TObject); | |
201 | +procedure Tfr_Notes.lb_ItemsDblClick(Sender: TObject); | |
198 | 202 | begin |
199 | 203 | OpenSelected; |
200 | 204 | end; |
201 | 205 | |
202 | -procedure Tfr_Notes.lb_NotesKeyPress(Sender: TObject; var Key: char); | |
206 | +procedure Tfr_Notes.lb_ItemsKeyPress(Sender: TObject; var Key: Char); | |
203 | 207 | begin |
204 | 208 | if Key in [#13, #10] then |
205 | 209 | OpenSelected; |
@@ -235,7 +239,7 @@ | ||
235 | 239 | |
236 | 240 | procedure Tfr_Notes.mi_DeleteClick(Sender: TObject); |
237 | 241 | var |
238 | - Note: string; | |
242 | + Note: String; | |
239 | 243 | begin |
240 | 244 | if not TryGetNoteFn(Note) then |
241 | 245 | Exit; //==> |
@@ -266,11 +270,11 @@ | ||
266 | 270 | end; |
267 | 271 | |
268 | 272 | // for whatever reason menus.pp does not have StripHotKey |
269 | -// (even though it was added in may 2016, but that's probably not the main repository | |
273 | +// (even though it was added in May 2016, but that's probably not the main repository | |
270 | 274 | // https://github.com/alrieckert/lazarus/commit/8919d979e8cd628d1af2035fd9d230c69150c3cf |
271 | -function StripHotkey(const Text: string): string; | |
275 | +function StripHotkey(const Text: String): String; | |
272 | 276 | var |
273 | - I, R: integer; | |
277 | + I, R: Integer; | |
274 | 278 | begin |
275 | 279 | SetLength(Result, Length(Text)); |
276 | 280 | I := 1; |
@@ -294,8 +298,8 @@ | ||
294 | 298 | |
295 | 299 | procedure Tfr_Notes.mi_MoveToCategoryClick(_Sender: TObject); |
296 | 300 | var |
297 | - Category: string; | |
298 | - Path, fn: string; | |
301 | + Category: String; | |
302 | + Path, fn: String; | |
299 | 303 | begin |
300 | 304 | if not TryGetNoteFn(fn) then |
301 | 305 | Exit; //==> |
@@ -307,7 +311,7 @@ | ||
307 | 311 | Path := ExtractFileDir(path); |
308 | 312 | Path := IncludeTrailingPathDelimiter(Path) + Category; |
309 | 313 | Path := IncludeTrailingPathDelimiter(Path); |
310 | - if not RenameFile(FCategoryPathBS+fn, Path+fn) then | |
314 | + if not RenameFile(FCategoryPathBS + fn, Path + fn) then | |
311 | 315 | raise Exception.Create('Moving the note failed.'); |
312 | 316 | Init(FCategory, FCategoryPathBS, nil); |
313 | 317 | end; |
@@ -314,32 +318,38 @@ | ||
314 | 318 | |
315 | 319 | procedure Tfr_Notes.FrameEnter(Sender: TObject); |
316 | 320 | begin |
317 | - TWinControl_SetFocus(lb_Notes); | |
318 | - if lb_Notes.ItemIndex = -1 then | |
319 | - if lb_Notes.Items.Count > 0 then | |
320 | - lb_Notes.ItemIndex := 0; | |
321 | + TWinControl_SetFocus(lb_Items); | |
322 | + if lb_Items.ItemIndex = -1 then | |
323 | + if lb_Items.Items.Count > 0 then | |
324 | + lb_Items.ItemIndex := 0; | |
321 | 325 | end; |
322 | 326 | |
327 | +procedure Tfr_Notes.ed_FilterKeyPress(Sender: TObject; var Key: char); | |
328 | +begin | |
329 | + if Key in [#13, #10] then | |
330 | + OpenSelected; | |
331 | +end; | |
332 | + | |
323 | 333 | procedure Tfr_Notes.FrameResize(Sender: TObject); |
324 | 334 | var |
325 | - w, h: integer; | |
335 | + w, h: Integer; | |
326 | 336 | begin |
327 | - w := lb_Notes.Width; | |
337 | + w := lb_Items.Width; | |
328 | 338 | w := w - p_NoNotes.Width; |
329 | - p_NoNotes.Left := lb_Notes.Left + w div 2; | |
330 | - h := lb_Notes.Height; | |
339 | + p_NoNotes.Left := lb_Items.Left + w div 2; | |
340 | + h := lb_Items.Height; | |
331 | 341 | h := h - p_NoNotes.Height; |
332 | - p_NoNotes.Top := lb_Notes.Top + h div 2; | |
342 | + p_NoNotes.Top := lb_Items.Top + h div 2; | |
333 | 343 | end; |
334 | 344 | |
335 | -procedure Tfr_Notes.lb_NotesDrawItem(Control: TWinControl; Index: integer; | |
336 | - ARect: TRect; State: TOwnerDrawState); | |
345 | +procedure Tfr_Notes.lb_ItemsDrawItem(Control: TWinControl; Index: Integer; ARect: TRect; | |
346 | + State: TOwnerDrawState); | |
337 | 347 | var |
338 | 348 | lb: TListBox absolute Control; |
339 | 349 | NoteColor: TDenkzettelColor; |
340 | - IsChecklist: boolean; | |
350 | + IsChecklist: Boolean; | |
341 | 351 | cnv: TCanvas; |
342 | - s: string; | |
352 | + s: String; | |
343 | 353 | begin |
344 | 354 | s := lb.Items[Index]; |
345 | 355 | PointerToProperties(lb.Items.Objects[Index], NoteColor, IsChecklist); |