IDE: renamed TUnitInfo.Unit_Name to SrcUnitName and fixed updating it, bug #27713

git-svn-id: branches/fixes_1_4@48913 -
This commit is contained in:
mattias 2015-05-01 10:39:09 +00:00
parent 4964caa738
commit 44faf4bfd0
8 changed files with 125 additions and 88 deletions

View File

@ -614,7 +614,7 @@ begin
end else begin end else begin
ClassUnitInfo:=Project1.UnitWithComponentClassName(aMissingTypes[i]); ClassUnitInfo:=Project1.UnitWithComponentClassName(aMissingTypes[i]);
if ClassUnitInfo<>nil then if ClassUnitInfo<>nil then
NeededUnitName:=ClassUnitInfo.Unit_Name; NeededUnitName:=ClassUnitInfo.GetUsesUnitName;
end; end;
if NeededUnitName<>'' then begin if NeededUnitName<>'' then begin
if fUsedUnitsTool.AddUnitImmediately(NeededUnitName) then if fUsedUnitsTool.AddUnitImmediately(NeededUnitName) then

View File

@ -322,6 +322,7 @@
<Unit42> <Unit42>
<Filename Value="project.pp"/> <Filename Value="project.pp"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="Project"/>
</Unit42> </Unit42>
<Unit43> <Unit43>
<Filename Value="customformeditor.pp"/> <Filename Value="customformeditor.pp"/>
@ -565,6 +566,7 @@
<Unit82> <Unit82>
<Filename Value="sourcefilemanager.pas"/> <Filename Value="sourcefilemanager.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="SourceFileManager"/>
</Unit82> </Unit82>
<Unit83> <Unit83>
<Filename Value="../packager/lpkcache.pas"/> <Filename Value="../packager/lpkcache.pas"/>
@ -649,6 +651,7 @@
<Unit97> <Unit97>
<Filename Value="etquickfixes.pas"/> <Filename Value="etquickfixes.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="etQuickFixes"/>
</Unit97> </Unit97>
<Unit98> <Unit98>
<Filename Value="etsrceditmarks.pas"/> <Filename Value="etsrceditmarks.pas"/>
@ -783,6 +786,7 @@
<Unit125> <Unit125>
<Filename Value="mainintf.pas"/> <Filename Value="mainintf.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="MainIntf"/>
</Unit125> </Unit125>
<Unit126> <Unit126>
<Filename Value="mainbase.pas"/> <Filename Value="mainbase.pas"/>
@ -1223,6 +1227,7 @@
<Filename Value="useunitdlg.pas"/> <Filename Value="useunitdlg.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<UnitName Value="UseUnitDlg"/>
</Unit220> </Unit220>
<Unit221> <Unit221>
<Filename Value="keymapping.pp"/> <Filename Value="keymapping.pp"/>
@ -1311,6 +1316,18 @@
<Filename Value="initialsetupproc.pas"/> <Filename Value="initialsetupproc.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit239> </Unit239>
<Unit240>
<Filename Value="qfinitlocalvardlg.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="QFInitLocalVarDialog"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit240>
<Unit241>
<Filename Value="../packager/interpkgconflictfiles.pas"/>
<IsPartOfProject Value="True"/>
<HasResources Value="True"/>
</Unit241>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -10712,7 +10712,7 @@ var
ConflictingClass: TClass; ConflictingClass: TClass;
s: string; s: string;
begin begin
if SysUtils.CompareText(ActiveUnitInfo.Unit_Name,AName)=0 then if SysUtils.CompareText(ActiveUnitInfo.SrcUnitName,AName)=0 then
raise Exception.Create(Format( raise Exception.Create(Format(
lisTheUnitItselfHasAlreadyTheNamePascalIdentifiersMus, [AName])); lisTheUnitItselfHasAlreadyTheNamePascalIdentifiersMus, [AName]));
if ActiveUnitInfo.IsPartOfProject then begin if ActiveUnitInfo.IsPartOfProject then begin
@ -11671,7 +11671,7 @@ begin
OkToAdd:=SourceFileMgr.CheckDirIsInSearchPath(AnUnitInfo,False,False); OkToAdd:=SourceFileMgr.CheckDirIsInSearchPath(AnUnitInfo,False,False);
if (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags) then begin if (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags) then begin
AnUnitInfo.ReadUnitNameFromSource(false); AnUnitInfo.ReadUnitNameFromSource(false);
ShortUnitName:=AnUnitInfo.Unit_Name; ShortUnitName:=AnUnitInfo.SrcUnitName;
if (ShortUnitName<>'') then begin if (ShortUnitName<>'') then begin
if CodeToolBoss.AddUnitToMainUsesSectionIfNeeded( if CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(
Project1.MainUnitInfo.Source,ShortUnitName,'') then begin Project1.MainUnitInfo.Source,ShortUnitName,'') then begin

View File

@ -555,7 +555,7 @@ procedure TFileDescInheritedComponent.SetInheritedUnit(const AValue: TUnitInfo);
begin begin
if FInheritedUnit=AValue then exit; if FInheritedUnit=AValue then exit;
FInheritedUnit:=AValue; FInheritedUnit:=AValue;
InheritedUnits:=FInheritedUnit.Unit_Name; InheritedUnits:=FInheritedUnit.SrcUnitName;
end; end;
constructor TFileDescInheritedComponent.Create; constructor TFileDescInheritedComponent.Create;

View File

@ -287,7 +287,7 @@ type
FRunFileIfActive: boolean; FRunFileIfActive: boolean;
FSessionModified: boolean; FSessionModified: boolean;
fSource: TCodeBuffer; fSource: TCodeBuffer;
fUnitName: String; fSrcUnitName: String;
fUsageCount: extended; fUsageCount: extended;
fUserReadOnly: Boolean; fUserReadOnly: Boolean;
fSourceChangeStep: LongInt; fSourceChangeStep: LongInt;
@ -326,7 +326,7 @@ type
procedure SetRunFileIfActive(const AValue: boolean); procedure SetRunFileIfActive(const AValue: boolean);
procedure SetSessionModified(const AValue: boolean); procedure SetSessionModified(const AValue: boolean);
procedure SetSource(ABuffer: TCodeBuffer); procedure SetSource(ABuffer: TCodeBuffer);
procedure SetUnitName(const NewUnitName:string); procedure SetSrcUnitName(const NewUnitName:string);
procedure SetUserReadOnly(const NewValue: boolean); procedure SetUserReadOnly(const NewValue: boolean);
protected protected
function GetFileName: string; override; function GetFileName: string; override;
@ -364,10 +364,9 @@ type
procedure IgnoreCurrentFileDateOnDisk; procedure IgnoreCurrentFileDateOnDisk;
procedure IncreaseAutoRevertLock; // do not auto revert from disk procedure IncreaseAutoRevertLock; // do not auto revert from disk
procedure DecreaseAutoRevertLock; procedure DecreaseAutoRevertLock;
function ParseUnitNameFromSource(TryCache: boolean): string;// fetch name fom source function ReadUnitNameFromSource(TryCache: boolean): string;// fetch unit name from source and update property UnitName
procedure ReadUnitNameFromSource(TryCache: boolean);// fetch unit name from source and update property UnitName function GetUsesUnitName: string;
function CreateUnitName: string; function CreateUnitName: string;
procedure ImproveUnitNameCache(const NewUnitName: string);
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string; procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string;
Merge, IgnoreIsPartOfProject: boolean; Merge, IgnoreIsPartOfProject: boolean;
FileVersion: integer); FileVersion: integer);
@ -469,7 +468,7 @@ type
property Source: TCodeBuffer read fSource write SetSource; property Source: TCodeBuffer read fSource write SetSource;
property DefaultSyntaxHighlighter: TLazSyntaxHighlighter property DefaultSyntaxHighlighter: TLazSyntaxHighlighter
read FDefaultSyntaxHighlighter write SetDefaultSyntaxHighlighter; read FDefaultSyntaxHighlighter write SetDefaultSyntaxHighlighter;
property Unit_Name: String read fUnitName write SetUnitName; property SrcUnitName: String read fSrcUnitName write SetSrcUnitName; // unit name in source
property UserReadOnly: Boolean read fUserReadOnly write SetUserReadOnly; property UserReadOnly: Boolean read fUserReadOnly write SetUserReadOnly;
property SourceDirectoryReferenced: boolean read FSourceDirectoryReferenced; property SourceDirectoryReferenced: boolean read FSourceDirectoryReferenced;
property AutoReferenceSourceDir: boolean read FAutoReferenceSourceDir property AutoReferenceSourceDir: boolean read FAutoReferenceSourceDir
@ -1610,34 +1609,56 @@ begin
end; end;
until Result<>mrRetry; until Result<>mrRetry;
if ReadUnitName then begin if ReadUnitName then begin
fUnitName:=CodeToolBoss.GetSourceName(fSource,false); ReadUnitNameFromSource(false);
end; end;
Result:=mrOk; Result:=mrOk;
end; end;
procedure TUnitInfo.ReadUnitNameFromSource(TryCache: boolean); function TUnitInfo.ReadUnitNameFromSource(TryCache: boolean): string;
var
NewUnitName: String;
begin begin
NewUnitName:=ParseUnitNameFromSource(TryCache); Result:='';
if NewUnitName<>'' then if TryCache then
fUnitName:=NewUnitName; Result:=CodeToolBoss.GetCachedSourceName(Source);
if Result='' then
Result:=CodeToolBoss.GetSourceName(fSource,false);
if Result<>'' then begin
// source can be parsed => update SrcUnitName
{$IFDEF VerboseIDESrcUnitName}
if CompareFilenames(ExtractFileNameOnly(Filename),'interpkgconflictfiles')=0 then
debugln(['TUnitInfo.ReadUnitNameFromSource ',Result]);
{$ENDIF}
fSrcUnitName:=Result;
end else begin
// unable to parse the source
if FilenameIsPascalSource(Filename) then begin
// use default: the filename
Result:=ExtractFileNameOnly(Filename);
if CompareText(Result,fSrcUnitName)=0 then begin
// the last stored unitname has the better case
Result:=SrcUnitName;
end;
end;
end;
end;
function TUnitInfo.GetUsesUnitName: string;
begin
if not FilenameIsPascalUnit(Filename) then
Result:=''
else begin
Result:=SrcUnitName;
if (Result='') or (CompareText(Result,ExtractFileNameOnly(Filename))<>0) then
Result:=ExtractFileNameOnly(Filename);
end;
end; end;
function TUnitInfo.CreateUnitName: string; function TUnitInfo.CreateUnitName: string;
begin begin
Result:=Unit_Name; Result:=SrcUnitName;
if (Result='') and FilenameIsPascalSource(Filename) then if (Result='') and FilenameIsPascalSource(Filename) then
Result:=ExtractFilenameOnly(Filename); Result:=ExtractFilenameOnly(Filename);
end; end;
procedure TUnitInfo.ImproveUnitNameCache(const NewUnitName: string);
begin
if (fUnitName='') or (CompareText(fUnitName,NewUnitName)=0) then begin
fUnitName:=NewUnitName;
end;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TUnitInfo Clear TUnitInfo Clear
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -1663,7 +1684,7 @@ begin
Modified := false; Modified := false;
SessionModified := false; SessionModified := false;
FRunFileIfActive:=false; FRunFileIfActive:=false;
fUnitName := ''; fSrcUnitName := '';
fUsageCount:=-1; fUsageCount:=-1;
fUserReadOnly := false; fUserReadOnly := false;
if fSource<>nil then fSource.Clear; if fSource<>nil then fSource.Clear;
@ -1716,6 +1737,7 @@ procedure TUnitInfo.SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string;
var var
AFilename: String; AFilename: String;
i, X, Y: Integer; i, X, Y: Integer;
s: String;
begin begin
// global data // global data
AFilename:=Filename; AFilename:=Filename;
@ -1740,7 +1762,9 @@ begin
XMLConfig.SetDeleteValue(Path+'ResourceBaseClass/Value', XMLConfig.SetDeleteValue(Path+'ResourceBaseClass/Value',
PFComponentBaseClassNames[FResourceBaseClass], PFComponentBaseClassNames[FResourceBaseClass],
PFComponentBaseClassNames[pfcbcNone]); PFComponentBaseClassNames[pfcbcNone]);
XMLConfig.SetDeleteValue(Path+'UnitName/Value',fUnitName,''); s:=fSrcUnitName;
if (s<>'') and (ExtractFileNameOnly(Filename)=s) then s:=''; // only save if SrcUnitName differ from filename
XMLConfig.SetDeleteValue(Path+'UnitName/Value',s,'');
// save custom data // save custom data
SaveStringToStringTree(XMLConfig,CustomData,Path+'CustomData/'); SaveStringToStringTree(XMLConfig,CustomData,Path+'CustomData/');
end; end;
@ -1815,8 +1839,16 @@ begin
AFilename:=XMLConfig.GetValue(Path+'ResourceFilename/Value',''); AFilename:=XMLConfig.GetValue(Path+'ResourceFilename/Value','');
if (AFilename<>'') and Assigned(fOnLoadSaveFilename) then if (AFilename<>'') and Assigned(fOnLoadSaveFilename) then
fOnLoadSaveFilename(AFilename,true); fOnLoadSaveFilename(AFilename,true);
if FilenameIsPascalSource(AFilename) then if FilenameIsPascalSource(Filename) then begin
fUnitName:=XMLConfig.GetValue(Path+'UnitName/Value',ExtractFileNameOnly(AFilename)); fSrcUnitName:=XMLConfig.GetValue(Path+'UnitName/Value','');
if fSrcUnitName='' then
fSrcUnitName:=ExtractFileNameOnly(Filename);
{$IFDEF VerboseIDESrcUnitName}
if CompareFilenames(ExtractFileNameOnly(Filename),'interpkgconflictfiles')=0 then
debugln(['TUnitInfo.LoadFromXMLConfig ',fSrcUnitName]);
{$ENDIF}
end else
fSrcUnitName:='';
// save custom data // save custom data
LoadStringToStringTree(XMLConfig,CustomData,Path+'CustomData/'); LoadStringToStringTree(XMLConfig,CustomData,Path+'CustomData/');
@ -1853,35 +1885,15 @@ begin
LoadStringToStringTree(XMLConfig,CustomSessionData,Path+'CustomSessionData/'); LoadStringToStringTree(XMLConfig,CustomSessionData,Path+'CustomSessionData/');
end; end;
function TUnitInfo.ParseUnitNameFromSource(TryCache: boolean): string; procedure TUnitInfo.SetSrcUnitName(const NewUnitName:string);
begin
Result:='';
if TryCache then
Result:=CodeToolBoss.GetCachedSourceName(Source);
if Result='' then
Result:=CodeToolBoss.GetSourceName(fSource,false);
if Result='' then begin
// unable to parse the source
if FilenameIsPascalSource(Filename) then begin
// use default: the filename
Result:=ExtractFileNameOnly(Filename);
if CompareText(Result,fUnitName)=0 then begin
// the last stored unitname has the better case
Result:=fUnitName;
end;
end;
end;
end;
procedure TUnitInfo.SetUnitName(const NewUnitName:string);
var var
Allowed: boolean; Allowed: boolean;
OldUnitName: String; OldUnitName: String;
begin begin
if (fUnitName <> NewUnitName) and (NewUnitName <> '') then if (fSrcUnitName <> NewUnitName) and (NewUnitName <> '') then
begin begin
Allowed := true; Allowed := true;
OldUnitName := fUnitName; OldUnitName := fSrcUnitName;
if OldUnitName = '' then if OldUnitName = '' then
OldUnitName := ExtractFileNameOnly(Filename); OldUnitName := ExtractFileNameOnly(Filename);
if Assigned(FOnUnitNameChange) then if Assigned(FOnUnitNameChange) then
@ -1891,7 +1903,11 @@ begin
begin begin
CodeToolBoss.RenameSource(fSource,NewUnitName); CodeToolBoss.RenameSource(fSource,NewUnitName);
end; end;
fUnitName := NewUnitName; {$IFDEF VerboseIDESrcUnitName}
if CompareFilenames(ExtractFileNameOnly(Filename),'interpkgconflictfiles')=0 then
debugln(['TUnitInfo.SetSrcUnitName ',NewUnitName]);
{$ENDIF}
fSrcUnitName := NewUnitName;
Modified := true; Modified := true;
if (Project <> nil) then Project.UnitModified(Self); if (Project <> nil) then Project.UnitModified(Self);
end; end;
@ -3455,6 +3471,7 @@ procedure TProject.AddFile(ProjectFile: TLazProjectFile; AddToProjectUsesClause:
var var
NewIndex: integer; NewIndex: integer;
AnUnit: TUnitInfo; AnUnit: TUnitInfo;
s: String;
begin begin
AnUnit:=ProjectFile as TUnitInfo; AnUnit:=ProjectFile as TUnitInfo;
//debugln('TProject.AddFile A ',AnUnit.Filename,' AddToProjectFile=',dbgs(AddToProjectFile)); //debugln('TProject.AddFile A ',AnUnit.Filename,' AddToProjectFile=',dbgs(AddToProjectFile));
@ -3473,8 +3490,11 @@ begin
MainUnitInfo.IncreaseAutoRevertLock; MainUnitInfo.IncreaseAutoRevertLock;
if AddToProjectUsesClause and (MainUnitID>=0) and (MainUnitID<>NewIndex) then if AddToProjectUsesClause and (MainUnitID>=0) and (MainUnitID<>NewIndex) then
if AnUnit.Unit_Name<>'' then // add unit to uses section begin
CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(MainUnitInfo.Source,AnUnit.Unit_Name,'',true); s:=AnUnit.GetUsesUnitName;
if s<>'' then // add unit to uses section
CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(MainUnitInfo.Source,s,'',true);
end;
EndUpdate; EndUpdate;
UnitModified(AnUnit); UnitModified(AnUnit);
end; end;
@ -3501,9 +3521,9 @@ begin
// remove unit from uses section and from createforms in program file // remove unit from uses section and from createforms in program file
if (OldUnitInfo.IsPartOfProject) then begin if (OldUnitInfo.IsPartOfProject) then begin
if RemoveFromUsesSection then begin if RemoveFromUsesSection then begin
if (OldUnitInfo.Unit_Name<>'') then begin if (OldUnitInfo.SrcUnitName<>'') then begin
CodeToolBoss.RemoveUnitFromAllUsesSections(MainUnitInfo.Source, CodeToolBoss.RemoveUnitFromAllUsesSections(MainUnitInfo.Source,
OldUnitInfo.Unit_Name); OldUnitInfo.SrcUnitName);
end; end;
if (OldUnitInfo.ComponentName<>'') then begin if (OldUnitInfo.ComponentName<>'') then begin
CodeToolBoss.RemoveCreateFormStatement(MainUnitInfo.Source, CodeToolBoss.RemoveCreateFormStatement(MainUnitInfo.Source,
@ -3864,8 +3884,7 @@ end;
function TProject.RemoveCreateFormFromProjectFile(const AClassName,AName:string):boolean; function TProject.RemoveCreateFormFromProjectFile(const AClassName,AName:string):boolean;
begin begin
Result:=CodeToolBoss.RemoveCreateFormStatement(MainUnitInfo.Source, Result:=CodeToolBoss.RemoveCreateFormStatement(MainUnitInfo.Source,AName);
AName);
if Result then begin if Result then begin
MainUnitInfo.Modified:=true; MainUnitInfo.Modified:=true;
end; end;
@ -3888,9 +3907,9 @@ begin
if ((OnlyProjectUnits and Units[Result].IsPartOfProject) if ((OnlyProjectUnits and Units[Result].IsPartOfProject)
or (not OnlyProjectUnits)) or (not OnlyProjectUnits))
and (IgnoreUnit<>Units[Result]) and (IgnoreUnit<>Units[Result])
and (Units[Result].Unit_Name<>'') and (Units[Result].SrcUnitName<>'')
then begin then begin
if (CompareDottedIdentifiers(PChar(Units[Result].Unit_Name),PChar(AnUnitName))=0) if (CompareDottedIdentifiers(PChar(Units[Result].SrcUnitName),PChar(AnUnitName))=0)
then then
exit; exit;
end; end;
@ -5043,8 +5062,8 @@ begin
// check if no other project unit has this name // check if no other project unit has this name
for i:=0 to UnitCount-1 do begin for i:=0 to UnitCount-1 do begin
if (Units[i].IsPartOfProject) if (Units[i].IsPartOfProject)
and (Units[i]<>AnUnitInfo) and (Units[i].Unit_Name<>'') and (Units[i]<>AnUnitInfo) and (Units[i].SrcUnitName<>'')
and (CompareText(Units[i].Unit_Name,NewUnitName)=0) then begin and (CompareText(Units[i].SrcUnitName,NewUnitName)=0) then begin
Allowed:=false; Allowed:=false;
exit; exit;
end; end;
@ -5564,7 +5583,7 @@ function TProject.ProjectUnitWithUnitname(const AnUnitName: string): TUnitInfo;
begin begin
Result:=fFirst[uilPartOfProject]; Result:=fFirst[uilPartOfProject];
while Result<>nil do begin while Result<>nil do begin
if CompareText(AnUnitName,Result.Unit_Name)=0 then exit; if CompareText(AnUnitName,Result.SrcUnitName)=0 then exit;
Result:=Result.fNext[uilPartOfProject]; Result:=Result.fNext[uilPartOfProject];
end; end;
end; end;

View File

@ -436,7 +436,7 @@ begin
if AnUnitInfo.OpenEditorInfoCount > 0 then if AnUnitInfo.OpenEditorInfoCount > 0 then
AShareEditor := TSourceEditor(AnUnitInfo.OpenEditorInfo[0].EditorComponent); AShareEditor := TSourceEditor(AnUnitInfo.OpenEditorInfo[0].EditorComponent);
NewSrcEdit:=SrcNotebook.NewFile( NewSrcEdit:=SrcNotebook.NewFile(
CreateSrcEditPageName(AnUnitInfo.Unit_Name, AFilename, AShareEditor), CreateSrcEditPageName(AnUnitInfo.SrcUnitName, AFilename, AShareEditor),
AnUnitInfo.Source, False, AShareEditor); AnUnitInfo.Source, False, AShareEditor);
NewSrcEdit.EditorComponent.BeginUpdate; NewSrcEdit.EditorComponent.BeginUpdate;
MainIDEBar.itmFileClose.Enabled:=True; MainIDEBar.itmFileClose.Enabled:=True;
@ -1712,7 +1712,8 @@ begin
end else end else
NewUnitInfo:=TUnitInfo.Create(NewBuffer); NewUnitInfo:=TUnitInfo.Create(NewBuffer);
//debugln(['TLazSourceFileManager.NewFile ',NewUnitInfo.Filename,' ',NewFilename]); //debugln(['TLazSourceFileManager.NewFile ',NewUnitInfo.Filename,' ',NewFilename]);
NewUnitInfo.ImproveUnitNameCache(NewUnitName); if (CompareText(NewUnitInfo.SrcUnitName,NewUnitName)=0) then
NewUnitInfo.SrcUnitName:=NewUnitName;
NewUnitInfo.BuildFileIfActive:=NewFileDescriptor.BuildFileIfActive; NewUnitInfo.BuildFileIfActive:=NewFileDescriptor.BuildFileIfActive;
NewUnitInfo.RunFileIfActive:=NewFileDescriptor.RunFileIfActive; NewUnitInfo.RunFileIfActive:=NewFileDescriptor.RunFileIfActive;
@ -1757,7 +1758,7 @@ begin
if NewUnitInfo.OpenEditorInfoCount > 0 then if NewUnitInfo.OpenEditorInfoCount > 0 then
AShareEditor := TSourceEditor(NewUnitInfo.OpenEditorInfo[0].EditorComponent); AShareEditor := TSourceEditor(NewUnitInfo.OpenEditorInfo[0].EditorComponent);
NewSrcEdit := SrcNoteBook.NewFile( NewSrcEdit := SrcNoteBook.NewFile(
CreateSrcEditPageName(NewUnitInfo.Unit_Name, NewUnitInfo.Filename, AShareEditor), CreateSrcEditPageName(NewUnitInfo.SrcUnitName, NewUnitInfo.Filename, AShareEditor),
NewUnitInfo.Source, True, AShareEditor); NewUnitInfo.Source, True, AShareEditor);
MainIDEBar.itmFileClose.Enabled:=True; MainIDEBar.itmFileClose.Enabled:=True;
MainIDEBar.itmFileCloseAll.Enabled:=True; MainIDEBar.itmFileCloseAll.Enabled:=True;
@ -2073,7 +2074,7 @@ begin
OldUnitName:=''; OldUnitName:='';
if WasPascalSource then if WasPascalSource then
OldUnitName:=AnUnitInfo.ParseUnitNameFromSource(true); OldUnitName:=AnUnitInfo.ReadUnitNameFromSource(true);
OldFilename:=AnUnitInfo.Filename; OldFilename:=AnUnitInfo.Filename;
if [sfSaveAs,sfSaveToTestDir]*Flags=[sfSaveAs] then begin if [sfSaveAs,sfSaveToTestDir]*Flags=[sfSaveAs] then begin
@ -2148,7 +2149,7 @@ begin
// fix all references // fix all references
NewUnitName:=''; NewUnitName:='';
if FilenameIsPascalSource(AnUnitInfo.Filename) then if FilenameIsPascalSource(AnUnitInfo.Filename) then
NewUnitName:=AnUnitInfo.ParseUnitNameFromSource(true); NewUnitName:=AnUnitInfo.ReadUnitNameFromSource(true);
NewFilename:=AnUnitInfo.Filename; NewFilename:=AnUnitInfo.Filename;
if (NewUnitName<>'') if (NewUnitName<>'')
and ((OldUnitName<>NewUnitName) and ((OldUnitName<>NewUnitName)
@ -2243,8 +2244,8 @@ begin
// ask user // ask user
if AnUnitInfo.Filename<>'' then if AnUnitInfo.Filename<>'' then
AText:=Format(lisFileHasChangedSave, [AnUnitInfo.Filename]) AText:=Format(lisFileHasChangedSave, [AnUnitInfo.Filename])
else if AnUnitInfo.Unit_Name<>'' then else if AnUnitInfo.SrcUnitName<>'' then
AText:=Format(lisUnitHasChangedSave, [AnUnitInfo.Unit_name]) AText:=Format(lisUnitHasChangedSave, [AnUnitInfo.SrcUnitName])
else else
AText:=Format(lisSourceOfPageHasChangedSave, [TSourceEditor(AEditor).PageName]); AText:=Format(lisSourceOfPageHasChangedSave, [TSourceEditor(AEditor).PageName]);
ACaption:=lisSourceModified; ACaption:=lisSourceModified;
@ -2934,7 +2935,7 @@ begin
if FileExistsCached(LFMFilename) if FileExistsCached(LFMFilename)
and ReadLFMHeaderFromFile(LFMFilename,LFMType,LFMComponentName,LFMClassName) and ReadLFMHeaderFromFile(LFMFilename,LFMType,LFMComponentName,LFMClassName)
then begin then begin
anUnitName:=CurUnitInfo.Unit_Name; anUnitName:=CurUnitInfo.SrcUnitName;
if anUnitName='' then if anUnitName='' then
anUnitName:=ExtractFileNameOnly(LFMFilename); anUnitName:=ExtractFileNameOnly(LFMFilename);
ItemList.Add(LFMComponentName, CurUnitInfo.Filename, ItemList.Add(LFMComponentName, CurUnitInfo.Filename,
@ -3089,7 +3090,7 @@ begin
AnUnitInfo.ResourceBaseClass:=FindLFMBaseClass(AnUnitInfo.Filename); AnUnitInfo.ResourceBaseClass:=FindLFMBaseClass(AnUnitInfo.Filename);
if not ResourceFits(AnUnitInfo.ResourceBaseClass) then continue; if not ResourceFits(AnUnitInfo.ResourceBaseClass) then continue;
end; end;
AddUnit(AnUnitInfo.Unit_Name,AnUnitInfo.Filename); AddUnit(AnUnitInfo.SrcUnitName,AnUnitInfo.Filename);
end; end;
end else if APackage<>nil then begin end else if APackage<>nil then begin
// add package units // add package units
@ -3155,8 +3156,8 @@ begin
s:='"'+ActiveUnitInfo.Filename+'"' s:='"'+ActiveUnitInfo.Filename+'"'
else else
s:='"'+ActiveSourceEditor.PageName+'"'; s:='"'+ActiveSourceEditor.PageName+'"';
if (ActiveUnitInfo.Unit_Name<>'') if (ActiveUnitInfo.SrcUnitName<>'')
and (Project1.IndexOfUnitWithName(ActiveUnitInfo.Unit_Name,true,ActiveUnitInfo)>=0) then and (Project1.IndexOfUnitWithName(ActiveUnitInfo.SrcUnitName,true,ActiveUnitInfo)>=0) then
begin begin
IDEMessageDialog(lisInformation, Format( IDEMessageDialog(lisInformation, Format(
lisUnableToAddToProjectBecauseThereIsAlreadyAUnitWith, [s]), lisUnableToAddToProjectBecauseThereIsAlreadyAUnitWith, [s]),
@ -4264,7 +4265,7 @@ function TLazSourceFileManager.NewUniqueComponentName(Prefix: string): string;
if CompareText(AnUnitInfo.Component.ClassName,Identifier)=0 then exit; if CompareText(AnUnitInfo.Component.ClassName,Identifier)=0 then exit;
end else if (AnUnitInfo.ComponentName<>'') end else if (AnUnitInfo.ComponentName<>'')
and ((AnUnitInfo.IsPartOfProject) or AnUnitInfo.Loaded) then begin and ((AnUnitInfo.IsPartOfProject) or AnUnitInfo.Loaded) then begin
if SysUtils.CompareText(AnUnitInfo.Unit_Name,Identifier)=0 then exit; if SysUtils.CompareText(AnUnitInfo.SrcUnitName,Identifier)=0 then exit;
if SysUtils.CompareText(AnUnitInfo.ComponentName,Identifier)=0 then exit; if SysUtils.CompareText(AnUnitInfo.ComponentName,Identifier)=0 then exit;
end; end;
end; end;
@ -4360,7 +4361,7 @@ begin
IsPascal:=FilenameIsPascalSource(AFilename); IsPascal:=FilenameIsPascalSource(AFilename);
if IsPascal then begin if IsPascal then begin
if AnUnitInfo<>nil then if AnUnitInfo<>nil then
OldUnitName:=AnUnitInfo.ParseUnitNameFromSource(false) OldUnitName:=AnUnitInfo.ReadUnitNameFromSource(false)
else else
OldUnitName:=ExtractFileNameOnly(AFilename); OldUnitName:=ExtractFileNameOnly(AFilename);
end else end else
@ -4981,8 +4982,8 @@ begin
OldLFMFilename:=ChangeFileExt(OldFilename,'.dfm'); OldLFMFilename:=ChangeFileExt(OldFilename,'.dfm');
end; end;
if NewUnitName='' then if NewUnitName='' then
NewUnitName:=AnUnitInfo.Unit_Name; NewUnitName:=AnUnitInfo.SrcUnitName;
debugln(['TLazSourceFileManager.RenameUnit ',AnUnitInfo.Filename,' NewUnitName=',NewUnitName,' OldUnitName=',AnUnitInfo.Unit_Name,' LFMCode=',LFMCode<>nil,' LRSCode=',LRSCode<>nil,' NewFilename="',NewFilename,'"']); debugln(['TLazSourceFileManager.RenameUnit ',AnUnitInfo.Filename,' NewUnitName=',NewUnitName,' OldUnitName=',AnUnitInfo.SrcUnitName,' LFMCode=',LFMCode<>nil,' LRSCode=',LRSCode<>nil,' NewFilename="',NewFilename,'"']);
// check new resource file // check new resource file
NewLFMFilename:=''; NewLFMFilename:='';
@ -5123,7 +5124,7 @@ begin
// the code is not changed, therefore the marks are kept // the code is not changed, therefore the marks are kept
// change unitname in lpi and in main source file // change unitname in lpi and in main source file
AnUnitInfo.Unit_Name:=NewUnitName; AnUnitInfo.SrcUnitName:=NewUnitName;
if LRSCode<>nil then begin if LRSCode<>nil then begin
// change resource filename in the source include directive // change resource filename in the source include directive
if not CodeToolBoss.RenameMainInclude(AnUnitInfo.Source, if not CodeToolBoss.RenameMainInclude(AnUnitInfo.Source,
@ -5332,7 +5333,7 @@ begin
mtConfirmation,[mrYes,mrIgnore,lisNo,mrAbort],''); mtConfirmation,[mrYes,mrIgnore,lisNo,mrAbort],'');
if Result<>mrYes then exit; if Result<>mrYes then exit;
end; end;
NewUnitName:=AnUnitInfo.Unit_Name; NewUnitName:=AnUnitInfo.SrcUnitName;
if NewUnitName='' then begin if NewUnitName='' then begin
AnUnitInfo.ReadUnitNameFromSource(false); AnUnitInfo.ReadUnitNameFromSource(false);
NewUnitName:=AnUnitInfo.CreateUnitName; NewUnitName:=AnUnitInfo.CreateUnitName;
@ -5706,7 +5707,7 @@ begin
FormEditor1.ClearSelection; FormEditor1.ClearSelection;
// create JIT component // create JIT component
NewUnitName:=AnUnitInfo.Unit_Name; NewUnitName:=AnUnitInfo.SrcUnitName;
if NewUnitName='' then if NewUnitName='' then
NewUnitName:=ExtractFileNameOnly(AnUnitInfo.Filename); NewUnitName:=ExtractFileNameOnly(AnUnitInfo.Filename);
DisableAutoSize:=true; DisableAutoSize:=true;
@ -7140,7 +7141,7 @@ begin
AFilename:=''; AFilename:='';
// build a nice project info filename suggestion // build a nice project info filename suggestion
if UseMainSourceFile and (Project1.MainUnitID>=0) then if UseMainSourceFile and (Project1.MainUnitID>=0) then
AFilename:=Project1.MainUnitInfo.Unit_Name; AFilename:=Project1.MainUnitInfo.SrcUnitName;
if AFilename='' then if AFilename='' then
AFilename:=ExtractFileName(Project1.ProjectInfoFile); AFilename:=ExtractFileName(Project1.ProjectInfoFile);
if AFilename='' then if AFilename='' then
@ -7321,7 +7322,7 @@ begin
MainUnitSrcEdit.CodeBuffer:=NewBuf; MainUnitSrcEdit.CodeBuffer:=NewBuf;
// change program name // change program name
MainUnitInfo.Unit_Name:=NewProgramName; MainUnitInfo.SrcUnitName:=NewProgramName;
MainUnitInfo.Modified:=true; MainUnitInfo.Modified:=true;
// update source notebook page names // update source notebook page names

View File

@ -311,13 +311,13 @@ begin
FImplUsedUnits.CaseSensitive := False; FImplUsedUnits.CaseSensitive := False;
end; end;
if SrcEdit.GetProjectFile is TUnitInfo then if SrcEdit.GetProjectFile is TUnitInfo then
CurrentUnitName := TUnitInfo(SrcEdit.GetProjectFile).Unit_Name CurrentUnitName := TUnitInfo(SrcEdit.GetProjectFile).SrcUnitName
else else
CurrentUnitName := ''; CurrentUnitName := '';
// Add available unit names to list // Add available unit names to list
ProjFile:=Project1.FirstPartOfProject; ProjFile:=Project1.FirstPartOfProject;
while ProjFile <> nil do begin while ProjFile <> nil do begin
s := ProjFile.Unit_Name; s := ProjFile.SrcUnitName;
if s = CurrentUnitName then // current unit if s = CurrentUnitName then // current unit
s := ''; s := '';
if (ProjFile <> Project1.MainUnitInfo) and (s <> '') then if (ProjFile <> Project1.MainUnitInfo) and (s <> '') then

View File

@ -2569,7 +2569,7 @@ var
NewHasRegisterProc:=OldPkgFile.HasRegisterProc; NewHasRegisterProc:=OldPkgFile.HasRegisterProc;
NewAddToUses:=OldPkgFile.AddToUsesPkgSection; NewAddToUses:=OldPkgFile.AddToUsesPkgSection;
end else begin end else begin
NewUnitName:=OldProjFile.Unit_Name; NewUnitName:=OldProjFile.SrcUnitName;
NewFileType:=FileNameToPkgFileType(OldFilename); NewFileType:=FileNameToPkgFileType(OldFilename);
NewCompPrio:=ComponentPriorityNormal; NewCompPrio:=ComponentPriorityNormal;
NewResourceBaseClass:=OldProjFile.ResourceBaseClass; NewResourceBaseClass:=OldProjFile.ResourceBaseClass;
@ -4350,7 +4350,7 @@ var
end else begin end else begin
ClassUnitInfo:=Project1.UnitWithComponentClassName(ComponentClassnames[i]); ClassUnitInfo:=Project1.UnitWithComponentClassName(ComponentClassnames[i]);
if ClassUnitInfo<>nil then if ClassUnitInfo<>nil then
NewUnitName:=ClassUnitInfo.Unit_Name; NewUnitName:=ClassUnitInfo.SrcUnitName;
end; end;
if (NewUnitName<>'') and (UnitNames.IndexOf(NewUnitName)<0) then begin if (NewUnitName<>'') and (UnitNames.IndexOf(NewUnitName)<0) then begin
// new needed unit // new needed unit