From 6f9335edb1e12fb287a1d43227e22eff78869c28 Mon Sep 17 00:00:00 2001 From: Wizzup? Date: Mon, 11 Jan 2010 16:47:19 +0000 Subject: [PATCH] Fixes mantis #39. git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@395 3f818213-9676-44b0-a9b4-5e4c4e03d09d --- Projects/SAMufasaGUI/simbasettings.pas | 5 ++- Units/MMLAddon/settings.pas | 52 ++++++++++++-------------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Projects/SAMufasaGUI/simbasettings.pas b/Projects/SAMufasaGUI/simbasettings.pas index 210b722..c3dbb92 100644 --- a/Projects/SAMufasaGUI/simbasettings.pas +++ b/Projects/SAMufasaGUI/simbasettings.pas @@ -87,13 +87,14 @@ begin pp := TSettingsForm(Sender).ScreenToClient(p); N := SettingsTreeView.GetNodeAt(pp.x, pp.y); if N <> nil then - if (N.Text = 'Value') and (N.Parent <> nil) then + if assigned(N.Data) then begin Path := Settings.GetNodePath(N.Parent); - NewVal := InputBox('Change Setting', 'Change value for ' + N.Parent.Text, + NewVal := InputBox('Change Setting', 'Change value for ' + TSettingData(N.Data).Val, Settings.GetKeyValue(Path)); writeln('NewVal: ' + NewVal); Settings.SetKeyValue(Path, NewVal); + N.Text := NewVal; end; end; diff --git a/Units/MMLAddon/settings.pas b/Units/MMLAddon/settings.pas index aa1fc6b..bdf3629 100644 --- a/Units/MMLAddon/settings.pas +++ b/Units/MMLAddon/settings.pas @@ -150,10 +150,7 @@ var if Node = nil then Exit; // Stops if reached a leaf // Adds a node to the tree - if (Node.NodeType = 3) then - s := 'Data' - else - s := Node.NodeName; + s := Node.NodeName; TreeNode := Nodes.AddChild(TreeNode, s); if (Node.NodeType = 3) then @@ -162,7 +159,7 @@ var D.Val := Node.NodeValue; TreeNode.Data := D; - TreeNode.Text := 'Value'; + TreeNode.Text := Node.NodeValue; end; // Goes to the child node cNode := Node.FirstChild; @@ -269,6 +266,8 @@ begin result := ''; for i := high(s) downto 0 do result := result + s[i] + '/'; + if length(result) > 1 then + setlength(result,length(result)-1); end; { @@ -313,23 +312,20 @@ end; function TMMLSettings.IsKey(KeyName: String): Boolean; var N: TTreeNode; - i: Integer; + begin N := WalkToNode(KeyName); if N = nil then Exit(False); - i := 0; - - N := N.GetFirstChild; - while N <> nil do + n := N.GetFirstChild; + while n <> nil do begin - if N.Text <> 'Value' then - inc(i); - N := N.GetNextSibling; + if n.HasChildren then + exit(false); + n := N.GetNextSibling; end; - - Exit(i = 0); + exit(true); end; { @@ -361,9 +357,10 @@ begin N := N.GetFirstChild; while N <> nil do begin - if N.Text = 'Value' then - if assigned(n.Data) then - Exit(TSettingData(n.Data).Val); + if assigned(n.Data) then + begin + Exit(TSettingData(n.Data).Val); + end; N := N.GetNextSibling; end; Exit(''); @@ -516,7 +513,7 @@ begin if not N.HasChildren then begin NN := TTreeNode.Create(Nodes); - NN.Text := 'Value'; + NN.Text := KeyValue; NN.MoveTo(N, naAddChild); end; @@ -524,14 +521,11 @@ begin N := N.GetFirstChild; while N <> nil do begin - if N.Text = 'Value' then - begin - if Assigned(N.Data) then - TSettingData(N.Data).Free; - N.Data := TSettingData.Create; - TSettingData(N.Data).Val := KeyValue; - writeln('Setting ' + KeyName + 'to ' + KeyValue); - end; + if Assigned(N.Data) then + TSettingData(N.Data).Free; + N.Data := TSettingData.Create; + TSettingData(N.Data).Val := KeyValue; + writeln('Setting ' + KeyName + ' to ' + KeyValue); N := N.GetNextSibling; end; end; @@ -556,7 +550,9 @@ var DDataNode, DataNode: TDOMNode; begin - if n.Text = 'Value' then + if assigned(n.data) and (n.HasChildren) then + writeln('Has data and children! Please close simba and remove settings.xml. if problem persists, please report your settings.xml'); + if assigned(n.Data) then begin XMLChild := XMLDoc.CreateTextNode(TSettingData(N.Data).Val); end else