mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-08-03 16:58:24 +02:00
Merge pull request #2366 from alicevision/dev/copyPasteAttributeEditor
[ui] Right click on text element in AttributeEditor open Copy/Paste menu
This commit is contained in:
commit
d5d2ee3095
1 changed files with 79 additions and 1 deletions
|
@ -112,6 +112,21 @@ RowLayout {
|
|||
updateAttributeLabel()
|
||||
}
|
||||
}
|
||||
MenuItem {
|
||||
text: "Copy"
|
||||
enabled: attribute.value != ""
|
||||
onTriggered: {
|
||||
Clipboard.clear()
|
||||
Clipboard.setText(attribute.value)
|
||||
}
|
||||
}
|
||||
MenuItem {
|
||||
text: "Paste"
|
||||
enabled: Clipboard.getText() != "" && root.editable
|
||||
onTriggered: {
|
||||
_reconstruction.setAttribute(attribute, Clipboard.getText())
|
||||
}
|
||||
}
|
||||
|
||||
MenuSeparator {
|
||||
visible: paramMenu.isFileAttribute
|
||||
|
@ -219,13 +234,22 @@ RowLayout {
|
|||
Component {
|
||||
id: textField_component
|
||||
TextField {
|
||||
id: textField
|
||||
readOnly: !root.editable
|
||||
text: attribute.value
|
||||
selectByMouse: true
|
||||
onEditingFinished: setTextFieldAttribute(text)
|
||||
persistentSelection: false
|
||||
property bool memoryActiveFocus: false
|
||||
onAccepted: {
|
||||
setTextFieldAttribute(text)
|
||||
root.forceActiveFocus()
|
||||
parameterLabel.forceActiveFocus()
|
||||
}
|
||||
Keys.onPressed: (event)=> {
|
||||
if ((event.key == Qt.Key_Escape)) {
|
||||
event.accepted = true
|
||||
parameterLabel.forceActiveFocus()
|
||||
}
|
||||
}
|
||||
Component.onDestruction: {
|
||||
if (activeFocus)
|
||||
|
@ -241,6 +265,60 @@ RowLayout {
|
|||
setTextFieldAttribute(drop.text)
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.RightButton
|
||||
onClicked: (mouse)=> {
|
||||
// Do not loose the selection during the right click
|
||||
textField.persistentSelection = true
|
||||
// We store the status of the activeFocus before opening the popup
|
||||
textField.memoryActiveFocus = textField.activeFocus
|
||||
var menu = menuCopy.createObject(textField)
|
||||
menu.parent = textField
|
||||
menu.popup()
|
||||
if(textField.memoryActiveFocus) {
|
||||
// If the focus was active, we continue to display the cursor
|
||||
// to explain that we will insert the new text in this position (in case of "Paste" action)
|
||||
textField.cursorVisible = true
|
||||
}
|
||||
// We do not want the selection to be globally persistent
|
||||
textField.persistentSelection = false
|
||||
}
|
||||
|
||||
property Component menuCopy : Menu {
|
||||
MenuItem {
|
||||
text: "Copy"
|
||||
enabled: attribute.value != ""
|
||||
onTriggered: {
|
||||
if (textField.selectionStart === textField.selectionEnd) {
|
||||
// If no selection
|
||||
Clipboard.clear()
|
||||
Clipboard.setText(attribute.value)
|
||||
} else {
|
||||
// copy selection only
|
||||
textField.copy()
|
||||
}
|
||||
}
|
||||
}
|
||||
MenuItem {
|
||||
text: "Paste"
|
||||
enabled: Clipboard.getText() != "" && !readOnly
|
||||
onTriggered: {
|
||||
if (textField.memoryActiveFocus) {
|
||||
// replace the selected text with the clipboard
|
||||
// or if there is no selection insert at the cursor position
|
||||
var before = textField.text.substr(0, textField.selectionStart)
|
||||
var after = textField.text.substr(textField.selectionEnd, textField.text.length)
|
||||
setTextFieldAttribute(before + Clipboard.getText() + after)
|
||||
// set the cursor at the end of the added text
|
||||
textField.cursorPosition = before.length + Clipboard.getText().length
|
||||
} else {
|
||||
setTextFieldAttribute(Clipboard.getText())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue