source: branches/2.19.1/NewView/BookmarksFormUnit.pas@ 265

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

improved StringUtilsUnit

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