unit SplitpanReg;

interface

uses
	DesignIntf, DesignEditors, AddonLibReg;

type
	TPaneFrameEditor = class(TComponentEditor)
		function GetVerb(anIndex: Integer): string; override;
		function GetVerbCount: Integer; override;
		procedure ExecuteVerb(anIndex: Integer); override;
	end;

procedure Register;

implementation

uses
	SysUtils, Classes, Forms, Splitpan;

procedure Register;
begin
	RegisterComponents(AddonLibPageName, [TPaneFrame]);
	RegisterComponentEditor(TPaneFrame, TPaneFrameEditor);
	RegisterNoIcon([TPane]);
	RegisterClass(TPane);
end;

{	TPaneFrameEditor }

function TPaneFrameEditor.GetVerb(anIndex: Integer): string;
begin
	case anIndex of
		0: Result := 'Добавить панель';
		else
			Result := 'Удалить панель "'+(Component as TPaneFrame)[anIndex - 1].Name + '"';
	end;
end;

function TPaneFrameEditor.GetVerbCount: Integer;
begin
	Result := 1 + (Component as TPaneFrame).PaneCount;
end;

procedure TPaneFrameEditor.ExecuteVerb(anIndex: Integer);
var
	aPaneFrame: TPaneFrame;

	procedure AddPane;
	var
		i: integer;
		aName: TComponentName;
		aPane: TPane;
		aForm: TCustomForm;
	begin
		aForm := ValidParentForm(Component as TPaneFrame);
		aPane := TPane.Create(aForm);
		i := 1;
		repeat
			aName := aPaneFrame.Name+'Pane'+IntToStr(i);
			if aForm.FindComponent(aName) <> nil then begin
				aName := '';
				inc(i);
			end;
		until aName <> '';
		aPane.Name := aName;
		aPane.Percent := 10000;
		case aPaneFrame.PaneCount of
			0:;
			1: aPaneFrame[0].Percent := 5000;
			else
				aPaneFrame[aPaneFrame.PaneCount - 1].Percent :=
					(aPaneFrame[aPaneFrame.PaneCount - 2].Percent + longint(10000)) div 2;
		end;
		aPaneFrame.AddPane(aPane);
	end;

begin
	aPaneFrame := Component as TPaneFrame;
	case anIndex of
		0: AddPane;
		else
			aPaneFrame[anIndex - 1].Free;
	end;
end;

end.

