////////////////////////////////////////////////////////////////////////////////
// Options
//
// Suspention
////////////////////////////////////////////////////////////////////////////////
unit Pref;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, Registry, PrefTypesNProcs, ExtCtrls, Buttons;

type
  TPrefDlg = class(TForm)
    TreeView1: TTreeView;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Label1: TLabel;
    Button1: TButton;
    TabSheet2: TTabSheet;
    Label2: TLabel;
    CheckBox4: TCheckBox;
    Label4: TLabel;
    CheckBox5: TCheckBox;
    Label3: TLabel;
    RadioGroup1: TRadioGroup;
    TabSheet3: TTabSheet;
    Label5: TLabel;
    CheckBox3: TCheckBox;
    Label6: TLabel;
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    SaveDialog1: TSaveDialog;
    procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
    function Execute: boolean;
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
  end;

var
  PrefDlg: TPrefDlg;

implementation

uses Unit1;

{$R *.dfm}

function TPrefDlg.Execute: boolean;
begin
 Checkbox1.Checked := CM2MainForm.Options.Suspend.AutoSuspend;
 Checkbox2.Checked := CM2MainForm.Options.Suspend.PollOnResume;
 Checkbox4.Checked := CM2MainForm.Options.SystrayIcon.SwitchIconWhenSuspended;
 Checkbox5.Checked := CM2MainForm.Options.General.PreventShowDesktop;
 If CM2MainForm.Options.ScreenRelation.InRelationToDesktop Then RadioGroup1.ItemIndex := 1
  else RadioGroup1.ItemIndex := 0;
 Checkbox3.Checked := CM2MainForm.Options.XML.DumpToXML;
 Edit1.Text := CM2MainForm.Options.XML.Filename;
 Result := Showmodal = mrOk;
 CM2MainForm.Options.General.PreventShowDesktop := Checkbox5.Checked;
 CM2MainForm.Options.Suspend.AutoSuspend := Checkbox1.Checked;
 CM2MainForm.Options.Suspend.PollOnResume := Checkbox2.Checked;
 CM2MainForm.Options.SystrayIcon.SwitchIconWhenSuspended := Checkbox4.checked;
 CM2MainForm.Options.ScreenRelation.InRelationToDesktop := RadioGroup1.ItemIndex = 1;
 CM2MainForm.Options.XML.DumpToXML := Checkbox3.checked;
 CM2MainForm.Options.XML.Filename := Edit1.text;
end;

procedure TPrefDlg.TreeView1Change(Sender: TObject; Node: TTreeNode);
Var
 I: Integer;
begin
 For I := 0 to PageControl1.PageCount - 1 do begin
  If PageControl1.Pages[I].Tag = Node.SelectedIndex then begin
   PageControl1.ActivePageIndex := I;
   exit;
  end;
 end;
end;

procedure TPrefDlg.FormCreate(Sender: TObject);
begin
 InitOptions;
 LoadOptions;
 SetOptions;
 Treeview1.FullExpand;
end;

procedure TPrefDlg.SpeedButton1Click(Sender: TObject);
begin
 Savedialog1.filename := Edit1.Text;
 If not savedialog1.Execute then exit;
 Edit1.Text := Savedialog1.Filename;
end;

end.
