implemented getting define properties for Repair broken LFM wizard

git-svn-id: trunk@5757 -
This commit is contained in:
mattias 2004-08-09 15:46:34 +00:00
parent 966f3701b9
commit ae15cfe4a8
8 changed files with 262 additions and 96 deletions

View File

@ -60,6 +60,8 @@ type
const TheUnitName, TheUnitInFilename: string
): TCodeBuffer of object;
TOnCodeToolCheckAbort = function: boolean of object;
TOnGetDefinePropertiesForClass = procedure(Sender: TObject;
const ComponentClassName: string; var List: TStrings) of object;
TCodeToolManager = class
private
@ -83,6 +85,7 @@ type
FOnCheckAbort: TOnCodeToolCheckAbort;
FOnGatherExternalChanges: TOnGatherExternalChanges;
FOnGetDefineProperties: TOnGetDefineProperties;
FOnGetDefinePropertiesForClass: TOnGetDefinePropertiesForClass;
FOnSearchUsedUnit: TOnSearchUsedUnit;
FResourceTool: TResourceCodeTool;
FSetPropertyVariablename: string;
@ -353,6 +356,9 @@ type
// resources
property OnGetDefineProperties: TOnGetDefineProperties
read FOnGetDefineProperties write FOnGetDefineProperties;
property OnGetDefinePropertiesForClass: TOnGetDefinePropertiesForClass
read FOnGetDefinePropertiesForClass
write FOnGetDefinePropertiesForClass;
function FindLFMFileName(Code: TCodeBuffer): string;
function CheckLFM(UnitCode, LFMBuf: TCodeBuffer;
var LFMTree: TLFMTree;
@ -371,6 +377,9 @@ type
KeepPath: boolean): boolean;
function RenameIncludeDirective(Code: TCodeBuffer; LinkIndex: integer;
const NewFilename: string; KeepPath: boolean): boolean;
procedure DefaultGetDefineProperties(Sender: TObject;
const ClassContext: TFindContext; LFMNode: TLFMTreeNode;
const IdentName: string; var DefineProperties: TStrings);
// register proc
function HasInterfaceRegisterProc(Code: TCodeBuffer;
@ -489,6 +498,7 @@ constructor TCodeToolManager.Create;
begin
inherited Create;
FCheckFilesOnDisk:=true;
FOnGetDefineProperties:=@DefaultGetDefineProperties;
DefineTree:=TDefineTree.Create;
DefineTree.OnReadValue:=@OnDefineTreeReadValue;
DefinePool:=TDefinePool.Create;
@ -2189,6 +2199,20 @@ begin
end;
end;
procedure TCodeToolManager.DefaultGetDefineProperties(Sender: TObject;
const ClassContext: TFindContext; LFMNode: TLFMTreeNode;
const IdentName: string; var DefineProperties: TStrings);
var
ComponentClassName: String;
begin
if Assigned(OnGetDefinePropertiesForClass) then begin
ComponentClassName:=ClassContext.Tool.ExtractClassName(
ClassContext.Node,false);
OnGetDefinePropertiesForClass(ClassContext.Tool,ComponentClassName,
DefineProperties);
end;
end;
function TCodeToolManager.FindCreateFormStatement(Code: TCodeBuffer;
StartPos: integer;
const AClassName, AVarName: string;

View File

@ -971,7 +971,8 @@ var
ObjectNode.DefineProperties.Add('TOP');
end;
end;
Result:=ObjectNode.DefineProperties.IndexOf(IdentName)>=0;
Result:=(ObjectNode.DefineProperties<>nil)
and (ObjectNode.DefineProperties.IndexOf(IdentName)>=0);
end;
function FindLFMIdentifier(LFMNode: TLFMTreeNode;

View File

@ -207,7 +207,7 @@ var
function CheckProperties: boolean;
begin
Result:=CheckLFMBuffer(UnitCode,LFMBuffer,nil,false,false);
Result:=CheckLFMBuffer(UnitCode,LFMBuffer,nil,false,false)=mrOk;
if not Result and (CodeToolBoss.ErrorMessage<>'') then
MainIDEInterface.DoJumpToCodeToolBossError;
end;

View File

@ -80,12 +80,12 @@ type
function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer;
const OnOutput: TOnOutputString;
RootMustBeClassInIntf, ObjectsMustExists: boolean): boolean;
RootMustBeClassInIntf, ObjectsMustExists: boolean): TModalResult;
function CheckLFMText(PascalBuffer: TCodeBuffer; var LFMText: string;
const OnOutput: TOnOutputString;
RootMustBeClassInIntf, ObjectsMustExists: boolean): boolean;
RootMustBeClassInIntf, ObjectsMustExists: boolean): TModalResult;
function ShowRepairLFMWizard(LFMBuffer: TCodeBuffer;
LFMTree: TLFMTree): boolean;
LFMTree: TLFMTree): TModalResult;
implementation
@ -99,7 +99,7 @@ type
function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer;
const OnOutput: TOnOutputString;
RootMustBeClassInIntf, ObjectsMustExists: boolean): boolean;
RootMustBeClassInIntf, ObjectsMustExists: boolean): TModalResult;
var
LFMTree: TLFMTree;
@ -125,7 +125,7 @@ var
end;
end;
function FixMissingComponentClasses: boolean;
function FixMissingComponentClasses: TModalResult;
// returns true, if after adding units to uses section all errors are fixed
var
CurError: TLFMError;
@ -134,7 +134,7 @@ var
RegComp: TRegisteredComponent;
i: Integer;
begin
Result:=false;
Result:=mrCancel;
MissingObjectTypes:=TStringList.Create;
try
// collect all missing object types
@ -157,29 +157,34 @@ var
if MissingObjectTypes.Count=0 then exit;
// there are missing object types with registered component classes
if PackageEditingInterface.AddUnitDependenciesForComponentClasses(
PascalBuffer.Filename,MissingObjectTypes)<>mrOk
then
exit;
Result:=PackageEditingInterface.AddUnitDependenciesForComponentClasses(
PascalBuffer.Filename,MissingObjectTypes);
if Result<>mrOk then exit;
// check LFM again
LFMTree.Free;
LFMTree:=nil;
Result:=CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree,
RootMustBeClassInIntf,ObjectsMustExists);
if CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree,
RootMustBeClassInIntf,ObjectsMustExists)
then
Result:=mrOk;
finally
MissingObjectTypes.Free;
end;
end;
begin
Result:=mrCancel;
LFMTree:=nil;
try
Result:=CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree,
RootMustBeClassInIntf,ObjectsMustExists);
if Result then exit;
if CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree,
RootMustBeClassInIntf,ObjectsMustExists)
then begin
Result:=mrOk;
exit;
end;
Result:=FixMissingComponentClasses;
if Result then exit;
if Result in [mrAbort,mrOk] then exit;
WriteLFMErrors;
Result:=ShowRepairLFMWizard(LFMBuffer,LFMTree);
finally
@ -189,11 +194,11 @@ end;
function CheckLFMText(PascalBuffer: TCodeBuffer; var LFMText: string;
const OnOutput: TOnOutputString;
RootMustBeClassInIntf, ObjectsMustExists: boolean): boolean;
RootMustBeClassInIntf, ObjectsMustExists: boolean): TModalResult;
var
LFMBuf: TCodeBuffer;
begin
Result:=false;
Result:=mrCancel;
LFMBuf:=CodeToolBoss.CreateTempFile('temp.lfm');
try
LFMBuf.Source:=LFMText;
@ -206,17 +211,16 @@ begin
end;
function ShowRepairLFMWizard(LFMBuffer: TCodeBuffer;
LFMTree: TLFMTree): boolean;
LFMTree: TLFMTree): TModalResult;
var
CheckLFMDialog: TCheckLFMDialog;
begin
Result:=false;
Result:=mrCancel;
CheckLFMDialog:=TCheckLFMDialog.Create(Application);
CheckLFMDialog.LFMTree:=LFMTree;
CheckLFMDialog.LFMSource:=LFMBuffer;
CheckLFMDialog.LoadLFM;
if CheckLFMDialog.ShowModal=mrOk then
Result:=true;
Result:=CheckLFMDialog.ShowModal;
CheckLFMDialog.Free;
end;

View File

@ -39,7 +39,7 @@ uses
MemCheck,
{$ENDIF}
// LCL+FCL
Classes, SysUtils, TypInfo, Math, Controls, Forms, Menus, Dialogs,
Classes, SysUtils, TypInfo, Math, LCLProc, Controls, Forms, Menus, Dialogs,
// components
AVL_Tree, PropEdits, ObjectInspector, IDECommands,
// IDE
@ -119,6 +119,7 @@ each control that's dropped onto the form
// component
FSelection: TPersistentSelectionList;
FObj_Inspector: TObjectInspector;
FDefineProperties: TAVLTree;
function GetPropertyEditorHook: TPropertyEditorHook;
protected
FNonControlForms: TAVLTree; // tree of TNonControlForm sorted for LookupRoot
@ -198,6 +199,10 @@ each control that's dropped onto the form
ParentControl: TWinControl): TIComponentInterface; override;
Procedure SetComponentNameAndClass(CI: TIComponentInterface;
const NewName, NewClassName: shortstring);
// define properties
procedure GetDefineProperties(const AComponentClassname: string;
List: TStrings);
// keys
function TranslateKeyToDesignerCommand(Key: word; Shift: TShiftState): word;
@ -210,8 +215,50 @@ each control that's dropped onto the form
end;
{ TDefinePropertiesCacheItem }
TDefinePropertiesCacheItem = class
public
ComponentClassname: string;
RegisteredComponent: TRegisteredComponent;
DefineProperties: TStrings;
destructor Destroy; override;
end;
{ TDefinePropertiesReader }
TDefinePropertiesReader = class(TFiler)
private
FDefinePropertyNames: TStrings;
protected
procedure AddPropertyName(const Name: string);
public
destructor Destroy; override;
procedure DefineProperty(const Name: string;
ReadData: TReaderProc; WriteData: TWriterProc;
HasData: Boolean); override;
procedure DefineBinaryProperty(const Name: string;
ReadData, WriteData: TStreamProc;
HasData: Boolean); override;
property DefinePropertyNames: TStrings read FDefinePropertyNames;
end;
{ TDefinePropertiesComponent( }
TDefinePropertiesComponent = class(TComponent)
public
procedure PublicDefineProperties(Filer: TFiler);
end;
function CompareComponentInterfaces(Data1, Data2: Pointer): integer;
function CompareComponentAndInterface(Key, Data: Pointer): integer;
function CompareDefPropCacheItems(Item1, Item2: TDefinePropertiesCacheItem): integer;
function CompareCompClassNameAndDefPropCacheItem(Key: Pointer;
Item: TDefinePropertiesCacheItem): integer;
implementation
@ -236,7 +283,19 @@ begin
Result:=integer(AComponent)-integer(CompIntf.Component);
end;
{TComponentInterface}
function CompareDefPropCacheItems(Item1, Item2: TDefinePropertiesCacheItem
): integer;
begin
Result:=CompareText(Item1.ComponentClassname,Item2.ComponentClassname);
end;
function CompareCompClassNameAndDefPropCacheItem(Key: Pointer;
Item: TDefinePropertiesCacheItem): integer;
begin
Result:=CompareText(AnsiString(Key),Item.ComponentClassname);
end;
{ TComponentInterface }
constructor TComponentInterface.Create;
begin
@ -691,6 +750,8 @@ destructor TCustomFormEditor.Destroy;
begin
FormEditingHook:=nil;
DesignerMenuItemClick:=nil;
FDefineProperties.FreeAndClear;
FreeAndNil(FDefineProperties);
FreeAndNil(JITFormList);
FreeAndNil(JITDataModuleList);
FreeAndNil(FComponentInterfaces);
@ -1341,6 +1402,73 @@ begin
AComponent.Name:=NewName;
end;
procedure TCustomFormEditor.GetDefineProperties(
const AComponentClassname: string; List: TStrings);
var
CacheItem: TDefinePropertiesCacheItem;
AComponent: TComponent;
DefinePropertiesReader: TDefinePropertiesReader;
ANode: TAVLTreeNode;
begin
List.Clear;
if FDefineProperties=nil then
FDefineProperties:=TAVLTree.Create(@CompareDefPropCacheItems);
ANode:=FDefineProperties.FindKey(PChar(AComponentClassname),
@CompareCompClassNameAndDefPropCacheItem);
if ANode=nil then begin
// cache component class, try to retrieve the define properties
CacheItem:=TDefinePropertiesCacheItem.Create;
CacheItem.ComponentClassname:=AComponentClassname;
FDefineProperties.Add(CacheItem);
CacheItem.RegisteredComponent:=IDEComponentPalette.FindComponent(
AComponentClassname);
if (CacheItem.RegisteredComponent<>nil)
and (CacheItem.RegisteredComponent.ComponentClass<>nil) then begin
// try creating a component class and call DefineProperties
AComponent:=nil;
DefinePropertiesReader:=nil;
try
try
AComponent:=CacheItem.RegisteredComponent.ComponentClass.Create(nil);
DefinePropertiesReader:=TDefinePropertiesReader.Create;
TDefinePropertiesComponent(AComponent).PublicDefineProperties(
DefinePropertiesReader);
except
on E: Exception do begin
debugln('TCustomFormEditor.GetDefineProperties Error creating ',
CacheItem.RegisteredComponent.ComponentClass.Classname,
': ',E.Message);
end;
end;
try
AComponent.Free;
except
on E: Exception do begin
debugln('TCustomFormEditor.GetDefineProperties Error freeing ',
CacheItem.RegisteredComponent.ComponentClass.Classname,
': ',E.Message);
end;
end;
finally
// cache defined properties
if (DefinePropertiesReader<>nil)
and (DefinePropertiesReader.DefinePropertyNames<>nil) then begin
CacheItem.DefineProperties:=TStringList.Create;
CacheItem.DefineProperties.Assign(
DefinePropertiesReader.DefinePropertyNames);
debugln('TCustomFormEditor.GetDefineProperties CompClass=',AComponentClassname,
' DefineProps=',CacheItem.DefineProperties.Text);
DefinePropertiesReader.Free;
end;
end;
end;
end else begin
CacheItem:=TDefinePropertiesCacheItem(ANode.Data);
end;
if CacheItem.DefineProperties<>nil then
List.Assign(CacheItem.DefineProperties);
end;
procedure TCustomFormEditor.JITListReaderError(Sender: TObject;
ErrorType: TJITFormError; var Action: TModalResult);
var
@ -1526,5 +1654,47 @@ begin
end;
{ TDefinePropertiesCacheItem }
destructor TDefinePropertiesCacheItem.Destroy;
begin
DefineProperties.Free;
inherited Destroy;
end;
{ TDefinePropertiesReader }
procedure TDefinePropertiesReader.AddPropertyName(const Name: string);
begin
if FDefinePropertyNames=nil then FDefinePropertyNames:=TStringList.Create;
if FDefinePropertyNames.IndexOf(Name)<=0 then
FDefinePropertyNames.Add(Name);
end;
destructor TDefinePropertiesReader.Destroy;
begin
FDefinePropertyNames.Free;
inherited Destroy;
end;
procedure TDefinePropertiesReader.DefineProperty(const Name: string;
ReadData: TReaderProc; WriteData: TWriterProc; HasData: Boolean);
begin
AddPropertyName(Name);
end;
procedure TDefinePropertiesReader.DefineBinaryProperty(const Name: string;
ReadData, WriteData: TStreamProc; HasData: Boolean);
begin
AddPropertyName(Name);
end;
{ TDefinePropertiesComponent }
procedure TDefinePropertiesComponent.PublicDefineProperties(Filer: TFiler);
begin
DefineProperties(Filer);
end;
end.

View File

@ -386,12 +386,14 @@ type
var Abort: boolean);
procedure OnAfterCodeToolBossApplyChanges(Manager: TCodeToolManager);
function OnCodeToolBossSearchUsedUnit(const SrcFilename: string;
const TheUnitName, TheUnitInFilename: string): TCodeBuffer;
const TheUnitName, TheUnitInFilename: string): TCodeBuffer;
function OnCodeToolBossCheckAbort: boolean;
procedure CodeToolBossGetVirtualDirectoryAlias(Sender: TObject;
var RealDir: string);
var RealDir: string);
procedure CodeToolBossGetVirtualDirectoryDefines(DefTree: TDefineTree;
DirDef: TDirectoryDefines);
DirDef: TDirectoryDefines);
procedure OnCodeToolBossGetDefineProperties(Sender: TObject;
const ComponentClassName: string; var List: TStrings);
function MacroFunctionProject(Data: Pointer): boolean;
procedure OnCompilerGraphStampIncreased;
@ -6550,8 +6552,8 @@ begin
DoArrangeSourceEditorAndMessageView(false);
// parse the LFM file and the pascal unit
if not CheckLFMBuffer(PascalBuf,LFMUnitInfo.Source,@MessagesView.AddMsg,
true,true)
if CheckLFMBuffer(PascalBuf,LFMUnitInfo.Source,@MessagesView.AddMsg,
true,true)<>mrOk
then begin
DoJumpToCompilerMessage(-1,true);
end;
@ -6638,7 +6640,7 @@ begin
if HasDFMFile and (LFMCode=nil) then
writeln('WARNING: TMainIDE.DoConvertDelphiUnit unable to load LFMCode');
if (LFMCode<>nil)
and (not CheckLFMBuffer(UnitCode,LFMCode,@MessagesView.AddMsg,true,true))
and (CheckLFMBuffer(UnitCode,LFMCode,@MessagesView.AddMsg,true,true)<>mrOk)
then begin
DoJumpToCompilerMessage(-1,true);
exit;
@ -8575,6 +8577,7 @@ begin
OnBeforeApplyChanges:=@OnBeforeCodeToolBossApplyChanges;
OnAfterApplyChanges:=@OnAfterCodeToolBossApplyChanges;
OnSearchUsedUnit:=@OnCodeToolBossSearchUsedUnit;
OnGetDefinePropertiesForClass:=@OnCodeToolBossGetDefineProperties;
end;
CodeToolsOpts.AssignGlobalDefineTemplatesToTree(CodeToolBoss.DefineTree);
@ -8776,6 +8779,13 @@ begin
Project1.GetVirtualDefines(DefTree,DirDef);
end;
procedure TMainIDE.OnCodeToolBossGetDefineProperties(Sender: TObject;
const ComponentClassName: string; var List: TStrings);
begin
List:=TStringList.Create;
FormEditor1.GetDefineProperties(ComponentClassName,List);
end;
function TMainIDE.MacroFunctionProject(Data: Pointer): boolean;
var
FuncData: PReadFunctionData;
@ -10533,6 +10543,9 @@ end.
{ =============================================================================
$Log$
Revision 1.749 2004/08/09 15:46:34 mattias
implemented getting define properties for Repair broken LFM wizard
Revision 1.748 2004/08/08 21:52:01 mattias
change component class dlg now works with child controls

View File

@ -212,7 +212,6 @@ else
UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
endif
PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages/base $(FPCDIR)/packages/extra)
override TARGET_DIRS+=registration
override CLEAN_FILES+=$(wildcard ./units/*$(OEXT)) $(wildcard ./units/*$(PPUEXT)) $(wildcard ./units/*$(RSTEXT))
ifdef REQUIRE_UNITSDIR
override UNITSDIR+=$(REQUIRE_UNITSDIR)
@ -1391,68 +1390,24 @@ endif
fpc_makefile_sub2: $(addsuffix _makefile_dirs,$(TARGET_DIRS) $(TARGET_EXAMPLEDIRS))
fpc_makefile_dirs: fpc_makefile_sub1 fpc_makefile_sub2
fpc_makefiles: fpc_makefile fpc_makefile_dirs
TARGET_DIRS_REGISTRATION=1
ifdef TARGET_DIRS_REGISTRATION
registration_all:
$(MAKE) -C registration all
registration_debug:
$(MAKE) -C registration debug
registration_smart:
$(MAKE) -C registration smart
registration_release:
$(MAKE) -C registration release
registration_examples:
$(MAKE) -C registration examples
registration_shared:
$(MAKE) -C registration shared
registration_install:
$(MAKE) -C registration install
registration_sourceinstall:
$(MAKE) -C registration sourceinstall
registration_exampleinstall:
$(MAKE) -C registration exampleinstall
registration_distinstall:
$(MAKE) -C registration distinstall
registration_zipinstall:
$(MAKE) -C registration zipinstall
registration_zipsourceinstall:
$(MAKE) -C registration zipsourceinstall
registration_zipexampleinstall:
$(MAKE) -C registration zipexampleinstall
registration_zipdistinstall:
$(MAKE) -C registration zipdistinstall
registration_clean:
$(MAKE) -C registration clean
registration_distclean:
$(MAKE) -C registration distclean
registration_cleanall:
$(MAKE) -C registration cleanall
registration_info:
$(MAKE) -C registration info
registration_makefiles:
$(MAKE) -C registration makefiles
registration:
$(MAKE) -C registration all
.PHONY: registration_all registration_debug registration_smart registration_release registration_examples registration_shared registration_install registration_sourceinstall registration_exampleinstall registration_distinstall registration_zipinstall registration_zipsourceinstall registration_zipexampleinstall registration_zipdistinstall registration_clean registration_distclean registration_cleanall registration_info registration_makefiles registration
endif
all: $(addsuffix _all,$(TARGET_DIRS))
debug: $(addsuffix _debug,$(TARGET_DIRS))
smart: $(addsuffix _smart,$(TARGET_DIRS))
release: $(addsuffix _release,$(TARGET_DIRS))
examples: $(addsuffix _examples,$(TARGET_DIRS))
shared: $(addsuffix _shared,$(TARGET_DIRS))
install: $(addsuffix _install,$(TARGET_DIRS))
sourceinstall: $(addsuffix _sourceinstall,$(TARGET_DIRS))
exampleinstall: $(addsuffix _exampleinstall,$(TARGET_DIRS))
distinstall: $(addsuffix _distinstall,$(TARGET_DIRS))
zipinstall: $(addsuffix _zipinstall,$(TARGET_DIRS))
zipsourceinstall: $(addsuffix _zipsourceinstall,$(TARGET_DIRS))
zipexampleinstall: $(addsuffix _zipexampleinstall,$(TARGET_DIRS))
zipdistinstall: $(addsuffix _zipdistinstall,$(TARGET_DIRS))
clean: fpc_clean $(addsuffix _clean,$(TARGET_DIRS))
distclean: fpc_distclean $(addsuffix _distclean,$(TARGET_DIRS))
all:
debug:
smart:
release:
examples:
shared:
install:
sourceinstall:
exampleinstall:
distinstall:
zipinstall:
zipsourceinstall:
zipexampleinstall:
zipdistinstall:
clean: fpc_clean
distclean: fpc_distclean
info: fpc_info
makefiles: fpc_makefiles $(addsuffix _makefiles,$(TARGET_DIRS))
makefiles: fpc_makefiles
.PHONY: all debug smart release examples shared install sourceinstall exampleinstall distinstall zipinstall zipsourceinstall zipexampleinstall zipdistinstall clean distclean info makefiles
ifneq ($(wildcard fpcmake.loc),)
include fpcmake.loc

View File

@ -4,7 +4,6 @@
#
[target]
dirs=registration
[clean]
files=$(wildcard ./units/*$(OEXT)) $(wildcard ./units/*$(PPUEXT)) $(wildcard ./units/*$(RSTEXT))