unit _frmBiggerEditor;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, SynEdit, _SearchTextHightlighterSynEditPlugin;

type
  TfrmBiggerEditor = class(TForm)
    EditorBiggerEditor: TSynEdit;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure EditorBiggerEditorMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure EditorBiggerEditorKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
  private
    FMainActiveEditor: TSynEdit;
  public
    { Public-Deklarationen }
  end;

var
  frmBiggerEditor: TfrmBiggerEditor;

implementation

{$R *.dfm}

uses _frmMain, System.UITypes;

procedure TfrmBiggerEditor.EditorBiggerEditorKeyUp(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if Key = vkF11 then
  begin
    Close;
  end;

  if Key = vkF3 then
  begin
    frmMain.ActiveEditor := EditorBiggerEditor;
    frmMain.DoSearchReplaceText(false, frmMain.gbSearchBackwards);
  end;

  if (Key = 70) and (Shift = [ssCtrl]) then
  begin
    frmMain.ActiveEditor := EditorBiggerEditor;
    frmMain.ShowSearchReplaceDialog(false);
  end;
end;

procedure TfrmBiggerEditor.EditorBiggerEditorMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbRight then
  begin
    frmMain.ActiveEditor := EditorBiggerEditor;
    frmMain.PopupEditor.PopupFromCursorPos;
  end;
end;

procedure TfrmBiggerEditor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  frmMain.MainConfig.WriteInteger('BiggerEditorPos', 'Left', Left);
  frmMain.MainConfig.WriteInteger('BiggerEditorPos', 'Top', Top);
  frmMain.MainConfig.WriteInteger('BiggerEditorPos', 'Width', Width);
  frmMain.MainConfig.WriteInteger('BiggerEditorPos', 'Height', Height);

  frmMain.ActiveEditor := FMainActiveEditor;
  frmMain.ActiveEditor.Lines.Text := EditorBiggerEditor.Lines.Text;
  frmMain.ActiveEditor.CaretXY := EditorBiggerEditor.CaretXY;
  frmMain.ActiveEditor.SelStart := EditorBiggerEditor.SelStart;
  frmMain.ActiveEditor.SelEnd := EditorBiggerEditor.SelEnd;

  EditorBiggerEditor.Lines.Clear;
end;

procedure TfrmBiggerEditor.FormCreate(Sender: TObject);
begin
  with TSearchTextHightlighterSynEditPlugin.Create(EditorBiggerEditor) do
  begin
    Attribute.Background := $0078AAFF;
  end;
end;

procedure TfrmBiggerEditor.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #27 then
  begin
    Close;
  end;
end;

procedure TfrmBiggerEditor.FormShow(Sender: TObject);
begin
  Left := frmMain.MainConfig.ReadInteger('BiggerEditorPos', 'Left', Round((Screen.Width - Width) div 2));

  if Left >= Screen.Width then
  begin
    Left := 10;
  end;

  Top := frmMain.MainConfig.ReadInteger('BiggerEditorPos', 'Top', Round((Screen.Height - Height) div 2));

  if Top >= Screen.Height then
  begin
    Top := 10;
  end;

  Width := frmMain.MainConfig.ReadInteger('BiggerEditorPos', 'Width', 1212);
  Height := frmMain.MainConfig.ReadInteger('BiggerEditorPos', 'Height', 920);

  FMainActiveEditor := frmMain.ActiveEditor;
  EditorBiggerEditor.Highlighter := frmMain.ActiveEditor.Highlighter;
  EditorBiggerEditor.Lines.Text := frmMain.ActiveEditor.Lines.Text;

  EditorBiggerEditor.CaretXY := frmMain.ActiveEditor.CaretXY;
  EditorBiggerEditor.SelStart := frmMain.ActiveEditor.SelStart;
  EditorBiggerEditor.SelEnd := frmMain.ActiveEditor.SelEnd;
  EditorBiggerEditor.SetFocus;
end;

end.
