replaced TDBEdit.WMKillFocus by EditingDone, Change Class basically working

git-svn-id: trunk@5751 -
This commit is contained in:
mattias 2004-08-08 20:51:15 +00:00
parent 674612146d
commit dffc4d0999
13 changed files with 384 additions and 112 deletions

View File

@ -353,7 +353,7 @@ type
read FOnGetDefineProperties write FOnGetDefineProperties; read FOnGetDefineProperties write FOnGetDefineProperties;
function FindLFMFileName(Code: TCodeBuffer): string; function FindLFMFileName(Code: TCodeBuffer): string;
function CheckLFM(UnitCode, LFMBuf: TCodeBuffer; function CheckLFM(UnitCode, LFMBuf: TCodeBuffer;
var LFMTree: TLFMTree): boolean; var LFMTree: TLFMTree; RootMustBeClassInIntf: boolean): boolean;
function FindNextResourceFile(Code: TCodeBuffer; function FindNextResourceFile(Code: TCodeBuffer;
var LinkIndex: integer): TCodeBuffer; var LinkIndex: integer): TCodeBuffer;
function AddLazarusResourceHeaderComment(Code: TCodeBuffer; function AddLazarusResourceHeaderComment(Code: TCodeBuffer;
@ -610,6 +610,7 @@ begin
TempFilename:=VirtualTempDir+PathDelim+IntToStr(i)+PathDelim+AFilename; TempFilename:=VirtualTempDir+PathDelim+IntToStr(i)+PathDelim+AFilename;
Result:=FindFile(TempFilename); Result:=FindFile(TempFilename);
if (Result<>nil) and (Result.ReferenceCount=0) then exit; if (Result<>nil) and (Result.ReferenceCount=0) then exit;
inc(i);
until Result=nil; until Result=nil;
Result:=SourceCache.CreateFile(TempFilename); Result:=SourceCache.CreateFile(TempFilename);
Result.IncrementRefCount; Result.IncrementRefCount;
@ -2031,7 +2032,7 @@ begin
end; end;
function TCodeToolManager.CheckLFM(UnitCode, LFMBuf: TCodeBuffer; function TCodeToolManager.CheckLFM(UnitCode, LFMBuf: TCodeBuffer;
var LFMTree: TLFMTree): boolean; var LFMTree: TLFMTree; RootMustBeClassInIntf: boolean): boolean;
begin begin
Result:=false; Result:=false;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
@ -2039,7 +2040,8 @@ begin
{$ENDIF} {$ENDIF}
if not InitCurCodeTool(UnitCode) then exit; if not InitCurCodeTool(UnitCode) then exit;
try try
Result:=FCurCodeTool.CheckLFM(LFMBuf,LFMTree,OnGetDefineProperties); Result:=FCurCodeTool.CheckLFM(LFMBuf,LFMTree,OnGetDefineProperties,
RootMustBeClassInIntf);
except except
on e: Exception do HandleException(e); on e: Exception do HandleException(e);
end; end;

View File

@ -248,6 +248,7 @@ type
function FindErrorAtLine(Line: integer): TLFMError; function FindErrorAtLine(Line: integer): TLFMError;
function FindErrorAtNode(Node: TLFMTreeNode): TLFMError; function FindErrorAtNode(Node: TLFMTreeNode): TLFMError;
function FindError(ErrorTypes: TLFMErrorTypes): TLFMError; function FindError(ErrorTypes: TLFMErrorTypes): TLFMError;
function FirstErrorAsString: string;
end; end;
const const
@ -366,6 +367,12 @@ begin
Result:=Result.NextError; Result:=Result.NextError;
end; end;
function TLFMTree.FirstErrorAsString: string;
begin
Result:='';
if FirstError<>nil then Result:=FirstError.ErrorMessage;
end;
procedure TLFMTree.ProcessValue; procedure TLFMTree.ProcessValue;
var var
s: String; s: String;

View File

@ -116,7 +116,8 @@ type
KeepPath: boolean; KeepPath: boolean;
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
function CheckLFM(LFMBuf: TCodeBuffer; var LFMTree: TLFMTree; function CheckLFM(LFMBuf: TCodeBuffer; var LFMTree: TLFMTree;
const OnGetDefineProperties: TOnGetDefineProperties): boolean; const OnGetDefineProperties: TOnGetDefineProperties;
RootMustBeClassInIntf: boolean): boolean;
// Application.Createform statements // Application.Createform statements
function FindCreateFormStatement(StartPos: integer; function FindCreateFormStatement(StartPos: integer;
@ -892,7 +893,8 @@ begin
end; end;
function TStandardCodeTool.CheckLFM(LFMBuf: TCodeBuffer; var LFMTree: TLFMTree; function TStandardCodeTool.CheckLFM(LFMBuf: TCodeBuffer; var LFMTree: TLFMTree;
const OnGetDefineProperties: TOnGetDefineProperties): boolean; const OnGetDefineProperties: TOnGetDefineProperties;
RootMustBeClassInIntf: boolean): boolean;
var var
RootContext: TFindContext; RootContext: TFindContext;
@ -1147,7 +1149,6 @@ var
DefaultErrorPosition); DefaultErrorPosition);
exit; exit;
end; end;
end; end;
procedure CheckLFMProperty(LFMProperty: TLFMPropertyNode; procedure CheckLFMProperty(LFMProperty: TLFMPropertyNode;
@ -1220,6 +1221,43 @@ var
end; end;
Result:=true; Result:=true;
end; end;
function FindClassContext(const ClassName: string): TFindContext;
var
Params: TFindDeclarationParams;
Identifier: PChar;
OldInput: TFindDeclarationInput;
StartTool: TStandardCodeTool;
begin
Result:=CleanFindContext;
Params:=TFindDeclarationParams.Create;
StartTool:=Self;
Identifier:=PChar(ClassName);
try
Params.Flags:=[fdfExceptionOnNotFound,
fdfSearchInParentNodes,
fdfExceptionOnPredefinedIdent,fdfIgnoreMissingParams,
fdfIgnoreOverloadedProcs];
Params.ContextNode:=FindInterfaceNode;
if Params.ContextNode=nil then
Params.ContextNode:=FindMainUsesSection;
Params.SetIdentifier(StartTool,Identifier,nil);
try
Params.Save(OldInput);
if FindIdentifierInContext(Params) then begin
Params.Load(OldInput);
Result:=Params.NewCodeTool.FindBaseTypeOfNode(Params,Params.NewNode);
if (Result.Node=nil) or (Result.Node.Desc<>ctnClass) then
Result:=CleanFindContext;
end;
except
// ignore search/parse errors
on E: ECodeToolError do ;
end;
finally
Params.Free;
end;
end;
function CheckLFMRoot(RootLFMNode: TLFMTreeNode): boolean; function CheckLFMRoot(RootLFMNode: TLFMTreeNode): boolean;
var var
@ -1245,17 +1283,21 @@ var
end; end;
// find root type // find root type
RootClassNode:=FindClassNodeInInterface(LookupRootTypeName,true,false,false); if RootMustBeClassInIntf then begin
RootClassNode:=FindClassNodeInInterface(LookupRootTypeName,true,false,false);
RootContext:=CleanFindContext;
RootContext.Node:=RootClassNode;
RootContext.Tool:=Self;
end else begin
RootContext:=FindClassContext(LookupRootTypeName);
RootClassNode:=RootContext.Node;
end;
if RootClassNode=nil then begin if RootClassNode=nil then begin
LFMTree.AddError(lfmeMissingRoot,LookupRootLFMNode, LFMTree.AddError(lfmeMissingRoot,LookupRootLFMNode,
'type '+LookupRootLFMNode.TypeName+' not found', 'type '+LookupRootLFMNode.TypeName+' not found',
LookupRootLFMNode.TypeNamePosition); LookupRootLFMNode.TypeNamePosition);
exit; exit;
end; end;
RootContext:=CleanFindContext;
RootContext.Node:=RootClassNode;
RootContext.Tool:=Self;
Result:=CheckLFMObjectValues(LookupRootLFMNode,RootContext); Result:=CheckLFMObjectValues(LookupRootLFMNode,RootContext);
end; end;

View File

@ -27,6 +27,10 @@
Abstract: Abstract:
Functions and Dialog to change the class of a designer component. Functions and Dialog to change the class of a designer component.
ToDo:
- add uses and package of new class if needed
- test controls with childs
} }
unit ChangeClassDialog; unit ChangeClassDialog;
@ -35,11 +39,11 @@ unit ChangeClassDialog;
interface interface
uses uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
Buttons, AVGLvlTree, LFMTrees, CodeCache, CodeToolManager, StdCtrls, Buttons, AVGLvlTree, LFMTrees, CodeCache, CodeToolManager,
// IDE // IDE
SrcEditorIntf, PropEdits, LazarusIDEStrConsts, ComponentReg, FormEditingIntf, SrcEditorIntf, PropEdits, LazarusIDEStrConsts, ComponentReg, ComponentEditors,
CheckLFMDlg, Project, MainIntf; FormEditingIntf, CheckLFMDlg, Project, MainIntf;
type type
TChangeClassDlg = class(TForm) TChangeClassDlg = class(TForm)
@ -132,7 +136,8 @@ var
// stream selection // stream selection
ComponentStream:=TMemoryStream.Create; ComponentStream:=TMemoryStream.Create;
if not FormEditingHook.SaveSelectionToStream(ComponentStream) then begin if (not FormEditingHook.SaveSelectionToStream(ComponentStream))
or (ComponentStream.Size=0) then begin
ShowAbortMessage('Unable to stream selected components.'); ShowAbortMessage('Unable to stream selected components.');
exit; exit;
end; end;
@ -142,6 +147,7 @@ var
function ParseLFMStream: boolean; function ParseLFMStream: boolean;
var var
SrcEdit: TSourceEditorInterface; SrcEdit: TSourceEditorInterface;
Msg: String;
begin begin
Result:=false; Result:=false;
if not CodeToolBoss.GatherExternalChanges then begin if not CodeToolBoss.GatherExternalChanges then begin
@ -155,15 +161,23 @@ var
end; end;
UnitCode:=UnitInfo.Source; UnitCode:=UnitInfo.Source;
LFMBuffer:=CodeToolBoss.CreateTempFile('changeclass.lfm'); LFMBuffer:=CodeToolBoss.CreateTempFile('changeclass.lfm');
if LFMBuffer=nil then begin if (LFMBuffer=nil) or (ComponentStream.Size=0) then begin
ShowAbortMessage('Unable to create temporary lfm buffer.'); ShowAbortMessage('Unable to create temporary lfm buffer.');
exit; exit;
end; end;
if not CodeToolBoss.CheckLFM(UnitCode,LFMBuffer,LFMTree) then begin ComponentStream.Position:=0;
LFMBuffer.LoadFromStream(ComponentStream);
if not CodeToolBoss.CheckLFM(UnitCode,LFMBuffer,LFMTree,false) then begin
debugln('ChangePersistentClass-Before--------------------------------------------');
debugln(LFMBuffer.Source);
debugln('ChangePersistentClass-Before--------------------------------------------');
if CodeToolBoss.ErrorMessage<>'' then if CodeToolBoss.ErrorMessage<>'' then
MainIDEInterface.DoJumpToCodeToolBossError MainIDEInterface.DoJumpToCodeToolBossError
else else begin
ShowAbortMessage('Error parsing lfm component stream.'); Msg:='Error parsing lfm component stream.';
if LFMTree<>nil then Msg:=Msg+#13#13+LFMTree.FirstErrorAsString+#13;
ShowAbortMessage(Msg);
end;
exit; exit;
end; end;
Result:=true; Result:=true;
@ -196,19 +210,30 @@ var
function CheckProperties: boolean; function CheckProperties: boolean;
begin begin
Result:=CheckLFMBuffer(UnitCode,LFMBuffer,nil); Result:=CheckLFMBuffer(UnitCode,LFMBuffer,nil,false);
if not Result and (CodeToolBoss.ErrorMessage<>'') then if not Result and (CodeToolBoss.ErrorMessage<>'') then
MainIDEInterface.DoJumpToCodeToolBossError; MainIDEInterface.DoJumpToCodeToolBossError;
end; end;
function DeleteSelection: boolean;
begin
Result:=false;
end;
function InsertStreamedSelection: boolean; function InsertStreamedSelection: boolean;
var
MemStream: TMemoryStream;
begin begin
Result:=false; Result:=false;
if LFMBuffer.SourceLength=0 then exit;
MemStream:=TMemoryStream.Create;
try
debugln('ChangePersistentClass-After--------------------------------------------');
debugln(LFMBuffer.Source);
debugln('ChangePersistentClass-After--------------------------------------------');
LFMBuffer.SaveToStream(MemStream);
MemStream.Position:=0;
Result:=FormEditingHook.InsertFromStream(MemStream,nil,[cpsfReplace]);
if not Result then
ShowAbortMessage('Replacing selection failed.');
finally
MemStream.Free;
end;
end; end;
begin begin
@ -231,7 +256,6 @@ begin
if not ParseLFMStream then exit; if not ParseLFMStream then exit;
if not ChangeClassName then exit; if not ChangeClassName then exit;
if not CheckProperties then exit; if not CheckProperties then exit;
if not DeleteSelection then exit;
if not InsertStreamedSelection then exit; if not InsertStreamedSelection then exit;
finally finally
ComponentStream.Free; ComponentStream.Free;

View File

@ -53,7 +53,7 @@ type
TOnPersistentAdded = procedure(Sender: TObject; APersistent: TPersistent; TOnPersistentAdded = procedure(Sender: TObject; APersistent: TPersistent;
ComponentClass: TRegisteredComponent) of object; ComponentClass: TRegisteredComponent) of object;
TOnPasteComponent = procedure(Sender: TObject; LookupRoot: TComponent; TOnPasteComponent = procedure(Sender: TObject; LookupRoot: TComponent;
TxtCompStream: TStream; ParentControl: TWinControl; TxtCompStream: TStream; Parent: TComponent;
var NewComponent: TComponent) of object; var NewComponent: TComponent) of object;
TOnRemovePersistent = procedure(Sender: TObject; APersistent: TPersistent) TOnRemovePersistent = procedure(Sender: TObject; APersistent: TPersistent)
of object; of object;
@ -166,7 +166,7 @@ type
function HandleSetCursor(var TheMessage: TLMessage): boolean; function HandleSetCursor(var TheMessage: TLMessage): boolean;
// procedures for working with components and persistents // procedures for working with components and persistents
procedure DoDeleteSelectedPersistents; function DoDeleteSelectedPersistents: boolean;
procedure DoDeletePersistent(APersistent: TPersistent; FreeIt: boolean); procedure DoDeletePersistent(APersistent: TPersistent; FreeIt: boolean);
procedure MarkPersistentForDeletion(APersistent: TPersistent); procedure MarkPersistentForDeletion(APersistent: TPersistent);
function PersistentIsMarkedForDeletion(APersistent: TPersistent): boolean; function PersistentIsMarkedForDeletion(APersistent: TPersistent): boolean;
@ -175,7 +175,11 @@ type
Procedure NudgeSize(DiffX, DiffY: Integer); Procedure NudgeSize(DiffX, DiffY: Integer);
procedure SelectParentOfSelection; procedure SelectParentOfSelection;
function DoCopySelectionToClipboard: boolean; function DoCopySelectionToClipboard: boolean;
procedure DoPasteSelectionFromClipboard; function GetPasteParent: TComponent;
function DoPasteSelectionFromClipboard(Flags: TComponentPasteSelectionFlags
): boolean;
function DoInsertFromStream(s: TStream; PasteParent: TComponent;
Flags: TComponentPasteSelectionFlags): Boolean;
procedure DoShowTabOrderEditor; procedure DoShowTabOrderEditor;
procedure DoShowChangeClassDialog; procedure DoShowChangeClassDialog;
procedure GiveComponentsNames; procedure GiveComponentsNames;
@ -216,12 +220,14 @@ type
procedure Modified; override; procedure Modified; override;
Procedure SelectOnlyThisComponent(AComponent:TComponent); override; Procedure SelectOnlyThisComponent(AComponent:TComponent); override;
procedure CopySelection; override; function CopySelection: boolean; override;
procedure CutSelection; override; function CutSelection: boolean; override;
function CanPaste: Boolean; override; function CanPaste: Boolean; override;
procedure PasteSelection; override; function PasteSelection(Flags: TComponentPasteSelectionFlags): boolean; override;
procedure DeleteSelection; override; function DeleteSelection: boolean; override;
function CopySelectionToStream(AllComponentsStream: TStream): boolean; override; function CopySelectionToStream(AllComponentsStream: TStream): boolean; override;
function InsertFromStream(s: TStream; Parent: TComponent;
Flags: TComponentPasteSelectionFlags): Boolean; override;
function InvokeComponentEditor(AComponent: TComponent; function InvokeComponentEditor(AComponent: TComponent;
MenuIndex: integer): boolean; override; MenuIndex: integer): boolean; override;
procedure DoProcessCommand(Sender: TObject; var Command: word; procedure DoProcessCommand(Sender: TObject; var Command: word;
@ -513,6 +519,12 @@ begin
Result:=true; Result:=true;
end; end;
function TDesigner.InsertFromStream(s: TStream; Parent: TComponent;
Flags: TComponentPasteSelectionFlags): Boolean;
begin
Result:=DoInsertFromStream(s,Parent,Flags);
end;
function TDesigner.DoCopySelectionToClipboard: boolean; function TDesigner.DoCopySelectionToClipboard: boolean;
var var
AllComponentsStream: TMemoryStream; AllComponentsStream: TMemoryStream;
@ -549,34 +561,58 @@ begin
Result:=true; Result:=true;
end; end;
procedure TDesigner.DoPasteSelectionFromClipboard; function TDesigner.GetPasteParent: TComponent;
var
i: Integer;
begin
Result:=nil;
for i:=0 to ControlSelection.Count-1 do begin
if (ControlSelection[i].IsTWinControl)
and (csAcceptsControls in
TWinControl(ControlSelection[i].Persistent).ControlStyle)
and (not ControlSelection[i].ParentInSelection) then begin
Result:=TWinControl(ControlSelection[i].Persistent);
break;
end;
end;
if (Result=nil)
and (FLookupRoot is TWinControl) then
Result:=TWinControl(FLookupRoot);
end;
function TDesigner.DoPasteSelectionFromClipboard(
Flags: TComponentPasteSelectionFlags): boolean;
var
PasteParent: TComponent;
AllComponentText: string;
CurTextCompStream: TMemoryStream;
begin
Result:=false;
if not CanPaste then exit;
// read component stream from clipboard
AllComponentText:=ClipBoard.AsText;
if AllComponentText='' then exit;
CurTextCompStream:=TMemoryStream.Create;
try
CurTextCompStream.Write(AllComponentText[1],length(AllComponentText));
PasteParent:=GetPasteParent;
if not DoInsertFromStream(CurTextCompStream,PasteParent,Flags) then
exit;
finally
CurTextCompStream.Free;
end;
Result:=true;
end;
function TDesigner.DoInsertFromStream(s: TStream;
PasteParent: TComponent; Flags: TComponentPasteSelectionFlags): Boolean;
var var
AllComponentText: string; AllComponentText: string;
StartPos: Integer; StartPos: Integer;
EndPos: Integer; EndPos: Integer;
CurTextCompStream: TStream; CurTextCompStream: TStream;
PasteParent: TWinControl;
NewSelection: TControlSelection; NewSelection: TControlSelection;
l: Integer;
procedure GetPasteParent;
var
i: Integer;
begin
if PasteParent<>nil then exit;
for i:=0 to ControlSelection.Count-1 do begin
if (ControlSelection[i].IsTWinControl)
and (csAcceptsControls in
TWinControl(ControlSelection[i].Persistent).ControlStyle)
and (not ControlSelection[i].ParentInSelection) then begin
PasteParent:=TWinControl(ControlSelection[i].Persistent);
break;
end;
end;
if (PasteParent=nil)
and (FLookupRoot is TWinControl) then
PasteParent:=TWinControl(FLookupRoot);
end;
procedure FindUniquePosition(AComponent: TComponent); procedure FindUniquePosition(AComponent: TComponent);
var var
@ -643,7 +679,8 @@ var
// add new component to new selection // add new component to new selection
NewSelection.Add(NewComponent); NewSelection.Add(NewComponent);
// set new nice bounds // set new nice bounds
FindUniquePosition(NewComponent); if cpsfFindUniquePositions in Flags then
FindUniquePosition(NewComponent);
// finish adding component // finish adding component
NotifyPersistentAdded(NewComponent); NotifyPersistentAdded(NewComponent);
Modified; Modified;
@ -653,16 +690,18 @@ var
end; end;
begin begin
if not CanPaste then exit; Result:=false;
if (cpsfReplace in Flags) and (not DeleteSelection) then exit;
PasteParent:=nil; if PasteParent=nil then PasteParent:=GetPasteParent;
GetPasteParent;
NewSelection:=TControlSelection.Create; NewSelection:=TControlSelection.Create;
try try
// read component stream from clipboard // read component stream from clipboard
AllComponentText:=ClipBoard.AsText; if (s.Size<=S.Position) then exit;
if AllComponentText='' then exit; l:=s.Size-s.Position;
SetLength(AllComponentText,l);
s.Read(AllComponentText[1],length(AllComponentText));
StartPos:=1; StartPos:=1;
EndPos:=StartPos; EndPos:=StartPos;
@ -682,9 +721,9 @@ begin
inc(EndPos); inc(EndPos);
// extract text for the current component // extract text for the current component
{$IFDEF VerboseDesigner} {$IFDEF VerboseDesigner}
writeln('TDesigner.DoPasteSelectionFromClipboard=============================='); writeln('TDesigner.DoInsertFromStream==============================');
writeln(copy(AllComponentText,StartPos,EndPos-StartPos)); writeln(copy(AllComponentText,StartPos,EndPos-StartPos));
writeln('TDesigner.DoPasteSelectionFromClipboard=============================='); writeln('TDesigner.DoInsertFromStream==============================');
{$ENDIF} {$ENDIF}
CurTextCompStream:=TMemoryStream.Create; CurTextCompStream:=TMemoryStream.Create;
@ -709,6 +748,7 @@ begin
ControlSelection.Assign(NewSelection); ControlSelection.Assign(NewSelection);
NewSelection.Free; NewSelection.Free;
end; end;
Result:=true;
end; end;
procedure TDesigner.DoShowTabOrderEditor; procedure TDesigner.DoShowTabOrderEditor;
@ -754,15 +794,16 @@ begin
ControlSelection.AssignPersistent(AComponent); ControlSelection.AssignPersistent(AComponent);
end; end;
procedure TDesigner.CopySelection; function TDesigner.CopySelection: boolean;
begin begin
DoCopySelectionToClipboard; Result:=DoCopySelectionToClipboard;
end; end;
procedure TDesigner.CutSelection; function TDesigner.CutSelection: boolean;
begin begin
if DoCopySelectionToClipboard then Result:=DoCopySelectionToClipboard;
DoDeleteSelectedPersistents; if Result then
Result:=DoDeleteSelectedPersistents;
end; end;
function TDesigner.CanPaste: Boolean; function TDesigner.CanPaste: Boolean;
@ -772,14 +813,15 @@ begin
and (not (csDestroying in FLookupRoot.ComponentState)); and (not (csDestroying in FLookupRoot.ComponentState));
end; end;
procedure TDesigner.PasteSelection; function TDesigner.PasteSelection(
Flags: TComponentPasteSelectionFlags): boolean;
begin begin
DoPasteSelectionFromClipboard; Result:=DoPasteSelectionFromClipboard(Flags);
end; end;
procedure TDesigner.DeleteSelection; function TDesigner.DeleteSelection: boolean;
begin begin
DoDeleteSelectedPersistents; Result:=DoDeleteSelectedPersistents;
end; end;
function TDesigner.InvokeComponentEditor(AComponent: TComponent; function TDesigner.InvokeComponentEditor(AComponent: TComponent;
@ -836,7 +878,7 @@ begin
CutSelection; CutSelection;
ecPasteComponents: ecPasteComponents:
PasteSelection; PasteSelection([cpsfFindUniquePositions]);
else else
Handled:=false; Handled:=false;
@ -1564,13 +1606,15 @@ Begin
{$ENDIF} {$ENDIF}
end; end;
procedure TDesigner.DoDeleteSelectedPersistents; function TDesigner.DoDeleteSelectedPersistents: boolean;
var var
i: integer; i: integer;
APersistent: TPersistent; APersistent: TPersistent;
begin begin
Result:=true;
if (ControlSelection.Count=0) or (ControlSelection.SelectionForm<>Form) then if (ControlSelection.Count=0) or (ControlSelection.SelectionForm<>Form) then
exit; exit;
Result:=false;
if (ControlSelection.LookupRootSelected) then begin if (ControlSelection.LookupRootSelected) then begin
if ControlSelection.Count>1 then if ControlSelection.Count>1 then
MessageDlg(lisInvalidDelete, MessageDlg(lisInvalidDelete,
@ -1595,6 +1639,7 @@ begin
IgnoreDeletingPersistent.Clear; IgnoreDeletingPersistent.Clear;
Exclude(FFlags,dfDeleting); Exclude(FFlags,dfDeleting);
Modified; Modified;
Result:=true;
end; end;
procedure TDesigner.DoDeletePersistent(APersistent: TPersistent; procedure TDesigner.DoDeletePersistent(APersistent: TPersistent;
@ -1917,7 +1962,7 @@ end;
procedure TDesigner.OnPasteMenuClick(Sender: TObject); procedure TDesigner.OnPasteMenuClick(Sender: TObject);
begin begin
PasteSelection; PasteSelection([cpsfFindUniquePositions]);
end; end;
procedure TDesigner.OnTabOrderMenuClick(Sender: TObject); procedure TDesigner.OnTabOrderMenuClick(Sender: TObject);

View File

@ -78,9 +78,9 @@ type
end; end;
function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer; function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer;
const OnOutput: TOnOutputString): boolean; const OnOutput: TOnOutputString; RootMustBeClassInIntf: boolean): boolean;
function CheckLFMText(PascalBuffer: TCodeBuffer; var LFMText: string; function CheckLFMText(PascalBuffer: TCodeBuffer; var LFMText: string;
const OnOutput: TOnOutputString): boolean; const OnOutput: TOnOutputString; RootMustBeClassInIntf: boolean): boolean;
function ShowRepairLFMWizard(LFMBuffer: TCodeBuffer; function ShowRepairLFMWizard(LFMBuffer: TCodeBuffer;
LFMTree: TLFMTree): boolean; LFMTree: TLFMTree): boolean;
@ -95,7 +95,7 @@ type
end; end;
function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer; function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer;
const OnOutput: TOnOutputString): boolean; const OnOutput: TOnOutputString; RootMustBeClassInIntf: boolean): boolean;
var var
LFMTree: TLFMTree; LFMTree: TLFMTree;
@ -124,7 +124,8 @@ var
begin begin
LFMTree:=nil; LFMTree:=nil;
try try
Result:=CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree); Result:=CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree,
RootMustBeClassInIntf);
if Result then exit; if Result then exit;
WriteLFMErrors; WriteLFMErrors;
Result:=ShowRepairLFMWizard(LFMBuffer,LFMTree); Result:=ShowRepairLFMWizard(LFMBuffer,LFMTree);
@ -134,7 +135,7 @@ begin
end; end;
function CheckLFMText(PascalBuffer: TCodeBuffer; var LFMText: string; function CheckLFMText(PascalBuffer: TCodeBuffer; var LFMText: string;
const OnOutput: TOnOutputString): boolean; const OnOutput: TOnOutputString; RootMustBeClassInIntf: boolean): boolean;
var var
LFMBuf: TCodeBuffer; LFMBuf: TCodeBuffer;
begin begin
@ -142,7 +143,7 @@ begin
LFMBuf:=CodeToolBoss.CreateTempFile('temp.lfm'); LFMBuf:=CodeToolBoss.CreateTempFile('temp.lfm');
try try
LFMBuf.Source:=LFMText; LFMBuf.Source:=LFMText;
Result:=CheckLFMBuffer(PascalBuffer,LFMBuf,OnOutput); Result:=CheckLFMBuffer(PascalBuffer,LFMBuf,OnOutput,RootMustBeClassInIntf);
LFMText:=LFMBuf.Source; LFMText:=LFMBuf.Source;
finally finally
CodeToolBoss.ReleaseTempFile(LFMBuf); CodeToolBoss.ReleaseTempFile(LFMBuf);

View File

@ -141,12 +141,20 @@ each control that's dropped onto the form
destructor Destroy; override; destructor Destroy; override;
// selection // selection
Function AddSelected(Value : TComponent) : Integer; Function AddSelected(Value: TComponent) : Integer;
Procedure DeleteComponent(AComponent: TComponent; FreeComponent: boolean); Procedure DeleteComponent(AComponent: TComponent; FreeComponent: boolean);
Function FindComponentByName(const Name : ShortString) : TIComponentInterface; override; Function FindComponentByName(const Name: ShortString
): TIComponentInterface; override;
Function FindComponent(AComponent: TComponent): TIComponentInterface; override; Function FindComponent(AComponent: TComponent): TIComponentInterface; override;
function SaveSelectionToStream(s: TStream): Boolean; override; function SaveSelectionToStream(s: TStream): Boolean; override;
Procedure ClearSelected; function InsertFromStream(s: TStream; Parent: TComponent;
Flags: TComponentPasteSelectionFlags): Boolean; override;
function ClearSelection: Boolean; override;
function DeleteSelection: Boolean; override;
function CopySelectionToClipboard: Boolean; override;
function CutSelectionToClipboard: Boolean; override;
function PasteSelectionFromClipboard(Flags: TComponentPasteSelectionFlags
): Boolean; override;
// JIT forms // JIT forms
function IsJITComponent(AComponent: TComponent): boolean; function IsJITComponent(AComponent: TComponent): boolean;
@ -676,10 +684,12 @@ begin
DesignerMenuItemClick:=@OnDesignerMenuItemClick; DesignerMenuItemClick:=@OnDesignerMenuItemClick;
OnGetDesignerForm:=@GetDesignerForm; OnGetDesignerForm:=@GetDesignerForm;
FormEditingHook:=Self;
end; end;
destructor TCustomFormEditor.Destroy; destructor TCustomFormEditor.Destroy;
begin begin
FormEditingHook:=nil;
DesignerMenuItemClick:=nil; DesignerMenuItemClick:=nil;
FreeAndNil(JITFormList); FreeAndNil(JITFormList);
FreeAndNil(JITDataModuleList); FreeAndNil(JITDataModuleList);
@ -798,6 +808,115 @@ begin
Result:=false; Result:=false;
end; end;
function TCustomFormEditor.InsertFromStream(s: TStream; Parent: TComponent;
Flags: TComponentPasteSelectionFlags): Boolean;
var
ADesigner: TIDesigner;
begin
ADesigner:=GetCurrentDesigner;
if ADesigner is TComponentEditorDesigner then
Result:=TComponentEditorDesigner(ADesigner).InsertFromStream(s,Parent,Flags)
else
Result:=false;
end;
function TCustomFormEditor.ClearSelection: Boolean;
var
ASelection: TPersistentSelectionList;
begin
if Selection.Count=0 then exit;
ASelection:=TPersistentSelectionList.Create;
try
Selection:=ASelection;
except
on E: Exception do begin
MessageDlg('Error',
'Unable to clear form editing selection'#13
+E.Message,mtError,[mbCancel],0);
end;
end;
ASelection.Free;
Result:=(Selection=nil) or (Selection.Count=0);
end;
function TCustomFormEditor.DeleteSelection: Boolean;
var
ADesigner: TIDesigner;
begin
if (Selection.Count=0) then begin
Result:=true;
exit;
end;
if Selection[0] is TComponent then begin
ADesigner:=FindRootDesigner(TComponent(Selection[0]));
if ADesigner is TComponentEditorDesigner then begin
TComponentEditorDesigner(ADesigner).DeleteSelection;
end;
end;
Result:=Selection.Count=0;
if Selection.Count>0 then begin
MessageDlg('Error',
'Do not know how to delete this form editing selection',
mtError,[mbCancel],0);
end;
end;
function TCustomFormEditor.CopySelectionToClipboard: Boolean;
var
ADesigner: TIDesigner;
begin
if (Selection.Count=0) then begin
Result:=false;
exit;
end;
if Selection[0] is TComponent then begin
ADesigner:=FindRootDesigner(TComponent(Selection[0]));
if ADesigner is TComponentEditorDesigner then begin
TComponentEditorDesigner(ADesigner).CopySelection;
end;
end;
Result:=Selection.Count=0;
if Selection.Count>0 then begin
MessageDlg('Error',
'Do not know how to copy this form editing selection',
mtError,[mbCancel],0);
end;
end;
function TCustomFormEditor.CutSelectionToClipboard: Boolean;
var
ADesigner: TIDesigner;
begin
if (Selection.Count=0) then begin
Result:=false;
exit;
end;
if Selection[0] is TComponent then begin
ADesigner:=FindRootDesigner(TComponent(Selection[0]));
if ADesigner is TComponentEditorDesigner then begin
TComponentEditorDesigner(ADesigner).CutSelection;
end;
end;
Result:=Selection.Count=0;
if Selection.Count>0 then begin
MessageDlg('Error',
'Do not know how to cut this form editing selection',
mtError,[mbCancel],0);
end;
end;
function TCustomFormEditor.PasteSelectionFromClipboard(
Flags: TComponentPasteSelectionFlags): Boolean;
var
ADesigner: TIDesigner;
begin
ADesigner:=GetCurrentDesigner;
if ADesigner is TComponentEditorDesigner then begin
Result:=TComponentEditorDesigner(ADesigner).PasteSelection(Flags);
end else
Result:=false;
end;
function TCustomFormEditor.IsJITComponent(AComponent: TComponent): boolean; function TCustomFormEditor.IsJITComponent(AComponent: TComponent): boolean;
begin begin
Result:=JITFormList.IsJITForm(AComponent) Result:=JITFormList.IsJITForm(AComponent)
@ -1346,11 +1465,6 @@ begin
end; end;
end; end;
Procedure TCustomFormEditor.ClearSelected;
Begin
FSelection.Clear;
end;
function TCustomFormEditor.TranslateKeyToDesignerCommand(Key: word; function TCustomFormEditor.TranslateKeyToDesignerCommand(Key: word;
Shift: TShiftState): word; Shift: TShiftState): word;
begin begin

View File

@ -2960,7 +2960,7 @@ begin
// clear formeditor // clear formeditor
if not Assigned(FormEditor1) then if not Assigned(FormEditor1) then
FormEditor1 := TFormEditor.Create; FormEditor1 := TFormEditor.Create;
FormEditor1.ClearSelected; FormEditor1.ClearSelection;
// create jit component // create jit component
CInterface := TComponentInterface( CInterface := TComponentInterface(
@ -3791,7 +3791,7 @@ begin
if ComponentLoadingOk then begin if ComponentLoadingOk then begin
if not Assigned(FormEditor1) then if not Assigned(FormEditor1) then
FormEditor1 := TFormEditor.Create; FormEditor1 := TFormEditor.Create;
if not (ofProjectLoading in Flags) then FormEditor1.ClearSelected; if not (ofProjectLoading in Flags) then FormEditor1.ClearSelection;
// create JIT component // create JIT component
CInterface := TComponentInterface( CInterface := TComponentInterface(
@ -6550,8 +6550,8 @@ begin
DoArrangeSourceEditorAndMessageView(false); DoArrangeSourceEditorAndMessageView(false);
// parse the LFM file and the pascal unit // parse the LFM file and the pascal unit
if not CheckLFMBuffer(PascalBuf,LFMUnitInfo.Source,@MessagesView.AddMsg) then if not CheckLFMBuffer(PascalBuf,LFMUnitInfo.Source,@MessagesView.AddMsg,true)
begin then begin
DoJumpToCompilerMessage(-1,true); DoJumpToCompilerMessage(-1,true);
end; end;
@ -6637,7 +6637,8 @@ begin
if HasDFMFile and (LFMCode=nil) then if HasDFMFile and (LFMCode=nil) then
writeln('WARNING: TMainIDE.DoConvertDelphiUnit unable to load LFMCode'); writeln('WARNING: TMainIDE.DoConvertDelphiUnit unable to load LFMCode');
if (LFMCode<>nil) if (LFMCode<>nil)
and (not CheckLFMBuffer(UnitCode,LFMCode,@MessagesView.AddMsg)) then begin and (not CheckLFMBuffer(UnitCode,LFMCode,@MessagesView.AddMsg,true)) then
begin
DoJumpToCompilerMessage(-1,true); DoJumpToCompilerMessage(-1,true);
exit; exit;
end; end;
@ -10531,6 +10532,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.747 2004/08/08 20:51:15 mattias
replaced TDBEdit.WMKillFocus by EditingDone, Change Class basically working
Revision 1.746 2004/08/08 18:20:41 mattias Revision 1.746 2004/08/08 18:20:41 mattias
added main IDe hints added main IDe hints

View File

@ -30,20 +30,31 @@ uses
PropEdits, ObjInspStrConsts; PropEdits, ObjInspStrConsts;
{ TComponentEditorDesigner }
type type
{ TComponentEditorDesigner }
TComponentPasteSelectionFlag = (
cpsfReplace,
cpsfFindUniquePositions
);
TComponentPasteSelectionFlags = set of TComponentPasteSelectionFlag;
TComponentEditorDesigner = class(TIDesigner) TComponentEditorDesigner = class(TIDesigner)
protected protected
FForm: TCustomForm; FForm: TCustomForm;
function GetPropertyEditorHook: TPropertyEditorHook; virtual; abstract; function GetPropertyEditorHook: TPropertyEditorHook; virtual; abstract;
public public
procedure CopySelection; virtual; abstract; function CopySelection: boolean; virtual; abstract;
procedure CutSelection; virtual; abstract; function CutSelection: boolean; virtual; abstract;
function CanPaste: Boolean; virtual; abstract; function CanPaste: boolean; virtual; abstract;
procedure PasteSelection; virtual; abstract; function PasteSelection(Flags: TComponentPasteSelectionFlags): boolean; virtual; abstract;
procedure DeleteSelection; virtual; abstract; function DeleteSelection: boolean; virtual; abstract;
function CopySelectionToStream(s: TStream): boolean; virtual; abstract; function CopySelectionToStream(s: TStream): boolean; virtual; abstract;
function InsertFromStream(s: TStream; Parent: TComponent;
Flags: TComponentPasteSelectionFlags
): Boolean; virtual; abstract;
function InvokeComponentEditor(AComponent: TComponent; function InvokeComponentEditor(AComponent: TComponent;
MenuIndex: integer): boolean; virtual; abstract; MenuIndex: integer): boolean; virtual; abstract;

View File

@ -22,7 +22,7 @@ unit FormEditingIntf;
interface interface
uses uses
Classes, SysUtils, TypInfo, Forms, Controls; Classes, SysUtils, TypInfo, Forms, Controls, ComponentEditors;
type type
{ TIComponentInterface } { TIComponentInterface }
@ -77,16 +77,18 @@ type
end; end;
{ TAbstractFormEditor } { TAbstractFormEditor }
TAbstractFormEditor = class TAbstractFormEditor = class
protected protected
function GetDesigner(Index: integer): TIDesigner; virtual; abstract; function GetDesigner(Index: integer): TIDesigner; virtual; abstract;
public public
// components // components
Function FindComponentByName(const Name : ShortString) : TIComponentInterface; virtual; abstract; Function FindComponentByName(const Name: ShortString
): TIComponentInterface; virtual; abstract;
Function FindComponent(AComponent: TComponent): TIComponentInterface; virtual; abstract; Function FindComponent(AComponent: TComponent): TIComponentInterface; virtual; abstract;
Function CreateComponent(CI : TIComponentInterface; TypeClass : TComponentClass; Function CreateComponent(CI : TIComponentInterface;
TypeClass : TComponentClass;
X,Y,W,H : Integer): TIComponentInterface; virtual; abstract; X,Y,W,H : Integer): TIComponentInterface; virtual; abstract;
Function CreateComponentFromStream(BinStream: TStream; Function CreateComponentFromStream(BinStream: TStream;
AncestorType: TComponentClass; Interactive: boolean AncestorType: TComponentClass; Interactive: boolean
@ -102,10 +104,20 @@ type
property Designer[Index: integer]: TIDesigner read GetDesigner; property Designer[Index: integer]: TIDesigner read GetDesigner;
function GetCurrentDesigner: TIDesigner; virtual; abstract; function GetCurrentDesigner: TIDesigner; virtual; abstract;
function GetDesignerForm(AComponent: TComponent): TCustomForm; virtual; abstract; function GetDesignerForm(AComponent: TComponent): TCustomForm; virtual; abstract;
function GetDesignerByComponent(AComponent: TComponent): TIDesigner; virtual; abstract; function GetDesignerByComponent(AComponent: TComponent
): TIDesigner; virtual; abstract;
// selection // selection
function SaveSelectionToStream(s: TStream): Boolean; virtual; abstract; function SaveSelectionToStream(s: TStream): Boolean; virtual; abstract;
function InsertFromStream(s: TStream; Parent: TComponent;
Flags: TComponentPasteSelectionFlags
): Boolean; virtual; abstract;
function ClearSelection: Boolean; virtual; abstract;
function DeleteSelection: Boolean; virtual; abstract;
function CopySelectionToClipboard: Boolean; virtual; abstract;
function CutSelectionToClipboard: Boolean; virtual; abstract;
function PasteSelectionFromClipboard(Flags: TComponentPasteSelectionFlags
): Boolean; virtual; abstract;
end; end;

View File

@ -142,7 +142,7 @@ Type
procedure Reset; override; procedure Reset; override;
procedure SetFocus; override; procedure SetFocus; override;
procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS; procedure EditingDone; override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
@ -1248,6 +1248,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.16 2004/08/08 20:51:15 mattias
replaced TDBEdit.WMKillFocus by EditingDone, Change Class basically working
Revision 1.15 2003/09/22 15:03:19 ajgenius Revision 1.15 2003/09/22 15:03:19 ajgenius
partly fixed streaming of DBCalendar, and opRemove notification of DBText DBEdit DBCalendar partly fixed streaming of DBCalendar, and opRemove notification of DBText DBEdit DBCalendar

View File

@ -174,6 +174,10 @@ Begin
//if ObjectMenuItem = AComponent then ObjectMenuItem := nil; //if ObjectMenuItem = AComponent then ObjectMenuItem := nil;
end; end;
if FActiveControl=AComponent then FActiveControl:=nil; if FActiveControl=AComponent then FActiveControl:=nil;
if AComponent=FDefaultControl then
FDefaultControl:=nil;
if AComponent=FCancelControl then
FCancelControl:=nil;
end; end;
end; end;
if FDesigner<>nil then FDesigner.Notification(AComponent,Operation); if FDesigner<>nil then FDesigner.Notification(AComponent,Operation);
@ -1719,6 +1723,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.147 2004/08/08 20:51:15 mattias
replaced TDBEdit.WMKillFocus by EditingDone, Change Class basically working
Revision 1.146 2004/07/25 01:04:45 mattias Revision 1.146 2004/07/25 01:04:45 mattias
TXMLPropStorage basically working TXMLPropStorage basically working

View File

@ -195,12 +195,9 @@ begin
end; end;
end; end;
procedure TDBEdit.WMKillFocus(var Message: TLMKillFocus); procedure TDBEdit.EditingDone;
begin begin
//I am not sure where else to do this :/ inherited EditingDone;
//we need to make sure the field is updated
//if we leave the edit after changes
FDataLink.UpdateRecord; FDataLink.UpdateRecord;
end; end;
@ -227,6 +224,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.6 2004/08/08 20:51:15 mattias
replaced TDBEdit.WMKillFocus by EditingDone, Change Class basically working
Revision 1.5 2004/08/05 19:33:48 vincents Revision 1.5 2004/08/05 19:33:48 vincents
allow backspace as a valid input allow backspace as a valid input