{ *************************************************************************** }
{                                                                             }
{ EControl Syntax Editor SDK                                                  }
{                                                                             }
{ Copyright (c) 2004 - 2008 EControl Ltd., Zaharov Michael                    }
{     www.econtrol.ru                                                         }
{     support@econtrol.ru                                                     }
{                                                                             }
{ *************************************************************************** }
{$I ecSyntEdit.INC}

unit ecCustEditDlg;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
{$IFNDEF EC_VCL6_UP} ecColCombo,{$ENDIF}
  Dialogs, StdCtrls, ExtCtrls, ecSyntMemo;

type
  TCustSyntMemoDlg = class(TForm)
    GroupBox1: TGroupBox;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    GroupBox2: TGroupBox;
    CheckBox5: TCheckBox;
    Label1: TLabel;
    ColorBox1: TColorBox;
    Label2: TLabel;
    Edit1: TEdit;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    GroupBox3: TGroupBox;
    CheckBox9: TCheckBox;
    Label6: TLabel;
    ColorBox2: TColorBox;
    Edit4: TEdit;
    Label7: TLabel;
    Button3: TButton;
    Button4: TButton;
    FD: TFontDialog;
    CheckBox10: TCheckBox;
    CheckBox11: TCheckBox;
    CheckBox12: TCheckBox;
    CheckBox13: TCheckBox;
    CheckBox14: TCheckBox;
    CheckBox15: TCheckBox;
    CheckBox16: TCheckBox;
    CheckBox17: TCheckBox;
    CheckBox18: TCheckBox;
    CheckBox19: TCheckBox;
    CheckBox20: TCheckBox;
    CheckBox21: TCheckBox;
    CheckBox22: TCheckBox;
    CheckBox23: TCheckBox;
    CheckBox24: TCheckBox;
    CheckBox25: TCheckBox;
    CheckBox26: TCheckBox;
    CheckBox27: TCheckBox;
    CheckBox28: TCheckBox;
    CheckBox29: TCheckBox;
    GroupBox4: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    CheckBox6: TCheckBox;
    Label9: TLabel;
    ColorBox3: TColorBox;
    Panel1: TPanel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Edit3: TEdit;
    ComboBox1: TComboBox;
    Edit5: TEdit;
    Edit2: TEdit;
    CheckBox30: TCheckBox;
    CheckBox31: TCheckBox;
    CheckBox32: TCheckBox;
    Label10: TLabel;
    Edit6: TEdit;
    CheckBox33: TCheckBox;
    CheckBox34: TCheckBox;
    CheckBox35: TCheckBox;
    CheckBox36: TCheckBox;
    ComboBox2: TComboBox;
    procedure Button1Click(Sender: TObject);
  public
  end;

function CustomizeSyntaxMemo(Memo: TCustomSyntaxMemo): Boolean;

implementation

{$R *.dfm}

function CustomizeSyntaxMemo(Memo: TCustomSyntaxMemo): Boolean;
var opt: TSyntaxMemoOptions;
  procedure CheckDiap(Edit: TEdit; aMin, aMax: integer);
  var v: integer;
  begin
    v := StrToInt(Edit.Text);
    if (aMin <> -1) and (v < aMin) then
      raise Exception.CreateFmt('Invalid value "%d".'#13#10'Minimum value is "%d"', [v, aMin]);
    if (aMax <> -1) and (v > aMax) then
      raise Exception.CreateFmt('Invalid value "%d".'#13#10'Maximum value is "%d"', [v, aMax]);
  end;

begin
  with TCustSyntMemoDlg.Create(nil) do
   try
    CheckBox1.Checked := soAutoIndentMode in Memo.Options;
    CheckBox2.Checked := soBackUnindent in Memo.Options;
    CheckBox4.Checked := soGroupUndo in Memo.Options;
    CheckBox7.Checked := soDoubleClickLine in Memo.Options;
    CheckBox8.Checked := soFixedLineHeight in Memo.Options;
    CheckBox10.Checked := soPersistentBlocks in Memo.Options;
    CheckBox11.Checked := soOverwriteBlocks in Memo.Options;
    CheckBox12.Checked := soKeepCaretInText in Memo.Options;
    CheckBox13.Checked := soCopyAsRTF in Memo.Options;
    CheckBox14.Checked := soEnableBlockSel in Memo.Options;
    CheckBox15.Checked := soHideSelection in Memo.Options;
    CheckBox16.Checked := soHideDynamic in Memo.Options;
    CheckBox17.Checked := soDragText in Memo.Options;
    CheckBox18.Checked := soCallapseEmptyLines in Memo.Options;
    CheckBox19.Checked := soKeepTrailingBlanks in Memo.Options;
    CheckBox20.Checked := soGroupRedo in Memo.Options;
    CheckBox21.Checked := soFloatMarkers in Memo.Options;
    CheckBox22.Checked := soUndoAfterSave in Memo.Options;
    CheckBox23.Checked := soDisableSelection in Memo.Options;
    CheckBox24.Checked := soAlwaysShowCaret in Memo.Options;
    CheckBox25.Checked := soDrawCurLineFocus in Memo.Options;
    CheckBox26.Checked := soHideCursorOnType in Memo.Options;
    CheckBox27.Checked := soScrollLastLine in Memo.Options;
    CheckBox28.Checked := soGreedySelect in Memo.Options;
    CheckBox29.Checked := soKeepSelMode in Memo.Options;
    CheckBox30.Checked := soSmartCaret in Memo.Options;
    CheckBox31.Checked := soBreakOnRightMargin in Memo.Options;
    CheckBox32.Checked := soOptimalFill in Memo.Options;
    CheckBox34.Checked := soFixedColumnMove in Memo.Options;
    CheckBox35.Checked := soVariableHorzScrollBar in Memo.Options;
    CheckBox36.Checked := soUnindentKeepAlign in Memo.Options;

    CheckBox33.Checked := Memo.WordWrap;
    CheckBox5.Checked := Memo.Gutter.Visible;
    CheckBox6.Checked := Memo.LineNumbers.Visible;
    CheckBox9.Checked := Memo.ShowRightMargin;
    CheckBox3.Checked := Memo.ReplaceMode;
    ColorBox1.Selected := Memo.Gutter.Color;
    ColorBox2.Selected := Memo.RightMarginColor;
    ColorBox3.Selected := Memo.Color;
    Edit1.Text := IntToStr(Memo.Gutter.Width);
    Edit2.Text := IntToStr(Memo.UndoLimit);
    Edit3.Text := Memo.TabList.AsString;
    Edit4.Text := IntToStr(Memo.RightMargin);
    Edit5.Text := IntToStr(Memo.CollapseLevel);
    Edit6.Text := IntToStr(Memo.BlockIndent);
    ComboBox1.ItemIndex := integer(Memo.TabMode);
    Button1.Font := Memo.Font;
    Button2.Font := Memo.LineNumbers.Font;
    ComboBox2.ItemIndex := integer(Memo.LineNumbers.NumberingStyle);

    Result := ShowModal = mrOk;
    if Result then
     begin
       CheckDiap(Edit1, 0, 1000);
       CheckDiap(Edit2, 0, -1);
       CheckDiap(Edit4, 0, 1024);
       opt := [];
       if CheckBox1.Checked then Include(opt, soAutoIndentMode);
       if CheckBox2.Checked then Include(opt, soBackUnindent);
       if CheckBox4.Checked then Include(opt, soGroupUndo);
       if CheckBox7.Checked then Include(opt, soDoubleClickLine);
       if CheckBox8.Checked then Include(opt, soFixedLineHeight);
       if CheckBox10.Checked then Include(opt, soPersistentBlocks);
       if CheckBox11.Checked then Include(opt, soOverwriteBlocks);
       if CheckBox12.Checked then Include(opt, soKeepCaretInText);
       if CheckBox13.Checked then Include(opt, soCopyAsRTF);
       if CheckBox14.Checked then Include(opt, soEnableBlockSel);
       if CheckBox15.Checked then Include(opt, soHideSelection);
       if CheckBox16.Checked then Include(opt, soHideDynamic);
       if CheckBox17.Checked then Include(opt, soDragText);
       if CheckBox18.Checked then Include(opt, soCallapseEmptyLines);
       if CheckBox19.Checked then Include(opt, soKeepTrailingBlanks);
       if CheckBox20.Checked then Include(opt, soGroupRedo);
       if CheckBox21.Checked then Include(opt, soFloatMarkers);
       if CheckBox22.Checked then Include(opt, soUndoAfterSave);
       if CheckBox23.Checked then Include(opt, soDisableSelection);
       if CheckBox24.Checked then Include(opt, soAlwaysShowCaret);
       if CheckBox25.Checked then Include(opt, soDrawCurLineFocus);
       if CheckBox26.Checked then Include(opt, soHideCursorOnType);
       if CheckBox27.Checked then Include(opt, soScrollLastLine);
       if CheckBox28.Checked then Include(opt, soGreedySelect);
       if CheckBox29.Checked then Include(opt, soKeepSelMode);
       if CheckBox30.Checked then Include(opt, soSmartCaret);
       if CheckBox31.Checked then Include(opt, soBreakOnRightMargin);
       if CheckBox32.Checked then Include(opt, soOptimalFill);
       if CheckBox34.Checked then Include(opt, soFixedColumnMove);
       if CheckBox35.Checked then Include(opt, soVariableHorzScrollBar);
       if CheckBox36.Checked then Include(opt, soUnindentKeepAlign);
       Memo.Options := Opt;

       Memo.ShowRightMargin := CheckBox9.Checked;
       Memo.ReplaceMode := CheckBox3.Checked;
       Memo.Gutter.Color := ColorBox1.Selected;
       Memo.RightMarginColor := ColorBox2.Selected;
       Memo.Gutter.Width := StrToInt(Edit1.Text);
       Memo.UndoLimit := StrToInt(Edit2.Text);
       Memo.CollapseLevel := StrToInt(Edit5.Text);
       Memo.TabList.AsString := Edit3.Text;
       Memo.RightMargin := StrToInt(Edit4.Text);
       Memo.BlockIndent := StrToInt(Edit6.Text);
       Memo.TabMode := TTabMode(ComboBox1.ItemIndex);
       Memo.Font := Button1.Font;
       Memo.LineNumbers.Font := Button2.Font;
       Memo.Gutter.Visible := CheckBox5.Checked;
       Memo.LineNumbers.Visible := CheckBox6.Checked;
       Memo.Color := ColorBox3.Selected;
       Memo.WordWrap := CheckBox33.Checked;
       Memo.LineNumbers.NumberingStyle := TLineNumberingStyle(ComboBox2.ItemIndex);
     end;
   finally
     Free;
   end;
end;

{ TCustSyntMemoDlg }

procedure TCustSyntMemoDlg.Button1Click(Sender: TObject);
begin
  FD.Font := (Sender as TButton).Font;
  if FD.Execute then
    (Sender as TButton).Font := FD.Font;
end;

end.
