unit uEditorBase;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uGUIBase, uCustomEditor, ToolWin, ComCtrls, JvExControls,
  JvComponent, JvNavigationPane, ActnList, TB2Dock, TB2Toolbar, TBX,
  TB2Item, ImgList, PngImageList, StdActns, JvFormAutoSize, AppEvnts,
  uCustomView, uViewBase, JvAppStorage, JvAppRegistryStorage,
  JvFormPlacement, pngimage, ExtCtrls, dxLayoutLookAndFeels,
  JvComponentBase;

type
  IEditorBase = interface(ICustomEditor)
    ['{CB8CDE00-B225-4A1D-9A5C-EC6FBE2C854B}']
  end;
  
  TfEditorBase = class(TCustomEditor, IEditorBase)
    actAcercaDe: TAction;
    actAnterior: TAction;
    actBuscar: TAction;
    actCancelarCambios: TAction;
    actCerrar: TAction;
    actConfPagina: TAction;
    actCopiar: TEditCopy;
    actCortar: TEditCut;
    actDeshacer: TEditUndo;
    actEliminar: TAction;
    actGuardar: TAction;
    actGuardarCerrar: TAction;
    actImprimir: TAction;
    actLimpiar: TEditDelete;
    actModificar: TAction;
    actNuevo: TAction;
    actPegar: TEditPaste;
    actPrevisualizar: TAction;
    actRefrescar: TAction;
    actSeleccionarTodo: TEditSelectAll;
    actSiguiente: TAction;
    EditorActionList: TActionList;
    JvNavPanelHeader: TJvNavPanelHeader;
    LargeImages: TPngImageList;
    SmallImages: TPngImageList;
    TBXDock: TTBXDock;
    TBXItem1: TTBXItem;
    TBXItem10: TTBXItem;
    TBXItem11: TTBXItem;
    TBXItem12: TTBXItem;
    TBXItem13: TTBXItem;
    TBXItem14: TTBXItem;
    TBXItem15: TTBXItem;
    TBXItem16: TTBXItem;
    TBXItem17: TTBXItem;
    TBXItem18: TTBXItem;
    TBXItem19: TTBXItem;
    TBXItem2: TTBXItem;
    TBXItem20: TTBXItem;
    TBXItem21: TTBXItem;
    TBXItem22: TTBXItem;
    TBXItem23: TTBXItem;
    TBXItem24: TTBXItem;
    TBXItem25: TTBXItem;
    TBXItem26: TTBXItem;
    TBXItem27: TTBXItem;
    TBXItem28: TTBXItem;
    TBXItem29: TTBXItem;
    TBXItem3: TTBXItem;
    TBXItem30: TTBXItem;
    TBXItem31: TTBXItem;
    TBXItem32: TTBXItem;
    TBXItem4: TTBXItem;
    TBXItem5: TTBXItem;
    TBXItem6: TTBXItem;
    TBXItem8: TTBXItem;
    TBXItem9: TTBXItem;
    tbxMain: TTBXToolbar;
    tbxMenu: TTBXToolbar;
    TBXSeparatorItem1: TTBXSeparatorItem;
    TBXSeparatorItem10: TTBXSeparatorItem;
    TBXSeparatorItem11: TTBXSeparatorItem;
    TBXSeparatorItem12: TTBXSeparatorItem;
    TBXSeparatorItem13: TTBXSeparatorItem;
    TBXSeparatorItem2: TTBXSeparatorItem;
    TBXSeparatorItem3: TTBXSeparatorItem;
    TBXSeparatorItem4: TTBXSeparatorItem;
    TBXSeparatorItem5: TTBXSeparatorItem;
    TBXSeparatorItem6: TTBXSeparatorItem;
    TBXSeparatorItem7: TTBXSeparatorItem;
    TBXSeparatorItem8: TTBXSeparatorItem;
    TBXSeparatorItem9: TTBXSeparatorItem;
    TBXSubmenuItem1: TTBXSubmenuItem;
    TBXSubmenuItem4: TTBXSubmenuItem;
    TBXSubmenuItem5: TTBXSubmenuItem;
    TBXSubmenuItem6: TTBXSubmenuItem;
    TBXSubmenuItem7: TTBXSubmenuItem;
    StatusBar: TStatusBar;
    JvFormStorage: TJvFormStorage;
    JvAppRegistryStorage: TJvAppRegistryStorage;
    Image1: TImage;
    dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList;
    procedure actCerrarExecute(Sender: TObject);
    procedure actGuardarCerrarExecute(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  protected
    function ModifiedQuery : Boolean;
  public
    constructor Create(AOwner: TComponent); override;
  published
    procedure FormShow(Sender: TObject); virtual;
  end;

  TfEditorBaseClass = class of TfEditorBase;

implementation

{$R *.dfm}

uses
  Menus, uDataModuleBase;

{
********************************* TfEditorBase *********************************
}
procedure TfEditorBase.actCerrarExecute(Sender: TObject);
begin
  Close;
end;

procedure TfEditorBase.actGuardarCerrarExecute(Sender: TObject);
var
  ACursor: TCursor;
begin
  ACursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
  Application.ProcessMessages;
  try
    if actGuardar.Execute then
      actCerrar.Execute;
  finally
    Screen.Cursor := ACursor;
  end;
end;

constructor TfEditorBase.Create(AOwner: TComponent);
begin
  inherited;
  JvFormStorage.AppStoragePath := Name;
  JvNavPanelHeader.StyleManager := dmBase.StyleManager;
end;

procedure TfEditorBase.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if Valid then
    CanClose := ModifiedQuery
  else
    CanClose := False;
end;

procedure TfEditorBase.FormShow(Sender: TObject);
begin
  if Assigned(Parent) then
  begin
    StatusBar.Visible := False;
    actCerrar.ShortCut := 0
  end
  else begin
    StatusBar.Visible := True;
    actCerrar.ShortCut := ShortCut(VK_ESCAPE, []);
  end;
end;

function TfEditorBase.ModifiedQuery: Boolean;
var
  Respuesta: Integer;
begin
  Result := True;
  if Modified then
  begin
    Respuesta := Application.MessageBox('Se han producido cambios.' + #10#13 +
      '¿Desea guardarlos antes de salir?', 'Atención', MB_YESNOCANCEL);
    case Respuesta of
      IDYES   : actGuardar.Execute;
      IDNO    : actCancelarCambios.Execute;
      else
        Result := False;
    end;
  end
{  else
    actCancelarCambios.Execute;}
end;

initialization
  RegisterClass(TfEditorBase);

finalization
  UnRegisterClass(TfEditorBase);

end.
