2010-01-25 08:59:44 -05:00
|
|
|
unit simbasettings;
|
|
|
|
|
2010-04-02 11:55:54 -04:00
|
|
|
{$mode objfpc}{$H+}
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2010-03-07 10:57:10 -05:00
|
|
|
Classes, SysUtils, FileUtil, LResources, Forms, Controls,MufasaBase, Graphics, Dialogs,
|
2010-04-03 17:27:10 -04:00
|
|
|
ComCtrls, StdCtrls, Menus, settings;
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TSettingsForm }
|
|
|
|
|
|
|
|
TSettingsForm = class(TForm)
|
2010-04-03 17:27:10 -04:00
|
|
|
DeleteButton: TButton;
|
|
|
|
PopupCreate: TMenuItem;
|
|
|
|
PopupRename: TMenuItem;
|
|
|
|
PopupDelete: TMenuItem;
|
|
|
|
SettingsPopup: TPopupMenu;
|
2010-01-25 08:59:44 -05:00
|
|
|
SettingsFormButtonCancel: TButton;
|
|
|
|
SettingsFormButtonOK: TButton;
|
|
|
|
SettingsTreeView: TTreeView;
|
|
|
|
Settings: TMMLSettings;
|
2010-04-03 17:27:10 -04:00
|
|
|
procedure DeleteSelected(Sender: TObject);
|
|
|
|
procedure MouseUp(Sender: TObject; Button: TMouseButton;
|
|
|
|
Shift: TShiftState; X, Y: Integer);
|
|
|
|
procedure OnKeyPress(Sender: TObject; var Key: char);
|
|
|
|
procedure PopupCreateKey(Sender: TObject);
|
|
|
|
procedure PopupDeleteClick(Sender: TObject);
|
|
|
|
procedure PopupRenameClick(Sender: TObject);
|
2010-01-25 08:59:44 -05:00
|
|
|
procedure SettingsFormButtonCancelClick(Sender: TObject);
|
|
|
|
procedure SettingsFormButtonOKClick(Sender: TObject);
|
2010-04-03 17:27:10 -04:00
|
|
|
procedure DeleteANode(N: TTreeNode);
|
2010-01-25 08:59:44 -05:00
|
|
|
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
|
|
|
|
|
2010-04-03 17:27:10 -04:00
|
|
|
uses LCLtype;
|
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
{ 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;
|
|
|
|
|
2010-04-03 17:27:10 -04:00
|
|
|
procedure TSettingsForm.MouseUp(Sender: TObject; Button: TMouseButton;
|
|
|
|
Shift: TShiftState; X, Y: Integer);
|
|
|
|
var
|
|
|
|
N: TTreeNode;
|
|
|
|
begin
|
|
|
|
if Button = mbRight then
|
|
|
|
begin
|
|
|
|
N := SettingsTreeView.GetNodeAt(X, Y);
|
|
|
|
if N = nil then
|
|
|
|
exit;
|
|
|
|
SettingsTreeView.Selected := N;
|
|
|
|
SettingsPopup.PopUp();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.OnKeyPress(Sender: TObject; var Key: char);
|
|
|
|
var
|
|
|
|
N: TTreeNode;
|
|
|
|
begin
|
|
|
|
if (Ord(Key) = VK_DELETE) or (Ord(Key) = VK_BACK) then
|
|
|
|
begin
|
|
|
|
N := SettingsTreeView.Selected;
|
|
|
|
if N = nil then
|
|
|
|
exit;
|
|
|
|
DeleteANode(N);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.PopupCreateKey(Sender: TObject);
|
|
|
|
var
|
|
|
|
KeyName, P: String;
|
|
|
|
N, NN: TTreeNode;
|
|
|
|
begin
|
|
|
|
N := SettingsTreeView.Selected;
|
|
|
|
if N = nil then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
if N.Data <> nil then
|
|
|
|
exit;
|
|
|
|
|
2010-04-05 05:00:53 -04:00
|
|
|
if N.GetFirstChild <> nil then
|
|
|
|
if N.GetFirstChild.Data <> nil then
|
|
|
|
exit;
|
2010-04-03 17:27:10 -04:00
|
|
|
|
|
|
|
KeyName := InputBox('Create new Key', 'Please enter the key name', '');
|
|
|
|
|
|
|
|
if KeyName = '' then
|
|
|
|
exit;
|
|
|
|
P := Settings.GetNodePath(N);
|
|
|
|
|
2010-04-05 05:00:53 -04:00
|
|
|
if Settings.CreateKey(P + '/' + KeyName) then
|
2010-04-05 05:02:44 -04:00
|
|
|
mDebugLn('Added key ' + KeyName);
|
2010-04-03 17:27:10 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
procedure TSettingsForm.FormDestroy(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Settings.Free;
|
2010-04-03 17:27:10 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.PopupDeleteClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DeleteSelected(Sender);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.PopupRenameClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
N: TTreeNode;
|
|
|
|
MBox, Path: String;
|
|
|
|
begin
|
|
|
|
N := SettingsTreeView.Selected;
|
|
|
|
if N = nil then
|
|
|
|
exit;
|
|
|
|
|
2010-04-05 05:00:53 -04:00
|
|
|
Path := Settings.GetNodePath(N);
|
|
|
|
|
2010-04-03 17:27:10 -04:00
|
|
|
MBox := InputBox('Rename', 'Please fill in the new name', '');
|
|
|
|
if MBox = '' then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
if Settings.RenameKey(Path, MBox) then
|
|
|
|
N.Text := MBox;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.DeleteSelected(Sender: TObject);
|
|
|
|
var
|
|
|
|
N: TTreeNode;
|
|
|
|
begin
|
|
|
|
N := SettingsTreeView.Selected;
|
|
|
|
if N = nil then
|
|
|
|
exit;
|
|
|
|
DeleteANode(N);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsForm.DeleteANode(N: TTreeNode);
|
|
|
|
var
|
|
|
|
Path: String;
|
|
|
|
begin
|
|
|
|
if N = nil then
|
|
|
|
exit;
|
|
|
|
if MessageDlg('Delete a setting', 'Are you sure you want to delete this setting?', mtWarning, [mbYes, mbNo], 0) = mrNo then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
Path := Settings.GetNodePath(N);
|
|
|
|
Settings.DeleteKey(Path);
|
|
|
|
N.DeleteChildren;
|
|
|
|
N.Delete;
|
2010-01-25 08:59:44 -05:00
|
|
|
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
|
2010-04-07 08:44:55 -04:00
|
|
|
{$R *.lfm}
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
end.
|
|
|
|
|