From dffc4d0999f6d06feb0e5976d8781f098d891baf Mon Sep 17 00:00:00 2001 From: mattias Date: Sun, 8 Aug 2004 20:51:15 +0000 Subject: [PATCH] replaced TDBEdit.WMKillFocus by EditingDone, Change Class basically working git-svn-id: trunk@5751 - --- components/codetools/codetoolmanager.pas | 8 +- components/codetools/lfmtrees.pas | 7 ++ components/codetools/stdcodetools.pas | 58 +++++++-- designer/changeclassdialog.pas | 56 ++++++--- designer/designer.pp | 143 +++++++++++++++-------- ide/checklfmdlg.pas | 13 ++- ide/customformeditor.pp | 130 +++++++++++++++++++-- ide/main.pp | 14 ++- ideintf/componenteditors.pas | 23 +++- ideintf/formeditingintf.pas | 22 +++- lcl/dbctrls.pp | 5 +- lcl/include/customform.inc | 7 ++ lcl/include/dbedit.inc | 10 +- 13 files changed, 384 insertions(+), 112 deletions(-) diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 5ac4b61462..73adec4d74 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -353,7 +353,7 @@ type read FOnGetDefineProperties write FOnGetDefineProperties; function FindLFMFileName(Code: TCodeBuffer): string; function CheckLFM(UnitCode, LFMBuf: TCodeBuffer; - var LFMTree: TLFMTree): boolean; + var LFMTree: TLFMTree; RootMustBeClassInIntf: boolean): boolean; function FindNextResourceFile(Code: TCodeBuffer; var LinkIndex: integer): TCodeBuffer; function AddLazarusResourceHeaderComment(Code: TCodeBuffer; @@ -610,6 +610,7 @@ begin TempFilename:=VirtualTempDir+PathDelim+IntToStr(i)+PathDelim+AFilename; Result:=FindFile(TempFilename); if (Result<>nil) and (Result.ReferenceCount=0) then exit; + inc(i); until Result=nil; Result:=SourceCache.CreateFile(TempFilename); Result.IncrementRefCount; @@ -2031,7 +2032,7 @@ begin end; function TCodeToolManager.CheckLFM(UnitCode, LFMBuf: TCodeBuffer; - var LFMTree: TLFMTree): boolean; + var LFMTree: TLFMTree; RootMustBeClassInIntf: boolean): boolean; begin Result:=false; {$IFDEF CTDEBUG} @@ -2039,7 +2040,8 @@ begin {$ENDIF} if not InitCurCodeTool(UnitCode) then exit; try - Result:=FCurCodeTool.CheckLFM(LFMBuf,LFMTree,OnGetDefineProperties); + Result:=FCurCodeTool.CheckLFM(LFMBuf,LFMTree,OnGetDefineProperties, + RootMustBeClassInIntf); except on e: Exception do HandleException(e); end; diff --git a/components/codetools/lfmtrees.pas b/components/codetools/lfmtrees.pas index fb8c34f469..b34b79b0f5 100644 --- a/components/codetools/lfmtrees.pas +++ b/components/codetools/lfmtrees.pas @@ -248,6 +248,7 @@ type function FindErrorAtLine(Line: integer): TLFMError; function FindErrorAtNode(Node: TLFMTreeNode): TLFMError; function FindError(ErrorTypes: TLFMErrorTypes): TLFMError; + function FirstErrorAsString: string; end; const @@ -366,6 +367,12 @@ begin Result:=Result.NextError; end; +function TLFMTree.FirstErrorAsString: string; +begin + Result:=''; + if FirstError<>nil then Result:=FirstError.ErrorMessage; +end; + procedure TLFMTree.ProcessValue; var s: String; diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 276e5564b3..04e47cdc08 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -116,7 +116,8 @@ type KeepPath: boolean; SourceChangeCache: TSourceChangeCache): boolean; function CheckLFM(LFMBuf: TCodeBuffer; var LFMTree: TLFMTree; - const OnGetDefineProperties: TOnGetDefineProperties): boolean; + const OnGetDefineProperties: TOnGetDefineProperties; + RootMustBeClassInIntf: boolean): boolean; // Application.Createform statements function FindCreateFormStatement(StartPos: integer; @@ -892,7 +893,8 @@ begin end; function TStandardCodeTool.CheckLFM(LFMBuf: TCodeBuffer; var LFMTree: TLFMTree; - const OnGetDefineProperties: TOnGetDefineProperties): boolean; + const OnGetDefineProperties: TOnGetDefineProperties; + RootMustBeClassInIntf: boolean): boolean; var RootContext: TFindContext; @@ -1147,7 +1149,6 @@ var DefaultErrorPosition); exit; end; - end; procedure CheckLFMProperty(LFMProperty: TLFMPropertyNode; @@ -1220,6 +1221,43 @@ var end; Result:=true; 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; var @@ -1245,17 +1283,21 @@ var end; // 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 LFMTree.AddError(lfmeMissingRoot,LookupRootLFMNode, 'type '+LookupRootLFMNode.TypeName+' not found', LookupRootLFMNode.TypeNamePosition); exit; end; - - RootContext:=CleanFindContext; - RootContext.Node:=RootClassNode; - RootContext.Tool:=Self; Result:=CheckLFMObjectValues(LookupRootLFMNode,RootContext); end; diff --git a/designer/changeclassdialog.pas b/designer/changeclassdialog.pas index 1c45f299e2..16e8763a86 100644 --- a/designer/changeclassdialog.pas +++ b/designer/changeclassdialog.pas @@ -27,6 +27,10 @@ Abstract: 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; @@ -35,11 +39,11 @@ unit ChangeClassDialog; interface uses - Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, - Buttons, AVGLvlTree, LFMTrees, CodeCache, CodeToolManager, + Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs, + StdCtrls, Buttons, AVGLvlTree, LFMTrees, CodeCache, CodeToolManager, // IDE - SrcEditorIntf, PropEdits, LazarusIDEStrConsts, ComponentReg, FormEditingIntf, - CheckLFMDlg, Project, MainIntf; + SrcEditorIntf, PropEdits, LazarusIDEStrConsts, ComponentReg, ComponentEditors, + FormEditingIntf, CheckLFMDlg, Project, MainIntf; type TChangeClassDlg = class(TForm) @@ -132,7 +136,8 @@ var // stream selection 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.'); exit; end; @@ -142,6 +147,7 @@ var function ParseLFMStream: boolean; var SrcEdit: TSourceEditorInterface; + Msg: String; begin Result:=false; if not CodeToolBoss.GatherExternalChanges then begin @@ -155,15 +161,23 @@ var end; UnitCode:=UnitInfo.Source; 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.'); exit; 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 MainIDEInterface.DoJumpToCodeToolBossError - else - ShowAbortMessage('Error parsing lfm component stream.'); + else begin + Msg:='Error parsing lfm component stream.'; + if LFMTree<>nil then Msg:=Msg+#13#13+LFMTree.FirstErrorAsString+#13; + ShowAbortMessage(Msg); + end; exit; end; Result:=true; @@ -196,19 +210,30 @@ var function CheckProperties: boolean; begin - Result:=CheckLFMBuffer(UnitCode,LFMBuffer,nil); + Result:=CheckLFMBuffer(UnitCode,LFMBuffer,nil,false); if not Result and (CodeToolBoss.ErrorMessage<>'') then MainIDEInterface.DoJumpToCodeToolBossError; end; - function DeleteSelection: boolean; - begin - Result:=false; - end; - function InsertStreamedSelection: boolean; + var + MemStream: TMemoryStream; begin 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; begin @@ -231,7 +256,6 @@ begin if not ParseLFMStream then exit; if not ChangeClassName then exit; if not CheckProperties then exit; - if not DeleteSelection then exit; if not InsertStreamedSelection then exit; finally ComponentStream.Free; diff --git a/designer/designer.pp b/designer/designer.pp index 8cce35260a..f2d780df50 100644 --- a/designer/designer.pp +++ b/designer/designer.pp @@ -53,7 +53,7 @@ type TOnPersistentAdded = procedure(Sender: TObject; APersistent: TPersistent; ComponentClass: TRegisteredComponent) of object; TOnPasteComponent = procedure(Sender: TObject; LookupRoot: TComponent; - TxtCompStream: TStream; ParentControl: TWinControl; + TxtCompStream: TStream; Parent: TComponent; var NewComponent: TComponent) of object; TOnRemovePersistent = procedure(Sender: TObject; APersistent: TPersistent) of object; @@ -166,7 +166,7 @@ type function HandleSetCursor(var TheMessage: TLMessage): boolean; // procedures for working with components and persistents - procedure DoDeleteSelectedPersistents; + function DoDeleteSelectedPersistents: boolean; procedure DoDeletePersistent(APersistent: TPersistent; FreeIt: boolean); procedure MarkPersistentForDeletion(APersistent: TPersistent); function PersistentIsMarkedForDeletion(APersistent: TPersistent): boolean; @@ -175,7 +175,11 @@ type Procedure NudgeSize(DiffX, DiffY: Integer); procedure SelectParentOfSelection; 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 DoShowChangeClassDialog; procedure GiveComponentsNames; @@ -216,12 +220,14 @@ type procedure Modified; override; Procedure SelectOnlyThisComponent(AComponent:TComponent); override; - procedure CopySelection; override; - procedure CutSelection; override; + function CopySelection: boolean; override; + function CutSelection: boolean; override; function CanPaste: Boolean; override; - procedure PasteSelection; override; - procedure DeleteSelection; override; + function PasteSelection(Flags: TComponentPasteSelectionFlags): boolean; override; + function DeleteSelection: boolean; override; function CopySelectionToStream(AllComponentsStream: TStream): boolean; override; + function InsertFromStream(s: TStream; Parent: TComponent; + Flags: TComponentPasteSelectionFlags): Boolean; override; function InvokeComponentEditor(AComponent: TComponent; MenuIndex: integer): boolean; override; procedure DoProcessCommand(Sender: TObject; var Command: word; @@ -513,6 +519,12 @@ begin Result:=true; end; +function TDesigner.InsertFromStream(s: TStream; Parent: TComponent; + Flags: TComponentPasteSelectionFlags): Boolean; +begin + Result:=DoInsertFromStream(s,Parent,Flags); +end; + function TDesigner.DoCopySelectionToClipboard: boolean; var AllComponentsStream: TMemoryStream; @@ -549,34 +561,58 @@ begin Result:=true; 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 AllComponentText: string; StartPos: Integer; EndPos: Integer; CurTextCompStream: TStream; - PasteParent: TWinControl; NewSelection: TControlSelection; - - 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; + l: Integer; procedure FindUniquePosition(AComponent: TComponent); var @@ -643,7 +679,8 @@ var // add new component to new selection NewSelection.Add(NewComponent); // set new nice bounds - FindUniquePosition(NewComponent); + if cpsfFindUniquePositions in Flags then + FindUniquePosition(NewComponent); // finish adding component NotifyPersistentAdded(NewComponent); Modified; @@ -653,16 +690,18 @@ var end; begin - if not CanPaste then exit; + Result:=false; + if (cpsfReplace in Flags) and (not DeleteSelection) then exit; - PasteParent:=nil; - GetPasteParent; + if PasteParent=nil then PasteParent:=GetPasteParent; NewSelection:=TControlSelection.Create; try // read component stream from clipboard - AllComponentText:=ClipBoard.AsText; - if AllComponentText='' then exit; + if (s.Size<=S.Position) then exit; + l:=s.Size-s.Position; + SetLength(AllComponentText,l); + s.Read(AllComponentText[1],length(AllComponentText)); StartPos:=1; EndPos:=StartPos; @@ -682,9 +721,9 @@ begin inc(EndPos); // extract text for the current component {$IFDEF VerboseDesigner} - writeln('TDesigner.DoPasteSelectionFromClipboard=============================='); + writeln('TDesigner.DoInsertFromStream=============================='); writeln(copy(AllComponentText,StartPos,EndPos-StartPos)); - writeln('TDesigner.DoPasteSelectionFromClipboard=============================='); + writeln('TDesigner.DoInsertFromStream=============================='); {$ENDIF} CurTextCompStream:=TMemoryStream.Create; @@ -709,6 +748,7 @@ begin ControlSelection.Assign(NewSelection); NewSelection.Free; end; + Result:=true; end; procedure TDesigner.DoShowTabOrderEditor; @@ -754,15 +794,16 @@ begin ControlSelection.AssignPersistent(AComponent); end; -procedure TDesigner.CopySelection; +function TDesigner.CopySelection: boolean; begin - DoCopySelectionToClipboard; + Result:=DoCopySelectionToClipboard; end; -procedure TDesigner.CutSelection; +function TDesigner.CutSelection: boolean; begin - if DoCopySelectionToClipboard then - DoDeleteSelectedPersistents; + Result:=DoCopySelectionToClipboard; + if Result then + Result:=DoDeleteSelectedPersistents; end; function TDesigner.CanPaste: Boolean; @@ -772,14 +813,15 @@ begin and (not (csDestroying in FLookupRoot.ComponentState)); end; -procedure TDesigner.PasteSelection; +function TDesigner.PasteSelection( + Flags: TComponentPasteSelectionFlags): boolean; begin - DoPasteSelectionFromClipboard; + Result:=DoPasteSelectionFromClipboard(Flags); end; -procedure TDesigner.DeleteSelection; +function TDesigner.DeleteSelection: boolean; begin - DoDeleteSelectedPersistents; + Result:=DoDeleteSelectedPersistents; end; function TDesigner.InvokeComponentEditor(AComponent: TComponent; @@ -836,7 +878,7 @@ begin CutSelection; ecPasteComponents: - PasteSelection; + PasteSelection([cpsfFindUniquePositions]); else Handled:=false; @@ -1564,13 +1606,15 @@ Begin {$ENDIF} end; -procedure TDesigner.DoDeleteSelectedPersistents; +function TDesigner.DoDeleteSelectedPersistents: boolean; var i: integer; APersistent: TPersistent; begin + Result:=true; if (ControlSelection.Count=0) or (ControlSelection.SelectionForm<>Form) then exit; + Result:=false; if (ControlSelection.LookupRootSelected) then begin if ControlSelection.Count>1 then MessageDlg(lisInvalidDelete, @@ -1595,6 +1639,7 @@ begin IgnoreDeletingPersistent.Clear; Exclude(FFlags,dfDeleting); Modified; + Result:=true; end; procedure TDesigner.DoDeletePersistent(APersistent: TPersistent; @@ -1917,7 +1962,7 @@ end; procedure TDesigner.OnPasteMenuClick(Sender: TObject); begin - PasteSelection; + PasteSelection([cpsfFindUniquePositions]); end; procedure TDesigner.OnTabOrderMenuClick(Sender: TObject); diff --git a/ide/checklfmdlg.pas b/ide/checklfmdlg.pas index babf0fc305..22443fcd6e 100644 --- a/ide/checklfmdlg.pas +++ b/ide/checklfmdlg.pas @@ -78,9 +78,9 @@ type end; function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer; - const OnOutput: TOnOutputString): boolean; + const OnOutput: TOnOutputString; RootMustBeClassInIntf: boolean): boolean; function CheckLFMText(PascalBuffer: TCodeBuffer; var LFMText: string; - const OnOutput: TOnOutputString): boolean; + const OnOutput: TOnOutputString; RootMustBeClassInIntf: boolean): boolean; function ShowRepairLFMWizard(LFMBuffer: TCodeBuffer; LFMTree: TLFMTree): boolean; @@ -95,7 +95,7 @@ type end; function CheckLFMBuffer(PascalBuffer, LFMBuffer: TCodeBuffer; - const OnOutput: TOnOutputString): boolean; + const OnOutput: TOnOutputString; RootMustBeClassInIntf: boolean): boolean; var LFMTree: TLFMTree; @@ -124,7 +124,8 @@ var begin LFMTree:=nil; try - Result:=CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree); + Result:=CodeToolBoss.CheckLFM(PascalBuffer,LFMBuffer,LFMTree, + RootMustBeClassInIntf); if Result then exit; WriteLFMErrors; Result:=ShowRepairLFMWizard(LFMBuffer,LFMTree); @@ -134,7 +135,7 @@ begin end; function CheckLFMText(PascalBuffer: TCodeBuffer; var LFMText: string; - const OnOutput: TOnOutputString): boolean; + const OnOutput: TOnOutputString; RootMustBeClassInIntf: boolean): boolean; var LFMBuf: TCodeBuffer; begin @@ -142,7 +143,7 @@ begin LFMBuf:=CodeToolBoss.CreateTempFile('temp.lfm'); try LFMBuf.Source:=LFMText; - Result:=CheckLFMBuffer(PascalBuffer,LFMBuf,OnOutput); + Result:=CheckLFMBuffer(PascalBuffer,LFMBuf,OnOutput,RootMustBeClassInIntf); LFMText:=LFMBuf.Source; finally CodeToolBoss.ReleaseTempFile(LFMBuf); diff --git a/ide/customformeditor.pp b/ide/customformeditor.pp index a1d9e33ee5..312589f3b8 100644 --- a/ide/customformeditor.pp +++ b/ide/customformeditor.pp @@ -141,12 +141,20 @@ each control that's dropped onto the form destructor Destroy; override; // selection - Function AddSelected(Value : TComponent) : Integer; + Function AddSelected(Value: TComponent) : Integer; 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 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 function IsJITComponent(AComponent: TComponent): boolean; @@ -676,10 +684,12 @@ begin DesignerMenuItemClick:=@OnDesignerMenuItemClick; OnGetDesignerForm:=@GetDesignerForm; + FormEditingHook:=Self; end; destructor TCustomFormEditor.Destroy; begin + FormEditingHook:=nil; DesignerMenuItemClick:=nil; FreeAndNil(JITFormList); FreeAndNil(JITDataModuleList); @@ -798,6 +808,115 @@ begin Result:=false; 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; begin Result:=JITFormList.IsJITForm(AComponent) @@ -1346,11 +1465,6 @@ begin end; end; -Procedure TCustomFormEditor.ClearSelected; -Begin - FSelection.Clear; -end; - function TCustomFormEditor.TranslateKeyToDesignerCommand(Key: word; Shift: TShiftState): word; begin diff --git a/ide/main.pp b/ide/main.pp index 97468031e5..23f575da2c 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -2960,7 +2960,7 @@ begin // clear formeditor if not Assigned(FormEditor1) then FormEditor1 := TFormEditor.Create; - FormEditor1.ClearSelected; + FormEditor1.ClearSelection; // create jit component CInterface := TComponentInterface( @@ -3791,7 +3791,7 @@ begin if ComponentLoadingOk then begin if not Assigned(FormEditor1) then FormEditor1 := TFormEditor.Create; - if not (ofProjectLoading in Flags) then FormEditor1.ClearSelected; + if not (ofProjectLoading in Flags) then FormEditor1.ClearSelection; // create JIT component CInterface := TComponentInterface( @@ -6550,8 +6550,8 @@ begin DoArrangeSourceEditorAndMessageView(false); // parse the LFM file and the pascal unit - if not CheckLFMBuffer(PascalBuf,LFMUnitInfo.Source,@MessagesView.AddMsg) then - begin + if not CheckLFMBuffer(PascalBuf,LFMUnitInfo.Source,@MessagesView.AddMsg,true) + then begin DoJumpToCompilerMessage(-1,true); end; @@ -6637,7 +6637,8 @@ 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)) then begin + and (not CheckLFMBuffer(UnitCode,LFMCode,@MessagesView.AddMsg,true)) then + begin DoJumpToCompilerMessage(-1,true); exit; end; @@ -10531,6 +10532,9 @@ end. { ============================================================================= $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 added main IDe hints diff --git a/ideintf/componenteditors.pas b/ideintf/componenteditors.pas index 38be57804c..348f3ef92e 100644 --- a/ideintf/componenteditors.pas +++ b/ideintf/componenteditors.pas @@ -30,20 +30,31 @@ uses PropEdits, ObjInspStrConsts; -{ TComponentEditorDesigner } type + { TComponentEditorDesigner } + + TComponentPasteSelectionFlag = ( + cpsfReplace, + cpsfFindUniquePositions + ); + TComponentPasteSelectionFlags = set of TComponentPasteSelectionFlag; + + TComponentEditorDesigner = class(TIDesigner) protected FForm: TCustomForm; function GetPropertyEditorHook: TPropertyEditorHook; virtual; abstract; public - procedure CopySelection; virtual; abstract; - procedure CutSelection; virtual; abstract; - function CanPaste: Boolean; virtual; abstract; - procedure PasteSelection; virtual; abstract; - procedure DeleteSelection; virtual; abstract; + function CopySelection: boolean; virtual; abstract; + function CutSelection: boolean; virtual; abstract; + function CanPaste: boolean; virtual; abstract; + function PasteSelection(Flags: TComponentPasteSelectionFlags): boolean; virtual; abstract; + function DeleteSelection: 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; MenuIndex: integer): boolean; virtual; abstract; diff --git a/ideintf/formeditingintf.pas b/ideintf/formeditingintf.pas index 06605a12cf..553e75500e 100644 --- a/ideintf/formeditingintf.pas +++ b/ideintf/formeditingintf.pas @@ -22,7 +22,7 @@ unit FormEditingIntf; interface uses - Classes, SysUtils, TypInfo, Forms, Controls; + Classes, SysUtils, TypInfo, Forms, Controls, ComponentEditors; type { TIComponentInterface } @@ -77,16 +77,18 @@ type end; { TAbstractFormEditor } - + TAbstractFormEditor = class protected function GetDesigner(Index: integer): TIDesigner; virtual; abstract; public // 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 CreateComponent(CI : TIComponentInterface; TypeClass : TComponentClass; + Function CreateComponent(CI : TIComponentInterface; + TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface; virtual; abstract; Function CreateComponentFromStream(BinStream: TStream; AncestorType: TComponentClass; Interactive: boolean @@ -102,10 +104,20 @@ type property Designer[Index: integer]: TIDesigner read GetDesigner; function GetCurrentDesigner: TIDesigner; virtual; abstract; function GetDesignerForm(AComponent: TComponent): TCustomForm; virtual; abstract; - function GetDesignerByComponent(AComponent: TComponent): TIDesigner; virtual; abstract; + function GetDesignerByComponent(AComponent: TComponent + ): TIDesigner; virtual; abstract; // selection 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; diff --git a/lcl/dbctrls.pp b/lcl/dbctrls.pp index fb50ae434d..33e934a4b1 100644 --- a/lcl/dbctrls.pp +++ b/lcl/dbctrls.pp @@ -142,7 +142,7 @@ Type procedure Reset; override; procedure SetFocus; override; - procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS; + procedure EditingDone; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -1248,6 +1248,9 @@ end. { ============================================================================= $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 partly fixed streaming of DBCalendar, and opRemove notification of DBText DBEdit DBCalendar diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index 604b9ea59a..9b9415ee39 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -174,6 +174,10 @@ Begin //if ObjectMenuItem = AComponent then ObjectMenuItem := nil; end; if FActiveControl=AComponent then FActiveControl:=nil; + if AComponent=FDefaultControl then + FDefaultControl:=nil; + if AComponent=FCancelControl then + FCancelControl:=nil; end; end; if FDesigner<>nil then FDesigner.Notification(AComponent,Operation); @@ -1719,6 +1723,9 @@ end; { ============================================================================= $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 TXMLPropStorage basically working diff --git a/lcl/include/dbedit.inc b/lcl/include/dbedit.inc index 4ed13a8943..b05132ee55 100644 --- a/lcl/include/dbedit.inc +++ b/lcl/include/dbedit.inc @@ -195,12 +195,9 @@ begin end; end; -procedure TDBEdit.WMKillFocus(var Message: TLMKillFocus); +procedure TDBEdit.EditingDone; begin - //I am not sure where else to do this :/ - //we need to make sure the field is updated - //if we leave the edit after changes - + inherited EditingDone; FDataLink.UpdateRecord; end; @@ -227,6 +224,9 @@ end; { ============================================================================= $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 allow backspace as a valid input