Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
uglide committed Sep 13, 2017
1 parent b2840a4 commit d965d00
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/qml/value-editor/ValueTabs.qml
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ Repeater {
function clear() {
if (valueEditor.item) {
currentRow = -1
valueEditor.item.resetAndDisableEditor()
valueEditor.item.reset()
}
}
}
Expand Down
20 changes: 13 additions & 7 deletions src/qml/value-editor/editors/MultilineEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ ColumnLayout

function loadFormattedValue(val) {

value = val

if (!value)
return
if (val) {
root.value = val
}

var isBin = binaryUtils.isBinaryString(root.value)

Expand All @@ -67,9 +66,14 @@ ColumnLayout

formatter.instance.getFormatted(root.value, function (error, formatted, isReadOnly, format) {

// TODO: process error
if (error) {
uiBlocker.visible = false
formatterSelector.currentIndex = 0 // Reset formatter to plain text
notification.showError(error)
return
}

if (format == "json") {
if (format === "json") {
// 1 is JSON
return formatterSelector.model[1].instance.getFormatted(formatted, function (formattedJson, r, f) {

Expand Down Expand Up @@ -130,7 +134,9 @@ ColumnLayout
Formatters.defaultFormatterIndex = currentIndex
loadFormattedValue()
}
Component.onCompleted: currentIndex = Formatters.defaultFormatterIndex
Component.onCompleted: {
currentIndex = Formatters.defaultFormatterIndex;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/qml/value-editor/editors/formatters/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ var json = {

getFormatted: function (raw, callback) {
try {
return callback(JSONFormatter.prettyPrint(raw), false, FORMAT_PLAIN_TEXT)
return callback("", JSONFormatter.prettyPrint(String(raw)), false, FORMAT_PLAIN_TEXT)
} catch (e) {
return callback("Error: Invalid JSON")
return callback("Error: Invalid JSON: " + e)
}
},

getRaw: function (formatted, callback) {
try {
return callback(JSONFormatter.minify(formatted))
return callback("", JSONFormatter.minify(formatted))
} catch (e) {
return callback("Error: " + e)
}
Expand Down
21 changes: 21 additions & 0 deletions tests/qml_tests/tst_formatters.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,25 @@ TestCase {
compare(plain, testValue)
})
}

function test_json() {
//given
// given
var formatter = Formatters.json
var testValue = '{"test": 123}'
var formattedValid = "{\n \"test\": 123\n}"

// checks
verify(formatter.title.length !== 0, "title")

formatter.getFormatted(testValue, function (error, formatted, readOnly, format){
console.log(error)
compare(formatted, formattedValid)
})

formatter.getRaw(testValue, function (error, plain){
console.log(error)
compare(plain, testValue)
})
}
}

0 comments on commit d965d00

Please sign in to comment.