diff options
author | Graeme Geldenhuys <graemeg@gmail.com> | 2009-11-21 17:10:19 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@gmail.com> | 2009-11-21 17:10:19 +0200 |
commit | 76c91c9753c948da37a43ace9ba20ee6500c6e2a (patch) | |
tree | 72a15be9b1eee887cf9f9f2f239f7cbc04779652 | |
parent | 2865cd142b35616fa887ae48e28b11dda9386fcf (diff) | |
download | fpGUI-76c91c9753c948da37a43ace9ba20ee6500c6e2a.tar.xz |
Implement correct handling of MRU files
* Menu is now correctly populated
* Menu items are now the Titles of the INF or HLP files
* Multile files opened at once are saved correctly.
-rw-r--r-- | TODO.txt | 2 | ||||
-rw-r--r-- | src/SettingsUnit.pas | 25 | ||||
-rw-r--r-- | src/docview.lpi | 2 | ||||
-rw-r--r-- | src/dvconstants.pas | 2 | ||||
-rw-r--r-- | src/frm_main.pas | 147 |
5 files changed, 133 insertions, 45 deletions
@@ -38,7 +38,6 @@ Todo list [ ] - Options or Configuration dialog to set various things. [ ] - Hyperlinks on scrolled content doesn't work. [ ] - Implement popup window for "notes" hyperlinks. -[ ] - MRU menu item doesn't seem to remember all opened documents. [x] - Display topic by ID via command line parameters [x] - 'Could not load topic slots' message when trying to view some topics. @@ -46,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/src/SettingsUnit.pas b/src/SettingsUnit.pas index f6b34bc4..82a3aaf7 100644 --- a/src/SettingsUnit.pas +++ b/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/src/docview.lpi b/src/docview.lpi index 7ad05235..2996f4cf 100644 --- a/src/docview.lpi +++ b/src/docview.lpi @@ -150,7 +150,7 @@ <Unit23> <Filename Value="dvconstants.pas"/> <IsPartOfProject Value="True"/> - <UnitName Value="dvconstants"/> + <UnitName Value="dvConstants"/> </Unit23> <Unit24> <Filename Value="dvHelpers.pas"/> diff --git a/src/dvconstants.pas b/src/dvconstants.pas index ae8b414d..ff84376d 100644 --- a/src/dvconstants.pas +++ b/src/dvconstants.pas @@ -1,4 +1,4 @@ -unit dvconstants; +unit dvConstants; {$mode objfpc}{$H+} diff --git a/src/frm_main.pas b/src/frm_main.pas index ec442218..bc7cba75 100644 --- a/src/frm_main.pas +++ b/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; @@ -92,7 +91,7 @@ type 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); @@ -139,7 +138,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; @@ -156,6 +156,8 @@ uses ,fpg_constants ,fpg_iniutils ,fpg_cmdlineparams + ,fpg_utils + ,fpg_stringutils ,nvUtilities ,ACLStringUtility ,TextSearchQuery @@ -253,7 +255,7 @@ begin LogEvent(LogSettings, 'Loading settings'); LoadSettings; - + CreateMRUMenuItems; ProcessCommandLineParams; end; @@ -494,9 +496,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); @@ -852,7 +861,6 @@ begin if dlg.RunOpenFile then begin - mru.AddItem(dlg.Filename); Settings.LastOpenDirectory := ExtractFilePath(dlg.Filename); OpenFile(dlg.Filename, '', true); end; @@ -912,7 +920,6 @@ begin for FileIndex := 0 to LoadingFilenameList.Count - 1 do begin Filename := LoadingFilenameList[ FileIndex ]; - mru.AddItem(FileName); LogEvent(LogStartup, ' Loading: ' + Filename ); try LoadingFileIndex := FileIndex; @@ -996,7 +1003,7 @@ begin ProgressBar.Position := 50; SetStatus( rsDVDisplaying ); -// AddCurrentToMRUFiles; + AddCurrentToMRUFiles; if AWindowTitle = '' then MainTitle := THelpFile( CurrentOpenFiles[ 0 ] ).Title @@ -1549,19 +1556,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; @@ -2027,16 +2029,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; @@ -2047,15 +2049,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; @@ -2214,5 +2207,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. |