IDE: Save a virtual (non-saved) unit before inheriting from it. Issue #29642.

git-svn-id: trunk@63044 -
This commit is contained in:
juha 2020-04-21 15:14:34 +00:00
parent 7be629b269
commit f624f6188d
2 changed files with 22 additions and 10 deletions

View File

@ -4045,6 +4045,7 @@ resourcestring
// new dialog
lisNewDlgNoItemSelected = 'No item selected';
lisUnitMustSaveBeforeInherit = 'Unit "%s" must be saved before it can be inherited from. Save now?';
lisErrorOpeningComponent = 'Error opening component';
lisUnableToOpenAncestorComponent = 'Unable to open ancestor component';
lisNewDlgPleaseSelectAnItemFirst = 'Please select an item first.';

View File

@ -190,7 +190,6 @@ var
AnUnitInfo: TUnitInfo;
InhCompItem: TFileDescInheritedComponent;
begin
ANode := ItemsTreeView.Selected;
if (ANode = nil) or (ANode.Data = nil) or
(not (TObject(ANode.Data) is TNewIDEItemTemplate)) then
@ -211,9 +210,6 @@ begin
// if the selected item is an inherited one
if FNewItem is TNewItemProjectFile then
begin
//
InputHistories.NewProjectType:=FNewItem.Name;
NewFile:=TNewItemProjectFile(FNewItem);
if (NewFile.Descriptor is TFileDescInheritedItem) then
begin
@ -224,9 +220,25 @@ begin
if Assigned(AInheritedNode) then begin
// load the ancestor component
AnUnitInfo:=TUnitInfo(AInheritedNode.Data);
// Save the unit if not done yet.
if AnUnitInfo.IsVirtual then
begin
if IDEQuestionDialog(lisSave,
Format(lisUnitMustSaveBeforeInherit, [AnUnitInfo.Filename]),
mtInformation, [mrOK,mrCancel]) <> mrOK
then begin
FNewItem := nil;
ModalResult:=mrNone;
Exit;
end;
LazarusIDE.DoSaveProject([]);
end;
InputHistories.NewProjectType:=FNewItem.Name;
if LazarusIDE.DoOpenComponent(AnUnitInfo.Filename,
[ofOnlyIfExists,ofQuiet,ofLoadHiddenResource,ofUseCache],[],
AncestorComponent)<>mrOk then
[ofOnlyIfExists,ofQuiet,ofLoadHiddenResource,ofUseCache],[],
AncestorComponent)<>mrOk then
begin
IDEMessageDialog(lisErrorOpeningComponent,
lisUnableToOpenAncestorComponent, mtError, [mbCancel]);
@ -266,10 +278,9 @@ Begin
// Loop trough project units which have a component
for i := 0 to Project1.UnitCount-1 do begin
if (not Project1.Units[i].IsPartOfProject)
or (not FilenameIsPascalUnit(Project1.Units[i].Filename)) then
continue;
if Project1.Units[i].ComponentName<>'' then
if Project1.Units[i].IsPartOfProject
and FilenameIsPascalUnit(Project1.Units[i].Filename)
and (Project1.Units[i].ComponentName<>'') then
aComponentList.AddObject(Project1.Units[i].ComponentName, Project1.Units[i]);
end;
// Sort lists (by component name)