summaryrefslogtreecommitdiff
path: root/docview
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2011-07-29 00:21:33 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2011-07-29 00:21:33 +0200
commit292e10ff07835e2809d1cc20f0cf3edcff0b18cf (patch)
tree2f2bfbb8a62452007d69bcfc895cb264afec5fe2 /docview
parent43af951107f1fd81ded2247c43b11b9e3ac6dce4 (diff)
downloadfpGUI-292e10ff07835e2809d1cc20f0cf3edcff0b18cf.tar.xz
docview: implemented saving and loading of bookmarks per file.
- A new toolbar button is added in the main form. - The Bookmarks menu is correctly updated - Closing a help file correctly clears the bookmarks menu too.
Diffstat (limited to 'docview')
-rw-r--r--docview/src/dvconstants.pas3
-rw-r--r--docview/src/frm_main.pas237
2 files changed, 160 insertions, 80 deletions
diff --git a/docview/src/dvconstants.pas b/docview/src/dvconstants.pas
index 3e44ef58..9e0073be 100644
--- a/docview/src/dvconstants.pas
+++ b/docview/src/dvconstants.pas
@@ -34,6 +34,8 @@ const
HELP_FILE_EXTENSION = ExtensionSeparator + 'hlp';
INF_FILE_EXTENSION = ExtensionSeparator + 'inf';
NOTES_FILE_EXTENSION = ExtensionSeparator + 'notes';
+ BOOKMARK_FILE_EXTENSION = ExtensionSeparator + 'bookmark';
+ BOOKMARK_SECTION = '[BOOKMARK]';
cDocViewHelpFile = 'docview.inf';
@@ -52,6 +54,7 @@ resourcestring
rsDVSearchSyntaxError = 'Error in search syntax: ';
rsDVSearchFoundMsg = 'Found %d matches for ';
rsDVCouldNotOpen = 'Could not open <%s>';
+ rsDVUntitled = '(Untitled)';
const
hcConfigGeneralTab = 510;
diff --git a/docview/src/frm_main.pas b/docview/src/frm_main.pas
index 357b5f6d..7fd4ea21 100644
--- a/docview/src/frm_main.pas
+++ b/docview/src/frm_main.pas
@@ -9,7 +9,7 @@ uses
fpg_tree, fpg_splitter, fpg_menu, fpg_button, fpg_listbox,
fpg_label, fpg_edit, fpg_radiobutton, fpg_progressbar, fpg_imagelist,
fpg_imgfmt_bmp, fpg_combobox,
- HelpFile, RichTextView, HelpTopic;
+ HelpFile, RichTextView, HelpTopic, HelpBookmark;
type
// Used by Index ListBox. We can generate a custom Index if the help file
@@ -67,6 +67,7 @@ type
btnFwd: TfpgButton;
btnPrev: TfpgButton;
btnNext: TfpgButton;
+ btnBookmark: TfpgButton;
btnHelp: TfpgButton;
btnQuit: TfpgButton;
Bevel1: TfpgBevel;
@@ -99,6 +100,7 @@ type
OpenAdditionalFile: boolean;
Notes: TList; // Notes in current files.
Bookmarks: TList;
+ BookmarksMenuItems: TList;
procedure Splitter1DoubleClicked(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
procedure btnTBNoteAddClick(Sender: TObject);
@@ -115,6 +117,7 @@ type
procedure btnFwdHistClick(Sender: TObject);
procedure btnPrevClick(Sender: TObject);
procedure btnNextClick(Sender: TObject);
+ procedure btnBookmarkClick(Sender: TObject);
procedure RichViewClickLink(Sender: TRichTextView; Link: string);
procedure IndexSearchEditKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean);
procedure MainFormShow(Sender: TObject);
@@ -127,6 +130,7 @@ type
procedure miConfigureClicked(Sender: TObject);
procedure miViewExpandAllClicked(Sender: TObject);
procedure miViewCollapseAllClicked(Sender: TObject);
+ procedure miBookmarksMenuItemClicked(Sender: TObject);
procedure miHelpProdInfoClicked(Sender: TObject);
procedure miHelpAboutFPGui(Sender: TObject);
procedure miHelpCmdLineParams(Sender: TObject);
@@ -223,9 +227,11 @@ type
procedure SaveBookmarks;
procedure SaveBookmarksForFile(AHelpFile: THelpFile);
procedure AddBookmark;
+ procedure ClearBookmarks;
procedure OnBookmarksChanged(Sender: TObject);
procedure BuildBookmarksMenu;
procedure UpdateBookmarksDisplay;
+ procedure NavigateToBookmark(Bookmark: TBookmark);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@@ -259,7 +265,6 @@ uses
,CanvasFontManager
,HelpNote
,RichTextDocumentUnit
- ,HelpBookmark
;
const
@@ -404,6 +409,11 @@ begin
end;
end;
+procedure TMainForm.btnBookmarkClick(Sender: TObject);
+begin
+ AddBookmark;
+end;
+
procedure TMainForm.RichViewClickLink(Sender: TRichTextView; Link: string);
var
LinkIndex: integer;
@@ -580,6 +590,18 @@ begin
tvContents.FullCollapse;
end;
+procedure TMainForm.miBookmarksMenuItemClicked(Sender: TObject);
+var
+ t: PtrInt;
+ MenuItem: TfpgMenuItem;
+ Bookmark: TBookmark;
+begin
+ MenuItem:= Sender as TfpgMenuItem;
+ t:= MenuItem.Tag;
+ Bookmark := TBookmark(Bookmarks[t]);
+ NavigateToBookmark( Bookmark );
+end;
+
procedure TMainForm.miHelpProdInfoClicked(Sender: TObject);
var
s: TfpgString;
@@ -1307,19 +1329,19 @@ begin
SetStatus( rsDVDisplaying );
// Add our open files in the global filelist
- { TODO -ograeme : implement global filelist support }
- //for FileIndex := 0 to NewFiles.Count - 1 do
- //begin
- // HelpFile := NewFiles[ FileIndex ];
- // GlobalFilelist.AddFile( HelpFile.Filename, Frame.Handle );
- // // LoadNotes( HelpFile );
- // LoadBookmarks( HelpFile );
- //end;
+ for FileIndex := 0 to NewFiles.Count-1 do
+ begin
+ HelpFile := THelpFile(NewFiles[FileIndex]);
+ { TODO -ograeme : implement global filelist support }
+// GlobalFilelist.AddFile( HelpFile.Filename, Frame.Handle );
+ // LoadNotes( HelpFile );
+ LoadBookmarks( HelpFile );
+ end;
UpdateNotesDisplay;
{ TODO -ograeme : bookmarks }
- //BuildBookmarksMenu;
+ BuildBookmarksMenu;
//UpdateBookmarksForm;
ProgressBar.Position := 55;
@@ -1573,14 +1595,12 @@ begin
tvContents.Invalidate;
end;
+
// First save notes. It's important we do this first
// since we scan all notes each time to find the ones
// belonging to this file.
- for FileIndex := 0 to CurrentOpenFiles.Count - 1 do
- begin
- lHelpFile := THelpFile(CurrentOpenFiles[FileIndex]);
- SaveNotesForFile( lHelpFile );
- end;
+ SaveBookmarks;
+ SaveNotes;
ClearIndexComponents;
ClearAllWordSequences;
@@ -1593,6 +1613,7 @@ begin
end;
CurrentOpenFiles.Clear;
+ ClearBookmarks;
ClearNotes;
end;
@@ -2506,6 +2527,7 @@ begin
DisplayedIndex := TStringList.Create;
Notes := TList.Create;
Bookmarks := TList.Create;
+ BookmarksMenuItems := TList.Create;
CurrentHistoryIndex := -1;
FHistorySelection := False;
OpenAdditionalFile := False;
@@ -2556,7 +2578,9 @@ begin
FFileOpenRecent := nil; // it was a reference only
miOpenRecentMenu.Free;
// DestroyListAndObjects(Files);
- DestroyListAndObjects(Bookmarks);
+ ClearBookmarks;
+ Bookmarks.Free;
+ DestroyListAndObjects(BookmarksMenuItems);
DestroyListAndObjects(Notes);
DestroyListAndObjects(AllFilesWordSequences);
DestroyListAndObjects(CurrentOpenFiles);
@@ -3087,6 +3111,23 @@ begin
Style := bsLowered;
end;
+ btnQuit := TfpgButton.Create(ToolBar);
+ with btnQuit do
+ begin
+ Name := 'btnQuit';
+ SetPosition(4, 1, 24, 24);
+ Text := '';
+ Flat := True;
+ FontDesc := '#Label1';
+ Hint := 'Quit the application';
+ ImageMargin := -1;
+ ImageName := 'stdimg.quit';
+ ImageSpacing := 0;
+ TabOrder := 8;
+ OnClick := @miFileQuitClicked;
+ Focusable := False;
+ end;
+
btnOpen := TfpgButton.Create(ToolBar);
with btnOpen do
begin
@@ -3104,12 +3145,22 @@ begin
Focusable := False;
end;
+ Bevel1 := TfpgBevel.Create(ToolBar);
+ with Bevel1 do
+ begin
+ Name := 'Bevel1';
+ SetPosition(61, 0, 6, 24);
+ Hint := '';
+ Shape := bsLeftLine;
+ Style := bsLowered;
+ end;
+
btnBack := TfpgButton.Create(ToolBar);
with btnBack do
begin
Name := 'btnBack';
SetPosition(70, 1, 32, 24);
- Text := '<';
+ Text := '';
Flat := True;
FontDesc := '#Label1';
Hint := 'Previous history item';
@@ -3126,7 +3177,7 @@ begin
begin
Name := 'btnFwd';
SetPosition(104, 1, 32, 24);
- Text := '>';
+ Text := '';
Flat := True;
FontDesc := '#Label1';
Hint := 'Next history item';
@@ -3143,7 +3194,7 @@ begin
begin
Name := 'btnPrev';
SetPosition(138, 1, 32, 24);
- Text := 'prev';
+ Text := '';
Flat := True;
FontDesc := '#Label1';
Hint := 'Previous Topic';
@@ -3160,7 +3211,7 @@ begin
begin
Name := 'btnNext';
SetPosition(172, 1, 32, 24);
- Text := 'next';
+ Text := '';
Flat := True;
FontDesc := '#Label1';
Hint := 'Next Topic';
@@ -3172,58 +3223,75 @@ begin
OnClick := @btnNextClick;
end;
- btnHelp := TfpgButton.Create(ToolBar);
- with btnHelp do
+ Bevel2 := TfpgBevel.Create(ToolBar);
+ with Bevel2 do
begin
- Name := 'btnHelp';
- SetPosition(256, 1, 24, 24);
+ Name := 'Bevel2';
+ SetPosition(210, 0, 6, 24);
+ Hint := '';
+ Shape := bsLeftLine;
+ Style := bsLowered;
+ end;
+
+ btnTBNoteAdd := TfpgButton.Create(ToolBar);
+ with btnTBNoteAdd do
+ begin
+ Name := 'btnTBNoteAdd';
+ SetPosition(218, 1, 24, 24);
Text := '';
Flat := True;
FontDesc := '#Label1';
- Hint := 'Display Product Information';
+ Hint := 'Add an annotation';
ImageMargin := -1;
- ImageName := 'stdimg.about';
+ ImageName := 'dv.notegreen';
ImageSpacing := 0;
- TabOrder := 6;
+ TabOrder := 12;
Focusable := False;
- OnClick := @miHelpProdInfoClicked;
+ OnClick := @btnTBNoteAddClick;
end;
- btnQuit := TfpgButton.Create(ToolBar);
- with btnQuit do
+ btnBookmark := TfpgButton.Create(ToolBar);
+ with btnBookmark do
begin
- Name := 'btnQuit';
- SetPosition(4, 1, 24, 24);
+ Name := 'btnBookmark';
+ SetPosition(244, 1, 24, 24);
Text := '';
Flat := True;
FontDesc := '#Label1';
- Hint := 'Quit the application';
+ Hint := 'Add a bookmark';
ImageMargin := -1;
- ImageName := 'stdimg.quit';
+ ImageName := 'stdimg.bookmark';
ImageSpacing := 0;
- TabOrder := 8;
- OnClick := @miFileQuitClicked;
+ TabOrder := 5;
Focusable := False;
+ OnClick := @btnBookmarkClick;
end;
- Bevel1 := TfpgBevel.Create(ToolBar);
- with Bevel1 do
+ Bevel3 := TfpgBevel.Create(ToolBar);
+ with Bevel3 do
begin
- Name := 'Bevel1';
- SetPosition(61, 0, 6, 24);
+ Name := 'Bevel3';
+ SetPosition(275, 0, 6, 24);
Hint := '';
Shape := bsLeftLine;
Style := bsLowered;
end;
- Bevel2 := TfpgBevel.Create(ToolBar);
- with Bevel2 do
+ btnHelp := TfpgButton.Create(ToolBar);
+ with btnHelp do
begin
- Name := 'Bevel2';
- SetPosition(210, 0, 6, 24);
- Hint := '';
- Shape := bsLeftLine;
- Style := bsLowered;
+ Name := 'btnHelp';
+ SetPosition(283, 1, 24, 24);
+ Text := '';
+ Flat := True;
+ FontDesc := '#Label1';
+ Hint := 'Display Product Information';
+ ImageMargin := -1;
+ ImageName := 'stdimg.about';
+ ImageSpacing := 0;
+ TabOrder := 6;
+ Focusable := False;
+ OnClick := @miHelpProdInfoClicked;
end;
cbEncoding := TfpgComboBox.Create(ToolBar);
@@ -3243,33 +3311,6 @@ begin
OnChange := @cbEncodingChanged;
end;
- Bevel3 := TfpgBevel.Create(ToolBar);
- with Bevel3 do
- begin
- Name := 'Bevel3';
- SetPosition(248, 0, 6, 24);
- Hint := '';
- Shape := bsLeftLine;
- Style := bsLowered;
- end;
-
- btnTBNoteAdd := TfpgButton.Create(ToolBar);
- with btnTBNoteAdd do
- begin
- Name := 'btnTBNoteAdd';
- SetPosition(218, 1, 24, 24);
- Text := '';
- Flat := True;
- FontDesc := '#Label1';
- Hint := 'Add an annotation';
- ImageMargin := -1;
- ImageName := 'dv.notegreen';
- ImageSpacing := 0;
- TabOrder := 12;
- Focusable := False;
- OnClick := @btnTBNoteAddClick;
- end;
-
{@VFD_BODY_END: MainForm}
{%endregion}
@@ -3629,7 +3670,7 @@ var
begin
ProfileEvent( 'Load bookmarks for ' + AHelpFile.Filename );
- BookmarksFileName := fpgChangeFileExt( AHelpFile.FileName, '.bmark' );
+ BookmarksFileName := fpgChangeFileExt(AHelpFile.FileName, BOOKMARK_FILE_EXTENSION);
if not fpgFileExists( BookmarksFileName ) then
Exit;
@@ -3642,7 +3683,7 @@ begin
while not Eof( BookmarksFile ) do
begin
ReadLn( BookmarksFile, s );
- if Trim( Uppercase( s ) ) = '[BOOKMARK]' then
+ if Trim( Uppercase( s ) ) = BOOKMARK_SECTION then
begin
Bookmark := TBookmark.Load( BookmarksFile, AHelpFile );
Bookmarks.Add( Bookmark );
@@ -3679,7 +3720,7 @@ var
begin
ProfileEvent( 'Save bookmarks for ' + AHelpFile.Filename );
- BookmarksFileName:= ChangeFileExt(AHelpFile.FileName, '.bmark');
+ BookmarksFileName:= fpgChangeFileExt(AHelpFile.FileName, BOOKMARK_FILE_EXTENSION);
BookmarkCount := 0;
for i := 0 to Bookmarks.Count - 1 do
@@ -3705,7 +3746,7 @@ begin
Bookmark := TBookmark(Bookmarks[i]);
if Bookmark.ContentsTopic.HelpFile = AHelpFile then
begin
- WriteLn( BookmarksFile, '[BOOKMARK]' );
+ WriteLn( BookmarksFile, BOOKMARK_SECTION );
Bookmark.Save( BookmarksFile );
end;
end;
@@ -3731,14 +3772,26 @@ begin
end
else
begin
+ { Not all topics appear in the Contents treeview, so we handle that here }
Bookmark.ContentsTopic := nil;
- Bookmark.Name := '(Untitled)';
+ Bookmark.Name := rsDVUntitled;
end;
Bookmarks.Add( Bookmark );
OnBookmarksChanged( self );
end;
+procedure TMainForm.ClearBookmarks;
+begin
+ ClearListAndObjects( Bookmarks );
+ BuildBookmarksMenu;
+// if Assigned( BookmarksForm ) then
+// begin
+// UpdateBookmarksForm; // clear bookmarks for next show
+// BookmarksForm.Hide;
+// end;
+end;
+
procedure TMainForm.OnBookmarksChanged(Sender: TObject);
begin
BuildBookmarksMenu;
@@ -3747,8 +3800,27 @@ begin
end;
procedure TMainForm.BuildBookmarksMenu;
+var
+ i: integer;
+ Bookmark: TBookmark;
+ MenuItem: TfpgMenuItem;
begin
+ DestroyListObjects( BookmarksMenuItems );
+ BookmarksMenuItems.Clear;
+ if Bookmarks.Count > 0 then
+ begin
+ MenuItem := miBookmarks.AddMenuItem('-', '', nil);
+ BookmarksMenuItems.Add( MenuItem );
+ end;
+
+ for i:= 0 to Bookmarks.Count -1 do
+ begin
+ Bookmark := TBookmark(Bookmarks[i]);
+ MenuItem := miBookmarks.AddMenuItem(Bookmark.Name, '', @miBookmarksMenuItemClicked);
+ MenuItem.Tag:= i;
+ BookmarksMenuItems.Add( MenuItem );
+ end;
end;
procedure TMainForm.UpdateBookmarksDisplay;
@@ -3778,6 +3850,11 @@ Begin
*)
end;
+procedure TMainForm.NavigateToBookmark(Bookmark: TBookmark);
+begin
+ DisplayTopic(Bookmark.ContentsTopic);
+end;
+
end.