mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 16:59:49 +02:00
IDE: Simplify function ShowSaveProjectAsDialog. UseMainSourceFile parameter and sfSaveMainSourceAs flag are not needed.
This commit is contained in:
parent
ecf49109b1
commit
fa224fda62
@ -129,7 +129,6 @@ type
|
|||||||
sfSaveNonProjectFiles,
|
sfSaveNonProjectFiles,
|
||||||
sfDoNotSaveVirtualFiles,
|
sfDoNotSaveVirtualFiles,
|
||||||
sfCanAbort, // show 'Cancel all' button in error messages
|
sfCanAbort, // show 'Cancel all' button in error messages
|
||||||
sfSaveMainSourceAs, // on sfSaveAs use .lpr file instead of .lpi file
|
|
||||||
sfQuietUnitCheck // don't ask questions when adding unit dependency.
|
sfQuietUnitCheck // don't ask questions when adding unit dependency.
|
||||||
);
|
);
|
||||||
TSaveFlags = set of TSaveFlag;
|
TSaveFlags = set of TSaveFlag;
|
||||||
|
@ -298,7 +298,7 @@ function SaveEditorChangesToCodeCache(AEditor: TSourceEditorInterface): boolean;
|
|||||||
function LoadIDECodeBuffer(var ACodeBuffer: TCodeBuffer;
|
function LoadIDECodeBuffer(var ACodeBuffer: TCodeBuffer;
|
||||||
const AFilename: string; Flags: TLoadBufferFlags; ShowAbort: boolean): TModalResult;
|
const AFilename: string; Flags: TLoadBufferFlags; ShowAbort: boolean): TModalResult;
|
||||||
//save project
|
//save project
|
||||||
function ShowSaveProjectAsDialog(UseMainSourceFile: boolean): TModalResult;
|
function ShowSaveProjectAsDialog: TModalResult;
|
||||||
function SaveProjectInfo(var Flags: TSaveFlags): TModalResult;
|
function SaveProjectInfo(var Flags: TSaveFlags): TModalResult;
|
||||||
procedure GetMainUnit(out MainUnitInfo: TUnitInfo; out MainUnitSrcEdit: TSourceEditor);
|
procedure GetMainUnit(out MainUnitInfo: TUnitInfo; out MainUnitSrcEdit: TSourceEditor);
|
||||||
procedure SaveSrcEditorProjectSpecificSettings(AnEditorInfo: TUnitEditorInfo);
|
procedure SaveSrcEditorProjectSpecificSettings(AnEditorInfo: TUnitEditorInfo);
|
||||||
@ -2413,7 +2413,6 @@ var
|
|||||||
OldUnitName, OldFilename: String;
|
OldUnitName, OldFilename: String;
|
||||||
NewUnitName, NewFilename: String;
|
NewUnitName, NewFilename: String;
|
||||||
WasVirtual, WasPascalSource, CanAbort, Confirm: Boolean;
|
WasVirtual, WasPascalSource, CanAbort, Confirm: Boolean;
|
||||||
SaveProjectFlags: TSaveFlags;
|
|
||||||
EMacro: TEditorMacro;
|
EMacro: TEditorMacro;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
@ -2434,14 +2433,9 @@ begin
|
|||||||
WasPascalSource:=FilenameIsPascalSource(AnUnitInfo.Filename);
|
WasPascalSource:=FilenameIsPascalSource(AnUnitInfo.Filename);
|
||||||
|
|
||||||
// if this file is part of a virtual project then save the project first
|
// if this file is part of a virtual project then save the project first
|
||||||
if (not (sfProjectSaving in Flags)) and Project1.IsVirtual and AnUnitInfo.IsPartOfProject then
|
if (not (sfProjectSaving in Flags)) and Project1.IsVirtual and AnUnitInfo.IsPartOfProject
|
||||||
begin
|
then
|
||||||
SaveProjectFlags:=Flags*[sfSaveToTestDir];
|
exit(SaveProject(Flags*[sfSaveToTestDir]));
|
||||||
if AnUnitInfo=Project1.MainUnitInfo then
|
|
||||||
Include(SaveProjectFlags,sfSaveMainSourceAs);
|
|
||||||
Result:=SaveProject(SaveProjectFlags);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// update codetools cache and collect Modified flags
|
// update codetools cache and collect Modified flags
|
||||||
if not (sfProjectSaving in Flags) then
|
if not (sfProjectSaving in Flags) then
|
||||||
@ -2478,10 +2472,8 @@ begin
|
|||||||
// special cases (rare functions don't need front ends).
|
// special cases (rare functions don't need front ends).
|
||||||
MainUnitInfo:=AnUnitInfo.Project.MainUnitInfo;
|
MainUnitInfo:=AnUnitInfo.Project.MainUnitInfo;
|
||||||
if (sfSaveAs in Flags) and (not (sfProjectSaving in Flags)) and (AnUnitInfo=MainUnitInfo)
|
if (sfSaveAs in Flags) and (not (sfProjectSaving in Flags)) and (AnUnitInfo=MainUnitInfo)
|
||||||
then begin
|
then
|
||||||
Result:=SaveProject([sfSaveAs,sfSaveMainSourceAs]);
|
exit(SaveProject([sfSaveAs]));
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// if nothing modified then a simple Save can be skipped
|
// if nothing modified then a simple Save can be skipped
|
||||||
//debugln(['SaveEditorFile A ',AnUnitInfo.Filename,' ',AnUnitInfo.NeedsSaveToDisk]);
|
//debugln(['SaveEditorFile A ',AnUnitInfo.Filename,' ',AnUnitInfo.NeedsSaveToDisk]);
|
||||||
@ -7468,12 +7460,12 @@ begin
|
|||||||
Include(Flags,sfSaveAs);
|
Include(Flags,sfSaveAs);
|
||||||
if ([sfSaveAs,sfSaveToTestDir]*Flags=[sfSaveAs]) then begin
|
if ([sfSaveAs,sfSaveToTestDir]*Flags=[sfSaveAs]) then begin
|
||||||
// let user choose a filename
|
// let user choose a filename
|
||||||
Result := ShowSaveProjectAsDialog(sfSaveMainSourceAs in Flags);
|
Result := ShowSaveProjectAsDialog;
|
||||||
if Result<>mrOk then begin
|
if Result<>mrOk then begin
|
||||||
debugln(['Info: (lazarus) [SaveProjectInfo] ShowSaveProjectAsDialog failed']);
|
debugln(['Info: (lazarus) [SaveProjectInfo] ShowSaveProjectAsDialog failed']);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Flags:=Flags-[sfSaveAs,sfSaveMainSourceAs];
|
Exclude(Flags,sfSaveAs);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// update HasResources information
|
// update HasResources information
|
||||||
@ -7586,7 +7578,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ShowSaveProjectAsDialog(UseMainSourceFile: boolean): TModalResult;
|
function ShowSaveProjectAsDialog: TModalResult;
|
||||||
var
|
var
|
||||||
MainUnitSrcEdit: TSourceEditor;
|
MainUnitSrcEdit: TSourceEditor;
|
||||||
MainUnitInfo: TUnitInfo;
|
MainUnitInfo: TUnitInfo;
|
||||||
@ -7598,15 +7590,9 @@ var
|
|||||||
AText, ACaption, Ext: string;
|
AText, ACaption, Ext: string;
|
||||||
OldSourceCode, OldProjectDir, prDir: string;
|
OldSourceCode, OldProjectDir, prDir: string;
|
||||||
begin
|
begin
|
||||||
//DebugLn(['ShowSaveProjectAsDialog: UseMainSourceFile=', UseMainSourceFile]);
|
|
||||||
Project1.BeginUpdate(false);
|
Project1.BeginUpdate(false);
|
||||||
try
|
try
|
||||||
OldProjectDir := Project1.Directory;
|
OldProjectDir := Project1.Directory;
|
||||||
if Project1.IsVirtual then
|
|
||||||
UseMainSourceFile := False;
|
|
||||||
// ToDo: If this assertion never triggers, the code can be simplified a lot.
|
|
||||||
Assert(not UseMainSourceFile, 'ShowSaveProjectAsDialog: UseMainSourceFile is still on.');
|
|
||||||
|
|
||||||
// build a nice project info filename suggestion
|
// build a nice project info filename suggestion
|
||||||
if Assigned(Project1.MainUnitInfo) then
|
if Assigned(Project1.MainUnitInfo) then
|
||||||
AFileName := Project1.MainUnitInfo.ReadUnitNameFromSource(false);
|
AFileName := Project1.MainUnitInfo.ReadUnitNameFromSource(false);
|
||||||
@ -7616,18 +7602,11 @@ begin
|
|||||||
AFilename := Trim(Project1.GetTitle);
|
AFilename := Trim(Project1.GetTitle);
|
||||||
if AFilename = '' then
|
if AFilename = '' then
|
||||||
AFilename := 'Project1';
|
AFilename := 'Project1';
|
||||||
// Figure out a filename extension
|
// Filename extension
|
||||||
Ext := ExtractFileExt(AFilename);
|
Assert((ExtractFileExt(AFilename)='') or FilenameIsPascalSource(AFilename),
|
||||||
if UseMainSourceFile then
|
'ShowSaveProjectAsDialog: '+AFilename+' is not Pascal source.');
|
||||||
begin
|
Ext := '.lpi';
|
||||||
if (Ext = '') or (not FilenameIsPascalSource(AFilename)) then
|
AFilename := ChangeFileExt(AFilename, Ext);
|
||||||
AFilename := ChangeFileExt(AFilename, '.pas');
|
|
||||||
end else begin
|
|
||||||
if (Ext = '') or FilenameIsPascalSource(AFilename) then
|
|
||||||
AFilename := ChangeFileExt(AFilename, '.lpi');
|
|
||||||
end;
|
|
||||||
Ext := ExtractFileExt(AFilename);
|
|
||||||
//DebugLn(['ShowSaveProjectAsDialog: 1. AFilename=',AFilename]);
|
|
||||||
|
|
||||||
SaveDialog := IDESaveDialogClass.Create(nil);
|
SaveDialog := IDESaveDialogClass.Create(nil);
|
||||||
try
|
try
|
||||||
@ -7652,7 +7631,6 @@ begin
|
|||||||
if not SaveDialog.Execute then
|
if not SaveDialog.Execute then
|
||||||
exit; // user cancels
|
exit; // user cancels
|
||||||
AFilename := ExpandFileNameUTF8(SaveDialog.FileName);
|
AFilename := ExpandFileNameUTF8(SaveDialog.FileName);
|
||||||
//DebugLn(['ShowSaveProjectAsDialog: 2. AFilename=',AFilename]);
|
|
||||||
|
|
||||||
// check program name
|
// check program name
|
||||||
NewProgramName:=ExtractFileNameOnly(AFilename);
|
NewProgramName:=ExtractFileNameOnly(AFilename);
|
||||||
@ -7677,11 +7655,7 @@ begin
|
|||||||
// check mainunit filename
|
// check mainunit filename
|
||||||
Ext := ExtractFileExt(Project1.MainUnitInfo.Filename);
|
Ext := ExtractFileExt(Project1.MainUnitInfo.Filename);
|
||||||
Assert(Ext<>'', 'ShowSaveProjectAsDialog: Ext is empty');
|
Assert(Ext<>'', 'ShowSaveProjectAsDialog: Ext is empty');
|
||||||
if UseMainSourceFile then
|
NewProgramFN := NewPath + LCProgramName + Ext;
|
||||||
NewProgramFN := ExtractFileName(AFilename)
|
|
||||||
else
|
|
||||||
NewProgramFN := LCProgramName + Ext;
|
|
||||||
NewProgramFN := NewPath + NewProgramFN;
|
|
||||||
if CompareFilenames(NewLPIFilename, NewProgramFN) = 0 then
|
if CompareFilenames(NewLPIFilename, NewProgramFN) = 0 then
|
||||||
begin
|
begin
|
||||||
ACaption:=lisChooseADifferentName;
|
ACaption:=lisChooseADifferentName;
|
||||||
|
Loading…
Reference in New Issue
Block a user