{ ------------------------------------------------------------- }
{ Purpose : Next Grid 6                                         }
{ By      : Bojan Nikolic                                       }
{ For     : BergSoft                                            }
{ ------------------------------------------------------------- }
{ Copyright (C) BergSoft.net 2012. All Rights Reserved.         }
{ ------------------------------------------------------------- }
unit NxLayoutReg6;

interface

uses
  { Standard }
  Classes, Types, Windows, Graphics, ImgList,
  { Standard (Design) }
  DesignIntf, DesignEditors, VCLEditors,
  { Standard.Controls }
  Controls, StdCtrls, Menus, ComCtrls, ExtCtrls,
  { Next Standard 6 }
  NxConsts6, NxTypes6, NxIntf6, NxClasses6, NxStdCtrls6, NxControls6,
  { Next Standard 6 (Design) }
  NxStandardReg6, NxDesignWindow6,
  { NextLayout 6 }
  NxLayout6, NxLayoutNodes6;

type
  { TNxLayoutComponentEditor6 }

  TNxLayoutComponentEditor6 = class(TNextSuiteComponentEditor6, INxDesignerSelectable)
  private
    procedure SelectComponent(Instance: TPersistent);
  public
    constructor Create(AComponent: TComponent; ADesigner: IDesigner); override;
    destructor Destroy; override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
    procedure Edit; override;
    procedure EditProperty(const Prop: IProperty; var Continue: Boolean); override;
    procedure ExecuteVerb (Index: Integer); override;
  end;

  { TNxLayoutNodesProperty6 }

  TNxLayoutNodesProperty6 = class(TPropertyEditor)
  protected
    procedure OpenEditor;
  public
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
    procedure Edit; override;
  end;

procedure Register;

implementation

uses
  Forms, Dialogs,
  NxNodesEditor6;

procedure Register;
begin
  { Component Editors }
  RegisterComponentEditor(TNextLayout6, TNxLayoutComponentEditor6);

  { Property Editors }
  RegisterPropertyEditor(TypeInfo(TNxLayoutNodeList), TNextLayout6, 'Nodes', TNxLayoutNodesProperty6);

  { Required }
  RegisterClasses([
    TNxButtonLayoutNode6,
    TNxCheckBoxLayoutNode6,
    TNxEditLayoutNode6,
    TNxLabelLayoutNode6,
    TNxSeparatorLayoutNode6,
    TNxSpinLayoutNode6,
    TNxStringLayoutNode6,
    TNxToolbarLayoutNode6,
    TNxTrackBarLayoutNode6
  ]);

  RegisterNoIcon([
    TNxButtonLayoutNode6,
    TNxCheckBoxLayoutNode6,
    TNxEditLayoutNode6,
    TNxLabelLayoutNode6,
    TNxSeparatorLayoutNode6,
    TNxSpinLayoutNode6,
    TNxStringLayoutNode6,
    TNxToolbarLayoutNode6,
    TNxTrackBarLayoutNode6
  ]);
end;

{ TNxLayoutComponentEditor6 }

constructor TNxLayoutComponentEditor6.Create(AComponent: TComponent; ADesigner: IDesigner);
begin
  inherited;
  TNextLayout6(GetComponent).DesigningNotification(Self as INxDesignerSelectable);
end;

destructor TNxLayoutComponentEditor6.Destroy;
begin

  inherited;
end;

procedure TNxLayoutComponentEditor6.Edit;
begin
  inherited;

end;

procedure TNxLayoutComponentEditor6.EditProperty(const Prop: IProperty; var Continue: Boolean);
begin
  inherited;
  if Prop.GetName = 'Nodes' then
  begin
    Continue := False;

    { Call TNxLayoutNodesProperty6.Edit }
    Prop.Edit;
  end;
end;

procedure TNxLayoutComponentEditor6.ExecuteVerb(Index: Integer);
begin
  case Index of
    0: Edit;
  end;

  inherited;
end;

function TNxLayoutComponentEditor6.GetVerb(Index: Integer): string;
begin
  case Index of
    0: Result := '&Nodes Editor...';
  end;

  { TNextSuiteComponentEditor6 }
  Result := inherited GetVerb(Index);
end;

function TNxLayoutComponentEditor6.GetVerbCount: Integer;
begin
  Result := inherited GetVerbCount + 1;
end;

procedure TNxLayoutComponentEditor6.SelectComponent(Instance: TPersistent);
begin
  Designer.SelectComponent(Instance);
end;

{ TNxLayoutNodesProperty6 }

procedure TNxLayoutNodesProperty6.Edit;
begin
  inherited;
  OpenEditor;
end;

function TNxLayoutNodesProperty6.GetAttributes: TPropertyAttributes;
begin
  Result := inherited GetAttributes + [paDialog, paReadOnly];
end;

function TNxLayoutNodesProperty6.GetValue: string;
var
  Nodes: TNxLayoutNodeList;
begin
  Nodes := TNextLayout6(GetComponent(0)).Nodes;

  Result := '(' + Nodes.ClassName + ')';
end;

procedure TNxLayoutNodesProperty6.OpenEditor;
var
  EditorForm: TNodesEditor;
begin
  inherited;
  if not ShowForm(GetComponent(0), TNodesEditor) then
  begin
    EditorForm := TNodesEditor.Create(Application);
    try
      EditorForm.OwnerControl := GetComponent(0);
      EditorForm.Designer := Designer;
      EditorForm.WindowState := wsNormal;
      EditorForm.Show;
    except
      EditorForm.Free;
    end;
  end;
end;

end.
