| 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, Forms, StdCtrls, Buttons,
|
|---|
| 11 | ACLLanguageUnit,
|
|---|
| 12 | MiscUnit;
|
|---|
| 13 |
|
|---|
| 14 | Type
|
|---|
| 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 |
|
|---|
| 57 | Var
|
|---|
| 58 | BookmarksForm: TBookmarksForm;
|
|---|
| 59 |
|
|---|
| 60 | Implementation
|
|---|
| 61 |
|
|---|
| 62 | uses
|
|---|
| 63 | PMWin,
|
|---|
| 64 | Dialogs,
|
|---|
| 65 | ControlsUtility, ACLDialogs, ACLStringUtility;
|
|---|
| 66 |
|
|---|
| 67 | Procedure TBookmarksForm.BookmarksFormOnSetupShow (Sender: TObject);
|
|---|
| 68 | Begin
|
|---|
| 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;
|
|---|
| 77 | End;
|
|---|
| 78 |
|
|---|
| 79 | Procedure TBookmarksForm.OnLanguageEvent( Language: TLanguageFile;
|
|---|
| 80 | const Apply: boolean );
|
|---|
| 81 | begin
|
|---|
| 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' );
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | Procedure TBookmarksForm.BookmarksListBoxOnScan (Sender: TObject;
|
|---|
| 92 | Var KeyCode: TKeyCode);
|
|---|
| 93 | Begin
|
|---|
| 94 | if KeyCode = kb_VK + VK_NEWLINE then
|
|---|
| 95 | GotoSelectedBookmark;
|
|---|
| 96 | End;
|
|---|
| 97 |
|
|---|
| 98 | Procedure TBookmarksForm.CloseButtonOnClick (Sender: TObject);
|
|---|
| 99 | Begin
|
|---|
| 100 | Close;
|
|---|
| 101 | End;
|
|---|
| 102 |
|
|---|
| 103 | Procedure TBookmarksForm.BookmarksListBoxOnDblClick (Sender: TObject);
|
|---|
| 104 | Begin
|
|---|
| 105 | GotoSelectedBookmark;
|
|---|
| 106 | End;
|
|---|
| 107 |
|
|---|
| 108 | Procedure TBookmarksForm.BookmarksFormOnCreate (Sender: TObject);
|
|---|
| 109 | Begin
|
|---|
| 110 | RegisterForLanguages( OnLanguageEvent );
|
|---|
| 111 | End;
|
|---|
| 112 |
|
|---|
| 113 | Procedure TBookmarksForm.BookmarksListBoxOnItemFocus (Sender: TObject;
|
|---|
| 114 | Index: LongInt);
|
|---|
| 115 | Begin
|
|---|
| 116 | UpdateControls;
|
|---|
| 117 | End;
|
|---|
| 118 |
|
|---|
| 119 | Procedure TBookmarksForm.DeleteButtonOnClick (Sender: TObject);
|
|---|
| 120 | Var
|
|---|
| 121 | Bookmark: TBookmark;
|
|---|
| 122 | BookmarkIndex: longint;
|
|---|
| 123 | Begin
|
|---|
| 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;
|
|---|
| 147 | End;
|
|---|
| 148 |
|
|---|
| 149 | Procedure TBookmarksForm.RenameButtonOnClick (Sender: TObject);
|
|---|
| 150 | Var
|
|---|
| 151 | Bookmark: TBookmark;
|
|---|
| 152 | Begin
|
|---|
| 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;
|
|---|
| 166 | End;
|
|---|
| 167 |
|
|---|
| 168 | function TBookmarksForm.GetSelectedBookmark: TBookmark;
|
|---|
| 169 |
|
|---|
| 170 | begin
|
|---|
| 171 | if SelectedObject( BookmarksListBox ) = nil then
|
|---|
| 172 | result := nil
|
|---|
| 173 | else
|
|---|
| 174 | result := SelectedObject( BookmarksListBox ) as TBookmark;
|
|---|
| 175 |
|
|---|
| 176 | end;
|
|---|
| 177 |
|
|---|
| 178 | Procedure TBookmarksForm.GotoButtonOnClick (Sender: TObject);
|
|---|
| 179 | Begin
|
|---|
| 180 | GotoSelectedBookmark;
|
|---|
| 181 | End;
|
|---|
| 182 |
|
|---|
| 183 | Procedure TBookmarksForm.GotoSelectedBookmark;
|
|---|
| 184 | Begin
|
|---|
| 185 | if Assigned( OpenBookmarkCallback ) then
|
|---|
| 186 | if GetSelectedBookmark <> nil then
|
|---|
| 187 | OpenBookmarkCallback( GetSelectedBookmark );
|
|---|
| 188 | End;
|
|---|
| 189 |
|
|---|
| 190 | Procedure TBookmarksForm.BookmarksFormOnShow (Sender: TObject);
|
|---|
| 191 | begin
|
|---|
| 192 | GoToButton.Default := true;
|
|---|
| 193 | RefreshList;
|
|---|
| 194 | BookmarksListBox.Focus;
|
|---|
| 195 | end;
|
|---|
| 196 |
|
|---|
| 197 | procedure TBookmarksForm.UpdateControls;
|
|---|
| 198 | var
|
|---|
| 199 | Selected: Boolean;
|
|---|
| 200 | begin
|
|---|
| 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;
|
|---|
| 207 | end;
|
|---|
| 208 |
|
|---|
| 209 | procedure TBookmarksForm.RefreshList;
|
|---|
| 210 | var
|
|---|
| 211 | i: integer;
|
|---|
| 212 | Bookmark: TBookmark;
|
|---|
| 213 | Begin
|
|---|
| 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;
|
|---|
| 233 | End;
|
|---|
| 234 |
|
|---|
| 235 | Initialization
|
|---|
| 236 | RegisterClasses ([TBookmarksForm
|
|---|
| 237 | , TListBox, TButton]);
|
|---|
| 238 | End.
|
|---|