diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2009-11-27 15:57:13 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2009-11-27 15:57:13 +0200 |
commit | d5ad46c428b5cc8af92a7885a202fc1d881f1d25 (patch) | |
tree | 556753ad95d39948bd760a2b56fdedc0e3aba11c /docview | |
parent | 441add90d3183e0f5e8020442a21c9b3bf62c6ab (diff) | |
parent | b7e4f46fb289a7bdd7c363a76e8bec4d7b4ff339 (diff) | |
download | fpGUI-d5ad46c428b5cc8af92a7885a202fc1d881f1d25.tar.xz |
Merge commit 'remotes/DocView/work'
Diffstat (limited to 'docview')
-rw-r--r-- | docview/TODO.txt | 12 | ||||
-rw-r--r-- | docview/src/HelpFile.pas | 5 | ||||
-rw-r--r-- | docview/src/SettingsUnit.pas | 25 | ||||
-rw-r--r-- | docview/src/docview.lpi | 11 | ||||
-rw-r--r-- | docview/src/docview.lpr | 5 | ||||
-rw-r--r-- | docview/src/dvconstants.pas | 5 | ||||
-rw-r--r-- | docview/src/frm_main.pas | 185 |
7 files changed, 193 insertions, 55 deletions
diff --git a/docview/TODO.txt b/docview/TODO.txt index 38e2b3d5..03ad3642 100644 --- a/docview/TODO.txt +++ b/docview/TODO.txt @@ -28,7 +28,16 @@ Todo list [ ] - Communication between application and docview. Both directions. Possible solutions is Pipes or IPC unit. [ ] - Create help file for DocView listing all supported features etc.. -[ ] - +[ ] - Searching for two words as-is does not seem to work. + eg: 'file descriptor' exists is fppoll help, but trying to search for + those two words doesn't find anything. +[ ] - Sometimes searching for a word doesn't find help even though it exists. + eg: 'descriptor' doesn't find the help in fppoll topic, even though the + work is clearly in the topic contents. +[ ] - Implement History tab and tracking - including Back & Next buttons. +[ ] - Options or Configuration dialog to set various things. +[ ] - Hyperlinks on scrolled content doesn't work. +[ ] - Implement popup window for "notes" hyperlinks. [x] - Display topic by ID via command line parameters [x] - 'Could not load topic slots' message when trying to view some topics. @@ -36,6 +45,7 @@ Todo list LCL documentation needs to be split in two, to compile. (this was an issue with the Open Watcom WIPFC - limit is now set to 65000 entries) [x] - Clicking in index list should set the text in the index search edit box. +[x] - MRU menu item doesn't seem to remember all opened documents. fpdoc IPF todo list diff --git a/docview/src/HelpFile.pas b/docview/src/HelpFile.pas index b3ee7317..af4a2cb9 100644 --- a/docview/src/HelpFile.pas +++ b/docview/src/HelpFile.pas @@ -446,12 +446,12 @@ end; procedure THelpFile.Open; begin + LogEvent(LogDebug, 'Open File >>'); if not FileExists( _Filename ) then raise EHelpFileException.Create( FileErrorNotFound ); try - _Handle := TFileStream.Create(_FileName, fmOpenRead); - + _Handle := TFileStream.Create(_FileName, fmOpenRead or fmShareDenyWrite); except on E: Exception do raise EHelpFileException.Create(E.Message); @@ -471,6 +471,7 @@ begin //end; _FileSize := GetFileSize(_Filename); + LogEvent(LogDebug, 'Open File <<'); end; procedure THelpFile.Close; diff --git a/docview/src/SettingsUnit.pas b/docview/src/SettingsUnit.pas index f6b34bc4..82a3aaf7 100644 --- a/docview/src/SettingsUnit.pas +++ b/docview/src/SettingsUnit.pas @@ -13,6 +13,7 @@ Interface Uses Classes + ,contnrs ,fpg_base ,fpg_main ,CanvasFontManager @@ -75,7 +76,7 @@ Const Type - TIndexStyle = ( isFileOnly, isAlphabetical, isFull ); + TIndexStyle = ( isAlphabetical, isFileOnly, isFull ); TToolbarStyle = ( tsNone, tsImages, tsText, tsImagesAndText ); TGlobalSearchLocation = ( gsHelpPaths, gsFixedDrives, gsSelectedHelpPaths, gsCustom ); @@ -89,7 +90,7 @@ Type TSettings = record - MRUList: TList; + MRUList: TObjectList; LastOpenDirectory: string; LastSaveDirectory: string; StartupHelp: boolean; @@ -133,8 +134,7 @@ Uses ,nvUtilities ; -Const - IniFileName = 'NewView.ini'; +const GeneralSection = 'General'; FontsSection = 'Fonts'; ColoursSection = 'Colours'; @@ -172,7 +172,7 @@ var i: longint; Count: longint; MRUFilename: string; - MRUFileTitle: string; +// MRUFileTitle: string; begin LogEvent(LogSettings, 'LoadSettings' ); with gINI do @@ -224,7 +224,7 @@ begin else begin // not valid - MRUItem.Destroy; + MRUItem.Free; MRUItem := nil; end; end; @@ -459,9 +459,9 @@ begin if PreviousMRUIndex > -1 then begin - // is already in list, move to top of list - MRUItem := TMRUItem(Settings.MRUList[ PreviousMRUIndex ]); - Settings.MRUList.Delete( PreviousMRUIndex ); + // is already in list. Get instance so we can move it to the top of list + MRUItem := TMRUItem(Settings.MRUList[PreviousMRUIndex]); + Settings.MRUList.Extract(MRUItem); end else begin @@ -474,9 +474,7 @@ begin Settings.MRUList.Insert( 0, MRUItem ); while Settings.MRUList.Count > MaxMRUListEntries do begin - MRUItem := TMRUItem(Settings.MRUList[ MaxMRUListEntries ]); - Settings.MRUList.Delete( MaxMRUListEntries ); - MRUItem.Destroy; + Settings.MRUList.Remove(Settings.MRUList.Last); end; end; @@ -515,6 +513,8 @@ end; Initialization + Settings.MRUList := TObjectList.Create; + //Settings.NormalFont := fpgStyle.DefaultFont; //Settings.FixedFont := fpgStyle.FixedFont; //Settings.SearchDirectories := TStringList.Create; @@ -523,5 +523,6 @@ Finalization Settings.NormalFont.Free; Settings.FixedFont.Free; Settings.SearchDirectories.Free; + Settings.MRUList.Free; End. diff --git a/docview/src/docview.lpi b/docview/src/docview.lpi index 2495cb6a..2996f4cf 100644 --- a/docview/src/docview.lpi +++ b/docview/src/docview.lpi @@ -32,7 +32,7 @@ <PackageName Value="fpgui_toolkit"/> </Item1> </RequiredPackages> - <Units Count="27"> + <Units Count="28"> <Unit0> <Filename Value="docview.lpr"/> <IsPartOfProject Value="True"/> @@ -150,7 +150,7 @@ <Unit23> <Filename Value="dvconstants.pas"/> <IsPartOfProject Value="True"/> - <UnitName Value="dvconstants"/> + <UnitName Value="dvConstants"/> </Unit23> <Unit24> <Filename Value="dvHelpers.pas"/> @@ -166,6 +166,11 @@ <Filename Value="../TODO.txt"/> <IsPartOfProject Value="True"/> </Unit26> + <Unit27> + <Filename Value="frm_configuration.pas"/> + <IsPartOfProject Value="True"/> + <UnitName Value="frm_configuration"/> + </Unit27> </Units> </ProjectOptions> <CompilerOptions> @@ -190,7 +195,7 @@ </CodeGeneration> <Other> <CustomOptions Value="-O- -"/> +-Fu/home/graemeg/programming/fpgui/lib/i386-win32aa/"/> <CompilerPath Value="$(CompPath)"/> </Other> </CompilerOptions> diff --git a/docview/src/docview.lpr b/docview/src/docview.lpr index 32a80f3b..105414dc 100644 --- a/docview/src/docview.lpr +++ b/docview/src/docview.lpr @@ -7,13 +7,12 @@ uses cthreads, {$ENDIF}{$ENDIF} Classes, - {$IFDEF Timing}EpikTimer,{$ENDIF} fpg_main, frm_main, IPFEscapeCodes, HelpTopic, CompareWordUnit, SearchTable, TextSearchQuery, nvUtilities, nvNullObjects, HelpFile, SearchUnit, - fpg_cmdlineparams, customstyle, IPFFileFormatUnit, HelpWindowDimensions, + fpg_cmdlineparams, fpgui_toolkit, customstyle, IPFFileFormatUnit, HelpWindowDimensions, NewViewConstantsUnit, SettingsUnit, RichTextStyleUnit, CanvasFontManager, ACLStringUtility, RichTextDocumentUnit, RichTextView, RichTextLayoutUnit, - RichTextDisplayUnit, dvconstants, dvHelpers; + RichTextDisplayUnit, dvconstants, dvHelpers, frm_configuration; procedure MainProc; diff --git a/docview/src/dvconstants.pas b/docview/src/dvconstants.pas index ae8b414d..626e0840 100644 --- a/docview/src/dvconstants.pas +++ b/docview/src/dvconstants.pas @@ -1,4 +1,4 @@ -unit dvconstants; +unit dvConstants; {$mode objfpc}{$H+} @@ -29,6 +29,9 @@ resourcestring rsDVSearchFoundMsg = 'Found %d matches for '; rsDVCouldNotOpen = 'Could not open <%s>'; +const + hcConfigGeneralTab = 510; + hcConfigFontsColorTab = 520; implementation diff --git a/docview/src/frm_main.pas b/docview/src/frm_main.pas index 0d1a8495..b5120378 100644 --- a/docview/src/frm_main.pas +++ b/docview/src/frm_main.pas @@ -7,7 +7,7 @@ interface uses SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_panel, fpg_tab, fpg_tree, fpg_splitter, fpg_menu, fpg_button, fpg_listbox, - fpg_label, fpg_edit, fpg_radiobutton, fpg_progressbar, fpg_mru, + fpg_label, fpg_edit, fpg_radiobutton, fpg_progressbar, HelpFile, RichTextView, HelpTopic; type @@ -59,11 +59,10 @@ type miBookmarks: TfpgPopupMenu; miHelp: TfpgPopupMenu; miDebug: TfpgPopupMenu; - miOpenRecentMenu: TfpgPopupMenu; {@VFD_HEAD_END: MainForm} + miOpenRecentMenu: TfpgPopupMenu; Files: TList; // current open help files. Debug: boolean; - mru: TfpgMRU; FFileOpenRecent: TfpgMenuItem; LoadingFilenameList: TStringList; @@ -86,12 +85,13 @@ type procedure miFileQuitClicked(Sender: TObject); procedure miFileOpenClicked(Sender: TObject); procedure miFileCloseClicked(Sender: TObject); + procedure miConfigureClicked(Sender: TObject); procedure miHelpProdInfoClicked(Sender: TObject); procedure miHelpAboutFPGui(Sender: TObject); procedure miDebugHeader(Sender: TObject); procedure miDebugHex(Sender: TObject); procedure miFileSaveTopicAsIPF(Sender: TObject); - procedure miMRUClick(Sender: TObject; const FileName: String); + procedure OnMRUMenuItemClick(Sender: TObject); procedure btnShowIndex(Sender: TObject); procedure btnGoClicked(Sender: TObject); procedure tvContentsChange(Sender: TObject); @@ -102,6 +102,7 @@ type procedure PageControl1Change(Sender: TObject; NewActiveSheet: TfpgTabSheet); procedure tvContentsDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint); procedure lbIndexDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint); + procedure lbIndexKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); procedure lbSearchResultsDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint); procedure btnSearchClicked(Sender: TObject); procedure IndexSearchEditOnChange(Sender: TObject); @@ -126,6 +127,7 @@ type // Used in loading contents procedure AddChildNodes(AHelpFile: THelpFile; AParentNode: TfpgTreeNode; ALevel: longint; var ATopicIndex: longint ); procedure ClearNotes; + procedure ClearIndexComponents; procedure SaveNotes(AHelpFile: THelpFile); procedure DisplayTopic(ATopic: TTopic = nil); procedure ResetProgress; @@ -138,7 +140,8 @@ type function FindTopicForLink( Link: THelpLink ): TTopic; function FindTopicByResourceID( ID: word ): TTopic; function FindTopicByName(const AName: string): TTopic; - + procedure AddCurrentToMRUFiles; + procedure CreateMRUMenuItems; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -155,6 +158,8 @@ uses ,fpg_constants ,fpg_iniutils ,fpg_cmdlineparams + ,fpg_utils + ,fpg_stringutils ,nvUtilities ,ACLStringUtility ,TextSearchQuery @@ -163,6 +168,7 @@ uses ,IPFFileFormatUnit ,SettingsUnit ,dvHelpers + ,frm_configuration ; const @@ -177,6 +183,16 @@ begin TfpgMessageDialog.Critical('An unexpected error occurred.', E.Message); end; +procedure TMainForm.lbIndexKeyPress(Sender: TObject; var KeyCode: word; + var ShiftState: TShiftState; var Consumed: boolean); +begin + if (KeyCode = keyReturn) or (KeyCode = keyPEnter) then + begin + Consumed := True; + DisplayTopic(nil); + end +end; + procedure TMainForm.RichViewClickLink(Sender: TRichTextView; Link: string); var LinkIndex: integer; @@ -251,13 +267,14 @@ begin LogEvent(LogSettings, 'Loading settings'); LoadSettings; - + CreateMRUMenuItems; ProcessCommandLineParams; end; procedure TMainForm.MainFormDestroy(Sender: TObject); begin + ClearAllWordSequences; DisplayedIndex.Free; // save splitter position gINI.WriteInteger('Options', 'SplitterLeft', PageControl1.Width); @@ -283,6 +300,11 @@ begin CloseFile; end; +procedure TMainForm.miConfigureClicked(Sender: TObject); +begin + ShowConfigForm; +end; + procedure TMainForm.miHelpProdInfoClicked(Sender: TObject); var s: TfpgString; @@ -487,9 +509,16 @@ begin end; end; -procedure TMainForm.miMRUClick(Sender: TObject; const FileName: String); +procedure TMainForm.OnMRUMenuItemClick(Sender: TObject); +var + lTag: longint; + MenuItem: TfpgMenuItem; + MRUItem: TMRUItem; begin - OpenFile(FileName, '', True); + MenuItem := Sender as TfpgMenuItem; + lTag := MenuItem.Tag; + MRUItem := TMRUItem(Settings.MRUList[ lTag ]); + OpenFiles(MRUItem.FileNames, '', True); end; procedure TMainForm.btnShowIndex(Sender: TObject); @@ -845,7 +874,6 @@ begin if dlg.RunOpenFile then begin - mru.AddItem(dlg.Filename); Settings.LastOpenDirectory := ExtractFilePath(dlg.Filename); OpenFile(dlg.Filename, '', true); end; @@ -905,7 +933,6 @@ begin for FileIndex := 0 to LoadingFilenameList.Count - 1 do begin Filename := LoadingFilenameList[ FileIndex ]; - mru.AddItem(FileName); LogEvent(LogStartup, ' Loading: ' + Filename ); try LoadingFileIndex := FileIndex; @@ -966,7 +993,6 @@ begin SetWaitCursor; tmpHelpFiles := TList.Create; -// RBRi Translate if not LoadFiles(FileNames, tmpHelpFiles) then begin ClearWaitCursor; @@ -990,7 +1016,7 @@ begin ProgressBar.Position := 50; SetStatus( rsDVDisplaying ); -// AddCurrentToMRUFiles; + AddCurrentToMRUFiles; if AWindowTitle = '' then MainTitle := THelpFile( CurrentOpenFiles[ 0 ] ).Title @@ -1071,7 +1097,8 @@ begin SaveNotes( lHelpFile ); end; - DisplayedIndex.Clear; + ClearIndexComponents; + ClearAllWordSequences; // Now destroy help files for FileIndex := 0 to Files.Count - 1 do @@ -1344,7 +1371,9 @@ begin LogEvent(LogStartup, ' Display index (count = ' + IntToStr(DisplayedIndex.Count) + ')'); // Now display the final index list + lbIndex.BeginUpdate; lbIndex.Items.Assign( DisplayedIndex ); + lbIndex.EndUpdate; LogEvent(LogStartup, ' Tidy up' ); tmpIndexLists.Free; @@ -1399,6 +1428,15 @@ begin { TODO -oGraeme : Implement me } end; +procedure TMainForm.ClearIndexComponents; +begin + IndexSearchEdit.Clear; + lbIndex.FocusItem := -1; + lbIndex.Items.Clear; + DisplayedIndex.Clear; + IndexLoaded := False; +end; + procedure TMainForm.SaveNotes(AHelpFile: THelpFile); begin { TODO -oGraeme : Implement me } @@ -1541,19 +1579,14 @@ begin end; destructor TMainForm.Destroy; -var - FileIndex: integer; - lHelpFile: THelpFile; begin -writeln('DEBUG: TMainForm.Destroy >>>>'); CurrentTopic := nil; // it was a reference only FFileOpenRecent := nil; // it was a reference only + miOpenRecentMenu.Free; DestroyListAndObjects(Files); DestroyListAndObjects(AllFilesWordSequences); DestroyListAndObjects(CurrentOpenFiles); -writeln('DEBUG: TMainForm.Destroy 1'); inherited Destroy; -writeln('DEBUG: TMainForm.Destroy <<<<'); end; procedure TMainForm.AfterCreate; @@ -1683,6 +1716,7 @@ begin PopupFrame := False; TabOrder := 1; OnDoubleClick := @lbIndexDoubleClick; + OnKeyPress:=@lbIndexKeyPress; end; IndexSearchEdit := TfpgEdit.Create(tsIndex); @@ -1986,7 +2020,7 @@ begin begin Name := 'miSettings'; SetPosition(292, 76, 132, 20); - AddMenuItem('Options...', '', nil); + AddMenuItem('Options...', '', @miConfigureClicked); end; miBookmarks := TfpgPopupMenu.Create(self); @@ -2019,16 +2053,16 @@ begin AddMenuItem('Toggle Hex INF Values in Contents', '', @miDebugHex); end; - miOpenRecentMenu := TfpgPopupMenu.Create(self); + {@VFD_BODY_END: MainForm} + {%endregion} + + miOpenRecentMenu := TfpgPopupMenu.Create(nil); with miOpenRecentMenu do begin Name := 'miOpenRecentMenu'; SetPosition(309, 52, 132, 20); end; - {@VFD_BODY_END: MainForm} - {%endregion} - // hook up the sub-menus. MainMenu.AddMenuItem('&File', nil).SubMenu := miFile; MainMenu.AddMenuItem('&Settings', nil).SubMenu := miSettings; @@ -2039,15 +2073,6 @@ begin // correct default visible tabsheet PageControl1.ActivePageIndex := 0; - - // most recently used files - mru := TfpgMRU.Create(self); - mru.Name := 'MRU'; - mru.ParentMenuItem := miOpenRecentMenu; - mru.OnClick :=@miMRUClick; - mru.MaxItems := gINI.ReadInteger('Options', 'MRUFileCount', 8); - mru.ShowFullPath := gINI.ReadBool('Options', 'ShowFullPath', True); - mru.LoadMRU; end; procedure TMainForm.RefreshFontSubstitutions; @@ -2206,5 +2231,99 @@ begin Result := nil; end; +// Add the current list of open files as +// a Most Recently Used entry +procedure TMainForm.AddCurrentToMRUFiles; +var + tmpFilenames: TStringList; + i: longint; + tmpHelpFile: THelpFile; +begin + tmpFilenames := TStringList.Create; + + if CurrentOpenFiles.Count > 0 then + begin + for i := 0 to CurrentOpenFiles.Count - 1 do + begin + tmpHelpFile := THelpFile(CurrentOpenFiles[ i ]); + tmpFilenames.Add(tmpHelpFile.Filename); + end; + + // update most-recently-used file list + tmpHelpFile := THelpFile(CurrentOpenFiles[ 0 ]); + AddToMRUList(tmpHelpFile.Title, tmpFilenames); + end; + + // recreate menu + CreateMRUMenuItems; + + tmpFilenames.Destroy; +end; + +procedure TMainForm.CreateMRUMenuItems; +var + MenuItem: TfpgMenuItem; + i: integer; + FileName: TfpgString; + FileNameIndex: longint; + MRUText: TfpgString; + MRUItem: TMRUItem; +begin + FFileOpenRecent.SubMenu := nil; + miOpenRecentMenu.Free; + miOpenRecentMenu := TfpgPopupMenu.Create(nil); + FFileOpenRecent.SubMenu := miOpenRecentMenu; + + // Add items for the MRU files + for i:= 0 to Settings.MRUList.Count -1 do + begin + MRUItem := TMRUItem(Settings.MRUList[ i ]); + MenuItem := miOpenRecentMenu.AddMenuItem('?', '', @OnMRUMenuItemClick); +// MenuItem.Name := 'MRUItem' + IntToStr( i ) + 'MI'; + + MRUText := MRUItem.Title; + if Trim( MRUText ) = '' then + begin + // Take the filenames, less path, as caption... + MRUText := ''; + for FileNameIndex := 0 to MRUItem.Filenames.Count - 1 do + begin + FileName := MRUItem.Filenames[ FileNameIndex ]; + FileName := fpgExtractFileName(FileName); + FileName := ChangeFileExt( FileName, '' );// remove extension + + if FileNameIndex > 0 then + begin + MRUText := MRUText + HELP_FILE_DELIMITER; + end; + MRUText := MRUText + FileName; + + // stop after 50 chars + if UTF8Length( MRUText ) > 50 then + begin + MRUText := MRUText + HELP_FILE_DELIMITER + ' ...'; + break; + end; + end; + end; + + MenuItem.Text := '&' + + IntToStr( i + 1 ) + + '. ' + + MRUText; + if MRUItem.Filenames.Count = 1 then + MenuItem.Hint := MRUItem.Filenames[ 0 ] + else + MenuItem.Hint := MRUItem.Title + + ' (' + + IntToStr( MRUItem.Filenames.Count ) + + ' ' + + rsfiles + + ')'; + + MenuItem.Tag := i; + end; +end; + end. |