2010-01-25 08:59:44 -05:00
|
|
|
unit simbasettings;
|
|
|
|
|
|
|
|
{$mode objfpc} {$M+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2010-03-07 10:57:10 -05:00
|
|
|
Classes, SysUtils, FileUtil, LResources, Forms, Controls,MufasaBase, Graphics, Dialogs,
|
2010-01-25 08:59:44 -05:00
|
|
|
ComCtrls, StdCtrls, settings;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TSettingsForm }
|
|
|
|
|
|
|
|
TSettingsForm = class(TForm)
|
|
|
|
SettingsFormButtonCancel: TButton;
|
|
|
|
SettingsFormButtonOK: TButton;
|
|
|
|
SettingsTreeView: TTreeView;
|
|
|
|
Settings: TMMLSettings;
|
|
|
|
procedure SettingsFormButtonCancelClick(Sender: TObject);
|
|
|
|
procedure SettingsFormButtonOKClick(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure FormDestroy(Sender: TObject);
|
|
|
|
procedure SettingsTreeViewDblClick(Sender: TObject);
|
|
|
|
{ private declarations }
|
|
|
|
public
|
|
|
|
procedure SaveCurrent;
|
|
|
|
procedure Reload;
|
|
|
|
{ public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
SettingsForm: TSettingsForm;
|
2010-02-13 11:56:46 -05:00
|
|
|
SimbaSettingsFile : string;
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{ TSettingsForm }
|
|
|
|
|
|
|
|
procedure TSettingsForm.FormCreate(Sender: TObject);
|
2010-02-26 20:36:33 -05:00
|
|
|
var
|
|
|
|
FirstNode : TTreeNode;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
Settings := TMMLSettings.Create(SettingsTreeView.Items);
|
|
|
|
if not FileExists(SimbaSettingsFile) then
|
|
|
|
begin
|
|
|
|
SettingsTreeView.Items.Clear;
|
|
|
|
Settings.SaveToXML(SimbaSettingsFile);
|
|
|
|
end;
|
|
|
|
SettingsTreeView.Items.Clear;
|
|
|
|
Settings.LoadFromXML(SimbaSettingsFile);
|
2010-02-26 20:36:33 -05:00
|
|
|
FirstNode := SettingsTreeView.Items.GetFirstNode;
|
|
|
|
if FirstNode <> nil then
|
|
|
|
if FirstNode.Text = 'Settings' then
|
|
|
|
FirstNode.Expand(false);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.SettingsFormButtonOKClick(Sender: TObject);
|
|
|
|
begin
|
2010-02-07 10:59:03 -05:00
|
|
|
Self.Settings.SaveToXML(SimbaSettingsFile);
|
|
|
|
Self.ModalResult:=mrOK;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.SettingsFormButtonCancelClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if not FileExists(SimbaSettingsFile) then
|
|
|
|
begin
|
2010-02-07 10:59:03 -05:00
|
|
|
Self.SettingsTreeView.Items.Clear;
|
|
|
|
Self.Settings.SaveToXML(SimbaSettingsFile);
|
|
|
|
Self.SettingsTreeView.Items.Clear;
|
|
|
|
Self.Settings.LoadFromXML(SimbaSettingsFile);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
2010-02-07 10:59:03 -05:00
|
|
|
Self.ModalResult:=mrOK;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.FormDestroy(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Settings.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.SettingsTreeViewDblClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
p, pp: TPoint;
|
|
|
|
N: TTreeNode;
|
|
|
|
Path, NewVal: String;
|
|
|
|
|
|
|
|
begin
|
|
|
|
p := Mouse.CursorPos;
|
2010-03-25 08:25:58 -04:00
|
|
|
|
|
|
|
pp := TTreeView(Sender).ScreenToClient(p);
|
2010-01-25 08:59:44 -05:00
|
|
|
N := SettingsTreeView.GetNodeAt(pp.x, pp.y);
|
|
|
|
if N <> nil then
|
|
|
|
if assigned(N.Data) then
|
|
|
|
begin
|
|
|
|
Path := Settings.GetNodePath(N.Parent);
|
|
|
|
NewVal := InputBox('Change Setting', 'Change value for ' + TSettingData(N.Data).Val,
|
|
|
|
Settings.GetKeyValue(Path));
|
2010-03-07 10:57:10 -05:00
|
|
|
mDebugLn('NewVal: ' + NewVal);
|
2010-01-25 08:59:44 -05:00
|
|
|
Settings.SetKeyValue(Path, NewVal);
|
|
|
|
N.Text := NewVal;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.SaveCurrent;
|
|
|
|
begin
|
|
|
|
Settings.SaveToXML(SimbaSettingsFile);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.Reload;
|
|
|
|
begin
|
|
|
|
if not FileExists(SimbaSettingsFile) then
|
|
|
|
begin
|
|
|
|
SettingsTreeView.Items.Clear;
|
|
|
|
Settings.SaveToXML(SimbaSettingsFile);
|
|
|
|
end;
|
|
|
|
|
|
|
|
SettingsTreeView.Items.Clear;
|
|
|
|
Settings.LoadFromXML(SimbaSettingsFile);
|
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
{$I simbasettings.lrs}
|
|
|
|
|
|
|
|
end.
|
|
|
|
|