diff --git a/components/ideintf/lazideintf.pas b/components/ideintf/lazideintf.pas index 4a1f8615a6..7042d858c9 100644 --- a/components/ideintf/lazideintf.pas +++ b/components/ideintf/lazideintf.pas @@ -198,6 +198,7 @@ type FLazarusIDEHandlers: array[TLazarusIDEHandlerType] of TMethodList; FOwningComponent: TComponent; FIDEStarted: boolean; + FIDEIsClosing: Boolean; FLastActivatedWindows: TFPList; // used to find the last form so you can display the correct tab FLastFormActivated: TCustomForm; @@ -418,6 +419,7 @@ type const OnShowSourceOfActiveDesignerForm: TNotifyEvent); property IDEStarted: boolean read FIDEStarted; + property IDEIsClosing: boolean read FIDEIsClosing; property LastActivatedWindows: TFPList read FLastActivatedWindows; property LastFormActivated: TCustomForm read FLastFormActivated write FLastFormActivated; end; diff --git a/ide/environmentopts.pp b/ide/environmentopts.pp index 9999216adc..10604a4741 100644 --- a/ide/environmentopts.pp +++ b/ide/environmentopts.pp @@ -252,6 +252,12 @@ type type + TLastOpenPackagesList = class(TStringList) + public + function Remove(const aString: string): Boolean; + constructor Create; + end; + { TDesktopOpt } TDesktopOpt = class @@ -369,6 +375,7 @@ type FAutoSaveProject: boolean; FAutoSaveIntervalInSecs: integer; FLastSavedProjectFile: string; + FLastOpenPackages: TLastOpenPackagesList;//list of filenames with open packages // designer FCreateComponentFocusNameProperty: boolean; @@ -468,6 +475,7 @@ type FRecentPackageFiles: TStringList; FMaxRecentPackageFiles: integer; FOpenLastProjectAtStart: boolean; + FOpenPackagesAtStart: boolean; // Prevent repopulating Recent project files menu with example projects if it was already cleared up. FAlreadyPopulatedRecentFiles : Boolean; @@ -718,8 +726,11 @@ type property LastSavedProjectFile: string read FLastSavedProjectFile write FLastSavedProjectFile; { if empty then create new project, if '-' then do not load/create any project } + property LastOpenPackages: TLastOpenPackagesList read FLastOpenPackages; property OpenLastProjectAtStart: boolean read FOpenLastProjectAtStart write FOpenLastProjectAtStart; + property OpenPackagesAtStart: boolean read FOpenPackagesAtStart + write FOpenPackagesAtStart; property FileDialogFilter: string read FFileDialogFilter write FFileDialogFilter; // backup @@ -897,6 +908,25 @@ begin WriteStr(Result, u); end; +{ TLastOpenPackagesList } + +constructor TLastOpenPackagesList.Create; +begin + inherited Create; + Sorted:=true; + Duplicates:=dupIgnore; +end; + +function TLastOpenPackagesList.Remove(const aString: string): Boolean; +var + xIndex: Integer; +begin + xIndex := IndexOf(aString); + Result := xIndex >= 0; + if Result then + Delete(xIndex); +end; + { TDesktopOptList } constructor TDesktopOptList.Create(aEnvOpts: TEnvironmentOptions); @@ -1193,6 +1223,7 @@ begin FAutoSaveProject:=true; FAutoSaveIntervalInSecs:=300; // 5 minutes FLastSavedProjectFile:=''; + FLastOpenPackages:=TLastOpenPackagesList.Create; // EnvironmentOptionsDialog editor FShowGrid:=true; @@ -1280,6 +1311,7 @@ begin FRecentPackageFiles:=TStringList.Create; FMaxRecentPackageFiles:=DefaultMaxRecentPackageFiles; FOpenLastProjectAtStart:=true; + FOpenPackagesAtStart:=true; // backup with FBackupInfoProjectFiles do begin @@ -1348,6 +1380,7 @@ begin FreeAndNil(FConfigStore); FreeAndNil(FDbgConfigStore); FreeAndNil(FXMLCfg); + FreeAndNil(FLastOpenPackages); inherited Destroy; end; @@ -1551,7 +1584,7 @@ var Path, CurPath: String; i, j: Integer; Rec: PIDEOptionsGroupRec; - NodeName: String; + NodeName, xFileName: String; mwc: TMsgWndColor; u: TMessageLineUrgency; begin @@ -1583,9 +1616,21 @@ begin FAutoSaveIntervalInSecs:=FXMLCfg.GetValue(Path+'AutoSave/IntervalInSecs',600); FLastSavedProjectFile:=FXMLCfg.GetValue(Path+'AutoSave/LastSavedProjectFile',''); FOpenLastProjectAtStart:=FXMLCfg.GetValue(Path+'AutoSave/OpenLastProjectAtStart',true); + FOpenPackagesAtStart:=FXMLCfg.GetValue(Path+'AutoSave/OpenPackagesAtStart',true); FShowCompileDialog:=FXMLCfg.GetValue(Path+'ShowCompileDialog/Value',false); FAutoCloseCompileDialog:=FXMLCfg.GetValue(Path+'AutoCloseCompileDialog/Value',false); FAutoSaveActiveDesktop:=FXMLCfg.GetValue(Path+'AutoSave/ActiveDesktop',True); + FLastOpenPackages.Clear; + if FOpenPackagesAtStart then + begin + i := 1; + repeat + xFileName := FXMLCfg.GetValue(Path+'AutoSave/LastOpenPackages/Package'+IntToStr(i), ''); + if FileExistsCached(xFileName) then + FLastOpenPackages.Add(xFileName); + Inc(i); + until xFileName=''; + end; // form editor FShowGrid:=FXMLCfg.GetValue(Path+'FormEditor/ShowGrid',true); @@ -1901,7 +1946,14 @@ begin FXMLCfg.SetDeleteValue(Path+'AutoSave/IntervalInSecs',FAutoSaveIntervalInSecs,600); FXMLCfg.SetDeleteValue(Path+'AutoSave/LastSavedProjectFile',FLastSavedProjectFile,''); FXMLCfg.SetDeleteValue(Path+'AutoSave/OpenLastProjectAtStart',FOpenLastProjectAtStart,true); + FXMLCfg.SetDeleteValue(Path+'AutoSave/OpenPackagesAtStart',FOpenPackagesAtStart,true); FXMLCfg.SetDeleteValue(Path+'AutoSave/ActiveDesktop', FAutoSaveActiveDesktop, True); + if FOpenPackagesAtStart and (FLastOpenPackages.Count > 0) then + begin + for i := 0 to FLastOpenPackages.Count-1 do + FXMLCfg.SetValue(Path+'AutoSave/LastOpenPackages/Package'+IntToStr(i+1), FLastOpenPackages[i]); + end else + FXMLCfg.DeletePath(Path+'AutoSave/LastOpenPackages/'); // form editor FXMLCfg.SetDeleteValue(Path+'FormEditor/ShowBorderSpacing',FShowBorderSpacing,false); diff --git a/ide/frames/files_options.lfm b/ide/frames/files_options.lfm index c17f38099a..19e20d8db8 100644 --- a/ide/frames/files_options.lfm +++ b/ide/frames/files_options.lfm @@ -17,7 +17,7 @@ object FilesOptionsFrame: TFilesOptionsFrame Left = 2 Height = 15 Top = 2 - Width = 145 + Width = 138 Caption = 'MaxRecentOpenFilesLabel' ParentColor = False end @@ -27,7 +27,7 @@ object FilesOptionsFrame: TFilesOptionsFrame Left = 287 Height = 15 Top = 2 - Width = 155 + Width = 146 BorderSpacing.Left = 3 Caption = 'MaxRecentProjectFilesLabel' ParentColor = False @@ -38,22 +38,24 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom AnchorSideRight.Side = asrBottom Left = 2 - Height = 24 - Top = 50 - Width = 212 + Height = 19 + Top = 48 + Width = 195 BorderSpacing.Top = 6 Caption = 'OpenLastProjectAtStartCheckBox' + OnChange = OpenLastProjectAtStartCheckBoxChange TabOrder = 0 end object ShowCompileDialogCheckBox: TCheckBox AnchorSideLeft.Control = Owner - AnchorSideTop.Control = OpenLastProjectAtStartCheckBox + AnchorSideTop.Control = OpenPackagesAtStartCheckBox AnchorSideTop.Side = asrBottom AnchorSideRight.Side = asrBottom Left = 2 - Height = 24 - Top = 74 - Width = 188 + Height = 19 + Top = 88 + Width = 180 + BorderSpacing.Top = 2 Caption = 'ShowCompileDialogCheckBox' OnChange = ShowCompileDialogCheckBoxChange TabOrder = 1 @@ -64,8 +66,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom Left = 2 Height = 15 - Top = 132 - Width = 87 + Top = 136 + Width = 82 BorderSpacing.Top = 10 Caption = 'LazarusDirLabel' ParentColor = False @@ -78,8 +80,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideBottom.Control = LazarusDirComboBox AnchorSideBottom.Side = asrBottom Left = 542 - Height = 27 - Top = 147 + Height = 23 + Top = 151 Width = 25 Anchors = [akTop, akRight, akBottom] Caption = '...' @@ -92,11 +94,11 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom AnchorSideRight.Control = LazarusDirButton Left = 2 - Height = 27 - Top = 147 + Height = 23 + Top = 151 Width = 540 Anchors = [akTop, akLeft, akRight] - ItemHeight = 0 + ItemHeight = 15 TabOrder = 3 Text = 'LazarusDirComboBox' end @@ -106,11 +108,11 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom AnchorSideRight.Control = CompilerPathButton Left = 2 - Height = 27 + Height = 23 Top = 195 Width = 540 Anchors = [akTop, akLeft, akRight] - ItemHeight = 0 + ItemHeight = 15 TabOrder = 4 Text = 'CompilerPathComboBox' end @@ -121,7 +123,7 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideBottom.Control = CompilerPathComboBox AnchorSideBottom.Side = asrBottom Left = 542 - Height = 27 + Height = 23 Top = 195 Width = 25 Anchors = [akTop, akRight, akBottom] @@ -136,7 +138,7 @@ object FilesOptionsFrame: TFilesOptionsFrame Left = 2 Height = 15 Top = 180 - Width = 103 + Width = 101 BorderSpacing.Top = 6 Caption = 'CompilerPathLabel' ParentColor = False @@ -147,11 +149,11 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom AnchorSideRight.Control = FPCSourceDirButton Left = 2 - Height = 27 - Top = 243 + Height = 23 + Top = 239 Width = 540 Anchors = [akTop, akLeft, akRight] - ItemHeight = 0 + ItemHeight = 15 TabOrder = 6 Text = 'FPCSourceDirComboBox' end @@ -162,8 +164,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideBottom.Control = FPCSourceDirComboBox AnchorSideBottom.Side = asrBottom Left = 542 - Height = 27 - Top = 243 + Height = 23 + Top = 239 Width = 25 Anchors = [akTop, akRight, akBottom] Caption = '...' @@ -176,8 +178,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom Left = 2 Height = 15 - Top = 228 - Width = 104 + Top = 224 + Width = 100 BorderSpacing.Top = 6 Caption = 'FPCSourceDirLabel' ParentColor = False @@ -188,8 +190,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom Left = 2 Height = 15 - Top = 276 - Width = 83 + Top = 268 + Width = 81 BorderSpacing.Top = 6 Caption = 'MakePathLabel' ParentColor = False @@ -200,8 +202,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom Left = 2 Height = 15 - Top = 324 - Width = 97 + Top = 312 + Width = 91 BorderSpacing.Top = 6 Caption = 'TestBuildDirLabel' ParentColor = False @@ -212,11 +214,11 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom AnchorSideRight.Control = MakePathButton Left = 2 - Height = 27 - Top = 291 + Height = 23 + Top = 283 Width = 540 Anchors = [akTop, akLeft, akRight] - ItemHeight = 0 + ItemHeight = 15 TabOrder = 8 Text = 'MakePathComboBox' end @@ -227,8 +229,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideBottom.Control = MakePathComboBox AnchorSideBottom.Side = asrBottom Left = 542 - Height = 27 - Top = 291 + Height = 23 + Top = 283 Width = 25 Anchors = [akTop, akRight, akBottom] Caption = '...' @@ -241,11 +243,11 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom AnchorSideRight.Control = TestBuildDirButton Left = 2 - Height = 27 - Top = 339 + Height = 23 + Top = 327 Width = 540 Anchors = [akTop, akLeft, akRight] - ItemHeight = 0 + ItemHeight = 15 TabOrder = 10 Text = 'TestBuildDirComboBox' end @@ -256,8 +258,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideBottom.Control = TestBuildDirComboBox AnchorSideBottom.Side = asrBottom Left = 542 - Height = 27 - Top = 339 + Height = 23 + Top = 327 Width = 25 Anchors = [akTop, akRight, akBottom] Caption = '...' @@ -270,9 +272,9 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom AnchorSideRight.Side = asrBottom Left = 32 - Height = 24 - Top = 98 - Width = 215 + Height = 19 + Top = 107 + Width = 206 BorderSpacing.Left = 30 Caption = 'AutoCloseCompileDialogCheckBox' TabOrder = 12 @@ -283,8 +285,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom Left = 2 Height = 15 - Top = 372 - Width = 158 + Top = 356 + Width = 153 Alignment = taRightJustify BorderSpacing.Top = 6 Caption = 'CompilerTranslationFileLabel' @@ -299,8 +301,8 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideBottom.Control = CompilerTranslationFileComboBox AnchorSideBottom.Side = asrBottom Left = 542 - Height = 27 - Top = 387 + Height = 23 + Top = 371 Width = 25 Anchors = [akTop, akRight, akBottom] Caption = '...' @@ -315,11 +317,11 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideTop.Side = asrBottom AnchorSideRight.Control = CompilerTranslationFileButton Left = 2 - Height = 27 - Top = 387 + Height = 23 + Top = 371 Width = 540 Anchors = [akTop, akLeft, akRight] - ItemHeight = 0 + ItemHeight = 15 ParentShowHint = False ShowHint = True TabOrder = 14 @@ -341,7 +343,7 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideRight.Control = lblCenter AnchorSideRight.Side = asrBottom Left = 2 - Height = 25 + Height = 23 Top = 19 Width = 278 Anchors = [akTop, akLeft, akRight] @@ -356,7 +358,7 @@ object FilesOptionsFrame: TFilesOptionsFrame AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom Left = 289 - Height = 25 + Height = 23 Top = 19 Width = 278 Anchors = [akTop, akLeft, akRight] @@ -364,4 +366,17 @@ object FilesOptionsFrame: TFilesOptionsFrame BorderSpacing.Around = 2 TabOrder = 16 end + object OpenPackagesAtStartCheckBox: TCheckBox + AnchorSideLeft.Control = OpenLastProjectAtStartCheckBox + AnchorSideTop.Control = OpenLastProjectAtStartCheckBox + AnchorSideTop.Side = asrBottom + AnchorSideRight.Side = asrBottom + Left = 32 + Height = 19 + Top = 67 + Width = 186 + BorderSpacing.Left = 30 + Caption = 'OpenPackagesAtStartCheckBox' + TabOrder = 17 + end end diff --git a/ide/frames/files_options.pas b/ide/frames/files_options.pas index 14485f722a..5e57bca8b9 100644 --- a/ide/frames/files_options.pas +++ b/ide/frames/files_options.pas @@ -61,6 +61,7 @@ type MaxRecentProjectFilesSpin: TSpinEdit; MaxRecentProjectFilesLabel: TLabel; OpenLastProjectAtStartCheckBox: TCheckBox; + OpenPackagesAtStartCheckBox: TCheckBox; ShowCompileDialogCheckBox: TCheckBox; TestBuildDirButton:TButton; TestBuildDirComboBox:TComboBox; @@ -68,6 +69,7 @@ type procedure CompilerTranslationFileButtonClick(Sender:TObject); procedure FilesButtonClick(Sender: TObject); procedure DirectoriesButtonClick(Sender: TObject); + procedure OpenLastProjectAtStartCheckBoxChange(Sender: TObject); procedure ShowCompileDialogCheckBoxChange(Sender: TObject); private FOldLazarusDir: string; @@ -220,6 +222,7 @@ begin MaxRecentOpenFilesLabel.Caption:=dlgMaxRecentFiles; MaxRecentProjectFilesLabel.Caption:=dlgMaxRecentProjs; OpenLastProjectAtStartCheckBox.Caption:=dlgQOpenLastPrj; + OpenPackagesAtStartCheckBox.Caption:=dlgQOpenPackages; ShowCompileDialogCheckBox.Visible:=false; AutoCloseCompileDialogCheckBox.Visible:=false; LazarusDirLabel.Caption:=dlgLazarusDir; @@ -272,6 +275,12 @@ begin Result := dlgEnvFiles; end; +procedure TFilesOptionsFrame.OpenLastProjectAtStartCheckBoxChange( + Sender: TObject); +begin + OpenPackagesAtStartCheckBox.Enabled := OpenLastProjectAtStartCheckBox.Checked; +end; + function TFilesOptionsFrame.Check: Boolean; begin Result := False; @@ -360,6 +369,7 @@ begin // open last project at start OpenLastProjectAtStartCheckBox.Checked:=OpenLastProjectAtStart; + OpenPackagesAtStartCheckBox.Checked:=OpenPackagesAtStart; // compile dialog fOldShowCompileDialog:=ShowCompileDialog; @@ -391,6 +401,7 @@ begin MaxRecentOpenFiles := MaxRecentOpenFilesSpin.Value; MaxRecentProjectFiles := MaxRecentProjectFilesSpin.Value; OpenLastProjectAtStart:=OpenLastProjectAtStartCheckBox.Checked; + OpenPackagesAtStart:=OpenPackagesAtStartCheckBox.Checked; ShowCompileDialog := ShowCompileDialogCheckBox.Checked; AutoCloseCompileDialog := AutoCloseCompileDialogCheckBox.Checked; end; diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index d6818347db..7e7b4dbc7c 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -1339,6 +1339,7 @@ resourcestring dlgMaxRecentFiles = 'Max recent files'; dlgMaxRecentProjs = 'Max recent project files'; dlgQOpenLastPrj = 'Open last project at start'; + dlgQOpenPackages = 'Open packages'; dlgLazarusDir = 'Lazarus directory (default for all projects)'; dlgFpcExecutable = 'Compiler executable (e.g. %s)'; dlgFpcSrcPath = 'FPC source directory'; @@ -3989,6 +3990,7 @@ resourcestring +'%s%s' +'%slazbuild is non interactive, aborting now.'; lisPkgMangSavePackageLpk = 'Save Package %s (*.lpk)'; + lisPkgMangSaveAsAlreadyOpenedPackage = 'The package %s is already open in the IDE.'+sLineBreak+'You cannot save a package with the same name.'; lisPkgMangInvalidPackageFileExtension = 'Invalid package file extension'; lisPkgMangPackagesMustHaveTheExtensionLpk = 'Packages must have the ' +'extension .lpk'; diff --git a/ide/main.pp b/ide/main.pp index 03f38e433c..9bc15cf0f0 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -171,8 +171,6 @@ type TMainIDE = class(TMainIDEBase) private - IDEIsClosing: Boolean; - // event handlers procedure MainIDEFormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction); procedure MainIDEFormCloseQuery(Sender: TObject; var CanClose: boolean); @@ -1966,7 +1964,7 @@ procedure TMainIDE.MainIDEFormCloseQuery(Sender: TObject; var CanClose: boolean) begin CanClose := True; if IDEIsClosing then Exit; - IDEIsClosing := True; + FIDEIsClosing := True; CanClose := False; SourceFileMgr.CheckingFilesOnDisk := True; try @@ -1988,7 +1986,7 @@ begin CanClose:=(DoCloseProject <> mrAbort); finally - IDEIsClosing := CanClose; + FIDEIsClosing := CanClose; SourceFileMgr.CheckingFilesOnDisk:=false; if not CanClose then DoCheckFilesOnDisk(false); @@ -2175,6 +2173,7 @@ var i: Integer; OpenFlags: TOpenFlags; AFilename: String; + PkgOpenFlags: TPkgOpenFlags; begin {$IFDEF IDE_DEBUG} debugln('TMainIDE.SetupStartProject A ***********'); @@ -2220,7 +2219,27 @@ begin // protocol that the IDE was able to open the project without crashing IDEProtocolOpts.LastProjectLoadingCrashed := false; IDEProtocolOpts.Save; - if not ProjectLoaded then begin + if ProjectLoaded then + begin + if EnvironmentOptions.OpenPackagesAtStart then + begin + PkgOpenFlags:=[pofAddToRecent]; + for I := 0 to EnvironmentOptions.LastOpenPackages.Count-1 do + begin + AFilename:=EnvironmentOptions.LastOpenPackages[I]; + if AFilename='' then + continue; + if i end @@ -181,7 +180,7 @@ object PackageEditorForm: TPackageEditorForm Cursor = crVSplit Left = 0 Height = 5 - Top = 310 + Top = 309 Width = 464 Align = alBottom ResizeAnchor = akBottom @@ -314,11 +313,12 @@ object PackageEditorForm: TPackageEditorForm end object ItemsTreeView: TTreeView Left = 0 - Height = 233 + Height = 232 Top = 77 Width = 464 Align = alClient BorderSpacing.Top = 1 + DefaultItemHeight = 18 DragMode = dmAutomatic MultiSelect = True PopupMenu = ItemsPopupMenu diff --git a/packager/packageeditor.pas b/packager/packageeditor.pas index b25874567a..4af4a9d3c7 100644 --- a/packager/packageeditor.pas +++ b/packager/packageeditor.pas @@ -47,7 +47,7 @@ uses IDEDialogs, IDEProcs, LazarusIDEStrConsts, IDEDefs, CompilerOptions, ComponentReg, UnitResources, EnvironmentOpts, DialogProcs, InputHistory, PackageDefs, AddToPackageDlg, PkgVirtualUnitEditor, MissingPkgFilesDlg, - PackageSystem, CleanPkgDeps; + PackageSystem, CleanPkgDeps, MainBase; const PackageEditorMenuRootName = 'PackageEditor'; @@ -435,7 +435,9 @@ type procedure Clear; procedure Remove(Editor: TPackageEditorForm); function IndexOfPackage(Pkg: TLazPackage): integer; - function FindEditor(Pkg: TLazPackage): TPackageEditorForm; + function IndexOfPackage(const PkgName: string): integer; + function FindEditor(Pkg: TLazPackage): TPackageEditorForm; overload; + function FindEditor(const PkgName: string): TPackageEditorForm; overload; function OpenEditor(Pkg: TLazPackage): TPackageEditorForm; function OpenFile(Sender: TObject; const Filename: string): TModalResult; function OpenPkgFile(Sender: TObject; PkgFile: TPkgFile): TModalResult; @@ -1182,20 +1184,27 @@ var MsgResult: Integer; begin //debugln(['TPackageEditorForm.PackageEditorFormCloseQuery ',Caption]); - if (LazPackage<>nil) and (not (lpfDestroying in LazPackage.Flags)) - and (not LazPackage.ReadOnly) and LazPackage.Modified then begin - - MsgResult:=MessageDlg(lisPkgMangSavePackage, - Format(lisPckEditPackageHasChangedSavePackage, [LazPackage.IDAsString, LineEnding]), - mtConfirmation,[mbYes,mbNo,mbAbort],0); - case MsgResult of - mrYes: - MsgResult:=PackageEditors.SavePackage(LazPackage,false); - mrNo: - LazPackage.UserIgnoreChangeStamp:=LazPackage.ChangeStamp; + if (LazPackage<>nil) and (not (lpfDestroying in LazPackage.Flags)) then + begin + if (not LazPackage.ReadOnly) and LazPackage.Modified then + begin + MsgResult:=MessageDlg(lisPkgMangSavePackage, + Format(lisPckEditPackageHasChangedSavePackage, [LazPackage.IDAsString, LineEnding]), + mtConfirmation,[mbYes,mbNo,mbAbort],0); + case MsgResult of + mrYes: + MsgResult:=PackageEditors.SavePackage(LazPackage,false); + mrNo: + LazPackage.UserIgnoreChangeStamp:=LazPackage.ChangeStamp; + end; + if MsgResult=mrAbort then CanClose:=false; + LazPackage.Modified:=false; // clear modified flag, so that it will be closed + end; + if CanClose and not MainIDE.IDEIsClosing then + begin + EnvironmentOptions.LastOpenPackages.Remove(LazPackage.Filename); + MainIDE.SaveEnvironment; end; - if MsgResult=mrAbort then CanClose:=false; - LazPackage.Modified:=false; // clear modified flag, so that it will be closed end; //debugln(['TPackageEditorForm.PackageEditorFormCloseQuery CanClose=',CanClose,' ',Caption]); if CanClose then @@ -1845,13 +1854,23 @@ end; procedure TPackageEditorForm.SetLazPackage(const AValue: TLazPackage); begin - if FLazPackage=AValue then exit; - if FLazPackage<>nil then FLazPackage.Editor:=nil; + if (FLazPackage=AValue) and + not(Assigned(AValue) and (Name<>PackageEditorWindowPrefix+AValue.Name))//force editor name change when package name changed! + then + exit; + if FLazPackage<>nil then + begin + FLazPackage.Editor:=nil; + if EnvironmentOptions.LastOpenPackages.Remove(FLazPackage.Filename) then + MainIDE.SaveEnvironment; + end; FLazPackage:=AValue; if FLazPackage=nil then begin Name:=Name+'___off___'; exit; end; + EnvironmentOptions.LastOpenPackages.Add(FLazPackage.Filename); + MainIDE.SaveEnvironment; Name:=PackageEditorWindowPrefix+LazPackage.Name; FLazPackage.Editor:=Self; // update components @@ -3304,6 +3323,19 @@ begin Result:=TPackageEditorForm(FItems[Index]); end; +function TPackageEditors.IndexOfPackage(const PkgName: string): integer; +var + I: Integer; +begin + for I := 0 to Count-1 do + if Assigned(Editors[I].LazPackage) and + SameText(ExtractFileNameOnly(Editors[I].LazPackage.Filename), PkgName) + then + Exit(I); + + Result := -1; +end; + constructor TPackageEditors.Create; begin FItems:=TFPList.Create; @@ -3395,6 +3427,17 @@ begin if Assigned(OnFreeEditor) then OnFreeEditor(Pkg); end; +function TPackageEditors.FindEditor(const PkgName: string): TPackageEditorForm; +var + i: Integer; +begin + i:=IndexOfPackage(PkgName); + if i>=0 then + Result:=Editors[i] + else + Result:=nil; +end; + function TPackageEditors.CreateNewFile(Sender: TObject; Params: TAddToPkgResult): TModalResult; begin diff --git a/packager/pkgmanager.pas b/packager/pkgmanager.pas index ab440ea314..02616d201e 100644 --- a/packager/pkgmanager.pas +++ b/packager/pkgmanager.pas @@ -1155,6 +1155,15 @@ begin NewMainUnitFileName:=ChangeFileExt(NewFileName,'.pas') else NewMainUnitFileName:=''; + + if PackageEditors.FindEditor(NewPkgName) <> nil then + begin + Result:=IDEMessageDialog(lisPkgMangInvalidPackageName, + Format(lisPkgMangSaveAsAlreadyOpenedPackage, [NewPkgName]), + mtInformation,[mbRetry,mbAbort]); + if Result=mrAbort then exit; + continue; // try again + end; // check file extension if ExtractFileExt(NewFilename)='' then begin @@ -1291,6 +1300,8 @@ begin // set filename APackage.Filename:=NewFilename; + if Assigned(APackage.Editor) then + APackage.Editor.LazPackage := APackage;//force package editor name change! // rename package PackageGraph.ChangePackageID(APackage,NewPkgName,APackage.Version, @@ -1298,6 +1309,11 @@ begin SaveAutoInstallDependencies; RenamePackageInProject; + //update LastOpenPackages list + EnvironmentOptions.LastOpenPackages.Remove(OldPkgFilename); + EnvironmentOptions.LastOpenPackages.Add(NewFileName); + MainIDE.SaveEnvironment; + // clean up old package file to reduce ambiguousities if FileExistsUTF8(OldPkgFilename) and (CompareFilenames(OldPkgFilename,NewFilename)<>0) then begin