IDE: added unitresources

git-svn-id: trunk@40326 -
This commit is contained in:
mattias 2013-02-16 16:15:18 +00:00
parent 3d7f444396
commit f595fb71f7
8 changed files with 92 additions and 38 deletions

View File

@ -44,7 +44,7 @@ uses
{$ENDIF}
Classes, SysUtils, AvgLvlTree, BasicCodeTools, TypInfo, LCLProc, LResources,
Forms, Controls, LCLMemManager, LCLIntf, Dialogs, PropEditUtils, PropEdits,
IDEProcs, PackageDefs, BasePkgManager;
IDEProcs, PackageDefs, BasePkgManager, UnitResources, lfmUnitResource;
type
//----------------------------------------------------------------------------
@ -146,7 +146,9 @@ type
function GetItem(Index:integer):TComponent;
function OnFindGlobalComponent(const AName:AnsiString):TComponent;
procedure InitReading;
procedure CreateReader(BinStream: TStream; var Reader: TReader;
procedure CreateReader(BinStream: TStream;
UnitResourcefileFormat: TUnitResourcefileFormatClass;
var Reader: TReader;
DestroyDriver: Boolean); virtual;
function DoCreateJITComponent(const NewComponentName, NewClassName,
NewUnitName: shortstring; AncestorClass: TClass;
@ -165,6 +167,7 @@ type
AncestorClass: TClass;
DisableAutoSize: boolean): integer;
function AddJITComponentFromStream(BinStream: TStream;
UnitResourcefileFormat: TUnitResourcefileFormatClass;
AncestorClass: TClass;
const NewUnitName: ShortString;
Interactive, Visible, DisableAutoSize: Boolean;
@ -830,6 +833,7 @@ begin
end;
function TJITComponentList.AddJITComponentFromStream(BinStream: TStream;
UnitResourcefileFormat: TUnitResourcefileFormatClass;
AncestorClass: TClass;
const NewUnitName: ShortString;
Interactive, Visible, DisableAutoSize: Boolean;
@ -849,7 +853,7 @@ function TJITComponentList.AddJITComponentFromStream(BinStream: TStream;
FCurReadStreamClass:=StreamClass;
DestroyDriver:=false;
InitReading;
CreateReader(AStream,Reader,DestroyDriver);
CreateReader(AStream,UnitResourcefileFormat,Reader,DestroyDriver);
{$IFDEF VerboseJITForms}
DebugLn(['TJITComponentList.AddJITComponentFromStream.ReadStream Reading: FCurReadJITComponent=',DbgSName(FCurReadJITComponent),' StreamClass=',DbgSName(StreamClass)]);
{$ENDIF}
@ -908,7 +912,7 @@ var
begin
Result:=-1;
FContextObject:=ContextObj;
NewClassName:=GetClassNameFromLRSStream(BinStream, IsInherited);
NewClassName:=UnitResourcefileFormat.GetClassNameFromStream(BinStream,IsInherited);
if IsInherited then ;
if NewClassName='' then begin
MessageDlg('No classname in stream found.',mtError,[mbOK],0);
@ -982,13 +986,14 @@ begin
end;
procedure TJITComponentList.CreateReader(BinStream: TStream;
UnitResourcefileFormat: TUnitResourcefileFormatClass;
var Reader: TReader; DestroyDriver: Boolean);
begin
{$IFDEF VerboseJITForms}
debugln('[TJITComponentList.InitReading] A');
{$ENDIF}
DestroyDriver:=false;
Reader:=CreateLRSReader(BinStream,DestroyDriver);
Reader:=UnitResourcefileFormat.CreateReader(BinStream,DestroyDriver);
// connect TReader events
Reader.OnError:=@ReaderError;
Reader.OnPropertyNotFound:=@ReaderPropertyNotFound;
@ -1142,7 +1147,7 @@ begin
SubReader:=nil;
DestroyDriver:=false;
try
CreateReader(BinStream,SubReader,DestroyDriver);
CreateReader(BinStream,TLFMUnitResourcefileFormat,SubReader,DestroyDriver);
// The stream contains only the diff to the Ancestor instance,
// => give it the Ancestor instance
SubReader.Ancestor:=Ancestor;
@ -1303,7 +1308,7 @@ begin
try
DestroyDriver:=false;
InitReading;
CreateReader(BinStream,Reader,DestroyDriver);
CreateReader(BinStream,TLFMUnitResourcefileFormat, Reader,DestroyDriver);
{$IFDEF VerboseJITForms}
debugln('[TJITComponentList.AddJITChildComponentFromStream] B');
{$ENDIF}

View File

@ -44,6 +44,7 @@ uses
LCLProc, Graphics, Controls, Forms, Menus, Dialogs,
// IDEIntf
PropEdits, PropEditUtils, ObjectInspector, IDECommands, FormEditingIntf,
UnitResources,
// IDE
LazarusIDEStrConsts, ControlSelection, Project, JITForms, MainIntf,
CustomNonFormDesigner, NonControlDesigner, FrameDesigner, ComponentReg,
@ -200,6 +201,7 @@ type
NewLeft,NewTop,NewWidth,NewHeight: Integer;
DisableAutoSize: boolean): TComponent; override;
function CreateComponentFromStream(BinStream: TStream;
UnitResourcefileFormat: TUnitResourcefileFormatClass;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean;
@ -207,6 +209,7 @@ type
DisableAutoSize: boolean = false;
ContextObj: TObject = nil): TComponent; override;
function CreateRawComponentFromStream(BinStream: TStream;
UnitResourcefileFormat: TUnitResourcefileFormatClass;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean;
@ -1402,16 +1405,18 @@ end;
function TCustomFormEditor.CreateComponentFromStream(
BinStream: TStream;
UnitResourcefileFormat: TUnitResourcefileFormatClass;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean; Visible: boolean; DisableAutoSize: boolean;
ContextObj: TObject): TComponent;
begin
Result:=CreateRawComponentFromStream(BinStream,
Result:=CreateRawComponentFromStream(BinStream, UnitResourcefileFormat,
AncestorType,NewUnitName,Interactive,Visible,DisableAutoSize,ContextObj);
end;
function TCustomFormEditor.CreateRawComponentFromStream(BinStream: TStream;
UnitResourcefileFormat: TUnitResourcefileFormatClass;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean; Visible: boolean; DisableAutoSize: boolean;
@ -1425,7 +1430,7 @@ begin
if JITList=nil then
RaiseException('TCustomFormEditor.CreateComponentFromStream ClassName='+
AncestorType.ClassName);
NewJITIndex := JITList.AddJITComponentFromStream(BinStream,
NewJITIndex := JITList.AddJITComponentFromStream(BinStream, UnitResourcefileFormat,
AncestorType,NewUnitName,Interactive,Visible,DisableAutoSize,
ContextObj);
if NewJITIndex < 0 then begin

View File

@ -20,7 +20,7 @@
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Files Count="421">
<Files Count="422">
<Item1>
<Filename Value="aboutfrm.lfm"/>
<Type Value="LFM"/>
@ -1895,6 +1895,10 @@
<Filename Value="..\debugger\watchpropertydlg.pp"/>
<UnitName Value="WatchPropertyDlg"/>
</Item421>
<Item422>
<Filename Value="lfmunitresource.pas"/>
<UnitName Value="lfmUnitResource"/>
</Item422>
</Files>
<Type Value="RunTimeOnly"/>
<RequiredPkgs Count="6">

View File

@ -54,13 +54,16 @@ uses
CodeToolsConfig, ExprEval, FileProcs, DefineTemplates,
BasicCodeTools, CodeToolsCfgScript, CodeToolManager, CodeCache,
// IDEIntf
PropEdits, CompOptsIntf, ProjectIntf, MacroIntf, MacroDefIntf, LazIDEIntf,
PropEdits, CompOptsIntf, ProjectIntf, MacroIntf, MacroDefIntf, UnitResources,
LazIDEIntf, PackageIntf, SrcEditorIntf, IDEOptionsIntf,
// synedit
SynEdit,
// IDE
CompOptsModes, ProjectResources, LazConf, W32Manifest, ProjectIcon,
LazarusIDEStrConsts, CompilerOptions,
LazarusIDEStrConsts, CompilerOptions, lfmUnitResource,
TransferMacros, EditorOptions, IDEProcs, RunParamsOpts, ProjectDefs,
FileReferenceList, EditDefineTree, PackageDefs, PackageSystem, IDEOptionsIntf,
SrcEditorIntf, IDEDialogs, PackageIntf, SynEdit;
FileReferenceList, EditDefineTree, PackageDefs, PackageSystem,
IDEDialogs;
type
TUnitInfo = class;
@ -294,6 +297,7 @@ type
FSourceDirNeedReference: boolean;
fLastDirectoryReferenced: string;
FSetBookmarLock: Integer;
FUnitResourceFileformat: TUnitResourcefileFormatClass;
function GetEditorInfo(Index: Integer): TUnitEditorInfo;
function GetHasResources:boolean;
@ -309,6 +313,7 @@ type
function GetPrevPartOfProject: TUnitInfo;
function GetPrevUnitWithComponent: TUnitInfo;
function GetPrevUnitWithEditorIndex: TUnitInfo;
function GetUnitResourceFileformat: TUnitResourcefileFormatClass;
procedure SetAutoReferenceSourceDir(const AValue: boolean);
procedure SetBuildFileIfActive(const AValue: boolean);
procedure SetDefaultSyntaxHighlighter(const AValue: TLazSyntaxHighlighter);
@ -407,6 +412,8 @@ type
procedure UpdateDefaultHighlighter(aDefaultHighlighter: TLazSyntaxHighlighter);
public
{ Properties }
property UnitResourceFileformat: TUnitResourcefileFormatClass read GetUnitResourceFileformat;
// Unit lists
property NextUnitWithEditorIndex: TUnitInfo read GetNextUnitWithEditorIndex;
property PrevUnitWithEditorIndex: TUnitInfo read GetPrevUnitWithEditorIndex;
@ -2395,6 +2402,28 @@ begin
Result:=fPrev[uilWithEditorIndex];
end;
function TUnitInfo.GetUnitResourceFileformat: TUnitResourcefileFormatClass;
var
ResourceFormats : TUnitResourcefileFormatArr;
i: integer;
begin
if not assigned(FUnitResourceFileformat) then
begin
ResourceFormats := GetUnitResourcefileFormats;
for i := 0 to high(ResourceFormats) do
begin
if ResourceFormats[i].FindResourceDirective(Source) then
begin
FUnitResourceFileformat:=ResourceFormats[i];
result := FUnitResourceFileformat;
Exit;
end;
end;
FUnitResourceFileformat := TLFMUnitResourcefileFormat;
end;
result := FUnitResourceFileformat;
end;
procedure TUnitInfo.SetAutoReferenceSourceDir(const AValue: boolean);
begin
if FAutoReferenceSourceDir=AValue then exit;

View File

@ -43,7 +43,8 @@ uses
ControlSelection, TransferMacros, EnvironmentOpts, BuildManager, Designer,
EditorMacroListViewer, KeywordFuncLists, FindRenameIdentifier, MsgView,
InputHistory, CheckLFMDlg, LCLMemManager, CodeToolManager, CodeToolsStructs,
ConvCodeTool, CodeCache, CodeTree, FindDeclarationTool, BasicCodeTools;
ConvCodeTool, CodeCache, CodeTree, FindDeclarationTool, BasicCodeTools,
UnitResources;
type
@ -2851,7 +2852,7 @@ begin
repeat
try
BinCompStream.Position:=0;
Writer:=CreateLRSWriter(BinCompStream,DestroyDriver);
Writer:=AnUnitInfo.UnitResourceFileformat.CreateWriter(BinCompStream,DestroyDriver);
// used to save lrt files
HasI18N:=IsI18NEnabled(UnitOwners);
if HasI18N then
@ -2956,7 +2957,7 @@ begin
if (not AnUnitInfo.IsVirtual) or (sfSaveToTestDir in Flags) then
begin
// save lfm file
LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,'.lfm');
LFMFilename:=AnUnitInfo.UnitResourceFileformat.GetUnitResourceFilename(AnUnitInfo.Filename);
if AnUnitInfo.IsVirtual then
LFMFilename:=AppendPathDelim(MainBuildBoss.GetTestBuildDirectory)+LFMFilename;
if LFMCode=nil then begin
@ -2991,7 +2992,7 @@ begin
+LRSStreamChunkSize;
try
BinCompStream.Position:=0;
LRSObjectBinaryToText(BinCompStream,TxtCompStream);
AnUnitInfo.UnitResourceFileformat.BinStreamToTextStream(BinCompStream,TxtCompStream);
AnUnitInfo.ComponentLastLFMStreamSize:=TxtCompStream.Size;
// stream text to file
TxtCompStream.Position:=0;
@ -3860,26 +3861,28 @@ end;
function TLazSourceFileManager.LoadResourceFile(AnUnitInfo: TUnitInfo;
var LFMCode, LRSCode: TCodeBuffer;
IgnoreSourceErrors, AutoCreateResourceCode, ShowAbort: boolean): TModalResult;
const
LfmSuffices: array[0..1] of string = ('.lfm', '.dfm');
var
LFMFilename: string;
LRSFilename: String;
ResType: TResourceType;
i: Integer;
begin
LFMCode:=nil;
LRSCode:=nil;
//DebugLn(['TLazSourceFileManager.LoadResourceFile ',AnUnitInfo.Filename,' HasResources=',AnUnitInfo.HasResources,' IgnoreSourceErrors=',IgnoreSourceErrors,' AutoCreateResourceCode=',AutoCreateResourceCode]);
// Load the lfm file (without parsing)
if not AnUnitInfo.IsVirtual then begin // and (AnUnitInfo.Component<>nil)
for i := Low(LfmSuffices) to High(LfmSuffices) do begin
LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,LfmSuffices[i]);
LFMFilename:=AnUnitInfo.UnitResourceFileformat.GetUnitResourceFilename(AnUnitInfo.Filename);
if (FileExistsUTF8(LFMFilename)) then begin
Result:=LoadCodeBuffer(LFMCode,LFMFilename,[lbfCheckIfText],ShowAbort);
if not (Result in [mrOk,mrIgnore]) then
exit;
end else begin
// Is this still being used?!?
LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,'.dfm');
if (FileExistsUTF8(LFMFilename)) then begin
Result:=LoadCodeBuffer(LFMCode,LFMFilename,[lbfCheckIfText],ShowAbort);
if not (Result in [mrOk,mrIgnore]) then
exit;
Break;
end;
end;
end;
@ -3914,18 +3917,20 @@ function TLazSourceFileManager.LoadLFM(AnUnitInfo: TUnitInfo;
OpenFlags: TOpenFlags; CloseFlags: TCloseFlags): TModalResult;
// if there is a .lfm file, open the resource
var
LFMFilename: string;
UnitResourceFilename: string;
UnitResourceFileformat: TUnitResourcefileFormatClass;
LFMBuf: TCodeBuffer;
CanAbort: boolean;
begin
CanAbort:=[ofProjectLoading,ofMultiOpen]*OpenFlags<>[];
UnitResourceFileformat:=AnUnitInfo.UnitResourceFileformat;
// Note: think about virtual and normal .lfm files.
LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,'.lfm');
if not FileExistsInIDE(LFMFilename,[pfsfOnlyEditorFiles]) then
LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,'.dfm');
UnitResourceFilename:=UnitResourceFileformat.GetUnitResourceFilename(AnUnitInfo.Filename);
if not FileExistsInIDE(UnitResourceFilename,[pfsfOnlyEditorFiles]) then
UnitResourceFilename:=ChangeFileExt(AnUnitInfo.Filename,'.dfm');
LFMBuf:=nil;
if not FileExistsInIDE(LFMFilename,[pfsfOnlyEditorFiles]) then begin
if not FileExistsInIDE(UnitResourceFilename,[pfsfOnlyEditorFiles]) then begin
// there is no LFM file -> ok
{$IFDEF IDE_DEBUG}
debugln('TLazSourceFileManager.LoadLFM there is no LFM file for "',AnUnitInfo.Filename,'"');
@ -3935,7 +3940,7 @@ begin
end;
// there is a lazarus form text file -> load it
Result:=LoadIDECodeBuffer(LFMBuf,LFMFilename,[lbfUpdateFromDisk],CanAbort);
Result:=LoadIDECodeBuffer(LFMBuf,UnitResourceFilename,[lbfUpdateFromDisk],CanAbort);
if Result<>mrOk then begin
DebugLn(['TLazSourceFileManager.LoadLFM LoadIDECodeBuffer failed']);
exit;
@ -4019,7 +4024,7 @@ begin
AnUnitInfo.HasResources:=true;
// find the classname of the LFM, and check for inherited form
QuickCheckLFMBuffer(AnUnitInfo.Source,LFMBuf,LFMType,LFMComponentName,
AnUnitInfo.UnitResourceFileformat.QuickCheckResourceBuffer(AnUnitInfo.Source,LFMBuf,LFMType,LFMComponentName,
NewClassName,LCLVersion,MissingClasses);
{$IFDEF VerboseLFMSearch}
@ -4105,7 +4110,7 @@ begin
try
if AnUnitInfo.ComponentLastBinStreamSize>0 then
BinStream.Capacity:=AnUnitInfo.ComponentLastBinStreamSize+BufSize;
LRSObjectTextToBinary(TxtLFMStream,BinStream);
AnUnitInfo.UnitResourceFileformat.TextStreamToBinStream(TxtLFMStream, BinStream);
AnUnitInfo.ComponentLastBinStreamSize:=BinStream.Size;
BinStream.Position:=0;
@ -4140,7 +4145,7 @@ begin
NewUnitName:=ExtractFileNameOnly(AnUnitInfo.Filename);
// ToDo: create AncestorBinStream(s) via hook, not via parameters
DisableAutoSize:=true;
NewComponent:=FormEditor1.CreateRawComponentFromStream(BinStream,
NewComponent:=FormEditor1.CreateRawComponentFromStream(BinStream, AnUnitInfo.UnitResourceFileformat,
AncestorType,copy(NewUnitName,1,255),true,true,DisableAutoSize,AnUnitInfo);
if (NewComponent is TControl) then begin
NewControl:=TControl(NewComponent);

View File

@ -23,7 +23,7 @@ interface
uses
Math, Classes, SysUtils, LCLProc, TypInfo, types, Forms, Controls,
LCLClasses, ProjectIntf, ComponentEditors, ObjectInspector;
LCLClasses, ProjectIntf, ComponentEditors, ObjectInspector, UnitResources;
const
ComponentPaletteImageWidth = 24;
@ -118,6 +118,7 @@ type
X,Y,W,H: Integer;
DisableAutoSize: boolean): TComponent; virtual; abstract;
function CreateComponentFromStream(BinStream: TStream;
UnitResourcefileFormat: TUnitResourcefileFormatClass;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean;

View File

@ -22,7 +22,7 @@
<Description Value="IDEIntf - the interface units for the Lazarus IDE"/>
<License Value="Modified LPGL2"/>
<Version Major="1"/>
<Files Count="70">
<Files Count="71">
<Item1>
<Filename Value="actionseditor.lfm"/>
<Type Value="LFM"/>
@ -298,12 +298,16 @@
</Item68>
<Item69>
<Filename Value="oifavoriteproperties.pas"/>
<UnitName Value="OIFavouriteProperties"/>
<UnitName Value="oifavoriteproperties"/>
</Item69>
<Item70>
<Filename Value="unitresources.pas"/>
<UnitName Value="UnitResources"/>
</Item70>
<Item71>
<Filename Value="macrodefintf.pas"/>
<UnitName Value="macrodefintf"/>
</Item70>
</Item71>
</Files>
<LazDoc Paths="docs"/>
<i18n>

View File

@ -18,7 +18,8 @@ uses
newfield, NewItemIntf, ObjectInspector, ObjInspStrConsts, PackageIntf,
ProjectIntf, ProjectResourcesIntf, PropEdits, PropEditUtils, SrcEditorIntf,
StatusBarPropEdit, StringsPropEditDlg, TextTools, TreeViewPropEdit,
CompOptsIntf, OIFavoriteProperties, MacroDefIntf, LazarusPackageIntf;
CompOptsIntf, OIFavoriteProperties, UnitResources, MacroDefIntf,
LazarusPackageIntf;
implementation