aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-08-19 21:19:01 +0200
committerAdrian Kummerlaender2015-08-19 21:19:01 +0200
commit75891e7c90ff8ec3533a6a1e9aac66501693d561 (patch)
treebf366a816618fd045f3a67468a0d133e63074b9f
parente1c314b081fce85c80d1df8788f84cc173ff0e14 (diff)
downloadMetaTerm-75891e7c90ff8ec3533a6a1e9aac66501693d561.tar
MetaTerm-75891e7c90ff8ec3533a6a1e9aac66501693d561.tar.gz
MetaTerm-75891e7c90ff8ec3533a6a1e9aac66501693d561.tar.bz2
MetaTerm-75891e7c90ff8ec3533a6a1e9aac66501693d561.tar.lz
MetaTerm-75891e7c90ff8ec3533a6a1e9aac66501693d561.tar.xz
MetaTerm-75891e7c90ff8ec3533a6a1e9aac66501693d561.tar.zst
MetaTerm-75891e7c90ff8ec3533a6a1e9aac66501693d561.zip
Improve handling of non-existing properties in `set`
-rw-r--r--src/SettingsHandler.qml43
-rw-r--r--src/command/commands.js21
2 files changed, 52 insertions, 12 deletions
diff --git a/src/SettingsHandler.qml b/src/SettingsHandler.qml
index 8a9a862..f281da1 100644
--- a/src/SettingsHandler.qml
+++ b/src/SettingsHandler.qml
@@ -2,6 +2,49 @@ import QtQuick 2.0
import Qt.labs.settings 1.0
QtObject {
+ function getSetter(category, name) {
+ try {
+ var type = typeof eval(category + '.' + name);
+
+ switch ( type ) {
+ case 'undefined': {
+ throw new ReferenceError();
+ break;
+ }
+ case 'string': {
+ return function(value) {
+ return eval(category + '.' + name + ' = "' + value + '"');
+ }
+ break;
+ }
+ default: {
+ return function(value) {
+ return eval(category + '.' + name + ' = ' + value);
+ }
+ break;
+ }
+ }
+ }
+ catch (exception) {
+ throw category + '.' + name + ' doesnt exist.';
+ }
+ }
+
+ function read(category, name) {
+ try {
+ var value = eval(category + '.' + name);
+
+ if ( typeof value === 'undefined' ) {
+ throw new ReferenceError();
+ } else {
+ return value;
+ }
+ }
+ catch (exception) {
+ throw category + '.' + name + ' doesnt exist.';
+ }
+ }
+
property Settings window : Settings {
category: "window"
diff --git a/src/command/commands.js b/src/command/commands.js
index d5b9787..fce509a 100644
--- a/src/command/commands.js
+++ b/src/command/commands.js
@@ -14,13 +14,17 @@ function execute(output, command) {
notImplemented(args[0]);
}
} catch (exception) {
- notImplemented(args[0]);
+ if ( exception instanceof ReferenceError ) {
+ notImplemented(args[0]);
+ } else {
+ output.error(exception);
+ }
}
}
-function safeEval(output, code) {
+function exec(output, args) {
try {
- var result = eval(code);
+ var result = eval(args.join(' '));
if ( typeof result !== 'undefined' ) {
output.log(result);
@@ -30,10 +34,6 @@ function safeEval(output, code) {
}
}
-function exec(output, args) {
- safeEval(output, args.join(' '));
-}
-
function jump(output, index) {
terminalList.selectItem(index);
}
@@ -61,14 +61,11 @@ function ls(output) {
function set(output, args) {
switch ( args.length ) {
case 2: {
- safeEval(output, 'settings.' + args[0] + '.' + args[1]);
+ output.log(settings.read(args[0], args[1]));
break;
}
case 3: {
- safeEval(
- output,
- 'settings.' + args[0] + '.' + args[1] + ' = "' + args[2] + '"'
- );
+ settings.getSetter(args[0], args[1])(args[2]);
break;
}
default: {