From 64ed2096935284f443d41a9941aa6e8207c4e49f Mon Sep 17 00:00:00 2001 From: mattias Date: Fri, 29 Oct 2010 11:26:44 +0000 Subject: [PATCH] IDE: view forms: check lfm on disk git-svn-id: trunk@27942 - --- ide/main.pp | 40 +++++++++++++++++++++++++++++++--------- lcl/lresources.pp | 25 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/ide/main.pp b/ide/main.pp index 24417dfe41..b8cf79d836 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -8809,32 +8809,54 @@ var MainUnitInfo: TUnitInfo; ActiveSourceEditor: TSourceEditor; ActiveUnitInfo: TUnitInfo; + CurUnitInfo: TUnitInfo; + LFMFilename: String; + LFMType: String; + LFMComponentName: String; + LFMClassName: String; + anUnitName: String; begin GetCurrentUnit(ActiveSourceEditor, ActiveUnitInfo); for i := 0 to Project1.UnitCount - 1 do begin - if not Project1.Units[i].IsPartOfProject then + CurUnitInfo:=Project1.Units[i]; + if not CurUnitInfo.IsPartOfProject then Continue; if ItemType in [piComponent, piFrame] then begin // add all form names of project - if Project1.Units[i].ComponentName <> '' then + if CurUnitInfo.ComponentName <> '' then begin if (ItemType = piComponent) or - ((ItemType = piFrame) and (Project1.Units[i].ResourceBaseClass = pfcbcFrame)) then - ItemList.AddObject(Project1.Units[i].Unit_Name, - TViewUnitsEntry.Create(Project1.Units[i].ComponentName, i, - Project1.Units[i] = ActiveUnitInfo)); + ((ItemType = piFrame) and (CurUnitInfo.ResourceBaseClass = pfcbcFrame)) then + ItemList.AddObject(CurUnitInfo.Unit_Name, + TViewUnitsEntry.Create(CurUnitInfo.ComponentName, i, + CurUnitInfo = ActiveUnitInfo)); + end else if FilenameIsAbsolute(CurUnitInfo.Filename) + and FilenameIsPascalSource(CurUnitInfo.Filename) + and FileExistsCached(CurUnitInfo.Filename) then begin + LFMFilename:=ChangeFileExt(CurUnitInfo.Filename,'.lfm'); + if FileExistsCached(LFMFilename) then begin + if ReadLFMHeaderFromFile(LFMFilename,LFMType,LFMComponentName,LFMClassName) + then begin + anUnitName:=CurUnitInfo.Unit_Name; + if anUnitName='' then + anUnitName:=ExtractFileNameOnly(LFMFilename); + ItemList.AddObject(anUnitName, + TViewUnitsEntry.Create(LFMComponentName, i, + CurUnitInfo = ActiveUnitInfo)); + end; + end; end; end else begin // add all unit names of project - if (Project1.Units[i].FileName <> '') then + if (CurUnitInfo.FileName <> '') then begin - AUnitName := ExtractFileName(Project1.Units[i].Filename); + AUnitName := ExtractFileName(CurUnitInfo.Filename); if ItemList.IndexOf(AUnitName) = -1 then ItemList.AddObject(AUnitName, - TViewUnitsEntry.Create(AUnitName, i, Project1.Units[i] = ActiveUnitInfo)); + TViewUnitsEntry.Create(AUnitName, i, CurUnitInfo = ActiveUnitInfo)); end else if Project1.MainUnitID = i then diff --git a/lcl/lresources.pp b/lcl/lresources.pp index 8a63f8a195..07402676e7 100644 --- a/lcl/lresources.pp +++ b/lcl/lresources.pp @@ -487,6 +487,8 @@ procedure ReadLFMHeader(const LFMSource: string; out LFMClassName: String; out LFMType: String); procedure ReadLFMHeader(const LFMSource: string; out LFMType, LFMComponentName, LFMClassName: String); +function ReadLFMHeaderFromFile(const Filename: string; + out LFMType, LFMComponentName, LFMClassName: String): boolean; function CreateLFMFile(AComponent: TComponent; LFMStream: TStream): integer; type @@ -2048,6 +2050,29 @@ begin LFMClassName:=copy(LFMSource,StartPos,p-StartPos); end; +function ReadLFMHeaderFromFile(const Filename: string; out LFMType, + LFMComponentName, LFMClassName: String): boolean; +var + fs: TFileStream; + Header: string; + Cnt: LongInt; +begin + Result:=false; + try + fs:=TFileStream.Create(Filename,fmOpenRead); + try + SetLength(Header,600); + Cnt:=fs.Read(Header[1],length(Header)); + SetLength(Header,Cnt); + ReadLFMHeader(Header,LFMType,LFMComponentName,LFMClassName); + Result:=LFMClassName<>''; + finally + fs.Free; + end; + except + end; +end; + function CreateLFMFile(AComponent: TComponent; LFMStream: TStream): integer; // 0 = ok // -1 = error while streaming AForm to binary stream