source: branches/2.20_branch/NewView/BookmarksFormUnit.pas

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

refactoring for language handling

  • Property svn:eol-style set to native
File size: 6.4 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 StringUtilsUnit,
70 DebugUnit;
71
72Procedure TBookmarksForm.BookmarksFormOnSetupShow (Sender: TObject);
73Begin
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;
82End;
83
84Procedure TBookmarksForm.OnLanguageEvent( Language: TLanguageFile;
85 const Apply: boolean );
86var
87 tmpPrefix : String;
88begin
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' );
99end;
100
101Procedure TBookmarksForm.BookmarksListBoxOnScan (Sender: TObject;
102 Var KeyCode: TKeyCode);
103Begin
104 if KeyCode = kb_VK + VK_NEWLINE then
105 GotoSelectedBookmark;
106End;
107
108Procedure TBookmarksForm.CloseButtonOnClick (Sender: TObject);
109Begin
110 Close;
111End;
112
113Procedure TBookmarksForm.BookmarksListBoxOnDblClick (Sender: TObject);
114Begin
115 GotoSelectedBookmark;
116End;
117
118Procedure TBookmarksForm.BookmarksFormOnCreate (Sender: TObject);
119Begin
120 RegisterEventForLanguages( OnLanguageEvent );
121End;
122
123Procedure TBookmarksForm.BookmarksListBoxOnItemFocus (Sender: TObject;
124 Index: LongInt);
125Begin
126 UpdateControls;
127End;
128
129Procedure TBookmarksForm.DeleteButtonOnClick (Sender: TObject);
130Var
131 Bookmark: TBookmark;
132 BookmarkIndex: longint;
133Begin
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;
157End;
158
159Procedure TBookmarksForm.RenameButtonOnClick (Sender: TObject);
160Var
161 Bookmark: TBookmark;
162Begin
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;
176End;
177
178function TBookmarksForm.GetSelectedBookmark: TBookmark;
179
180begin
181 if SelectedObject( BookmarksListBox ) = nil then
182 result := nil
183 else
184 result := SelectedObject( BookmarksListBox ) as TBookmark;
185
186end;
187
188Procedure TBookmarksForm.GotoButtonOnClick (Sender: TObject);
189Begin
190 GotoSelectedBookmark;
191End;
192
193Procedure TBookmarksForm.GotoSelectedBookmark;
194Begin
195 if Assigned( OpenBookmarkCallback ) then
196 if GetSelectedBookmark <> nil then
197 OpenBookmarkCallback( GetSelectedBookmark );
198End;
199
200Procedure TBookmarksForm.BookmarksFormOnShow (Sender: TObject);
201begin
202 GoToButton.Default := true;
203 RefreshList;
204 BookmarksListBox.Focus;
205end;
206
207procedure TBookmarksForm.UpdateControls;
208var
209 Selected: Boolean;
210begin
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;
217end;
218
219procedure TBookmarksForm.RefreshList;
220var
221 i: integer;
222 Bookmark: TBookmark;
223Begin
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;
243End;
244
245Initialization
246 RegisterClasses ([TBookmarksForm
247 , TListBox, TButton]);
248End.
Note: See TracBrowser for help on using the repository browser.