unit uOptionsUI;
{$INCLUDE 'Plugin.inc'}

interface

uses
  SysUtils,
  {$INCLUDE 'DelphiFarUnits.inc'} ,
  uOptions;

type
  TOptionsDialog = class(TOkCancelDialog)
  private
    fOptions: TOptions;
    fCheckRenameFileUnderCursor: TFarDialog.TCheckbox;
    fCheckSavePatternSettings: TFarDialog.TCheckbox;
  protected
    procedure Clear; override;
    procedure CreateUserControls; override;
    procedure SetSize(Width, Height: integer); override;
    procedure ConsoleSizeToDialogSize(var Width, Height: Integer); override;
    property CheckRenameFileUnderCursor: TFarDialog.TCheckbox read fCheckRenameFileUnderCursor;
    property CheckSavePatternSettings: TFarDialog.TCheckbox read fCheckSavePatternSettings;
  public
    constructor Create;
    destructor Destroy; override;
    function Execute: boolean;
    property Options: TOptions read fOptions write fOptions;
  end;

implementation

uses
  uMessages, uPluginConsts;

{ TOptionsDialog }

procedure TOptionsDialog.Clear;
begin
  inherited;
  fCheckRenameFileUnderCursor := nil;
  fCheckSavePatternSettings := nil;
end;

constructor TOptionsDialog.Create;
begin
  inherited Create(DIALOG_OPTIONS_GUID);
end;

procedure TOptionsDialog.CreateUserControls;
begin
  inherited;
  fCheckRenameFileUnderCursor := AddCheckbox(0, 0, GetMsg(MRenameFileUnderCursor), False);
  fCheckSavePatternSettings := AddCheckbox(0, 0, GetMsg(MSavePatternSettingsByDefault), False);
end;

destructor TOptionsDialog.Destroy;
begin
  inherited;
end;

function TOptionsDialog.Execute: boolean;
begin
  Result := False;
  CheckRenameFileUnderCursor.Checked := Options.AllowRenameFileUnderCursor;
  CheckSavePatternSettings.Checked := Options.SavePatternSettings;
  if inherited Execute then
  begin
    Options.AllowRenameFileUnderCursor := CheckRenameFileUnderCursor.Checked;
    Options.SavePatternSettings := CheckSavePatternSettings.Checked;
    Result := True;
  end;
end;

procedure TOptionsDialog.SetSize(Width, Height: integer);
begin
  inherited;
  AutoPos(CheckRenameFileUnderCursor);
  AutoPos(CheckSavePatternSettings);
end;

procedure TOptionsDialog.ConsoleSizeToDialogSize(var Width, Height: Integer);
begin
  inherited;
  Height := 8;
end;

end.
