[18] | 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
|
---|
[32] | 10 | Classes,
|
---|
| 11 | Forms,
|
---|
| 12 | StdCtrls,
|
---|
| 13 | Buttons,
|
---|
[18] | 14 | ACLLanguageUnit,
|
---|
| 15 | MiscUnit;
|
---|
| 16 |
|
---|
| 17 | Type
|
---|
| 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 |
|
---|
| 60 | Var
|
---|
| 61 | BookmarksForm: TBookmarksForm;
|
---|
| 62 |
|
---|
| 63 | Implementation
|
---|
| 64 |
|
---|
| 65 | uses
|
---|
| 66 | PMWin,
|
---|
[32] | 67 | ControlsUtility,
|
---|
| 68 | ACLDialogs,
|
---|
[102] | 69 | StringUtilsUnit,
|
---|
[94] | 70 | DebugUnit;
|
---|
[18] | 71 |
|
---|
| 72 | Procedure TBookmarksForm.BookmarksFormOnSetupShow (Sender: TObject);
|
---|
| 73 | Begin
|
---|
| 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;
|
---|
| 82 | End;
|
---|
| 83 |
|
---|
| 84 | Procedure TBookmarksForm.OnLanguageEvent( Language: TLanguageFile;
|
---|
| 85 | const Apply: boolean );
|
---|
| 86 | begin
|
---|
[94] | 87 | LogEvent(LogI18n, 'TBookmarksForm.OnLanguageEvent apply: "' + BoolToStr(Apply) + '"');
|
---|
[18] | 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' );
|
---|
| 95 | end;
|
---|
| 96 |
|
---|
| 97 | Procedure TBookmarksForm.BookmarksListBoxOnScan (Sender: TObject;
|
---|
| 98 | Var KeyCode: TKeyCode);
|
---|
| 99 | Begin
|
---|
| 100 | if KeyCode = kb_VK + VK_NEWLINE then
|
---|
| 101 | GotoSelectedBookmark;
|
---|
| 102 | End;
|
---|
| 103 |
|
---|
| 104 | Procedure TBookmarksForm.CloseButtonOnClick (Sender: TObject);
|
---|
| 105 | Begin
|
---|
| 106 | Close;
|
---|
| 107 | End;
|
---|
| 108 |
|
---|
| 109 | Procedure TBookmarksForm.BookmarksListBoxOnDblClick (Sender: TObject);
|
---|
| 110 | Begin
|
---|
| 111 | GotoSelectedBookmark;
|
---|
| 112 | End;
|
---|
| 113 |
|
---|
| 114 | Procedure TBookmarksForm.BookmarksFormOnCreate (Sender: TObject);
|
---|
| 115 | Begin
|
---|
| 116 | RegisterForLanguages( OnLanguageEvent );
|
---|
| 117 | End;
|
---|
| 118 |
|
---|
| 119 | Procedure TBookmarksForm.BookmarksListBoxOnItemFocus (Sender: TObject;
|
---|
| 120 | Index: LongInt);
|
---|
| 121 | Begin
|
---|
| 122 | UpdateControls;
|
---|
| 123 | End;
|
---|
| 124 |
|
---|
| 125 | Procedure TBookmarksForm.DeleteButtonOnClick (Sender: TObject);
|
---|
| 126 | Var
|
---|
| 127 | Bookmark: TBookmark;
|
---|
| 128 | BookmarkIndex: longint;
|
---|
| 129 | Begin
|
---|
| 130 | Bookmark := GetSelectedBookmark;
|
---|
| 131 | if Bookmark = nil then
|
---|
| 132 | exit;
|
---|
| 133 |
|
---|
| 134 | if DoConfirmDlg( DeleteBookmarkTitle,
|
---|
| 135 | DeleteBookmarkA
|
---|
[102] | 136 | + StrInDoubleQuotes(Bookmark.Name)
|
---|
[18] | 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;
|
---|
| 153 | End;
|
---|
| 154 |
|
---|
| 155 | Procedure TBookmarksForm.RenameButtonOnClick (Sender: TObject);
|
---|
| 156 | Var
|
---|
| 157 | Bookmark: TBookmark;
|
---|
| 158 | Begin
|
---|
| 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;
|
---|
| 172 | End;
|
---|
| 173 |
|
---|
| 174 | function TBookmarksForm.GetSelectedBookmark: TBookmark;
|
---|
| 175 |
|
---|
| 176 | begin
|
---|
| 177 | if SelectedObject( BookmarksListBox ) = nil then
|
---|
| 178 | result := nil
|
---|
| 179 | else
|
---|
| 180 | result := SelectedObject( BookmarksListBox ) as TBookmark;
|
---|
| 181 |
|
---|
| 182 | end;
|
---|
| 183 |
|
---|
| 184 | Procedure TBookmarksForm.GotoButtonOnClick (Sender: TObject);
|
---|
| 185 | Begin
|
---|
| 186 | GotoSelectedBookmark;
|
---|
| 187 | End;
|
---|
| 188 |
|
---|
| 189 | Procedure TBookmarksForm.GotoSelectedBookmark;
|
---|
| 190 | Begin
|
---|
| 191 | if Assigned( OpenBookmarkCallback ) then
|
---|
| 192 | if GetSelectedBookmark <> nil then
|
---|
| 193 | OpenBookmarkCallback( GetSelectedBookmark );
|
---|
| 194 | End;
|
---|
| 195 |
|
---|
| 196 | Procedure TBookmarksForm.BookmarksFormOnShow (Sender: TObject);
|
---|
| 197 | begin
|
---|
| 198 | GoToButton.Default := true;
|
---|
| 199 | RefreshList;
|
---|
| 200 | BookmarksListBox.Focus;
|
---|
| 201 | end;
|
---|
| 202 |
|
---|
| 203 | procedure TBookmarksForm.UpdateControls;
|
---|
| 204 | var
|
---|
| 205 | Selected: Boolean;
|
---|
| 206 | begin
|
---|
| 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;
|
---|
| 213 | end;
|
---|
| 214 |
|
---|
| 215 | procedure TBookmarksForm.RefreshList;
|
---|
| 216 | var
|
---|
| 217 | i: integer;
|
---|
| 218 | Bookmark: TBookmark;
|
---|
| 219 | Begin
|
---|
| 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;
|
---|
| 239 | End;
|
---|
| 240 |
|
---|
| 241 | Initialization
|
---|
| 242 | RegisterClasses ([TBookmarksForm
|
---|
| 243 | , TListBox, TButton]);
|
---|
| 244 | End.
|
---|