feat(ui/scripts/Utils/utils): provide a getPathFromUri function

This commit is contained in:
Ronan Abhamon 2017-06-06 17:10:15 +02:00
parent 5f203eaac4
commit 0d526abde1
2 changed files with 20 additions and 1 deletions

View file

@ -82,7 +82,7 @@ TextField {
}
onAccepted: {
textField.selectedFile = fileUrl.toString().substring(7)
textField.selectedFile = Utils.getPathFromUri(fileUrl)
textField.accepted(textField.selectedFile)
}

View file

@ -155,6 +155,25 @@ function openWindow (window, parent, options) {
// -----------------------------------------------------------------------------
function getPathFromUri (uri) {
var str = uri.toString()
if (startsWith(str, 'file://')) {
str = str.substring(7)
// Absolute path.
if (str.charAt(0) === '/') {
var os = Qt.platform.os
return os === 'windows' || os === 'winrt'
? str.substring(1)
: str
}
}
return str
}
// -----------------------------------------------------------------------------
// Test if a point is in a item.
//
// `source` is the item that generated the point.