source: trunk/NewView/BookmarksFormUnit.pas@ 32

Last change on this file since 32 was 32, checked in by RBRi, 19 years ago

% more source cleanup (uses)

  • Property svn:eol-style set to native
File size: 6.1 KB
Line 
1Unit 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
7Interface
8
9Uses
10 Classes,
11 Forms,
12 StdCtrls,
13 Buttons,
14 ACLLanguageUnit,
15 MiscUnit;
16
17Type
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
60Var
61 BookmarksForm: TBookmarksForm;
62
63Implementation
64
65uses
66 PMWin,
67 ControlsUtility,
68 ACLDialogs,
69 ACLStringUtility;
70
71Procedure TBookmarksForm.BookmarksFormOnSetupShow (Sender: TObject);
72Begin
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;
81End;
82
83Procedure TBookmarksForm.OnLanguageEvent( Language: TLanguageFile;
84 const Apply: boolean );
85begin
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' );
93end;
94
95Procedure TBookmarksForm.BookmarksListBoxOnScan (Sender: TObject;
96 Var KeyCode: TKeyCode);
97Begin
98 if KeyCode = kb_VK + VK_NEWLINE then
99 GotoSelectedBookmark;
100End;
101
102Procedure TBookmarksForm.CloseButtonOnClick (Sender: TObject);
103Begin
104 Close;
105End;
106
107Procedure TBookmarksForm.BookmarksListBoxOnDblClick (Sender: TObject);
108Begin
109 GotoSelectedBookmark;
110End;
111
112Procedure TBookmarksForm.BookmarksFormOnCreate (Sender: TObject);
113Begin
114 RegisterForLanguages( OnLanguageEvent );
115End;
116
117Procedure TBookmarksForm.BookmarksListBoxOnItemFocus (Sender: TObject;
118 Index: LongInt);
119Begin
120 UpdateControls;
121End;
122
123Procedure TBookmarksForm.DeleteButtonOnClick (Sender: TObject);
124Var
125 Bookmark: TBookmark;
126 BookmarkIndex: longint;
127Begin
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;
151End;
152
153Procedure TBookmarksForm.RenameButtonOnClick (Sender: TObject);
154Var
155 Bookmark: TBookmark;
156Begin
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;
170End;
171
172function TBookmarksForm.GetSelectedBookmark: TBookmark;
173
174begin
175 if SelectedObject( BookmarksListBox ) = nil then
176 result := nil
177 else
178 result := SelectedObject( BookmarksListBox ) as TBookmark;
179
180end;
181
182Procedure TBookmarksForm.GotoButtonOnClick (Sender: TObject);
183Begin
184 GotoSelectedBookmark;
185End;
186
187Procedure TBookmarksForm.GotoSelectedBookmark;
188Begin
189 if Assigned( OpenBookmarkCallback ) then
190 if GetSelectedBookmark <> nil then
191 OpenBookmarkCallback( GetSelectedBookmark );
192End;
193
194Procedure TBookmarksForm.BookmarksFormOnShow (Sender: TObject);
195begin
196 GoToButton.Default := true;
197 RefreshList;
198 BookmarksListBox.Focus;
199end;
200
201procedure TBookmarksForm.UpdateControls;
202var
203 Selected: Boolean;
204begin
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;
211end;
212
213procedure TBookmarksForm.RefreshList;
214var
215 i: integer;
216 Bookmark: TBookmark;
217Begin
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;
237End;
238
239Initialization
240 RegisterClasses ([TBookmarksForm
241 , TListBox, TButton]);
242End.
Note: See TracBrowser for help on using the repository browser.