42
42
Classes, SysUtils, TypInfo, Math, LCLIntf, LCLType, LResources,
43
AVL_Tree, LCLMemManager,
43
AVL_Tree, LCLMemManager, FileUtil,
44
44
LCLProc, Graphics, Controls, Forms, Menus, Dialogs,
46
46
PropEdits, PropEditUtils, ObjectInspector, IDECommands, FormEditingIntf,
48
LazarusIDEStrConsts, Project, JITForms, MainIntf,
49
CustomNonFormDesigner, NonControlDesigner, FrameDesigner,
50
ComponentReg, IDEProcs, ComponentEditors, KeyMapping, EditorOptions,
51
EnvironmentOpts, DesignerProcs;
48
LazarusIDEStrConsts, ControlSelection, Project, JITForms, MainIntf,
49
CustomNonFormDesigner, NonControlDesigner, FrameDesigner, ComponentReg,
50
IDEProcs, ComponentEditors, IDEOptionsIntf, IDEDialogs, KeyMapping,
51
EditorOptions, EnvironmentOpts, DesignerProcs;
54
54
OrdinalTypes = [tkInteger,tkChar,tkEnumeration,tkbool];
212
213
Visible: boolean = true;
213
214
DisableAutoSize: boolean = false;
214
215
ContextObj: TObject = nil): TComponent;
215
function CreateChildComponentFromStream(BinStream: TStream;
216
procedure CreateChildComponentsFromStream(BinStream: TStream;
216
217
ComponentClass: TComponentClass; Root: TComponent;
217
ParentControl: TWinControl): TComponent; override;
218
ParentControl: TWinControl; NewComponents: TFPList); override;
218
219
function FixupReferences(AComponent: TComponent): TModalResult;
219
220
procedure WriterFindAncestor(Writer: TWriter; Component: TComponent;
220
221
const Name: string;
349
350
DebugLn('TryFreeComponent ERROR:',
350
351
' "'+OldName+':'+OldClassName+'" ',E.Message);
351
352
DumpExceptionBackTrace;
353
'An exception occured during deletion of'#13
354
+'"'+OldName+':'+OldClassName+'"'#13
353
MessageDlg(lisCCOErrorCaption,
354
Format(lisCFEAnExceptionOccuredDuringDeletionOf, [#13, OldName,
355
OldClassName, #13, E.Message]),
356
356
mtError,[mbOk],0);
439
441
const ASelection: TPersistentSelectionList);
441
443
FSelection.Assign(ASelection);
444
if Obj_Inspector=nil then exit;
442
445
if FSelection.Count>0 then begin
443
Obj_Inspector.PropertyEditorHook.LookupRoot:=
444
GetLookupRootForComponent(FSelection[0]);
446
Obj_Inspector.PropertyEditorHook.LookupRoot:=
447
GetLookupRootForComponent(FSelection[0]);
446
449
Obj_Inspector.Selection := FSelection;
449
452
Function TCustomFormEditor.AddSelected(Value : TComponent) : Integer;
451
454
Result := FSelection.Add(Value) + 1;
452
Obj_Inspector.Selection := FSelection;
455
if Obj_Inspector<>nil then
456
Obj_Inspector.Selection := FSelection;
455
459
Procedure TCustomFormEditor.DeleteComponent(AComponent: TComponent;
458
462
AForm: TCustomForm;
459
463
AWinControl: TWinControl;
466
aDesigner: TIDesigner;
468
IsJIT:=IsJITComponent(AComponent);
462
469
{$IFDEF IDE_DEBUG}
463
DebugLn(['TCustomFormEditor.DeleteComponent ',DbgSName(AComponent),' IsJITComponent=',IsJITComponent(AComponent),' FreeComponent=',FreeComponent]);
470
DebugLn(['TCustomFormEditor.DeleteComponent ',DbgSName(AComponent),' IsJITComponent=',IsJIT,' FreeComponent=',FreeComponent]);
472
if TheControlSelection.LookupRoot = AComponent then
474
TheControlSelection.BeginUpdate;
476
TheControlSelection.Clear;
478
TheControlSelection.EndUpdate;
465
481
if PropertyEditorHook.LookupRoot=AComponent then
466
482
PropertyEditorHook.LookupRoot:=nil;
467
IsJIT:=IsJITComponent(AComponent);
468
484
if IsJIT then begin
469
// value is a top level component
485
// AComponent is a top level component
486
if FreeComponent then
488
// tell hooks about deleting
489
for i := AComponent.ComponentCount - 1 downto 0 do
490
PropertyEditorHook.PersistentDeleting(AComponent.Components[i]);
491
PropertyEditorHook.PersistentDeleting(AComponent);
493
// disconnect designer
494
aDesigner:=GetDesignerByComponent(AComponent);
495
if aDesigner is TComponentEditorDesigner then
496
TComponentEditorDesigner(aDesigner).DisconnectComponent;
470
498
if JITFormList.IsJITForm(AComponent) then begin
471
499
// free/unbind a form component
472
500
if FreeComponent then
473
501
JITFormList.DestroyJITComponent(AComponent);
474
502
end else if JITNonFormList.IsJITNonForm(AComponent) then begin
475
503
// free/unbind a non form component and its designer form
476
AForm:=GetDesignerForm(AComponent);
504
aForm:=GetDesignerForm(AComponent);
477
505
if (AForm<>nil) and (not (AForm is TCustomNonFormDesignerForm)) then
478
RaiseException('TCustomFormEditor.DeleteComponent Where is the TCustomNonFormDesignerForm? '+AComponent.ClassName);
506
RaiseException(Format(
507
lisCFETCustomFormEditorDeleteComponentWhereIsTheTCustomN, [AComponent.
480
if (AForm <> nil) and (AForm is TCustomNonFormDesignerForm) then
510
if (AForm <> nil) then
482
512
FNonFormForms.Remove(AForm);
483
513
TCustomNonFormDesignerForm(AForm).LookupRoot := nil;
559
589
Selection:=ASelection;
561
591
on E: Exception do begin
563
'Unable to clear the form editing selection'#13
564
+E.Message,mtError,[mbCancel],0);
592
MessageDlg(lisCCOErrorCaption,
593
Format(lisCFEUnableToClearTheFormEditingSelection, [#13, E.Message]),
594
mtError, [mbCancel], 0);
585
615
Result:=Selection.Count=0;
586
616
if Selection.Count>0 then begin
588
'Do not know how to delete this form editing selection',
617
MessageDlg(lisCCOErrorCaption,
618
lisCFEDoNotKnowHowToDeleteThisFormEditingSelection,
589
619
mtError,[mbCancel],0);
607
637
Result:=Selection.Count=0;
608
638
if Selection.Count>0 then begin
610
'Do not know how to copy this form editing selection',
639
MessageDlg(lisCCOErrorCaption,
640
lisCFEDoNotKnowHowToCopyThisFormEditingSelection,
611
641
mtError,[mbCancel],0);
629
659
Result:=Selection.Count=0;
630
660
if Selection.Count>0 then begin
632
'Do not know how to cut this form editing selection',
661
MessageDlg(lisCCOErrorCaption,
662
lisCFEDoNotKnowHowToCutThisFormEditingSelection,
633
663
mtError,[mbCancel],0);
728
763
MediatorClass: TDesignerMediatorClass;
730
765
if FindNonFormFormNode(LookupRoot) <> nil then
731
RaiseException('TCustomFormEditor.CreateNonFormForm already exists');
766
RaiseException(lisCFETCustomFormEditorCreateNonFormFormAlreadyExists);
732
767
if LookupRoot is TComponent then
734
769
if LookupRoot is TCustomFrame then
746
781
TNonControlDesignerForm(Result).Mediator:=MediatorClass.CreateMediator(nil,LookupRoot);
749
RaiseException('TCustomFormEditor.CreateNonFormForm Unknown type '
750
+LookupRoot.ClassName);
784
RaiseException(Format(lisCFETCustomFormEditorCreateNonFormFormUnknownType, [
785
LookupRoot.ClassName]));
753
788
procedure TCustomFormEditor.RenameJITComponent(AComponent: TComponent;
1037
1072
MediatorClass: TDesignerMediatorClass);
1039
1074
if FDesignerMediatorClasses.IndexOf(MediatorClass)>=0 then
1040
raise Exception.Create('TCustomFormEditor.RegisterDesignerMediator already registered: '+DbgSName(MediatorClass));
1075
raise Exception.Create(Format(
1076
lisCFETCustomFormEditorRegisterDesignerMediatorAlreadyRe, [DbgSName(
1041
1078
FDesignerMediatorClasses.Add(MediatorClass);
1042
1079
RegisterDesignerBaseClass(MediatorClass.FormClass);
1151
1188
on e: Exception do begin
1152
1189
DumpExceptionBackTrace;
1153
MessageDlg('Error creating component',
1154
'Error creating component: '+TypeClass.ClassName+#13+E.Message,
1190
MessageDlg(lisCFEErrorCreatingComponent,
1191
Format(lisCFEErrorCreatingComponent2, [TypeClass.ClassName, #13, E.
1155
1193
mtError,[mbCancel],0);
1159
1197
// check if Owner was properly set
1160
1198
if NewComponent.Owner <> OwnerComponent then begin
1161
MessageDlg('Invalid component owner',
1162
'The component of type '+NewComponent.ClassName
1163
+' failed to set its owner to '
1164
+OwnerComponent.Name+':'+OwnerComponent.ClassName,
1199
MessageDlg(lisCFEInvalidComponentOwner,
1200
Format(lisCFETheComponentOfTypeFailedToSetItsOwnerTo, [NewComponent.
1201
ClassName, OwnerComponent.Name, OwnerComponent.ClassName]),
1165
1202
mtError,[mbCancel],0);
1261
1298
// no parent and not a form
1262
1299
AControl.SetBounds(0,0,CompWidth,CompHeight);
1263
1300
AControl.DesignInfo := LeftTopToDesignInfo(CompLeft, CompTop);
1264
//DebugLn(['TCustomFormEditor.CreateComponent ',dbgsName(AControl),' ',LongRec(AControl.DesignInfo).Lo,',',LongRec(AControl.DesignInfo).Hi]);
1301
//DebugLn(['TCustomFormEditor.CreateComponent ',dbgsName(AControl),' ',LazLongRec(AControl.DesignInfo).Lo,',',LongRec(AControl.DesignInfo).Hi]);
1335
1372
FreeAndNil(Mediator);
1337
1374
on E: Exception do begin
1338
s:='Error destroying mediator '+Mediator.ClassName
1339
+' of unit '+AUnitName+':'#13
1341
DebugLn(['TCustomFormEditor.CreateComponent ',s]);
1375
s:=Format(lisCFEErrorDestroyingMediatorOfUnit, [Mediator.ClassName,
1376
AUnitName, #13, E.Message]);
1377
DebugLn(['TCustomFormEditor.CreateComponent ',UTF8ToConsole(s)]);
1342
1378
DumpExceptionBackTrace;
1343
MessageDlg('Error destroying mediator',s,mtError,[mbCancel],0);
1379
MessageDlg(lisCFEErrorDestroyingMediator, s, mtError, [mbCancel], 0);
1351
1387
NewComponent:=nil;
1353
1389
on E: Exception do begin
1354
s:='Error destroying component of type '+TypeClass.ClassName
1355
+' of unit '+AUnitName+':'#13
1357
DebugLn(['TCustomFormEditor.CreateComponent ',s]);
1390
s:=Format(lisCFEErrorDestroyingComponentOfTypeOfUnit, [TypeClass.
1391
ClassName, AUnitName, #13, E.Message]);
1392
DebugLn(['TCustomFormEditor.CreateComponent ',UTF8ToConsole(s)]);
1358
1393
DumpExceptionBackTrace;
1359
MessageDlg('Error destroying component',s,mtError,[mbCancel],0);
1394
MessageDlg(lisCFEErrorDestroyingComponent, s, mtError, [mbCancel], 0
1399
1435
Result:=JITList[NewJITIndex];
1402
function TCustomFormEditor.CreateChildComponentFromStream(BinStream: TStream;
1438
procedure TCustomFormEditor.CreateChildComponentsFromStream(BinStream: TStream;
1403
1439
ComponentClass: TComponentClass; Root: TComponent;
1404
ParentControl: TWinControl): TComponent;
1440
ParentControl: TWinControl; NewComponents: TFPList);
1406
1442
JITList: TJITComponentList;
1410
1444
JITList:=FindJITList(Root);
1411
1445
if JITList=nil then
1412
1446
RaiseException('TCustomFormEditor.CreateChildComponentFromStream ClassName='+
1413
1447
Root.ClassName);
1415
Result:=JITList.AddJITChildComponentFromStream(
1416
Root,BinStream,ComponentClass,ParentControl);
1449
JITList.AddJITChildComponentsFromStream(
1450
Root,BinStream,ComponentClass,ParentControl,NewComponents);
1419
1453
function TCustomFormEditor.FixupReferences(AComponent: TComponent): TModalResult;
1824
1855
if LFMFilename<>'' then
1825
aCaption:='Error reading '+ExtractFilename(LFMFilename);
1856
aCaption:=Format(lisCFEErrorReading, [ExtractFilename(LFMFilename)]);
1827
1858
with JITComponentList do begin
1828
1859
if LFMFilename<>'' then
1829
1860
aMsg:=aMsg+LFMFilename
1830
1861
else if CurReadStreamClass<>nil then
1831
aMsg:=aMsg+'Stream='+CurReadStreamClass.ClassName
1862
aMsg:=Format(lisCFEStream, [aMsg, CurReadStreamClass.ClassName])
1833
1864
aMsg:=aMsg+'JITList='+ClassName;
1834
1865
aMsg:=aMsg+': ';
1835
1866
if CurReadJITComponent<>nil then
1836
aMsg:=aMsg+'Root='+CurReadJITComponent.Name+':'+CurReadJITComponent.ClassName;
1867
aMsg:=Format(lisCFERoot, [aMsg, CurReadJITComponent.Name,
1868
CurReadJITComponent.ClassName]);
1837
1869
if CurReadChild<>nil then
1838
aMsg:=aMsg+#13'Component: '
1839
+CurReadChild.Name+':'+CurReadChild.ClassName
1870
aMsg:=Format(lisCFEComponent, [aMsg, #13, CurReadChild.Name, CurReadChild.
1840
1872
else if CurReadChildClass<>nil then
1841
aMsg:=aMsg+#13'Component Class: '+CurReadChildClass.ClassName;
1873
aMsg:=Format(lisCFEComponentClass, [aMsg, #13, CurReadChildClass.ClassName
1842
1875
aMsg:=aMsg+#13+CurReadErrorMsg;
1844
1877
if (Reader<>nil) and (Reader.Driver is TLRSObjectReader) then begin
1845
1878
ErrorBinPos:=TLRSObjectReader(Reader.Driver).Stream.Position;
1846
aMsg:=aMsg+#13+'Stream position: '+dbgs(ErrorBinPos);
1879
aMsg:=Format(lisCFEStreamPosition, [aMsg, #13, dbgs(ErrorBinPos)]);
1849
1882
case ErrorType of
1854
1887
jfeUnknownComponentClass:
1856
aMsg:=aMsg+#13+'Class "'+JITComponentList.CurUnknownClass+'" not found.';
1889
aMsg:=Format(lisCFEClassNotFound, [aMsg, #13, JITComponentList.
1859
1893
if Buttons=[mbIgnore,mbCancel] then begin
1860
Action:=QuestionDlg(aCaption,aMsg,DlgType,
1861
[mrIgnore,'Continue loading',
1862
mrCancel,'Cancel loading this resource',
1863
mrAbort,'Stop all loading'],HelpCtx);
1894
Action:=IDEQuestionDialog(aCaption,aMsg,DlgType,
1895
[mrIgnore, lisCFEContinueLoading,
1896
mrCancel, lisCFECancelLoadingThisResource,
1897
mrAbort, lisCFEStopAllLoading]);
1865
Action:=QuestionDlg(aCaption,aMsg,DlgType,
1866
[mrCancel,'Cancel loading this resource',
1867
mrAbort,'Stop all loading'],HelpCtx);
1899
Action:=IDEQuestionDialog(aCaption,aMsg,DlgType,
1900
[mrCancel, lisCFECancelLoadingThisResource,
1901
mrAbort, lisCFEStopAllLoading]);
1903
1937
LFMFilename:=ChangeFileExt(TUnitInfo(List.ContextObject).Filename,'.lfm');
1905
1939
if LFMFilename<>'' then
1906
Msg:=Msg+'In file '+LFMFilename+#13;
1940
Msg:=Format(lisCFEInFile, [Msg, LFMFilename, #13]);
1908
1942
if List.CurReadErrorMsg<>'' then
1909
1943
Msg:=Msg+List.CurReadErrorMsg+#13;
1910
1944
if E is EReadError then;
1911
MessageDlg('Read error',Msg,mtError,[mbCancel],0);
1945
MessageDlg(lisCodeToolsDefsReadError, Msg, mtError, [mbCancel], 0);
1914
1948
procedure TCustomFormEditor.OnDesignerMenuItemClick(Sender: TObject);
1916
1950
CompEditor: TBaseComponentEditor;
1917
1951
MenuItem: TMenuItem;
1952
CompClassName: String;
1919
1954
if (Sender=nil) or (not (Sender is TMenuItem)) then exit;
1920
1955
MenuItem:=TMenuItem(Sender);
1923
1958
CompEditor:=GetComponentEditor(TComponent(Sender));
1924
1959
if CompEditor=nil then exit;
1960
CompClassName:=CompEditor.ClassName;
1926
1962
CompEditor.Edit;
1928
1964
on E: Exception do begin
1929
DebugLn('TCustomFormEditor.OnDesignerMenuItemClick ERROR: ',E.Message);
1930
MessageDlg('Error in '+CompEditor.ClassName,
1931
'The component editor of class "'+CompEditor.ClassName+'"'
1932
+'has created the error:'#13
1965
DebugLn('TCustomFormEditor.OnDesignerMenuItemClick ERROR on CompEditor.Edit: ',E.Message);
1966
MessageDlg(Format(lisErrorIn, [CompClassName]),
1967
Format(lisCFETheComponentEditorOfClassHasCreatedTheError, [CompClassName, #13, E.Message]),
1974
on E: Exception do begin
1975
DebugLn('TCustomFormEditor.OnDesignerMenuItemClick ERROR on CompEditor.Free: ',E.Message);
1976
MessageDlg(Format(lisErrorIn, [CompClassName]),
1977
Format(lisCFETheComponentEditorOfClassHasCreatedTheError, [CompClassName, #13, E.Message]),
1934
1978
mtError,[mbOk],0);
2048
2092
function TCustomFormEditor.GetPropertyEditorHook: TPropertyEditorHook;
2050
Result:=Obj_Inspector.PropertyEditorHook;
2094
Result:=GlobalDesignHook;
2095
if Obj_Inspector<>nil then
2096
Result:=Obj_Inspector.PropertyEditorHook;
2053
2099
function TCustomFormEditor.FindDefinePropertyNode(
2081
2127
while true do begin
2082
2128
j:=OwnerComponent.ComponentCount-1;
2084
if (length(Result)>1) and (Result[1]='T') then
2085
Result:=RightStr(Result,length(Result)-1);
2129
Result:=ClassNameToComponentName(AClassName);
2086
2130
if Result[length(Result)] in ['0'..'9'] then
2087
2131
Result:=Result+'_';
2088
2132
Result:=Result+IntToStr(i);