{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

You may retrieve the latest version of this file at the FBA Creator Home Page,
located at http://www.fbacreator.com

Known Issues:
-----------------------------------------------------------------------------}
unit Unit10;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, StdCtrls, Unit3, IniFiles;

type
  TFrmEnvOptions = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    btnok: TButton;
    btncancel: TButton;
    GroupBox1: TGroupBox;
    chktopmost: TCheckBox;
    TabSheet2: TTabSheet;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    txtTabsSize: TEdit;
    GroupBox3: TGroupBox;
    Label2: TLabel;
    col1: TShape;
    colordialog: TColorDialog;
    Label3: TLabel;
    col2: TShape;
    Label4: TLabel;
    col3: TShape;
    Label5: TLabel;
    col4: TShape;
    Label6: TLabel;
    col5: TShape;
    Label7: TLabel;
    col6: TShape;
    Label8: TLabel;
    col8: TShape;
    Label9: TLabel;
    col7: TShape;
    Label10: TLabel;
    col9: TShape;
    Label11: TLabel;
    col10: TShape;
    procedure btncancelClick(Sender: TObject);
    procedure btnokClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure col1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure col2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure col3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure col4MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure col5MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure col6MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure col7MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure col8MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure col9MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure col10MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    procedure LoadSettings();
    procedure SaveSettings();
  public
    { Public declarations }
  end;

var
  FrmEnvOptions: TFrmEnvOptions;

implementation

uses Unit1;

{$R *.dfm}

procedure TFrmEnvOptions.LoadSettings();
begin
  // NOTA: quando si aggiunge qualcosa qui, ricordati di aggiornare
  // la funzione che synca in memoria, dentro Unit3
  // LoadEditorOptionsInMemory
  chktopmost.Checked := OPTIONS_BOOL[IDE_OPTIONS_LAUNCER_TOPMOST];

  txtTabsSize.Text := IntToStr( OPTIONS_NUMBER[IDE_OPTIONS_TABS_SPACE] );

  col1.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_ACTIVELINEBACK] );
  col2.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_EDITORBACK] );
  col3.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_SELECTEDBACK] );
  col4.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_SELECTEDFORE] );

  col5.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_SYNTAX1] );
  col6.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_SYNTAX2] );
  col7.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_SYNTAX3] );
  col8.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_SYNTAX4] );
  col9.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_SYNTAX5] );
  col10.Brush.Color := StringToColor( OPTIONS_STRING[IDE_OPTIONS_COLOR_SYNTAX6] );
end;

procedure TFrmEnvOptions.SaveSettings();
var
ini: TIniFile;
begin
  ini := TIniFile.Create(GetIniFile);

  ini.WriteBool('Debugging_Player', 'TopMost', chktopmost.Checked);

  try
    ini.WriteInteger('Editor', 'TabsSpace', StrToInt(txtTabsSize.Text));
  except
    ini.WriteInteger('Editor', 'TabsSpace', 18);
  end;

  ini.WriteString('Editor', 'ActiveLineBackColor', ColorToString(col1.Brush.Color));
  ini.WriteString('Editor', 'Backcolor', ColorToString(col2.Brush.Color));
  ini.WriteString('Editor', 'SelectedTextBackcolor', ColorToString(col3.Brush.Color));
  ini.WriteString('Editor', 'SelectedTextForecolor', ColorToString(col4.Brush.Color));

  ini.WriteString('Editor', 'Syntax1Color', ColorToString(col5.Brush.Color));
  ini.WriteString('Editor', 'Syntax2Color', ColorToString(col6.Brush.Color));
  ini.WriteString('Editor', 'Syntax3Color', ColorToString(col7.Brush.Color));
  ini.WriteString('Editor', 'Syntax4Color', ColorToString(col8.Brush.Color));
  ini.WriteString('Editor', 'Syntax5Color', ColorToString(col9.Brush.Color));
  ini.WriteString('Editor', 'Syntax6Color', ColorToString(col10.Brush.Color));

  ini.Free;
end;

procedure TFrmEnvOptions.btncancelClick(Sender: TObject);
begin
  self.Close;
end;

procedure TFrmEnvOptions.btnokClick(Sender: TObject);
begin
  // salva su ini
  SaveSettings();
  // sync in memoria (dentro Unit3)
  LoadEditorOptionsInMemory();
  // setta impostazioni IDE dai settaggi in memoria (dentro Unit1)
  MainForm.SetSettingsFromOptionsInMemory();
  self.close;
end;

procedure TFrmEnvOptions.FormCreate(Sender: TObject);
begin
  PageControl1.TabIndex:=0;
  LoadSettings();
end;

procedure TFrmEnvOptions.col1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col1.Brush.Color := colordialog.Color;
end;

procedure TFrmEnvOptions.col2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col2.Brush.Color := colordialog.Color;
end;

procedure TFrmEnvOptions.col3MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col3.Brush.Color := colordialog.Color;
end;

procedure TFrmEnvOptions.col4MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col4.Brush.Color := colordialog.Color;
end;

procedure TFrmEnvOptions.col5MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col5.Brush.Color := colordialog.Color;
end;

procedure TFrmEnvOptions.col6MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col6.Brush.Color := colordialog.Color;
end;

procedure TFrmEnvOptions.col7MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col7.Brush.Color := colordialog.Color;
end;

procedure TFrmEnvOptions.col8MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col8.Brush.Color := colordialog.Color;
end;

procedure TFrmEnvOptions.col9MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col9.Brush.Color := colordialog.Color;
end;

procedure TFrmEnvOptions.col10MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if colordialog.Execute then col10.Brush.Color := colordialog.Color;
end;

end.
