source: trunk/NewView/BookmarksFormUnit.pas@ 18

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

+ newview source

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