From 0b97295d70f2910c091eafb018299e3e3e16e4ef Mon Sep 17 00:00:00 2001 From: lazarus Date: Thu, 8 Aug 2002 10:33:49 +0000 Subject: [PATCH] MG: main bar speedbar open arrow now shows recent projects and files git-svn-id: trunk@1831 - --- ide/main.pp | 93 +++++++++++++++++++++++++++++++++++++--- ide/mainbar.pas | 3 +- lcl/include/menuitem.inc | 18 ++++++++ lcl/menus.pp | 4 ++ 4 files changed, 111 insertions(+), 7 deletions(-) diff --git a/ide/main.pp b/ide/main.pp index 36c413b32f..7e41d46e7e 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -153,6 +153,7 @@ type procedure mnuHelpAboutLazarusClicked(Sender : TObject); procedure OpenFileDownArrowClicked(Sender : TObject); + procedure mnuOpenFilePopupClick(Sender : TObject); procedure ControlClick(Sender : TObject); // SourceNotebook events @@ -1847,8 +1848,8 @@ begin For I := 0 to OpenDialog.Files.Count-1 do Begin AFilename:=ExpandFilename(OpenDialog.Files.Strings[i]); - if DoOpenEditorFile(AFilename,-1,[])=mrOk then begin - EnvironmentOptions.AddToRecentOpenFiles(AFilename); + if DoOpenEditorFile(AFilename,-1,[ofAddToRecent])=mrOk then begin + end; end; UpdateEnvironment; @@ -1859,8 +1860,7 @@ begin end; end else if Sender is TMenuItem then begin AFileName:=ExpandFilename(TMenuItem(Sender).Caption); - if DoOpenEditorFile(AFilename,-1,[])=mrOk then begin - EnvironmentOptions.AddToRecentOpenFiles(AFilename); + if DoOpenEditorFile(AFilename,-1,[ofAddToRecent])=mrOk then begin UpdateEnvironment; end; end; @@ -2043,12 +2043,87 @@ end; {------------------------------------------------------------------------------} Procedure TMainIDE.OpenFileDownArrowClicked(Sender : TObject); +var + CurIndex: integer; + + procedure AddFile(const Filename: string); + var + AMenuItem: TMenuItem; + begin + if OpenFilePopupMenu.Items.Count>CurIndex then + AMenuItem:=OpenFilePopupMenu.Items[CurIndex] + else begin + AMenuItem:=TMenuItem.Create(Self); + AMenuItem.Name:=OpenFilePopupMenu.Name+'Recent'+IntToStr(CurIndex); + AMenuItem.OnClick:=@mnuOpenFilePopupClick; + OpenFilePopupMenu.Items.Add(AMenuItem); + end; + AMenuItem.Caption:=Filename; + inc(CurIndex); + end; + + procedure AddFiles(List: TStringList; MaxCount: integer); + var i: integer; + begin + i:=0; + while (iCurIndex do + OpenFilePopupMenu.Items[OpenFilePopupMenu.Items.Count-1].Free; + // display the PopupMenu if OpenFilePopupMenu.Items.Count > 0 then OpenFilePopupMenu.Popup(0,0); end; +procedure TMainIDE.mnuOpenFilePopupClick(Sender: TObject); +var + TheMenuItem: TMenuItem; + Index, SeparatorIndex: integer; + AFilename: string; +begin + TheMenuItem:=TMenuItem(Sender); + if TheMenuItem.Caption='-' then exit; + Index:=TheMenuItem.MenuIndex; + SeparatorIndex:=0; + while SeparatorIndex'') then + EnvironmentOptions.AddToRecentOpenFiles(AFilename); + // check if this is a hidden unit: // if this is a virtual (new, unsaved) project, the main unit is already // loaded and needs only to be shown in the sourceeditor/formeditor @@ -4448,7 +4526,7 @@ begin exit; end; - // if there is project info file, load that instead + // if there is a project info file, load that instead if (Ext<>'.lpi') and (FileExists(ChangeFileExt(AFileName,'.lpi'))) then begin // load instead of lazarus program file the project info file AFileName:=ChangeFileExt(AFileName,'.lpi'); @@ -6898,6 +6976,9 @@ end. { ============================================================================= $Log$ + Revision 1.338 2002/08/08 10:33:48 lazarus + MG: main bar speedbar open arrow now shows recent projects and files + Revision 1.337 2002/08/08 09:38:34 lazarus MG: recent file menus are now updated instantly diff --git a/ide/mainbar.pas b/ide/mainbar.pas index 5f6c5ae0b8..0239df7876 100644 --- a/ide/mainbar.pas +++ b/ide/mainbar.pas @@ -68,7 +68,8 @@ type TSaveFlag = (sfSaveAs, sfSaveToTestDir, sfProjectSaving); TSaveFlags = set of TSaveFlag; - TOpenFlag = (ofProjectLoading, ofOnlyIfExists, ofRevert, ofQuiet); + TOpenFlag = (ofProjectLoading, ofOnlyIfExists, ofRevert, ofQuiet, + ofAddToRecent); TOpenFlags = set of TOpenFlag; TRevertFlag = (rfQuiet); TRevertFlags = set of TRevertFlag; diff --git a/lcl/include/menuitem.inc b/lcl/include/menuitem.inc index 7225c008cb..ac50dc2bc6 100644 --- a/lcl/include/menuitem.inc +++ b/lcl/include/menuitem.inc @@ -404,6 +404,18 @@ begin else Result := FItems.IndexOf(Item); end; +{------------------------------------------------------------------------------ + function TMenuItem.IndexOfCaption(const ACaption: string): Integer; + + Resturns the index of the menuitem with the given caption or -1 + ------------------------------------------------------------------------------} +function TMenuItem.IndexOfCaption(const ACaption: string): Integer; +begin + for Result:=0 to Count-1 do + if Items[Result].Caption=ACaption then exit; + Result:=-1; +end; + {------------------------------------------------------------------------------ Method: TMenuItem.MenuChanged Params: Rebuild : Boolean @@ -752,6 +764,9 @@ end; { ============================================================================= $Log$ + Revision 1.22 2002/08/08 10:33:49 lazarus + MG: main bar speedbar open arrow now shows recent projects and files + Revision 1.21 2002/08/08 09:38:36 lazarus MG: recent file menus are now updated instantly @@ -843,6 +858,9 @@ end; $Log$ + Revision 1.22 2002/08/08 10:33:49 lazarus + MG: main bar speedbar open arrow now shows recent projects and files + Revision 1.21 2002/08/08 09:38:36 lazarus MG: recent file menus are now updated instantly diff --git a/lcl/menus.pp b/lcl/menus.pp index 20775208ad..94d1d115fa 100644 --- a/lcl/menus.pp +++ b/lcl/menus.pp @@ -158,6 +158,7 @@ type procedure HandleNeeded; function HasParent : Boolean; override; function IndexOf(Item: TMenuItem): Integer; + function IndexOfCaption(const ACaption: string): Integer; procedure Insert(Index: Integer; Item: TMenuItem); procedure Remove(Item: TMenuItem); property Count: Integer read GetCount; @@ -424,6 +425,9 @@ end. { $Log$ + Revision 1.20 2002/08/08 10:33:49 lazarus + MG: main bar speedbar open arrow now shows recent projects and files + Revision 1.19 2002/08/08 09:07:06 lazarus MG: TMenuItem can now be created/destroyed/moved at any time