[ui] AttributeEditor: add contextual actions on File params

* add 'Open Containing Folder'/'Open File' actions for filepaths
* add 'Open Folder' action for folders
* misc: tweak spacings
This commit is contained in:
Yann Lanthony 2018-02-05 19:03:27 +01:00
parent c45ebdf83c
commit 60f1f36ff8
3 changed files with 33 additions and 2 deletions

View file

@ -64,7 +64,7 @@ ColumnLayout {
id: attributesListView id: attributesListView
anchors.fill: parent anchors.fill: parent
anchors.margins: 6 anchors.margins: 4
clip: true clip: true
spacing: 1 spacing: 1

View file

@ -1,6 +1,7 @@
import QtQuick 2.9 import QtQuick 2.9
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import "../filepath.js" as Filepath
/** /**
Instantiate a control to visualize and edit an Attribute based on its type. Instantiate a control to visualize and edit an Attribute based on its type.
@ -52,11 +53,34 @@ RowLayout {
property Component menuComp: Menu { property Component menuComp: Menu {
id: paramMenu id: paramMenu
property bool isFileAttribute: attribute.type == "File"
property bool isFilepath: isFileAttribute && Filepath.isFile(attribute.value)
MenuItem { MenuItem {
text: "Reset To Default Value" text: "Reset To Default Value"
enabled: !attribute.isOutput && !attribute.isLink && !attribute.isDefault enabled: !attribute.isOutput && !attribute.isLink && !attribute.isDefault
onTriggered: _reconstruction.resetAttribute(attribute) onTriggered: _reconstruction.resetAttribute(attribute)
} }
MenuSeparator {
visible: paramMenu.isFileAttribute
height: visible ? implicitHeight : 0
}
MenuItem {
visible: paramMenu.isFileAttribute
height: visible ? implicitHeight : 0
text: paramMenu.isFilepath ? "Open Containing Folder" : "Open Folder"
onClicked: paramMenu.isFilepath ? Qt.openUrlExternally(Filepath.dirname(attribute.value)) :
Qt.openUrlExternally(attribute.value)
}
MenuItem {
visible: paramMenu.isFilepath
height: visible ? implicitHeight : 0
text: "Open File"
onClicked: Qt.openUrlExternally(attribute.value)
}
} }
onClicked: { onClicked: {
@ -240,7 +264,7 @@ RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.margins: 4 Layout.margins: 4
clip: true clip: true
spacing: 10 spacing: 4
ScrollBar.vertical: ScrollBar { id: sb } ScrollBar.vertical: ScrollBar { id: sb }

View file

@ -15,3 +15,10 @@ function extension(path) {
var dot_pos = path.lastIndexOf('.'); var dot_pos = path.lastIndexOf('.');
return dot_pos > -1 ? path.substring(dot_pos, path.length) : "" return dot_pos > -1 ? path.substring(dot_pos, path.length) : ""
} }
/// Return whether the given path is a path to a file.
/// (only based on the fact that the last portion of the path
/// matches the 'basename.extension' pattern)
function isFile(path) {
return extension(path) !== ""
}