MG: added backup code and fixed removing controls

git-svn-id: trunk@245 -
This commit is contained in:
lazarus 2001-03-28 14:08:45 +00:00
parent 5cc0992d9c
commit 566a5f3aa8
6 changed files with 1325 additions and 414 deletions

View File

@ -128,6 +128,7 @@ type
FUpdateLock: integer;
FChangedDuringLock: boolean;
FIsResizing: boolean;
FNotSaveBounds: boolean;
FOnChange: TNotifyEvent;
@ -157,6 +158,7 @@ type
procedure Clear;
procedure Assign(AControlSelection:TControlSelection);
procedure AdjustSize;
property IsResizing: boolean read FIsResizing;
function IsSelected(AComponent: TComponent): Boolean;
procedure SaveBounds;
procedure MoveSelection(dx, dy: integer);
@ -372,6 +374,7 @@ begin
FChangedDuringLock:=false;
FRubberbandActive:=false;
FIsResizing:=false;
FNotSaveBounds:=false;
end;
destructor TControlSelection.Destroy;
@ -509,6 +512,7 @@ procedure TControlSelection.SaveBounds;
var i:integer;
g:TGrabIndex;
begin
if FNotSaveBounds then exit;
writeln('TControlSelection.SaveBounds');
for i:=0 to FControls.Count-1 do Items[i].SaveBounds;
for g:=Low(TGrabIndex) to High(TGrabIndex) do FGrabbers[g].SaveBounds;
@ -543,6 +547,7 @@ begin
Result:=FControls.Add(NewSelectedControl);
if Count=1 then SetCustomForm;
AdjustSize;
SaveBounds;
EndUpdate;
DoChange;
end;
@ -561,6 +566,7 @@ begin
FControls.Delete(Index);
if Count=0 then SetCustomForm;
AdjustSize;
SaveBounds;
DoChange;
end;
@ -571,6 +577,7 @@ begin
FControls.Clear;
FCustomForm:=nil;
AdjustSize;
SaveBounds;
DoChange;
end;
@ -578,6 +585,7 @@ procedure TControlSelection.Assign(AControlSelection:TControlSelection);
var i:integer;
begin
if AControlSelection=Self then exit;
FNotSaveBounds:=true;
BeginUpdate;
Clear;
FControls.Capacity:=AControlSelection.Count;
@ -585,6 +593,8 @@ begin
Add(AControlSelection[i].Component);
SetCustomForm;
AdjustSize;
FNotSaveBounds:=false;
SaveBounds;
EndUpdate;
DoChange;
end;
@ -621,8 +631,10 @@ procedure TControlSelection.SizeSelection(dx, dy: integer);
// if ActiveGrabber=nil then Left,Top
var i:integer;
GrabberPos:TGrabPositions;
NewLeft, NewTop, NewRight, NewBottom: integer;
begin
if Count=0 then exit;
if (Count=0) or (FIsResizing) then exit;
writeln('[TControlSelection.SizeSelection] A ',dx,',',dy);
BeginUpdate;
FIsResizing:=true;
if FActiveGrabber<>nil then
@ -633,37 +645,49 @@ begin
if [gpLeft,gpRight] * GrabberPos = [] then dx:=0;
if (dx=0) and (dy=0) then exit;
if gpLeft in GrabberPos then begin
FLeft:=FOldLeft+dx;
FWidth:=FOldWidth-dx;
FLeft:=FLeft+dx;
FWidth:=FWidth-dx;
end;
if gpRight in GrabberPos then begin
FWidth:=FOldWidth+dx;
FWidth:=FWidth+dx;
end;
if gpTop in GrabberPos then begin
FTop:=FOldTop+dy;
FHeight:=FOldHeight-dy;
FTop:=FTop+dy;
FHeight:=FHeight-dy;
end;
if gpBottom in GrabberPos then begin
FHeight:=FOldHeight+dy;
FHeight:=FHeight+dy;
end;
AdjustGrabber;
if Count=1 then begin
// single selection
Items[0].SetBounds(FLeft,FTop,FWidth,FHeight);
NewLeft:=FLeft;
NewTop:=FTop;
NewRight:=FLeft+FWidth;
NewBottom:=FTop+FHeight;
Items[0].SetBounds(
Min(NewLeft,NewRight),
Min(NewTop,NewBottom),
Abs(FWidth),
Abs(FHeight)
);
end else if Count>1 then begin
// multi selection
if (FOldWidth<>0) and (FOldHeight<>0) then begin
for i:=0 to Count-1 do begin
Items[i].SetBounds(
FOldLeft + (((Items[i].OldLeft-FOldLeft) * FWidth) div FOldWidth),
FOldTop + (((Items[i].OldTop-FOldTop) * FHeight) div FOldHeight),
Max(1,Abs((Items[i].OldWidth * FWidth) div FOldWidth)),
Max(1,Abs((Items[i].OldHeight * FHeight) div FOldHeight))
);
NewLeft:=FOldLeft + (((Items[i].OldLeft-FOldLeft) * FWidth) div FOldWidth);
NewTop:=FOldTop + (((Items[i].OldTop-FOldTop) * FHeight) div FOldHeight);
NewRight:=Max(1,Abs(FOldLeft +
(((Items[i].OldLeft+Items[i].OldWidth-FOldLeft) * FWidth)
div FOldWidth)));
NewBottom:=Max(1,Abs(FOldTop +
(((Items[i].OldTop+Items[i].OldHeight-FOldTop) * FHeight)
div FOldHeight)));
Items[i].SetBounds(NewLeft,NewTop,NewRight-NewLeft,NewBottom-NewTop);
writeln('[TControlSelection.SizeSelection] i=',i,' ',Items[i].Width,' ',Items[i].Height);
end;
end;
end;
SaveBounds;
EndUpdate;
FIsResizing:=false;
end;
@ -672,6 +696,8 @@ function TControlSelection.GrabberAtPos(X,Y:integer):TGrabber;
var g:TGrabIndex;
begin
if FControls.Count>0 then begin
writeln('[TControlSelection.GrabberAtPos] ',x,',',y,' '
,FGrabbers[4].Left,',',FGrabbers[4].Top);
for g:=Low(TGrabIndex) to High(TGrabIndex) do
if (FGrabbers[g].Left<=x) and (FGrabbers[g].Top<=y)
and (FGrabbers[g].Left+FGrabbers[g].Width>x)

View File

@ -40,6 +40,8 @@ type
Value: boolean) of object;
TOnAddComponent = procedure(Sender: TObject; Component: TComponent;
ComponentClass: TRegisteredComponent) of object;
TOnRemoveComponent = procedure(Sender: TObject; Component: TComponent)
of object;
TDesigner = class(TIDesigner)
private
@ -52,6 +54,7 @@ type
FOnComponentListChanged: TNotifyEvent;
FOnPropertiesChanged: TNotifyEvent;
FOnAddComponent: TOnAddComponent;
FOnRemoveComponent: TOnRemoveComponent;
FHasSized: boolean;
FGridColor: TColor;
@ -71,8 +74,8 @@ type
Procedure KeyUP(Sender : TControl; Message:TLMKEY);
Procedure RemoveControl(Control : TComponent);
Procedure NudgeControl(Value1,Value2 : Integer);
Procedure NudgeSize(Value1,Value2 : Integer);
Procedure NudgeControl(DiffX, DiffY: Integer);
Procedure NudgeSize(DiffX, DiffY: Integer);
public
ControlSelection : TControlSelection;
@ -101,6 +104,8 @@ type
property OnPropertiesChanged: TNotifyEvent
read FOnPropertiesChanged write FOnPropertiesChanged;
property OnAddComponent: TOnAddComponent read FOnAddComponent write FOnAddComponent;
property OnRemoveComponent: TOnRemoveComponent
read FOnRemoveComponent write FOnRemoveComponent;
end;
@ -139,7 +144,8 @@ end;
Procedure TDesigner.RemoveControl(Control : TComponent);
Begin
Writeln('[TDesigner.RemoveControl] ',Control.Name,':',Control.ClassName);
FSourceEditor.RemoveControlCode(Control);
if Assigned(FOnRemoveComponent) then
FOnRemoveComponent(Self,Control);
Writeln('[TDesigner.RemoveControl] 1');
FCustomForm.RemoveControl(TCOntrol(Control));
//this send a message to notification and removes it from the controlselection
@ -148,16 +154,16 @@ Begin
Writeln('[TDesigner.RemoveControl] end');
end;
Procedure TDesigner.NudgeControl(Value1,Value2 : Integer);
Procedure TDesigner.NudgeControl(DiffX, DiffY : Integer);
Begin
Writeln('[TDesigner.NudgeControl]');
ControlSelection.MoveSelection(Value1,Value2);
ControlSelection.MoveSelection(DiffX, DiffY);
end;
Procedure TDesigner.NudgeSize(Value1,Value2 : Integer);
Procedure TDesigner.NudgeSize(DiffX, DiffY: Integer);
Begin
Writeln('[TDesigner.NudgeSize]');
ControlSelection.SizeSelection(Value1,Value2);
ControlSelection.SizeSelection(DiffX, DiffY);
end;
procedure TDesigner.SelectOnlyThisComponent(AComponent:TComponent);
@ -190,9 +196,11 @@ begin
if (ControlSelection.IsSelected(Sender)) then begin
writeln('*** LM_Size ',Sender.Name,':',Sender.ClassName,' Type=',Message.SizeType
,' ',Message.Width,',',Message.Height,' Pos=',Sender.Left,',',Sender.Top);
ControlSelection.AdjustSize;
if Assigned(FOnPropertiesChanged) then
FOnPropertiesChanged(Self);
if not ControlSelection.IsResizing then begin
ControlSelection.AdjustSize;
if Assigned(FOnPropertiesChanged) then
FOnPropertiesChanged(Self);
end;
end;
end;
@ -244,9 +252,12 @@ Begin
else
Writeln(', No CTRL down');
if (Message.Keys and MK_LButton) > 0 then
writeln('HALLLo ',Message.Keys and MK_LButton);
if (Message.Keys and MK_LButton) > 0 then begin
ControlSelection.ActiveGrabber:=
ControlSelection.GrabberAtPos(MouseDownPos.X,MouseDownPos.Y);
ControlSelection.GrabberAtPos(MouseDownPos.X,MouseDownPos.Y)
end else
ControlSelection.ActiveGrabber:=nil;
if Assigned(FOnGetSelectedComponentClass) then
FOnGetSelectedComponentClass(Self,SelectedCompClass)
@ -296,12 +307,16 @@ Begin
AControlSelection.Free;
end;
end;
end else begin
// mouse down on grabber -> begin sizing
// grabber is already activated
// the sizing is handled in mousemove
writeln('[TDesigner.MouseDownOnControl] Grabber activated');
end;
end else begin
// add component mode -> handled in mousemove and mouseup
end;
end;
ControlSelection.SaveBounds;
writeln('[TDesigner.MouseDownOnControl] END');
End;
@ -324,9 +339,9 @@ Begin
RubberBandWasActive:=ControlSelection.RubberBandActive;
Shift := [];
if (TLMMouse(Message).keys and MK_Shift) = MK_Shift then
if (Message.keys and MK_Shift) = MK_Shift then
Shift := [ssShift];
if (TLMMouse(Message).keys and MK_Control) = MK_Control then
if (Message.keys and MK_Control) = MK_Control then
Shift := Shift +[ssCTRL];
@ -349,6 +364,7 @@ Begin
else
SelectedCompClass:=nil;
writeln('UND JETZT ',Message.Keys and MK_LButton);
if (Message.Keys and MK_LButton) > 0 then begin
// left mouse button
if SelectedCompClass = nil then begin
@ -413,7 +429,6 @@ Begin
end;
end;
end;
ControlSelection.SaveBounds;
LastMouseMovePos.X:=-1;
FHasSized:=false;
@ -422,44 +437,33 @@ writeln('[TDesigner.MouseUpOnControl] END');
end;
Procedure TDesigner.MouseMoveOnControl(Sender : TControl; var Message : TLMMouse);
const
mk_lbutton = 1;
mk_rbutton = 2;
mk_shift = 4;
mk_control = 8;
mk_mbutton = $10;
var
Shift : TShiftState;
SenderOrigin:TPoint;
SenderParentForm:TCustomForm;
MouseX, MouseY :integer;
AGrabber: TGrabber;
Begin
SenderParentForm:=GetParentForm(Sender);
if SenderParentForm=nil then exit;
SenderOrigin:=GetFormRelativeControlTopLeft(Sender);
if (Message.keys and MK_LButton) = MK_LButton then begin
{ if (Message.keys and MK_LButton) = MK_LButton then begin
MouseX:=Message.Pos.X;
MouseY:=Message.Pos.Y;
end else begin
end else begin}
MouseX:=Message.Pos.X+SenderOrigin.X;
MouseY:=Message.Pos.Y+SenderOrigin.Y;
end;
AGrabber:=ControlSelection.GrabberAtPos(MouseX,MouseY);
if AGrabber=nil then begin
end else begin
end;
// end;
if MouseDownControl=nil then exit;
if true then begin
Write('MouseMoveOnControl');
Write(' ',Sender.Name,':',Sender.ClassName,' Origin=',SenderOrigin.X,',',SenderOrigin.Y);
Write(' Msg=',Message.Pos.x,',',Message.Pos.Y);
Write(' Mouse=',MouseX,',',MouseY);
Write('MouseMoveOnControl'
,' ',Sender.Name,':',Sender.ClassName
,' ',Sender.Left,',',Sender.Top
,' Origin=',SenderOrigin.X,',',SenderOrigin.Y
,' Msg=',Message.Pos.x,',',Message.Pos.Y
,' Mouse=',MouseX,',',MouseY
);
writeln();
end;
@ -469,15 +473,14 @@ Begin
if (TLMMouse(Message).keys and MK_Control) = MK_Control then
Shift := Shift + [ssCTRL];
if ControlSelection.ActiveGrabber<>nil then begin
if (Message.keys and MK_LButton) = MK_LButton then begin
if (Message.keys and MK_LButton) = MK_LButton then begin
if ControlSelection.ActiveGrabber<>nil then begin
FHasSized:=true;
ControlSelection.SizeSelection(MouseX-MouseDownPos.X, MouseY-LastMouseMovePos.Y);
ControlSelection.SizeSelection(
MouseX-LastMouseMovePos.X, MouseY-LastMouseMovePos.Y);
if Assigned(FOnPropertiesChanged) then
FOnPropertiesChanged(Self);
end;
end else begin
if (Message.keys and MK_LButton) = MK_LButton then begin
end else begin
if (not (MouseDownControl is TCustomForm)) and (ControlSelection.Count>=1)
and not (ControlSelection[0].Component is TCustomForm) then begin
// move selection
@ -493,6 +496,8 @@ Begin
SenderParentForm.Invalidate;
end;
end;
end else begin
ControlSelection.ActiveGrabber:=nil;
end;
LastMouseMovePos:=Point(MouseX,MouseY);
end;

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@ uses
ExtCtrls, StdCtrls, EditorOptions, LResources, LazConf, Dialogs;
const
EnvOptsVersion: integer = 100;
EnvOptsVersion: integer = 101;
type
//----------------------------------------------------------------------------
@ -28,8 +28,8 @@ type
bakSymbolInFront, // .~pp
bakSymbolBehind, // .pp~
bakCounter, // .pp;1
bakSameName, // .pp only available if backuping into subdirectory
bakUserDefinedAddExt // .pp.xxx
bakUserDefinedAddExt,// .pp.xxx
bakSameName // .pp only available if backuping into subdirectory
);
TBackupInfo = record
@ -71,7 +71,7 @@ type
FObjectInspectorOptions: TOIOptions;
// backup
FBackupInfoRepositoryFiles: TBackupInfo;
FBackupInfoProjectFiles: TBackupInfo;
FBackupInfoOtherFiles: TBackupInfo;
// recent files and directories
@ -126,8 +126,8 @@ type
read FObjectInspectorOptions write FObjectInspectorOptions;
// backup
property BackupInfoRepositoryFiles: TBackupInfo
read FBackupInfoRepositoryFiles write FBackupInfoRepositoryFiles;
property BackupInfoProjectFiles: TBackupInfo
read FBackupInfoProjectFiles write FBackupInfoProjectFiles;
property BackupInfoOtherFiles: TBackupInfo
read FBackupInfoOtherFiles write FBackupInfoOtherFiles;
@ -149,6 +149,7 @@ type
FOnLoadEnvironmentSettings: TOnLoadEnvironmentSettings;
FOnSaveEnvironmentSettings: TOnSaveEnvironmentSettings;
procedure SetupDesktopPage;
procedure SetupBackupPage;
procedure SetComboBoxText(AComboBox:TComboBox; AText:AnsiString);
published
@ -187,10 +188,30 @@ type
BackgroundColorLabel: TLabel;
BackgroundColorButton: TColorButton;
// backup
BackupHelpLabel: TLabel;
BackupProjectGroupBox: TGroupBox;
BakProjTypeRadioGroup: TRadioGroup;
BakProjAddExtLabel: TLabel;
BakProjAddExtComboBox: TComboBox;
BakProjMaxCounterLabel: TLabel;
BakProjMaxCounterComboBox: TComboBox;
BakProjSubDirLabel: TLabel;
BakProjSubDirComboBox: TComboBox;
BackupOtherGroupBox: TGroupBox;
BakOtherTypeRadioGroup: TRadioGroup;
BakOtherAddExtLabel: TLabel;
BakOtherAddExtComboBox: TComboBox;
BakOtherMaxCounterLabel: TLabel;
BakOtherMaxCounterComboBox: TComboBox;
BakOtherSubDirLabel: TLabel;
BakOtherSubDirComboBox: TComboBox;
// buttons at bottom
OkButton: TButton;
CancelButton: TButton;
procedure BakTypeRadioGroupClick(Sender: TObject);
procedure OkButtonClick(Sender: TObject);
procedure CancelButtonClick(Sender: TObject);
procedure SaveDesktopSettingsToFileButtonClick(Sender: TObject);
@ -217,7 +238,10 @@ implementation
{ TEnvironmentOptions }
const EnvOptsConfFileName='environmentoptions.xml';
const
EnvOptsConfFileName='environmentoptions.xml';
BakMaxCounterInfiniteTxt = 'infinite';
BakNoSubDirTxt = '(none)';
constructor TEnvironmentOptions.Create;
begin
@ -252,17 +276,17 @@ begin
FObjectInspectorOptions:=TOIOptions.Create;
// backup
with FBackupInfoRepositoryFiles do begin
with FBackupInfoProjectFiles do begin
BackupType:=bakSameName;
AdditionalExtension:='bak'; // for bakUserDefinedAddExt
MaxCounter:=9; // for bakCounter
SubDirectory:='backup';
MaxCounter:=3; // for bakCounter
SubDirectory:='';
end;
with FBackupInfoOtherFiles do begin
BackupType:=bakUserDefinedAddExt;
AdditionalExtension:='bak'; // for bakUserDefinedAddExt
MaxCounter:=9; // for bakCounter
SubDirectory:='backup';
MaxCounter:=3; // for bakCounter
SubDirectory:='';
end;
// recent files and directories
@ -327,7 +351,10 @@ var XMLConfig: TXMLConfig;
end;
AdditionalExtension:=XMLConfig.GetValue(Path+'AdditionalExtension','bak');
MaxCounter:=XMLConfig.GetValue(Path+'MaxCounter',9);
SubDirectory:=XMLConfig.GetValue(Path+'SubDirectory','backup');
if FileVersion<101 then
SubDirectory:=''
else
SubDirectory:=XMLConfig.GetValue(Path+'SubDirectory','backup');
end;
end;
@ -382,8 +409,8 @@ begin
if not OnlyDesktop then begin
// backup
LoadBackupInfo(FBackupInfoRepositoryFiles
,'EnvironmentOptions/BackupRepositoryFiles/');
LoadBackupInfo(FBackupInfoProjectFiles
,'EnvironmentOptions/BackupProjectFiles/');
LoadBackupInfo(FBackupInfoOtherFiles
,'EnvironmentOptions/BackupOtherFiles/');
end;
@ -478,8 +505,8 @@ begin
if not OnlyDesktop then begin
// backup
SaveBackupInfo(FBackupInfoRepositoryFiles
,'EnvironmentOptions/BackupRepositoryFiles/');
SaveBackupInfo(FBackupInfoProjectFiles
,'EnvironmentOptions/BackupProjectFiles/');
SaveBackupInfo(FBackupInfoOtherFiles
,'EnvironmentOptions/BackupOtherFiles/');
end;
@ -510,7 +537,7 @@ constructor TEnvironmentOptionsDialog.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
if LazarusResources.Find(ClassName)=nil then begin
SetBounds((Screen.Width-480) div 2,(Screen.Height-350) div 2, 485, 355);
SetBounds((Screen.Width-480) div 2,(Screen.Height-400) div 2, 485, 405);
Caption:='Environment Options';
NoteBook:=TNoteBook.Create(Self);
@ -519,9 +546,11 @@ begin
Parent:=Self;
SetBounds(0,0,Self.ClientWidth-4,Self.ClientHeight-50);
Pages[0]:='Desktop';
Pages.Add('Backup');
end;
SetupDesktopPage;
SetupBackupPage;
NoteBook.Show;
@ -839,7 +868,7 @@ begin
ObjectInspectorGroupBox:=TGroupBox.Create(Self);
with ObjectInspectorGroupBox do begin
Name:='ObjectInspectorGroupBox';
Parent:=NoteBook.Page[0];;
Parent:=NoteBook.Page[0];
Left:=FormEditorGroupBox.Left;
Top:=FormEditorGroupBox.Top+FormEditorGroupBox.Height+5;
Width:=FormEditorGroupBox.Width;
@ -852,7 +881,7 @@ begin
with BackgroundColorButton do begin
Name:='BackgroundColorButton';
Parent:=ObjectInspectorGroupBox;
Left:=2;
Left:=5;
Top:=2;
Width:=50;
Height:=25;
@ -864,7 +893,7 @@ begin
Name:='BackgroundColorLabel';
Parent:=ObjectInspectorGroupBox;
Left:=BackgroundColorButton.Left+BackgroundColorButton.Width+5;
Top:=BackgroundColorButton.Top+2;
Top:=BackgroundColorButton.Top;
Width:=ObjectInspectorGroupBox.ClientWidth-Left-5;
Height:=23;
Caption:='Background color';
@ -873,6 +902,294 @@ begin
end;
procedure TEnvironmentOptionsDialog.SetupBackupPage;
var MaxX:integer;
begin
MaxX:=ClientWidth-5;
BackupHelpLabel:=TLabel.Create(Self);
with BackupHelpLabel do begin
Name:='BackupHelpLabel';
Parent:=NoteBook.Page[1];
Left:=5;
Top:=2;
Width:=MaxX-Left*2;
Height:=23;
Caption:='Notes: ';
Show;
end;
BackupProjectGroupBox:=TGroupBox.Create(Self);
with BackupProjectGroupBox do begin
Name:='BackupProjectGroupBox';
Parent:=NoteBook.Page[1];
Left:=4;
Top:=BackupHelpLabel.Top+BackupHelpLabel.Height+4;
Width:=(MaxX div 2) - 11;
Height:=260;
Caption:='Project files';
Show;
end;
BakProjTypeRadioGroup:=TRadioGroup.Create(Self);
with BakProjTypeRadioGroup do begin
Name:='BakProjTypeRadioGroup';
Parent:=BackupProjectGroupBox;
Left:=5;
Top:=4;
Width:=BackupProjectGroupBox.ClientWidth-Left-Left-4;
Height:=140;
Caption:='Type';
with Items do begin
BeginUpdate;
Add('None');
Add('Symbol in front (.~pp)');
Add('Symbol behind (.pp~)');
Add('Counter (.pp;1)');
Add('User defined extension (.pp.xxx)');
Add('Same name (in subdirectory)');
EndUpdate;
end;
OnClick:=@BakTypeRadioGroupClick;
Show;
end;
BakProjAddExtLabel:=TLabel.Create(Self);
with BakProjAddExtLabel do begin
Name:='BakProjAddExtLabel';
Parent:=BackupProjectGroupBox;
Left:=5;
Top:=BakProjTypeRadioGroup.Top+BakProjTypeRadioGroup.Height+5;
Width:=BakProjTypeRadioGroup.Width-62;
Height:=23;
Caption:='User defined extension';
Show;
end;
BakProjAddExtComboBox:=TComboBox.Create(Self);
with BakProjAddExtComboBox do begin
Name:='BakProjAddExtComboBox';
Parent:=BackupProjectGroupBox;
Left:=BakProjAddExtLabel.Left+BakProjAddExtLabel.Width+2;
Top:=BakProjAddExtLabel.Top;
Width:=60;
Height:=25;
with Items do begin
BeginUpdate;
Add('bak');
Add('old');
EndUpdate;
end;
Show;
end;
BakProjMaxCounterLabel:=TLabel.Create(Self);
with BakProjMaxCounterLabel do begin
Name:='BakProjMaxCounterLabel';
Parent:=BackupProjectGroupBox;
Left:=5;
Top:=BakProjAddExtLabel.Top+BakProjAddExtLabel.Height+5;
Width:=110;
Height:=23;
Caption:='Maximum counter';
Show;
end;
BakProjMaxCounterComboBox:=TComboBox.Create(Self);
with BakProjMaxCounterComboBox do begin
Name:='BakProjMaxCounterComboBox';
Parent:=BackupProjectGroupBox;
Left:=BakProjMaxCounterLabel.Left+BakProjMaxCounterLabel.Width+2;
Top:=BakProjMaxCounterLabel.Top;
Width:=100;
Height:=25;
with Items do begin
BeginUpdate;
Add('1');
Add('2');
Add('3');
Add('5');
Add('9');
Add(BakMaxCounterInfiniteTxt);
EndUpdate;
end;
Show;
end;
BakProjSubDirLabel:=TLabel.Create(Self);
with BakProjSubDirLabel do begin
Name:='BakProjSubDirLabel';
Parent:=BackupProjectGroupBox;
Left:=5;
Top:=BakProjMaxCounterLabel.Top+BakProjMaxCounterLabel.Height+5;
Width:=110;
Height:=23;
Caption:='Sub directory';
Show;
end;
BakProjSubDirComboBox:=TComboBox.Create(Self);
with BakProjSubDirComboBox do begin
Name:='BakProjSubDirComboBox';
Parent:=BackupProjectGroupBox;
Left:=BakProjSubDirLabel.Left+BakProjSubDirLabel.Width+2;
Top:=BakProjSubDirLabel.Top;
Width:=100;
Height:=25;
with Items do begin
BeginUpdate;
Add(BakNoSubDirTxt);
Add('backup');
EndUpdate;
end;
Show;
end;
BackupOtherGroupBox:=TGroupBox.Create(Self);
with BackupOtherGroupBox do begin
Name:='BackupOtherGroupBox';
Parent:=NoteBook.Page[1];
Left:=BackupProjectGroupBox.Left+BackupProjectGroupBox.Width+10;
Top:=BackupHelpLabel.Top+BackupHelpLabel.Height+4;
Width:=(MaxX div 2) - 11;
Height:=260;
Caption:='Other files';
Show;
end;
BakOtherTypeRadioGroup:=TRadioGroup.Create(Self);
with BakOtherTypeRadioGroup do begin
Name:='BakOtherTypeRadioGroup';
Parent:=BackupOtherGroupBox;
Left:=5;
Top:=4;
Width:=BackupOtherGroupBox.ClientWidth-Left-Left-4;
Height:=140;
Caption:='Type';
with Items do begin
BeginUpdate;
Add('None');
Add('Symbol in front (.~pp)');
Add('Symbol behind (.pp~)');
Add('Counter (.pp;1)');
Add('User defined extension (.pp.xxx)');
Add('Same name (in subdirectory)');
EndUpdate;
end;
OnClick:=@BakTypeRadioGroupClick;
Show;
end;
BakOtherAddExtLabel:=TLabel.Create(Self);
with BakOtherAddExtLabel do begin
Name:='BakOtherAddExtLabel';
Parent:=BackupOtherGroupBox;
Left:=5;
Top:=BakOtherTypeRadioGroup.Top+BakOtherTypeRadioGroup.Height+5;
Width:=BakOtherTypeRadioGroup.Width-62;
Height:=23;
Caption:='User defined extension';
Show;
end;
BakOtherAddExtComboBox:=TComboBox.Create(Self);
with BakOtherAddExtComboBox do begin
Name:='BakOtherAddExtComboBox';
Parent:=BackupOtherGroupBox;
Left:=BakOtherAddExtLabel.Left+BakOtherAddExtLabel.Width+2;
Top:=BakOtherAddExtLabel.Top;
Width:=60;
Height:=25;
with Items do begin
BeginUpdate;
Add('bak');
Add('old');
EndUpdate;
end;
Show;
end;
BakOtherMaxCounterLabel:=TLabel.Create(Self);
with BakOtherMaxCounterLabel do begin
Name:='BakOtherMaxCounterLabel';
Parent:=BackupOtherGroupBox;
Left:=5;
Top:=BakOtherAddExtLabel.Top+BakOtherAddExtLabel.Height+5;
Width:=110;
Height:=23;
Caption:='Maximum counter';
Show;
end;
BakOtherMaxCounterComboBox:=TComboBox.Create(Self);
with BakOtherMaxCounterComboBox do begin
Name:='BakOtherMaxCounterComboBox';
Parent:=BackupOtherGroupBox;
Left:=BakOtherMaxCounterLabel.Left+BakOtherMaxCounterLabel.Width+2;
Top:=BakOtherMaxCounterLabel.Top;
Width:=100;
Height:=25;
with Items do begin
BeginUpdate;
Add('1');
Add('2');
Add('3');
Add('5');
Add('9');
Add(BakMaxCounterInfiniteTxt);
EndUpdate;
end;
Show;
end;
BakOtherSubDirLabel:=TLabel.Create(Self);
with BakOtherSubDirLabel do begin
Name:='BakOtherSubDirLabel';
Parent:=BackupOtherGroupBox;
Left:=5;
Top:=BakOtherMaxCounterLabel.Top+BakOtherMaxCounterLabel.Height+5;
Width:=110;
Height:=23;
Caption:='Sub directory';
Show;
end;
BakOtherSubDirComboBox:=TComboBox.Create(Self);
with BakOtherSubDirComboBox do begin
Name:='BakOtherSubDirComboBox';
Parent:=BackupOtherGroupBox;
Left:=BakOtherSubDirLabel.Left+BakOtherSubDirLabel.Width+2;
Top:=BakOtherSubDirLabel.Top;
Width:=100;
Height:=25;
with Items do begin
BeginUpdate;
Add('(no subdirectoy)');
Add('backup');
EndUpdate;
end;
Show;
end;
end;
procedure TEnvironmentOptionsDialog.BakTypeRadioGroupClick(Sender: TObject);
var i: integer;
begin
i:=TRadioGroup(Sender).ItemIndex;
if Sender=BakProjTypeRadioGroup then begin
writeln('[TEnvironmentOptionsDialog.BakTypeRadioGroupClick] ',i);
BakProjAddExtComboBox.Enabled:=(i=4);
BakProjAddExtLabel.Enabled:=BakProjAddExtComboBox.Enabled;
BakProjMaxCounterComboBox.Enabled:=(i=3);
BakProjMaxCounterLabel.EnableD:=BakProjMaxCounterComboBox.Enabled;
end else begin
BakOtherAddExtComboBox.Enabled:=(i=4);
BakOtherAddExtLabel.Enabled:=BakOtherAddExtComboBox.Enabled;
BakOtherMaxCounterComboBox.Enabled:=(i=3);
BakOtherMaxCounterLabel.EnableD:=BakOtherMaxCounterComboBox.Enabled;
end;
end;
procedure TEnvironmentOptionsDialog.OkButtonClick(Sender: TObject);
begin
// ToDo: save options
@ -973,6 +1290,48 @@ begin
AutoCreateFormsCheckBox.Checked:=AutoCreateForms;
SetComboBoxText(GridSizeXComboBox,IntToStr(GridSizeX));
SetComboBoxText(GridSizeYComboBox,IntToStr(GridSizeY));
// backup
with BackupInfoProjectFiles do begin
case BackupType of
bakNone: BakProjTypeRadioGroup.ItemIndex:=0;
bakSymbolInFront: BakProjTypeRadioGroup.ItemIndex:=1;
bakSymbolBehind: BakProjTypeRadioGroup.ItemIndex:=2;
bakCounter: BakProjTypeRadioGroup.ItemIndex:=3;
bakUserDefinedAddExt: BakProjTypeRadioGroup.ItemIndex:=4;
bakSameName: BakProjTypeRadioGroup.ItemIndex:=5;
end;
SetComboBoxText(BakProjAddExtComboBox,AdditionalExtension);
if MaxCounter<=0 then
SetComboBoxText(BakProjMaxCounterComboBox,BakMaxCounterInfiniteTxt)
else
SetComboBoxText(BakProjMaxCounterComboBox,IntToStr(MaxCounter));
if SubDirectory<>'' then
SetComboBoxText(BakProjSubDirComboBox,SubDirectory)
else
SetComboBoxText(BakProjSubDirComboBox,BakNoSubDirTxt);
end;
BakTypeRadioGroupClick(BakProjTypeRadioGroup);
with BackupInfoOtherFiles do begin
case BackupType of
bakNone: BakOtherTypeRadioGroup.ItemIndex:=0;
bakSymbolInFront: BakOtherTypeRadioGroup.ItemIndex:=1;
bakSymbolBehind: BakOtherTypeRadioGroup.ItemIndex:=2;
bakCounter: BakOtherTypeRadioGroup.ItemIndex:=3;
bakUserDefinedAddExt: BakOtherTypeRadioGroup.ItemIndex:=4;
bakSameName: BakOtherTypeRadioGroup.ItemIndex:=5;
end;
SetComboBoxText(BakOtherAddExtComboBox,AdditionalExtension);
if MaxCounter<=0 then
SetComboBoxText(BakOtherMaxCounterComboBox,BakMaxCounterInfiniteTxt)
else
SetComboBoxText(BakOtherMaxCounterComboBox,IntToStr(MaxCounter));
if SubDirectory<>'' then
SetComboBoxText(BakOtherSubDirComboBox,SubDirectory)
else
SetComboBoxText(BakOtherSubDirComboBox,BakNoSubDirTxt);
end;
BakTypeRadioGroupClick(BakOtherTypeRadioGroup);
end;
end;
@ -1001,6 +1360,46 @@ begin
AutoCreateForms:=AutoCreateFormsCheckBox.Checked;
GridSizeX:=StrToIntDef(GridSizeXComboBox.Text,GridSizeX);
GridSizeY:=StrToIntDef(GridSizeYComboBox.Text,GridSizeY);
// backup
with BackupInfoProjectFiles do begin
case BakProjTypeRadioGroup.ItemIndex of
0: BackupType:=bakNone;
1: BackupType:=bakSymbolInFront;
2: BackupType:=bakSymbolBehind;
3: BackupType:=bakCounter;
4: BackupType:=bakUserDefinedAddExt;
5: BackupType:=bakSameName;
end;
AdditionalExtension:=BakProjAddExtComboBox.Text;
if BakProjMaxCounterComboBox.Text=BakMaxCounterInfiniteTxt then
MaxCounter:=0
else
MaxCounter:=StrToIntDef(BakProjMaxCounterComboBox.Text,1);
if BakProjSubDirComboBox.Text=BakNoSubDirTxt then
SubDirectory:=''
else
SubDirectory:=BakProjSubDirComboBox.Text;
end;
with BackupInfoOtherFiles do begin
case BakOtherTypeRadioGroup.ItemIndex of
0: BackupType:=bakNone;
1: BackupType:=bakSymbolInFront;
2: BackupType:=bakSymbolBehind;
3: BackupType:=bakCounter;
4: BackupType:=bakUserDefinedAddExt;
5: BackupType:=bakSameName;
end;
AdditionalExtension:=BakOtherAddExtComboBox.Text;
if BakOtherMaxCounterComboBox.Text=BakMaxCounterInfiniteTxt then
MaxCounter:=0
else
MaxCounter:=StrToIntDef(BakOtherMaxCounterComboBox.Text,1);
if BakOtherSubDirComboBox.Text=BakNoSubDirTxt then
SubDirectory:=''
else
SubDirectory:=BakOtherSubDirComboBox.Text;
end;
end;
end;

View File

@ -28,10 +28,11 @@ interface
uses
Classes, LclLinux, Compiler, StdCtrls, Forms, Buttons, Menus, ComCtrls, Spin,
Project, Sysutils, Controls, Graphics, ExtCtrls, Dialogs, CompReg, CodeTools,
MsgView, NewProjectDlg, Process, IDEComp, AbstractFormEditor, FormEditor,
CustomFormEditor, ObjectInspector, ControlSelection, PropEdits, UnitEditor,
CompilerOptions, EditorOptions, EnvironmentOpts, TransferMacros, KeyMapping;
Project, Sysutils, FileCtrl, Controls, Graphics, ExtCtrls, Dialogs, CompReg,
CodeTools, MsgView, NewProjectDlg, Process, IDEComp, AbstractFormEditor,
FormEditor, CustomFormEditor, ObjectInspector, ControlSelection, PropEdits,
UnitEditor, CompilerOptions, EditorOptions, EnvironmentOpts, TransferMacros,
KeyMapping;
const
Version_String = '0.7';
@ -258,6 +259,7 @@ type
procedure OnDesignerPropertiesChanged(Sender: TObject);
procedure OnDesignerAddComponent(Sender: TObject; Component: TComponent;
ComponentClass: TRegisteredComponent);
procedure OnDesignerRemoveComponent(Sender: TObject; Component: TComponent);
procedure OnControlSelectionChanged(Sender: TObject);
procedure SaveDesktopSettings(TheEnvironmentOptions: TEnvironmentOptions);
@ -1344,6 +1346,7 @@ writeln('[TMainIDE.SetDefaultsforForm] 2');
OnComponentListChanged:=@OnDesignerComponentListChanged;
OnPropertiesChanged:=@OnDesignerPropertiesChanged;
OnAddComponent:=@OnDesignerAddComponent;
OnRemoveComponent:=@OnDesignerRemoveComponent;
writeln('[TMainIDE.SetDefaultsforForm] 3');
end;
end;
@ -2027,6 +2030,7 @@ writeln('TMainIDE.DoOpenEditorFile');
NewSrcEdit.SyntaxHighlighterType:=NewUnitInfo.SyntaxHighlighter;
NewSrcEdit.EditorComponent.CaretXY:=NewUnitInfo.CursorPos;
NewSrcEdit.EditorComponent.TopLine:=NewUnitInfo.TopLine;
NewSrcEdit.EditorComponent.LeftChar:=0;
NewUnitInfo.Loaded:=true;
// read form data
if (NewUnitInfo.Unitname<>'') then begin
@ -2705,38 +2709,133 @@ end;
function TMainIDE.DoBackupFile(Filename:string;
IsPartOfProject:boolean): TModalResult;
var BackupFilename:string;
var BackupFilename, CounterFilename: string;
AText,ACaption:string;
BackupInfo: TBackupInfo;
FilePath, FileNameOnly, FileExt, SubDir: string;
i: integer;
begin
// ToDo: implement the other backup methods
Result:=mrOk;
BackupFilename:=FileName+'.bak';
// remove old backup file
repeat
if FileExists(BackupFilename) then begin
if not DeleteFile(BackupFilename) then begin
ACaption:='Delete file failed';
AText:='Unable to remove old backup file "'+BackupFilename+'"!';
Result:=Application.MessageBox(PChar(AText),PChar(ACaption)
,MB_ABORTRETRYIGNORE);
if Result=mrAbort then exit;
if Result=mrIgnore then Result:=mrOk;
end;
end;
until Result<>mrRetry;
// backup file
if FileExists(Filename) then begin
if not (FileExists(Filename)) then exit;
if IsPartOfProject then
BackupInfo:=EnvironmentOptions.BackupInfoProjectFiles
else
BackupInfo:=EnvironmentOptions.BackupInfoOtherFiles;
if (BackupInfo.BackupType=bakNone)
or ((BackupInfo.BackupType=bakSameName) and (BackupInfo.SubDirectory='')) then
exit;
FilePath:=ExtractFilePath(Filename);
FileExt:=ExtractFileExt(Filename);
FileNameOnly:=copy(Filename,1,length(Filename)-length(FileExt));
if BackupInfo.SubDirectory<>'' then begin
SubDir:=FilePath+BackupInfo.SubDirectory;
repeat
if not RenameFile(Filename,BackupFilename) then begin
ACaption:='Rename file failed';
AText:='Unable to rename file "'+Filename+'" to "'+BackupFilename+'"!';
Result:=Application.MessageBox(PChar(AText),PChar(ACaption)
,MB_ABORTRETRYIGNORE);
if Result=mrAbort then exit;
if Result=mrIgnore then Result:=mrOk;
if not DirectoryExists(SubDir) then begin
if not CreateDir(SubDir) then begin
Result:=MessageDlg('Unable to create backup directory "'+SubDir+'".'
,mtWarning,[mbAbort,mbRetry,mbIgnore],0);
if Result=mrAbort then exit;
if Result=mrIgnore then Result:=mrOk;
end;
end;
until Result<>mrRetry;
end;
if BackupInfo.BackupType in
[bakSymbolInFront,bakSymbolBehind,bakUserDefinedAddExt,bakSameName] then
begin
case BackupInfo.BackupType of
bakSymbolInFront:
BackupFilename:=FileNameOnly+'.~'+copy(FileExt,2,length(FileExt)-1);
bakSymbolBehind:
BackupFilename:=FileNameOnly+FileExt+'~';
bakUserDefinedAddExt:
BackupFilename:=FileNameOnly+FileExt+'.'+BackupInfo.AdditionalExtension;
bakSameName:
BackupFilename:=FileNameOnly+FileExt;
end;
if BackupInfo.SubDirectory<>'' then
BackupFilename:=SubDir+OSDirSeparator+BackupFilename
else
BackupFilename:=FilePath+BackupFilename;
// remove old backup file
repeat
if FileExists(BackupFilename) then begin
if not DeleteFile(BackupFilename) then begin
ACaption:='Delete file failed';
AText:='Unable to remove old backup file "'+BackupFilename+'"!';
Result:=Application.MessageBox(PChar(AText),PChar(ACaption)
,MB_ABORTRETRYIGNORE);
if Result=mrAbort then exit;
if Result=mrIgnore then Result:=mrOk;
end;
end;
until Result<>mrRetry;
end else begin
// backup with counter
if BackupInfo.SubDirectory<>'' then
BackupFilename:=SubDir+OSDirSeparator+FileNameOnly+FileExt+';'
else
BackupFilename:=Filename+';';
if BackupInfo.MaxCounter<=0 then begin
// search first non existing backup filename
i:=1;
while FileExists(BackupFilename+IntToStr(i)) do inc(i);
BackupFilename:=BackupFilename+IntToStr(i);
end else begin
// rename all backup files (increase number)
i:=1;
while FileExists(BackupFilename+IntToStr(i))
and (i<=BackupInfo.MaxCounter) do inc(i);
if i>BackupInfo.MaxCounter then begin
dec(i);
CounterFilename:=BackupFilename+IntToStr(BackupInfo.MaxCounter);
// remove old backup file
repeat
if FileExists(CounterFilename) then begin
if not DeleteFile(CounterFilename) then begin
ACaption:='Delete file failed';
AText:='Unable to remove old backup file "'+CounterFilename+'"!';
Result:=Application.MessageBox(PChar(AText),PChar(ACaption)
,MB_ABORTRETRYIGNORE);
if Result=mrAbort then exit;
if Result=mrIgnore then Result:=mrOk;
end;
end;
until Result<>mrRetry;
end;
// rename all old backup files
dec(i);
while i>=1 do begin
repeat
if not RenameFile(BackupFilename+IntToStr(i),
BackupFilename+IntToStr(i+1)) then
begin
ACaption:='Rename file failed';
AText:='Unable to rename file "'+BackupFilename+IntToStr(i)
+'" to "'+BackupFilename+IntToStr(i+1)+'"!';
Result:=Application.MessageBox(PChar(AText),PChar(ACaption)
,MB_ABORTRETRYIGNORE);
if Result=mrAbort then exit;
if Result=mrIgnore then Result:=mrOk;
end;
until Result<>mrRetry;
dec(i);
end;
BackupFilename:=BackupFilename+'1';
end;
end;
// backup file
repeat
if not RenameFile(Filename,BackupFilename) then begin
ACaption:='Rename file failed';
AText:='Unable to rename file "'+Filename+'" to "'+BackupFilename+'"!';
Result:=Application.MessageBox(PChar(AText),PChar(ACaption)
,MB_ABORTRETRYIGNORE);
if Result=mrAbort then exit;
if Result=mrIgnore then Result:=mrOk;
end;
until Result<>mrRetry;
end;
procedure TMainIDE.UpdateCaption;
@ -3010,6 +3109,56 @@ begin
end;
end;
procedure TMainIDE.OnDesignerRemoveComponent(Sender: TObject;
Component: TComponent);
var i: integer;
ActiveForm: TCustomForm;
ActiveUnitInfo: TUnitInfo;
SrcTxtChanged: boolean;
ActiveSrcEdit: TSourceEditor;
FormClassName: string;
FormClassNameStartPos, FormBodyStartPos: integer;
begin
ActiveForm:=TDesigner(Sender).Form;
if ActiveForm=nil then begin
writeln('[TMainIDE.OnDesignerAddComponent] Error: TDesigner without a form');
halt;
end;
// find source for form
i:=Project.UnitCount-1;
while (i>=0) do begin
if (Project.Units[i].Loaded)
and (Project.Units[i].Form=ActiveForm) then break;
dec(i);
end;
if i<0 then begin
writeln('[TMainIDE.OnDesignerAddComponent] Error: form without source');
halt;
end;
ActiveUnitInfo:=Project.Units[i];
SrcTxtChanged:=false;
// remove component definition to form source
FormClassName:=ActiveForm.ClassName;
if FindFormClassDefinitionInSource(ActiveUnitInfo.Source.Source,FormClassName,
FormClassNameStartPos, FormBodyStartPos) then begin
if RemoveFormComponentFromSource(ActiveUnitInfo.Source,FormBodyStartPos,
Component.Name, Component.ClassName) then begin
SrcTxtChanged:=true;
end;
end else begin
// the form is not mentioned in the source?
// ignore silently
end;
// update source
if SrcTxtChanged then begin
ActiveUnitInfo.Modified:=true;
ActiveSrcEdit:=SourceNoteBook.FindSourceEditorWithPageIndex(
ActiveUnitInfo.EditorIndex);
ActiveSrcEdit.Source.Text:=ActiveUnitInfo.Source.Source;
ActiveSrcEdit.EditorComponent.Modified:=true;
end;
end;
procedure TMainIDE.OnControlSelectionChanged(Sender: TObject);
var NewSelectedComponents : TComponentSelectionList;
i: integer;
@ -3034,6 +3183,9 @@ end.
{ =============================================================================
$Log$
Revision 1.83 2001/03/28 14:08:45 lazarus
MG: added backup code and fixed removing controls
Revision 1.82 2001/03/27 11:11:13 lazarus
MG: fixed mouse msg, added filedialog initialdir

View File

@ -107,7 +107,6 @@ type
Procedure SetCurrentCursorXLine(num : Integer);
Function GetCurrentCursorYLine : Integer;
Procedure SetCurrentCursorYLine(num : Integer);
Function GetAncestor : String;
Function GetModified : Boolean;
procedure SetModified(NewValue:boolean);
Function GetInsertMode : Boolean;
@ -155,8 +154,6 @@ type
public
constructor Create(AOwner : TComponent; AParent : TWinControl);
destructor Destroy; override;
Procedure AddControlCode(_Control : TComponent);
Procedure RemoveControlCode(_Control : TComponent);
Procedure SelectText(LineNum,CharStart,LineNum2,CharEnd : Integer);
Procedure CreateFormUnit(AForm : TCustomForm);
Procedure CreateNewUnit;
@ -1108,105 +1105,6 @@ writeln('TSourceEditor.CreateEditor freeing old FEditor');
FEditor.SetFocus;
end;
Procedure TSourceEditor.AddControlCode(_Control : TComponent);
var
PI : PTypeInfo;
nmControlType : String;
I : Integer;
NewSource : String;
TempSource : TStringList;
Ancestor : String;
begin
TempSource := TStringList.Create;
TempSource.Assign(Source);
//get the control name
PI := _Control.ClassInfo;
nmControlType := PI^.Name;
Ancestor := GetAncestor;
Ancestor := 'TFORM';
//find the place in the code to add this now.
//Anyone have good method sfor parsing the source to find spots like this?
//here I look for the Name of the customform, the word "Class", and it's ancestor on the same line
//not very good because it could be a comment or just a description of the class.
//but for now I'll use it.
For I := 0 to TempSource.Count-1 do
begin
Writeln('Ancestor is '+Ancestor);
Writeln('TWinControl(_Control.Owner).Name is '+TWinControl(_Control.Owner).Name);
Writeln('Line is '+TempSource.Strings[i]);
if (pos(Ancestor,TempSource.Strings[i]) <> 0)
and (pos(lowercase(TWinControl(_Control.Owner).Name),
lowercase(TempSource.Strings[i])) <> 0)
and (pos('CLASS',Uppercase(TempSource.Strings[i])) <> 0) then
Break;
end;
//if I => FSource.Count then I didn't find the line...
If I < TempSource.Count-1 then
Begin
//alphabetical
inc(i);
NewSource := _Control.Name+' : '+nmControlType+';';
// Here I decide if I need to try and insert the control's text code in any certain order.
//if there's no controls then I just insert it, otherwise...
if TWincontrol(_Control.Owner).ControlCount > 0 then
while NewSource > (trim(TempSource.Strings[i])) do
inc(i);
TempSource.Insert(i,' '+NewSource);
end;
Source := TempSource;
end;
{Called when a control is deleted from the form}
Procedure TSourceEditor.RemoveControlCode(_Control : TComponent);
var
nmControlType : String;
I : Integer;
NewSource : String;
TempSource : TStringList;
Ancestor : String;
begin
TempSource := TStringList.Create;
TempSource.Assign(Source);
//get the control name
nmControlType := _Control.name;
writeln('Calling GetAncestor');
Ancestor := GetAncestor;
Writeln('Called');
//find the place in the code to start looking for it
For I := 0 to TempSource.Count-1 do
if (pos(Ancestor,TempSource.Strings[i]) <> 0)
and (pos(TWinControl(_Control.Owner).Name,TempSource.Strings[i]) <> 0)
and (pos('CLASS',Uppercase(TempSource.Strings[i])) <> 0) then
Break;
//if I => FSource.Count then I didn't find the line...
If I < TempSource.Count then
Begin
//alphabetical
inc(i);
NewSource := _Control.Name+' : '+nmControlType+';';
while NewSource < (trim(TempSource.Strings[i])) do
inc(i);
If NewSource = (trim(TempSource.Strings[i])) then
TempSource.Delete(I);
end;
Source := TempSource;
end;
Procedure TSourceEditor.DisplayControl;
Begin
if FControl = nil then Exit;
@ -1283,26 +1181,6 @@ Begin
Result := FEditor.Insertmode;
end;
//Get's the ancestor of the FControl.
//For example the ancestor of a TForm1 = class(xxxx) is the xxxx
Function TSourceEditor.GetAncestor : String;
var
PI : PTypeInfo;
begin
writeln('In Get Ancewstor');
if (FControl <> nil) then
Begin
PI := FControl.ClassInfo;
Writeln('1');
Result := PI^.Name;
Writeln('2');
Delete(Result,1,1);
Writeln('3');
end;
end;
Procedure TSourceEditor.CreateFormUnit(AForm : TCustomForm);
Var
nmForm : String;