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 | ACLStringUtility;
|
---|
70 |
|
---|
71 | Procedure TBookmarksForm.BookmarksFormOnSetupShow (Sender: TObject);
|
---|
72 | Begin
|
---|
73 | ScaleForm( self, 11, 16 );
|
---|
74 | BookmarksListBox.XStretch := xsFrame;
|
---|
75 | BookmarksListBox.YStretch := ysFrame;
|
---|
76 | DeleteButton.Align := alFixedRightTop;
|
---|
77 | RenameButton.Align := alFixedRightTop;
|
---|
78 | GotoButton.Align := alFixedRightTop;
|
---|
79 | HelpButton.Align := alFixedRightTop;
|
---|
80 | CloseButton.Align := alFixedRightBottom;
|
---|
81 | End;
|
---|
82 |
|
---|
83 | Procedure TBookmarksForm.OnLanguageEvent( Language: TLanguageFile;
|
---|
84 | const Apply: boolean );
|
---|
85 | begin
|
---|
86 | Language.LoadComponentLanguage( self, Apply );
|
---|
87 |
|
---|
88 | Language.LL( Apply, DeleteBookmarkTitle, 'DeleteBookmarkTitle', 'Delete Bookmark' );
|
---|
89 | Language.LL( Apply, DeleteBookmarkA, 'DeleteBookmarkA', 'Delete the bookmark named ' );
|
---|
90 | Language.LL( Apply, DeleteBookmarkB, 'DeleteBookmarkB', '?' );
|
---|
91 | Language.LL( Apply, RenameBookmarkTitle, 'RenameBookmarkTitle', 'Rename Bookmark' );
|
---|
92 | Language.LL( Apply, RenameBookmark, 'RenameBookmark', 'Enter the new name of the bookmark' );
|
---|
93 | end;
|
---|
94 |
|
---|
95 | Procedure TBookmarksForm.BookmarksListBoxOnScan (Sender: TObject;
|
---|
96 | Var KeyCode: TKeyCode);
|
---|
97 | Begin
|
---|
98 | if KeyCode = kb_VK + VK_NEWLINE then
|
---|
99 | GotoSelectedBookmark;
|
---|
100 | End;
|
---|
101 |
|
---|
102 | Procedure TBookmarksForm.CloseButtonOnClick (Sender: TObject);
|
---|
103 | Begin
|
---|
104 | Close;
|
---|
105 | End;
|
---|
106 |
|
---|
107 | Procedure TBookmarksForm.BookmarksListBoxOnDblClick (Sender: TObject);
|
---|
108 | Begin
|
---|
109 | GotoSelectedBookmark;
|
---|
110 | End;
|
---|
111 |
|
---|
112 | Procedure TBookmarksForm.BookmarksFormOnCreate (Sender: TObject);
|
---|
113 | Begin
|
---|
114 | RegisterForLanguages( OnLanguageEvent );
|
---|
115 | End;
|
---|
116 |
|
---|
117 | Procedure TBookmarksForm.BookmarksListBoxOnItemFocus (Sender: TObject;
|
---|
118 | Index: LongInt);
|
---|
119 | Begin
|
---|
120 | UpdateControls;
|
---|
121 | End;
|
---|
122 |
|
---|
123 | Procedure TBookmarksForm.DeleteButtonOnClick (Sender: TObject);
|
---|
124 | Var
|
---|
125 | Bookmark: TBookmark;
|
---|
126 | BookmarkIndex: longint;
|
---|
127 | Begin
|
---|
128 | Bookmark := GetSelectedBookmark;
|
---|
129 | if Bookmark = nil then
|
---|
130 | exit;
|
---|
131 |
|
---|
132 | if DoConfirmDlg( DeleteBookmarkTitle,
|
---|
133 | DeleteBookmarkA
|
---|
134 | + StrDoubleQuote( Bookmark.Name )
|
---|
135 | + DeleteBookmarkB ) then
|
---|
136 | begin
|
---|
137 | BookmarkIndex := BookmarkList.IndexOf( Bookmark );
|
---|
138 | BookmarksListBox.Items.Delete( BookmarkIndex );
|
---|
139 | BookmarkList.Delete( BookmarkIndex );
|
---|
140 |
|
---|
141 | if BookmarkIndex > BookmarkList.Count - 1 then
|
---|
142 | BookmarkIndex := BookmarkList.Count - 1;
|
---|
143 |
|
---|
144 | BookmarksListBox.ItemIndex := BookmarkIndex;
|
---|
145 |
|
---|
146 | Bookmark.Destroy;
|
---|
147 | BookmarksChangedCallback( self );
|
---|
148 |
|
---|
149 | UpdateControls;
|
---|
150 | end;
|
---|
151 | End;
|
---|
152 |
|
---|
153 | Procedure TBookmarksForm.RenameButtonOnClick (Sender: TObject);
|
---|
154 | Var
|
---|
155 | Bookmark: TBookmark;
|
---|
156 | Begin
|
---|
157 | Bookmark := GetSelectedBookmark;
|
---|
158 | if Bookmark = nil then
|
---|
159 | exit;
|
---|
160 | if DoInputQuery( RenameBookmarkTitle,
|
---|
161 | RenameBookmark,
|
---|
162 | Bookmark.Name ) then
|
---|
163 | begin
|
---|
164 | BookmarksChangedCallback( self );
|
---|
165 |
|
---|
166 | // redisplay name in list
|
---|
167 | BookmarksListBox.Items[ BookmarksListBox.ItemIndex ] := Bookmark.Name;
|
---|
168 |
|
---|
169 | end;
|
---|
170 | End;
|
---|
171 |
|
---|
172 | function TBookmarksForm.GetSelectedBookmark: TBookmark;
|
---|
173 |
|
---|
174 | begin
|
---|
175 | if SelectedObject( BookmarksListBox ) = nil then
|
---|
176 | result := nil
|
---|
177 | else
|
---|
178 | result := SelectedObject( BookmarksListBox ) as TBookmark;
|
---|
179 |
|
---|
180 | end;
|
---|
181 |
|
---|
182 | Procedure TBookmarksForm.GotoButtonOnClick (Sender: TObject);
|
---|
183 | Begin
|
---|
184 | GotoSelectedBookmark;
|
---|
185 | End;
|
---|
186 |
|
---|
187 | Procedure TBookmarksForm.GotoSelectedBookmark;
|
---|
188 | Begin
|
---|
189 | if Assigned( OpenBookmarkCallback ) then
|
---|
190 | if GetSelectedBookmark <> nil then
|
---|
191 | OpenBookmarkCallback( GetSelectedBookmark );
|
---|
192 | End;
|
---|
193 |
|
---|
194 | Procedure TBookmarksForm.BookmarksFormOnShow (Sender: TObject);
|
---|
195 | begin
|
---|
196 | GoToButton.Default := true;
|
---|
197 | RefreshList;
|
---|
198 | BookmarksListBox.Focus;
|
---|
199 | end;
|
---|
200 |
|
---|
201 | procedure TBookmarksForm.UpdateControls;
|
---|
202 | var
|
---|
203 | Selected: Boolean;
|
---|
204 | begin
|
---|
205 | Selected := GetSelectedBookmark <> nil;
|
---|
206 | RenameButton.Enabled := Selected;
|
---|
207 | DeleteButton.Enabled := Selected;
|
---|
208 | GotoButton.Enabled := Selected;
|
---|
209 | if not GotoButton.Enabled then
|
---|
210 | GotoButton.Default := false;
|
---|
211 | end;
|
---|
212 |
|
---|
213 | procedure TBookmarksForm.RefreshList;
|
---|
214 | var
|
---|
215 | i: integer;
|
---|
216 | Bookmark: TBookmark;
|
---|
217 | Begin
|
---|
218 | BookmarksListBox.Items.BeginUpdate;
|
---|
219 |
|
---|
220 | BookmarksListBox.Clear;
|
---|
221 |
|
---|
222 | if not Assigned( BookmarkList ) then
|
---|
223 | exit;
|
---|
224 |
|
---|
225 | for i := 0 to BookmarkList.Count - 1 do
|
---|
226 | begin
|
---|
227 | Bookmark := BookmarkList[ i ];
|
---|
228 | BookmarksListBox.Items.AddObject( Bookmark.Name,
|
---|
229 | Bookmark );
|
---|
230 | end;
|
---|
231 |
|
---|
232 | if BookmarksListBox.Items.Count > 0 then
|
---|
233 | BookmarksListBox.ItemIndex := 0;
|
---|
234 |
|
---|
235 | BookmarksListBox.Items.EndUpdate;
|
---|
236 | UpdateControls;
|
---|
237 | End;
|
---|
238 |
|
---|
239 | Initialization
|
---|
240 | RegisterClasses ([TBookmarksForm
|
---|
241 | , TListBox, TButton]);
|
---|
242 | End.
|
---|