From abcfc2073b434c341f1b5defb75455ffb923a2e9 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Fri, 7 Dec 2012 22:42:18 +0000 Subject: [PATCH] Allow users to reset their joystick configuration from the Joystick Configuration dialog. --- Nasal/joystick.nas | 16 +++++++++++++--- gui/dialogs/joystick-config.xml | 26 +++++++++++++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Nasal/joystick.nas b/Nasal/joystick.nas index c5a69d9f7..9ed5eb2ae 100644 --- a/Nasal/joystick.nas +++ b/Nasal/joystick.nas @@ -632,12 +632,20 @@ var readConfig = func(dialog_root="/sim/gui/dialogs/joystick-config") { } } -var writeConfig = func(dialog_root="/sim/gui/dialogs/joystick-config") { +var writeConfig = func(dialog_root="/sim/gui/dialogs/joystick-config", reset=0) { # Write out the joystick file. var config = props.Node.new(); var id = getprop(dialog_root ~ "/selected-joystick"); - config.getNode("name", 1).setValue(id); + + if (reset == 1) { + # We've been asked to reset the joystick config to the default. As we can't + # delete the configuration file, we achieve this by setting an invalid name + # tag that won't match. + config.getNode("name", 1).setValue("UNUSED INVALID CONFIG"); + } else { + config.getNode("name", 1).setValue(id); + } var axes = props.globals.getNode(dialog_root).getChildren("axis"); forindex (var axis; axes) { @@ -690,4 +698,6 @@ var writeConfig = func(dialog_root="/sim/gui/dialogs/joystick-config") { io.write_properties(getprop("/sim/fg-home") ~ "/Input/Joysticks/" ~ filename ~ ".xml", config); } - +var resetConfig = func(dialog_root="/sim/gui/dialogs/joystick-config") { + writeConfig(dialog_root, 1); +} diff --git a/gui/dialogs/joystick-config.xml b/gui/dialogs/joystick-config.xml index 78e2f5ecc..739829a1c 100644 --- a/gui/dialogs/joystick-config.xml +++ b/gui/dialogs/joystick-config.xml @@ -188,12 +188,12 @@ var updateConfig = func() { left - + left - + @@ -203,7 +203,7 @@ var updateConfig = func() { left - + @@ -218,7 +218,7 @@ var updateConfig = func() { left - + @@ -259,6 +259,22 @@ var updateConfig = func() { 0 2 center + Reset Configuration + + nasal + + + + +