mirror of
https://github.com/moparisthebest/Simba
synced 2025-02-11 21:00:13 -05:00
Rename Setting, Create Setting and Delete Setting.
** Untested due to Lazarus crashes with InputQuery & InputBox **
This commit is contained in:
parent
c918d95b1c
commit
7007f28939
@ -9,6 +9,7 @@ object SettingsForm: TSettingsForm
|
|||||||
ClientWidth = 360
|
ClientWidth = 360
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
OnDestroy = FormDestroy
|
OnDestroy = FormDestroy
|
||||||
|
OnMouseUp = MouseUp
|
||||||
LCLVersion = '0.9.29'
|
LCLVersion = '0.9.29'
|
||||||
object SettingsTreeView: TTreeView
|
object SettingsTreeView: TTreeView
|
||||||
Left = 16
|
Left = 16
|
||||||
@ -16,11 +17,13 @@ object SettingsForm: TSettingsForm
|
|||||||
Top = 16
|
Top = 16
|
||||||
Width = 324
|
Width = 324
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
DefaultItemHeight = 15
|
DefaultItemHeight = 19
|
||||||
ReadOnly = True
|
ReadOnly = True
|
||||||
ScrollBars = ssAutoBoth
|
ScrollBars = ssAutoBoth
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
OnDblClick = SettingsTreeViewDblClick
|
OnDblClick = SettingsTreeViewDblClick
|
||||||
|
OnKeyPress = OnKeyPress
|
||||||
|
OnMouseUp = MouseUp
|
||||||
Options = [tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
|
Options = [tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
|
||||||
end
|
end
|
||||||
object SettingsFormButtonOK: TButton
|
object SettingsFormButtonOK: TButton
|
||||||
@ -43,4 +46,30 @@ object SettingsForm: TSettingsForm
|
|||||||
OnClick = SettingsFormButtonCancelClick
|
OnClick = SettingsFormButtonCancelClick
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
end
|
end
|
||||||
|
object DeleteButton: TButton
|
||||||
|
Left = 120
|
||||||
|
Height = 25
|
||||||
|
Top = 511
|
||||||
|
Width = 120
|
||||||
|
Anchors = [akBottom]
|
||||||
|
Caption = 'Delete Selected'
|
||||||
|
OnClick = DeleteSelected
|
||||||
|
TabOrder = 3
|
||||||
|
end
|
||||||
|
object SettingsPopup: TPopupMenu
|
||||||
|
left = 40
|
||||||
|
top = 32
|
||||||
|
object PopupRename: TMenuItem
|
||||||
|
Caption = 'Rename'
|
||||||
|
OnClick = PopupRenameClick
|
||||||
|
end
|
||||||
|
object PopupDelete: TMenuItem
|
||||||
|
Caption = 'Delete'
|
||||||
|
OnClick = PopupDeleteClick
|
||||||
|
end
|
||||||
|
object PopupCreate: TMenuItem
|
||||||
|
Caption = 'Create subkey'
|
||||||
|
OnClick = PopupCreateKey
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,17 +4,26 @@ LazarusResources.Add('TSettingsForm','FORMDATA',[
|
|||||||
'TPF0'#13'TSettingsForm'#12'SettingsForm'#4'Left'#3'3'#2#6'Height'#3'.'#2#3'T'
|
'TPF0'#13'TSettingsForm'#12'SettingsForm'#4'Left'#3'3'#2#6'Height'#3'.'#2#3'T'
|
||||||
+'op'#3#173#0#5'Width'#3'h'#1#13'ActiveControl'#7#16'SettingsTreeView'#7'Capt'
|
+'op'#3#173#0#5'Width'#3'h'#1#13'ActiveControl'#7#16'SettingsTreeView'#7'Capt'
|
||||||
+'ion'#6#14'Simba Settings'#12'ClientHeight'#3'.'#2#11'ClientWidth'#3'h'#1#8
|
+'ion'#6#14'Simba Settings'#12'ClientHeight'#3'.'#2#11'ClientWidth'#3'h'#1#8
|
||||||
+'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#10'LCLVersion'#6#6
|
+'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#9'OnMouseUp'#7#7
|
||||||
+'0.9.29'#0#9'TTreeView'#16'SettingsTreeView'#4'Left'#2#16#6'Height'#3#217#1#3
|
+'MouseUp'#10'LCLVersion'#6#6'0.9.29'#0#9'TTreeView'#16'SettingsTreeView'#4'L'
|
||||||
+'Top'#2#16#5'Width'#3'D'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akB'
|
+'eft'#2#16#6'Height'#3#217#1#3'Top'#2#16#5'Width'#3'D'#1#7'Anchors'#11#5'akT'
|
||||||
+'ottom'#0#17'DefaultItemHeight'#2#15#8'ReadOnly'#9#10'ScrollBars'#7#10'ssAut'
|
+'op'#6'akLeft'#7'akRight'#8'akBottom'#0#17'DefaultItemHeight'#2#19#8'ReadOnl'
|
||||||
+'oBoth'#8'TabOrder'#2#0#10'OnDblClick'#7#24'SettingsTreeViewDblClick'#7'Opti'
|
+'y'#9#10'ScrollBars'#7#10'ssAutoBoth'#8'TabOrder'#2#0#10'OnDblClick'#7#24'Se'
|
||||||
+'ons'#11#17'tvoAutoItemHeight'#16'tvoHideSelection'#21'tvoKeepCollapsedNodes'
|
+'ttingsTreeViewDblClick'#10'OnKeyPress'#7#10'OnKeyPress'#9'OnMouseUp'#7#7'Mo'
|
||||||
+#11'tvoReadOnly'#14'tvoShowButtons'#12'tvoShowLines'#11'tvoShowRoot'#11'tvoT'
|
+'useUp'#7'Options'#11#17'tvoAutoItemHeight'#16'tvoHideSelection'#21'tvoKeepC'
|
||||||
+'oolTips'#0#0#0#7'TButton'#20'SettingsFormButtonOK'#4'Left'#3#9#1#6'Height'#2
|
+'ollapsedNodes'#11'tvoReadOnly'#14'tvoShowButtons'#12'tvoShowLines'#11'tvoSh'
|
||||||
+#25#3'Top'#3#255#1#5'Width'#2'K'#7'Anchors'#11#7'akRight'#8'akBottom'#0#7'Ca'
|
+'owRoot'#11'tvoToolTips'#0#0#0#7'TButton'#20'SettingsFormButtonOK'#4'Left'#3
|
||||||
+'ption'#6#2'OK'#7'OnClick'#7#25'SettingsFormButtonOKClick'#8'TabOrder'#2#1#0
|
+#9#1#6'Height'#2#25#3'Top'#3#255#1#5'Width'#2'K'#7'Anchors'#11#7'akRight'#8
|
||||||
+#0#7'TButton'#24'SettingsFormButtonCancel'#4'Left'#2#16#6'Height'#2#25#3'Top'
|
+'akBottom'#0#7'Caption'#6#2'OK'#7'OnClick'#7#25'SettingsFormButtonOKClick'#8
|
||||||
+#3#255#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#6
|
+'TabOrder'#2#1#0#0#7'TButton'#24'SettingsFormButtonCancel'#4'Left'#2#16#6'He'
|
||||||
+'Cancel'#7'OnClick'#7#29'SettingsFormButtonCancelClick'#8'TabOrder'#2#2#0#0#0
|
+'ight'#2#25#3'Top'#3#255#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8'akBottom'
|
||||||
|
+#0#7'Caption'#6#6'Cancel'#7'OnClick'#7#29'SettingsFormButtonCancelClick'#8'T'
|
||||||
|
+'abOrder'#2#2#0#0#7'TButton'#12'DeleteButton'#4'Left'#2'x'#6'Height'#2#25#3
|
||||||
|
+'Top'#3#255#1#5'Width'#2'x'#7'Anchors'#11#8'akBottom'#0#7'Caption'#6#15'Dele'
|
||||||
|
+'te Selected'#7'OnClick'#7#14'DeleteSelected'#8'TabOrder'#2#3#0#0#10'TPopupM'
|
||||||
|
+'enu'#13'SettingsPopup'#4'left'#2'('#3'top'#2' '#0#9'TMenuItem'#11'PopupRena'
|
||||||
|
+'me'#7'Caption'#6#6'Rename'#7'OnClick'#7#16'PopupRenameClick'#0#0#9'TMenuIte'
|
||||||
|
+'m'#11'PopupDelete'#7'Caption'#6#6'Delete'#7'OnClick'#7#16'PopupDeleteClick'
|
||||||
|
+#0#0#9'TMenuItem'#11'PopupCreate'#7'Caption'#6#13'Create subkey'#7'OnClick'#7
|
||||||
|
+#14'PopupCreateKey'#0#0#0#0
|
||||||
]);
|
]);
|
||||||
|
@ -6,19 +6,32 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls,MufasaBase, Graphics, Dialogs,
|
Classes, SysUtils, FileUtil, LResources, Forms, Controls,MufasaBase, Graphics, Dialogs,
|
||||||
ComCtrls, StdCtrls, settings;
|
ComCtrls, StdCtrls, Menus, settings;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TSettingsForm }
|
{ TSettingsForm }
|
||||||
|
|
||||||
TSettingsForm = class(TForm)
|
TSettingsForm = class(TForm)
|
||||||
|
DeleteButton: TButton;
|
||||||
|
PopupCreate: TMenuItem;
|
||||||
|
PopupRename: TMenuItem;
|
||||||
|
PopupDelete: TMenuItem;
|
||||||
|
SettingsPopup: TPopupMenu;
|
||||||
SettingsFormButtonCancel: TButton;
|
SettingsFormButtonCancel: TButton;
|
||||||
SettingsFormButtonOK: TButton;
|
SettingsFormButtonOK: TButton;
|
||||||
SettingsTreeView: TTreeView;
|
SettingsTreeView: TTreeView;
|
||||||
Settings: TMMLSettings;
|
Settings: TMMLSettings;
|
||||||
|
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);
|
||||||
procedure SettingsFormButtonCancelClick(Sender: TObject);
|
procedure SettingsFormButtonCancelClick(Sender: TObject);
|
||||||
procedure SettingsFormButtonOKClick(Sender: TObject);
|
procedure SettingsFormButtonOKClick(Sender: TObject);
|
||||||
|
procedure DeleteANode(N: TTreeNode);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure FormDestroy(Sender: TObject);
|
procedure FormDestroy(Sender: TObject);
|
||||||
procedure SettingsTreeViewDblClick(Sender: TObject);
|
procedure SettingsTreeViewDblClick(Sender: TObject);
|
||||||
@ -35,6 +48,8 @@ var
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses LCLtype;
|
||||||
|
|
||||||
{ TSettingsForm }
|
{ TSettingsForm }
|
||||||
|
|
||||||
procedure TSettingsForm.FormCreate(Sender: TObject);
|
procedure TSettingsForm.FormCreate(Sender: TObject);
|
||||||
@ -73,11 +88,121 @@ begin
|
|||||||
Self.ModalResult:=mrOK;
|
Self.ModalResult:=mrOK;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
if N.GetFirstChild = nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
if N.GetFirstChild.Data <> nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
KeyName := InputBox('Create new Key', 'Please enter the key name', '');
|
||||||
|
|
||||||
|
if KeyName = '' then
|
||||||
|
exit;
|
||||||
|
P := Settings.GetNodePath(N);
|
||||||
|
|
||||||
|
if Settings.CreateKey(P + '/' + NN.Text) then
|
||||||
|
begin
|
||||||
|
NN := TTreeNode.Create(SettingsTreeView.Items);
|
||||||
|
|
||||||
|
NN.Text := KeyName;
|
||||||
|
|
||||||
|
NN.MoveTo(N,naAddChild);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TSettingsForm.FormDestroy(Sender: TObject);
|
procedure TSettingsForm.FormDestroy(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Settings.Free;
|
Settings.Free;
|
||||||
end;
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSettingsForm.SettingsTreeViewDblClick(Sender: TObject);
|
procedure TSettingsForm.SettingsTreeViewDblClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
p, pp: TPoint;
|
p, pp: TPoint;
|
||||||
|
@ -334,6 +334,9 @@ begin
|
|||||||
Exit('');
|
Exit('');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{
|
||||||
|
newKey is not the entire key path.
|
||||||
|
}
|
||||||
function TMMLSettings.RenameKey(oldKey, newKey: string): boolean;
|
function TMMLSettings.RenameKey(oldKey, newKey: string): boolean;
|
||||||
var
|
var
|
||||||
Node : TTreeNode;
|
Node : TTreeNode;
|
||||||
|
Loading…
Reference in New Issue
Block a user