1 | Unit BookmarksFormUnit;
|
---|
2 |
|
---|
3 | // NewView - a new OS/2 Help Viewer
|
---|
4 | // Copyright 2003 Aaron Lawrence (aaronl at consultant dot com)
|
---|
5 | // This software is released under the Gnu Public License - see readme.txt
|
---|
6 |
|
---|
7 | Interface
|
---|
8 |
|
---|
9 | Uses
|
---|
10 | Classes,
|
---|
11 | Forms,
|
---|
12 | StdCtrls,
|
---|
13 | Buttons,
|
---|
14 | ACLLanguageUnit,
|
---|
15 | MiscUnit;
|
---|
16 |
|
---|
17 | Type
|
---|
18 | TBookmarkCallback = procedure( Bookmark: TBookmark ) of object;
|
---|
19 |
|
---|
20 | TBookmarksForm = Class (TForm)
|
---|
21 | BookmarksListBox: TListBox;
|
---|
22 | GotoButton: TButton;
|
---|
23 | DeleteButton: TButton;
|
---|
24 | RenameButton: TButton;
|
---|
25 | CloseButton: TButton;
|
---|
26 | HelpButton: TButton;
|
---|
27 | Procedure BookmarksFormOnSetupShow (Sender: TObject);
|
---|
28 | Procedure BookmarksListBoxOnScan (Sender: TObject; Var KeyCode: TKeyCode);
|
---|
29 | Procedure CloseButtonOnClick (Sender: TObject);
|
---|
30 | Procedure BookmarksListBoxOnDblClick (Sender: TObject);
|
---|
31 | Procedure BookmarksFormOnCreate (Sender: TObject);
|
---|
32 | Procedure BookmarksListBoxOnItemFocus (Sender: TObject; Index: LongInt);
|
---|
33 | Procedure DeleteButtonOnClick (Sender: TObject);
|
---|
34 | Procedure RenameButtonOnClick (Sender: TObject);
|
---|
35 | Procedure GotoButtonOnClick (Sender: TObject);
|
---|
36 | Procedure BookmarksFormOnShow (Sender: TObject);
|
---|
37 | protected
|
---|
38 | function GetSelectedBookmark: TBookmark;
|
---|
39 | procedure UpdateControls;
|
---|
40 | procedure GotoSelectedBookmark;
|
---|
41 |
|
---|
42 | Protected
|
---|
43 | Procedure OnLanguageEvent( Language: TLanguageFile;
|
---|
44 | const Apply: boolean );
|
---|
45 | DeleteBookmarkTitle: string;
|
---|
46 | DeleteBookmarkA: string;
|
---|
47 | DeleteBookmarkB: string;
|
---|
48 | RenameBookmarkTitle: string;
|
---|
49 | RenameBookmark: string;
|
---|
50 |
|
---|
51 | Public
|
---|
52 | // Input
|
---|
53 | OpenBookmarkCallback: TBookmarkCallback;
|
---|
54 | BookmarksChangedCallback: TNotifyEvent;
|
---|
55 | // Input/Output parameter
|
---|
56 | BookmarkList: TList;
|
---|
57 | procedure RefreshList;
|
---|
58 | End;
|
---|
59 |
|
---|
60 | Var
|
---|
61 | BookmarksForm: TBookmarksForm;
|
---|
62 |
|
---|
63 | Implementation
|
---|
64 |
|
---|
65 | uses
|
---|
66 | PMWin,
|
---|
67 | ControlsUtility,
|
---|
68 | ACLDialogs,
|
---|
69 | StringUtilsUnit,
|
---|
70 | DebugUnit;
|
---|
71 |
|
---|
72 | Procedure TBookmarksForm.BookmarksFormOnSetupShow (Sender: TObject);
|
---|
73 | Begin
|
---|
74 | ScaleForm( self, 11, 16 );
|
---|
75 | BookmarksListBox.XStretch := xsFrame;
|
---|
76 | BookmarksListBox.YStretch := ysFrame;
|
---|
77 | DeleteButton.Align := alFixedRightTop;
|
---|
78 | RenameButton.Align := alFixedRightTop;
|
---|
79 | GotoButton.Align := alFixedRightTop;
|
---|
80 | HelpButton.Align := alFixedRightTop;
|
---|
81 | CloseButton.Align := alFixedRightBottom;
|
---|
82 | End;
|
---|
83 |
|
---|
84 | Procedure TBookmarksForm.OnLanguageEvent( Language: TLanguageFile;
|
---|
85 | const Apply: boolean );
|
---|
86 | var
|
---|
87 | tmpPrefix : String;
|
---|
88 | begin
|
---|
89 | // LogEvent(LogI18n, 'TBookmarksForm.OnLanguageEvent apply: "' + BoolToStr(Apply) + '"');
|
---|
90 | Language.LoadComponentLanguage( self, Apply );
|
---|
91 |
|
---|
92 | tmpPrefix := 'BookmarksForm' + LANGUAGE_LABEL_DELIMITER;
|
---|
93 |
|
---|
94 | Language.LL( Apply, DeleteBookmarkTitle, tmpPrefix + 'DeleteBookmarkTitle', 'Delete Bookmark' );
|
---|
95 | Language.LL( Apply, DeleteBookmarkA, tmpPrefix + 'DeleteBookmarkA', 'Delete the bookmark named ' );
|
---|
96 | Language.LL( Apply, DeleteBookmarkB, tmpPrefix + 'DeleteBookmarkB', '?' );
|
---|
97 | Language.LL( Apply, RenameBookmarkTitle, tmpPrefix + 'RenameBookmarkTitle', 'Rename Bookmark' );
|
---|
98 | Language.LL( Apply, RenameBookmark, tmpPrefix + 'RenameBookmark', 'Enter the new name of the bookmark' );
|
---|
99 | end;
|
---|
100 |
|
---|
101 | Procedure TBookmarksForm.BookmarksListBoxOnScan (Sender: TObject;
|
---|
102 | Var KeyCode: TKeyCode);
|
---|
103 | Begin
|
---|
104 | if KeyCode = kb_VK + VK_NEWLINE then
|
---|
105 | GotoSelectedBookmark;
|
---|
106 | End;
|
---|
107 |
|
---|
108 | Procedure TBookmarksForm.CloseButtonOnClick (Sender: TObject);
|
---|
109 | Begin
|
---|
110 | Close;
|
---|
111 | End;
|
---|
112 |
|
---|
113 | Procedure TBookmarksForm.BookmarksListBoxOnDblClick (Sender: TObject);
|
---|
114 | Begin
|
---|
115 | GotoSelectedBookmark;
|
---|
116 | End;
|
---|
117 |
|
---|
118 | Procedure TBookmarksForm.BookmarksFormOnCreate (Sender: TObject);
|
---|
119 | Begin
|
---|
120 | RegisterEventForLanguages( OnLanguageEvent );
|
---|
121 | End;
|
---|
122 |
|
---|
123 | Procedure TBookmarksForm.BookmarksListBoxOnItemFocus (Sender: TObject;
|
---|
124 | Index: LongInt);
|
---|
125 | Begin
|
---|
126 | UpdateControls;
|
---|
127 | End;
|
---|
128 |
|
---|
129 | Procedure TBookmarksForm.DeleteButtonOnClick (Sender: TObject);
|
---|
130 | Var
|
---|
131 | Bookmark: TBookmark;
|
---|
132 | BookmarkIndex: longint;
|
---|
133 | Begin
|
---|
134 | Bookmark := GetSelectedBookmark;
|
---|
135 | if Bookmark = nil then
|
---|
136 | exit;
|
---|
137 |
|
---|
138 | if DoConfirmDlg( DeleteBookmarkTitle,
|
---|
139 | DeleteBookmarkA
|
---|
140 | + StrInDoubleQuotes(Bookmark.Name)
|
---|
141 | + DeleteBookmarkB ) then
|
---|
142 | begin
|
---|
143 | BookmarkIndex := BookmarkList.IndexOf( Bookmark );
|
---|
144 | BookmarksListBox.Items.Delete( BookmarkIndex );
|
---|
145 | BookmarkList.Delete( BookmarkIndex );
|
---|
146 |
|
---|
147 | if BookmarkIndex > BookmarkList.Count - 1 then
|
---|
148 | BookmarkIndex := BookmarkList.Count - 1;
|
---|
149 |
|
---|
150 | BookmarksListBox.ItemIndex := BookmarkIndex;
|
---|
151 |
|
---|
152 | Bookmark.Destroy;
|
---|
153 | BookmarksChangedCallback( self );
|
---|
154 |
|
---|
155 | UpdateControls;
|
---|
156 | end;
|
---|
157 | End;
|
---|
158 |
|
---|
159 | Procedure TBookmarksForm.RenameButtonOnClick (Sender: TObject);
|
---|
160 | Var
|
---|
161 | Bookmark: TBookmark;
|
---|
162 | Begin
|
---|
163 | Bookmark := GetSelectedBookmark;
|
---|
164 | if Bookmark = nil then
|
---|
165 | exit;
|
---|
166 | if DoInputQuery( RenameBookmarkTitle,
|
---|
167 | RenameBookmark,
|
---|
168 | Bookmark.Name ) then
|
---|
169 | begin
|
---|
170 | BookmarksChangedCallback( self );
|
---|
171 |
|
---|
172 | // redisplay name in list
|
---|
173 | BookmarksListBox.Items[ BookmarksListBox.ItemIndex ] := Bookmark.Name;
|
---|
174 |
|
---|
175 | end;
|
---|
176 | End;
|
---|
177 |
|
---|
178 | function TBookmarksForm.GetSelectedBookmark: TBookmark;
|
---|
179 |
|
---|
180 | begin
|
---|
181 | if SelectedObject( BookmarksListBox ) = nil then
|
---|
182 | result := nil
|
---|
183 | else
|
---|
184 | result := SelectedObject( BookmarksListBox ) as TBookmark;
|
---|
185 |
|
---|
186 | end;
|
---|
187 |
|
---|
188 | Procedure TBookmarksForm.GotoButtonOnClick (Sender: TObject);
|
---|
189 | Begin
|
---|
190 | GotoSelectedBookmark;
|
---|
191 | End;
|
---|
192 |
|
---|
193 | Procedure TBookmarksForm.GotoSelectedBookmark;
|
---|
194 | Begin
|
---|
195 | if Assigned( OpenBookmarkCallback ) then
|
---|
196 | if GetSelectedBookmark <> nil then
|
---|
197 | OpenBookmarkCallback( GetSelectedBookmark );
|
---|
198 | End;
|
---|
199 |
|
---|
200 | Procedure TBookmarksForm.BookmarksFormOnShow (Sender: TObject);
|
---|
201 | begin
|
---|
202 | GoToButton.Default := true;
|
---|
203 | RefreshList;
|
---|
204 | BookmarksListBox.Focus;
|
---|
205 | end;
|
---|
206 |
|
---|
207 | procedure TBookmarksForm.UpdateControls;
|
---|
208 | var
|
---|
209 | Selected: Boolean;
|
---|
210 | begin
|
---|
211 | Selected := GetSelectedBookmark <> nil;
|
---|
212 | RenameButton.Enabled := Selected;
|
---|
213 | DeleteButton.Enabled := Selected;
|
---|
214 | GotoButton.Enabled := Selected;
|
---|
215 | if not GotoButton.Enabled then
|
---|
216 | GotoButton.Default := false;
|
---|
217 | end;
|
---|
218 |
|
---|
219 | procedure TBookmarksForm.RefreshList;
|
---|
220 | var
|
---|
221 | i: integer;
|
---|
222 | Bookmark: TBookmark;
|
---|
223 | Begin
|
---|
224 | BookmarksListBox.Items.BeginUpdate;
|
---|
225 |
|
---|
226 | BookmarksListBox.Clear;
|
---|
227 |
|
---|
228 | if not Assigned( BookmarkList ) then
|
---|
229 | exit;
|
---|
230 |
|
---|
231 | for i := 0 to BookmarkList.Count - 1 do
|
---|
232 | begin
|
---|
233 | Bookmark := BookmarkList[ i ];
|
---|
234 | BookmarksListBox.Items.AddObject( Bookmark.Name,
|
---|
235 | Bookmark );
|
---|
236 | end;
|
---|
237 |
|
---|
238 | if BookmarksListBox.Items.Count > 0 then
|
---|
239 | BookmarksListBox.ItemIndex := 0;
|
---|
240 |
|
---|
241 | BookmarksListBox.Items.EndUpdate;
|
---|
242 | UpdateControls;
|
---|
243 | End;
|
---|
244 |
|
---|
245 | Initialization
|
---|
246 | RegisterClasses ([TBookmarksForm
|
---|
247 | , TListBox, TButton]);
|
---|
248 | End.
|
---|