unit cxIntl_Editor;
{
  Design ime Editor for the TcxIntl component:
  Desciption: Saves and loads strings from INI files at design time
   by a the context menu of the component (right-clik on the component icon)
  Editor Added by Francisco Armando Dueñas Rodríguez
  fduenas@cancun.gob.mx
  fduenas@flashmail.com

  Component : TcxInternational
  Programmed by Jörg Pfander for Dev Express
  http://www.FreeDevExpressAddons.com
}

{$I cxVer.inc}

interface

uses
{$IFDEF DELPHI6}
  DesignIntF, DesignEditors,
  {$IFDEF VCL}
    VCLEditors,
  {$ENDIF}
{$ELSE}
  DsgnIntf,
{$ENDIF}
 cxIntl, Dialogs, IniFiles;

type

  TcxIntl_Editor = class(TComponentEditor)
  private
   procedure SaveToFile;
   procedure LoadFromFile;
  protected
  public
    procedure ExecuteVerb(Index: Integer); override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
  end;

procedure Register;


implementation

procedure Register;
begin
  RegisterComponentEditor(TcxIntl, TcxIntl_Editor);
end;
{ TcxIntl_Editor }

procedure TcxIntl_Editor.ExecuteVerb(Index: Integer);
begin
  inherited;
  case Index of
  0: LoadFromFile;
  {$IFDEF VCL}
  1: SaveToFile;
  {$ENDIF}
  end;
end;

function TcxIntl_Editor.GetVerb(Index: Integer): string;
begin
  case Index of
    0: Result := 'Load strings from file...';
    1: Result := 'Save strings to file...';
  end;
end;

function TcxIntl_Editor.GetVerbCount: Integer;
begin
 Result := 2;
end;

procedure TcxIntl_Editor.LoadFromFile;
var LoadFromFileDlg:TOpenDialog;
begin
 LoadFromFileDlg := TOpenDialog.Create(nil);
 LoadFromFileDlg.DefaultExt := 'ini';
 LoadFromFileDlg.Filter := 'INI Files (*.ini)|*.ini|'+
                           'LNG Files (*.lng)|*.txt|'+
                           'ASCII Text Files (*.txt)|*.txt|'+
                           'All files (*.*)|*.*';
 LoadFromFileDlg.FilterIndex := 1;
 LoadFromFileDlg.Options := [ofExtensionDifferent, ofPathMustExist,
                             ofFileMustExist, ofEnableSizing];
 LoadFromFileDlg.Title := 'Load strings from file...';
 if LoadFromFileDlg.Execute then
 begin
    tcxIntl(Component).LoadFromFile(LoadFromFileDlg.FileName);
 end;
 LoadFromFileDlg.Free;
end;

procedure TcxIntl_Editor.SaveToFile;
var SaveToFileDlg:TSaveDialog;
begin
 SaveToFileDlg := TSaveDialog.Create(nil);
 SaveToFileDlg.DefaultExt := 'ini';
 SaveToFileDlg.Filter := 'INI Files (*.ini)|*.ini|'+
                         'LNG Files (*.lng)|*.txt|'+
                         'ASCII Text Files (*.txt)|*.txt|'+
                         'All files (*.*)|*.*';
 SaveToFileDlg.FilterIndex := 1;
 SaveToFileDlg.Options := [ofExtensionDifferent, ofPathMustExist,
                           ofEnableSizing, ofOverwritePrompt];
 SaveToFileDlg.Title := 'Save strings to file...';
 if SaveToFileDlg.Execute then
 begin
    tcxIntl(Component).SaveToFile(SaveToFileDlg.FileName);
 end;
 SaveToFileDlg.Free;
end;

end.
