mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 20:39:14 +02:00
IDE: Refactor, join and reuse common code in methods CloseAll and InvertedFileClose. Also fixes a bug.
git-svn-id: trunk@45462 -
This commit is contained in:
parent
e4079b2d24
commit
8197d8ec37
@ -720,7 +720,7 @@ resourcestring
|
|||||||
lisFileHasChangedSave = 'File "%s" has changed. Save?';
|
lisFileHasChangedSave = 'File "%s" has changed. Save?';
|
||||||
lisUnitHasChangedSave = 'Unit "%s" has changed. Save?';
|
lisUnitHasChangedSave = 'Unit "%s" has changed. Save?';
|
||||||
lisSourceOfPageHasChangedSave = 'Source of page "%s" has changed. Save?';
|
lisSourceOfPageHasChangedSave = 'Source of page "%s" has changed. Save?';
|
||||||
lisSourceOfPageHasChangedSaveExtended = 'Sources of more than one page have changed. Save page "%s"? (%d more)';
|
lisSourceOfPageHasChangedSaveEx = 'Sources of pages have changed. Save page "%s"? (%d more)';
|
||||||
lisSourceModified = 'Source modified';
|
lisSourceModified = 'Source modified';
|
||||||
lisOpenProject = 'Open Project?';
|
lisOpenProject = 'Open Project?';
|
||||||
lisOpenTheProject = 'Open the project %s?';
|
lisOpenTheProject = 'Open the project %s?';
|
||||||
|
@ -65,6 +65,7 @@ type
|
|||||||
{$IFDEF EnableOldExtTools}
|
{$IFDEF EnableOldExtTools}
|
||||||
function ExternalTools: TExternalToolList;
|
function ExternalTools: TExternalToolList;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
procedure AskToSaveEditors(EditorList: TList);
|
||||||
function AddPathToBuildModes(aPath, CurDirectory: string; IsIncludeFile: Boolean): Boolean;
|
function AddPathToBuildModes(aPath, CurDirectory: string; IsIncludeFile: Boolean): Boolean;
|
||||||
function CheckMainSrcLCLInterfaces(Silent: boolean): TModalResult;
|
function CheckMainSrcLCLInterfaces(Silent: boolean): TModalResult;
|
||||||
function FileExistsInIDE(const Filename: string;
|
function FileExistsInIDE(const Filename: string;
|
||||||
@ -133,6 +134,7 @@ type
|
|||||||
function CloseProject: TModalResult;
|
function CloseProject: TModalResult;
|
||||||
procedure OpenProject(aMenuItem: TIDEMenuItem);
|
procedure OpenProject(aMenuItem: TIDEMenuItem);
|
||||||
procedure CloseAll;
|
procedure CloseAll;
|
||||||
|
procedure InvertedFileClose(PageIndex: LongInt; SrcNoteBook: TSourceNotebook);
|
||||||
// project inspector
|
// project inspector
|
||||||
// Checks if the UnitDirectory is part of the Unit Search Paths, if not,
|
// Checks if the UnitDirectory is part of the Unit Search Paths, if not,
|
||||||
// ask the user if he wants to extend dependencies or the Unit Search Paths.
|
// ask the user if he wants to extend dependencies or the Unit Search Paths.
|
||||||
@ -206,7 +208,6 @@ type
|
|||||||
function UnitComponentIsUsed(AnUnitInfo: TUnitInfo;
|
function UnitComponentIsUsed(AnUnitInfo: TUnitInfo;
|
||||||
CheckHasDesigner: boolean): boolean;
|
CheckHasDesigner: boolean): boolean;
|
||||||
function RemoveFilesFromProject(AProject: TProject; UnitInfos: TFPList): TModalResult;
|
function RemoveFilesFromProject(AProject: TProject; UnitInfos: TFPList): TModalResult;
|
||||||
procedure InvertedFileClose(PageIndex: LongInt; SrcNoteBook: TSourceNotebook);
|
|
||||||
|
|
||||||
// methods for open project, create project from source
|
// methods for open project, create project from source
|
||||||
function CompleteLoadingProjectInfo: TModalResult;
|
function CompleteLoadingProjectInfo: TModalResult;
|
||||||
@ -1264,8 +1265,7 @@ begin
|
|||||||
AText:=Format(lisSourceOfPageHasChangedSave, [TSourceEditor(AEditor).PageName]);
|
AText:=Format(lisSourceOfPageHasChangedSave, [TSourceEditor(AEditor).PageName]);
|
||||||
ACaption:=lisSourceModified;
|
ACaption:=lisSourceModified;
|
||||||
Result:=IDEQuestionDialog(ACaption, AText,
|
Result:=IDEQuestionDialog(ACaption, AText,
|
||||||
mtConfirmation, [mrYes, lisMenuSave, mrNo, lisDiscardChanges, mrAbort
|
mtConfirmation, [mrYes, lisMenuSave, mrNo, lisDiscardChanges, mrAbort]);
|
||||||
]);
|
|
||||||
end else
|
end else
|
||||||
Result:=mrYes;
|
Result:=mrYes;
|
||||||
if Result=mrYes then begin
|
if Result=mrYes then begin
|
||||||
@ -3429,56 +3429,67 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazSourceFileManager.CloseAll;
|
procedure TLazSourceFileManager.AskToSaveEditors(EditorList: TList);
|
||||||
|
// Ask from user about saving the changed SourceEditors in EditorList.
|
||||||
var
|
var
|
||||||
i, NeedSave, Idx: Integer;
|
|
||||||
r: TModalResult;
|
|
||||||
Ed: TSourceEditor;
|
Ed: TSourceEditor;
|
||||||
|
r: TModalResult;
|
||||||
|
i, Remain: Integer;
|
||||||
begin
|
begin
|
||||||
// Close editor files
|
if EditorList.Count = 1 then begin
|
||||||
NeedSave := 0;
|
Ed := TSourceEditor(EditorList[0]);
|
||||||
for i := 0 to SourceEditorManager.UniqueSourceEditorCount - 1 do begin
|
|
||||||
if CheckEditorNeedsSave(SourceEditorManager.UniqueSourceEditors[i], False) then begin
|
|
||||||
inc(NeedSave);
|
|
||||||
if NeedSave = 1 then Idx := i;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
if NeedSave = 1 then begin
|
|
||||||
Ed := TSourceEditor(SourceEditorManager.UniqueSourceEditors[Idx]);
|
|
||||||
r := IDEQuestionDialog(lisSourceModified,
|
r := IDEQuestionDialog(lisSourceModified,
|
||||||
Format(lisSourceOfPageHasChangedSave, [Ed.PageName]),
|
Format(lisSourceOfPageHasChangedSave, [Ed.PageName]),
|
||||||
mtConfirmation,
|
mtConfirmation, [mrYes,lisMenuSave, mrNo,lisDiscardChanges, mrAbort]);
|
||||||
[mrYes, lisMenuSave, mrNo, lisDiscardChanges, mrAbort]);
|
|
||||||
case r of
|
case r of
|
||||||
mrYes: SaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
|
mrYes: SaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
|
||||||
mrNo: ; // don't save
|
mrNo: ; // don't save
|
||||||
mrAbort: exit;
|
mrAbort: exit;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else if NeedSave > 1 then begin
|
else if EditorList.Count > 1 then
|
||||||
for i := 0 to SourceEditorManager.UniqueSourceEditorCount - 1 do begin
|
for i := 0 to EditorList.Count - 1 do begin
|
||||||
if CheckEditorNeedsSave(SourceEditorManager.UniqueSourceEditors[i], False) then begin
|
Ed := TSourceEditor(EditorList[i]);
|
||||||
dec(NeedSave);
|
Remain := EditorList.Count-i-1; // Remaining number of files to go.
|
||||||
Ed := TSourceEditor(SourceEditorManager.UniqueSourceEditors[i]);
|
r := IDEQuestionDialog(lisSourceModified,
|
||||||
r := IDEQuestionDialog(lisSourceModified,
|
Format(lisSourceOfPageHasChangedSaveEx, [Ed.PageName,Remain]),
|
||||||
Format(lisSourceOfPageHasChangedSaveExtended, [Ed.PageName, NeedSave]),
|
mtConfirmation,
|
||||||
mtConfirmation,
|
[mrYes,lisMenuSave, mrAll,lisSaveAll, mrNo,lisDiscardChanges,
|
||||||
[mrYes, lisMenuSave, mrAll, lisSaveAll,
|
mrIgnore,lisDiscardChangesAll, mrAbort]);
|
||||||
mrNo, lisDiscardChanges, mrIgnore, lisDiscardChangesAll,
|
case r of
|
||||||
mrAbort]);
|
mrYes: SaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
|
||||||
case r of
|
mrNo: ; // don't save
|
||||||
mrYes: SaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
|
mrAll: begin
|
||||||
mrNo: ; // don't save
|
MainIDE.DoSaveAll([]);
|
||||||
mrAll: begin
|
break;
|
||||||
MainIDE.DoSaveAll([]);
|
end;
|
||||||
break
|
mrIgnore: break; // don't save anymore
|
||||||
end;
|
mrAbort: exit;
|
||||||
mrIgnore: break; // don't save anymore
|
|
||||||
mrAbort: exit;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLazSourceFileManager.CloseAll;
|
||||||
|
// Close editor files
|
||||||
|
var
|
||||||
|
Ed: TSourceEditor;
|
||||||
|
EditorList: TList;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
EditorList := TList.Create;
|
||||||
|
try
|
||||||
|
// Collect changed editors into a list and save them after asking from user.
|
||||||
|
for i := 0 to SourceEditorManager.UniqueSourceEditorCount - 1 do
|
||||||
|
begin
|
||||||
|
Ed := TSourceEditor(SourceEditorManager.UniqueSourceEditors[i]);
|
||||||
|
if CheckEditorNeedsSave(Ed, False) then
|
||||||
|
EditorList.Add(Ed);
|
||||||
|
end;
|
||||||
|
AskToSaveEditors(EditorList);
|
||||||
|
finally
|
||||||
|
EditorList.Free;
|
||||||
end;
|
end;
|
||||||
|
// Now close them all.
|
||||||
SourceEditorManager.IncUpdateLock;
|
SourceEditorManager.IncUpdateLock;
|
||||||
try
|
try
|
||||||
while (SourceEditorManager.SourceEditorCount > 0) and
|
while (SourceEditorManager.SourceEditorCount > 0) and
|
||||||
@ -3492,6 +3503,40 @@ begin
|
|||||||
PkgBoss.DoCloseAllPackageEditors;
|
PkgBoss.DoCloseAllPackageEditors;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLazSourceFileManager.InvertedFileClose(PageIndex: LongInt; SrcNoteBook: TSourceNotebook);
|
||||||
|
// close all source editors except the clicked
|
||||||
|
var
|
||||||
|
Ed: TSourceEditor;
|
||||||
|
EditorList: TList;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
EditorList := TList.Create;
|
||||||
|
try
|
||||||
|
// Collect changed editors, except the active one, into a list and maybe save them.
|
||||||
|
for i := 0 to SrcNoteBook.EditorCount - 1 do begin
|
||||||
|
Ed := SrcNoteBook.Editors[i];
|
||||||
|
if (i <> PageIndex) and CheckEditorNeedsSave(Ed, True) then
|
||||||
|
EditorList.Add(Ed);
|
||||||
|
end;
|
||||||
|
AskToSaveEditors(EditorList);
|
||||||
|
finally
|
||||||
|
EditorList.Free;
|
||||||
|
end;
|
||||||
|
// Now close all editors except the active one.
|
||||||
|
SourceEditorManager.IncUpdateLock;
|
||||||
|
try
|
||||||
|
repeat
|
||||||
|
i:=SrcNoteBook.PageCount-1;
|
||||||
|
if i=PageIndex then dec(i);
|
||||||
|
if i<0 then break;
|
||||||
|
if CloseEditorFile(SrcNoteBook.FindSourceEditorWithPageIndex(i),[])<>mrOk then exit;
|
||||||
|
if i<PageIndex then PageIndex:=i;
|
||||||
|
until false;
|
||||||
|
finally
|
||||||
|
SourceEditorManager.DecUpdateLock;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TLazSourceFileManager.ShowCheckListBuildModes(DlgMsg: String): Boolean;
|
function TLazSourceFileManager.ShowCheckListBuildModes(DlgMsg: String): Boolean;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
@ -6706,71 +6751,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazSourceFileManager.InvertedFileClose(PageIndex: LongInt; SrcNoteBook: TSourceNotebook);
|
|
||||||
// close all source editors except the clicked
|
|
||||||
var
|
|
||||||
i, NeedSave, Idx: Integer;
|
|
||||||
Ed: TSourceEditor;
|
|
||||||
r: TModalResult;
|
|
||||||
begin
|
|
||||||
NeedSave := 0;
|
|
||||||
for i := 0 to SrcNoteBook.EditorCount - 1 do begin
|
|
||||||
//no need for CheckEditorNeedsSave ActiveSourcenoteBook (i = PageIndex)
|
|
||||||
if (i <> PageIndex) and CheckEditorNeedsSave(SrcNoteBook.Editors[i], True) then begin
|
|
||||||
inc(NeedSave);
|
|
||||||
if NeedSave = 1 then Idx := i;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
if NeedSave = 1 then begin
|
|
||||||
Ed := SrcNoteBook.Editors[Idx];
|
|
||||||
r := IDEQuestionDialog(lisSourceModified,
|
|
||||||
Format(lisSourceOfPageHasChangedSave, [Ed.PageName]),
|
|
||||||
mtConfirmation,
|
|
||||||
[mrYes, lisMenuSave, mrNo, lisDiscardChanges, mrAbort]);
|
|
||||||
case r of
|
|
||||||
mrYes: SaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
|
|
||||||
mrNo: ; // don't save
|
|
||||||
mrAbort: exit;
|
|
||||||
end;
|
|
||||||
end
|
|
||||||
else if NeedSave > 1 then begin
|
|
||||||
for i := 0 to SrcNoteBook.EditorCount - 1 do begin
|
|
||||||
if CheckEditorNeedsSave(SrcNoteBook.Editors[i], True) then begin
|
|
||||||
dec(NeedSave);
|
|
||||||
Ed := SrcNoteBook.Editors[i];
|
|
||||||
r := IDEQuestionDialog(lisSourceModified,
|
|
||||||
Format(lisSourceOfPageHasChangedSaveExtended, [Ed.PageName, NeedSave]),
|
|
||||||
mtConfirmation,
|
|
||||||
[mrYes, lisMenuSave, mrAll, lisSaveAll,
|
|
||||||
mrNo, lisDiscardChanges, mrIgnore, lisDiscardChangesAll,
|
|
||||||
mrAbort]);
|
|
||||||
case r of
|
|
||||||
mrYes: SaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
|
|
||||||
mrNo: ; // don't save
|
|
||||||
mrAll: begin
|
|
||||||
MainIDE.DoSaveAll([]);
|
|
||||||
break
|
|
||||||
end;
|
|
||||||
mrIgnore: break; // don't save anymore
|
|
||||||
mrAbort: exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
SourceEditorManager.IncUpdateLock;
|
|
||||||
try
|
|
||||||
repeat
|
|
||||||
i:=SrcNoteBook.PageCount-1;
|
|
||||||
if i=PageIndex then dec(i);
|
|
||||||
if i<0 then break;
|
|
||||||
if CloseEditorFile(SrcNoteBook.FindSourceEditorWithPageIndex(i),[])<>mrOk then exit;
|
|
||||||
if i<PageIndex then PageIndex:=i;
|
|
||||||
until false;
|
|
||||||
finally
|
|
||||||
SourceEditorManager.DecUpdateLock;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// methods for open project, create project from source
|
// methods for open project, create project from source
|
||||||
|
|
||||||
function TLazSourceFileManager.CompleteLoadingProjectInfo: TModalResult;
|
function TLazSourceFileManager.CompleteLoadingProjectInfo: TModalResult;
|
||||||
|
Loading…
Reference in New Issue
Block a user