mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-11-17 08:17:59 +00:00
ContextMenu: add Cut, Copy, Delete and Select All
This commit is contained in:
parent
113efbfdf0
commit
d3780abe33
4 changed files with 73 additions and 11 deletions
|
@ -5,14 +5,21 @@ import FontAwesome 1.0
|
||||||
import "../components" as MoneroComponents
|
import "../components" as MoneroComponents
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
signal cut()
|
||||||
|
signal copy()
|
||||||
signal paste()
|
signal paste()
|
||||||
|
signal remove()
|
||||||
|
signal selectAll()
|
||||||
|
|
||||||
id: root
|
id: root
|
||||||
acceptedButtons: Qt.RightButton
|
acceptedButtons: Qt.RightButton
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (mouse.button === Qt.RightButton)
|
if (mouse.button === Qt.RightButton) {
|
||||||
|
root.parent.persistentSelection = true;
|
||||||
contextMenu.open()
|
contextMenu.open()
|
||||||
|
root.parent.cursorVisible = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu {
|
Menu {
|
||||||
|
@ -22,19 +29,50 @@ MouseArea {
|
||||||
border.color: MoneroComponents.Style.buttonBackgroundColorDisabledHover
|
border.color: MoneroComponents.Style.buttonBackgroundColorDisabledHover
|
||||||
border.width: 1
|
border.width: 1
|
||||||
radius: 2
|
radius: 2
|
||||||
color: MoneroComponents.Style.buttonBackgroundColorDisabled
|
color: MoneroComponents.Style.blackTheme ? MoneroComponents.Style.buttonBackgroundColorDisabled : "#E5E5E5"
|
||||||
}
|
}
|
||||||
|
|
||||||
padding: 1
|
padding: 1
|
||||||
width: 100
|
width: 110
|
||||||
x: root.mouseX
|
x: root.mouseX
|
||||||
y: root.mouseY
|
y: root.mouseY
|
||||||
|
|
||||||
|
onClosed: {
|
||||||
|
if (!root.parent.activeFocus) {
|
||||||
|
root.parent.cursorVisible = false;
|
||||||
|
}
|
||||||
|
root.parent.persistentSelection = false;
|
||||||
|
root.parent.forceActiveFocus()
|
||||||
|
}
|
||||||
|
|
||||||
|
MoneroComponents.ContextMenuItem {
|
||||||
|
enabled: root.parent.selectedText != "" && !root.parent.readOnly
|
||||||
|
onTriggered: root.cut()
|
||||||
|
text: qsTr("Cut") + translationManager.emptyString
|
||||||
|
}
|
||||||
|
|
||||||
|
MoneroComponents.ContextMenuItem {
|
||||||
|
enabled: root.parent.selectedText != ""
|
||||||
|
onTriggered: root.copy()
|
||||||
|
text: qsTr("Copy") + translationManager.emptyString
|
||||||
|
}
|
||||||
|
|
||||||
MoneroComponents.ContextMenuItem {
|
MoneroComponents.ContextMenuItem {
|
||||||
enabled: root.parent.canPaste === true
|
enabled: root.parent.canPaste === true
|
||||||
glyphIcon: FontAwesome.paste
|
|
||||||
onTriggered: root.paste()
|
onTriggered: root.paste()
|
||||||
text: qsTr("Paste") + translationManager.emptyString
|
text: qsTr("Paste") + translationManager.emptyString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MoneroComponents.ContextMenuItem {
|
||||||
|
enabled: root.parent.selectedText != "" && !root.parent.readOnly
|
||||||
|
onTriggered: root.remove()
|
||||||
|
text: qsTr("Delete") + translationManager.emptyString
|
||||||
|
}
|
||||||
|
|
||||||
|
MoneroComponents.ContextMenuItem {
|
||||||
|
enabled: root.parent.text != ""
|
||||||
|
onTriggered: root.selectAll()
|
||||||
|
text: qsTr("Select All") + translationManager.emptyString
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,21 +13,31 @@ MenuItem {
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: MoneroComponents.Style.buttonBackgroundColorDisabledHover
|
color: MoneroComponents.Style.buttonBackgroundColorDisabledHover
|
||||||
opacity: mouse.containsMouse ? 1 : 0
|
opacity: 0
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: mouse
|
id: mouse
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onClicked: menuItem.triggered()
|
onEntered: {
|
||||||
visible: menuItem.enabled
|
parent.opacity = 1;
|
||||||
|
}
|
||||||
|
onExited: {
|
||||||
|
parent.opacity = 0;
|
||||||
|
}
|
||||||
|
onClicked: {
|
||||||
|
if (menuItem.enabled) {
|
||||||
|
menuItem.triggered();
|
||||||
|
parent.opacity = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contentItem: RowLayout {
|
contentItem: RowLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.leftMargin: 10
|
anchors.leftMargin: 20
|
||||||
anchors.rightMargin: 10
|
anchors.rightMargin: 10
|
||||||
opacity: menuItem.enabled ? 1 : 0.4
|
opacity: menuItem.enabled ? 1 : 0.4
|
||||||
spacing: 8
|
spacing: 8
|
||||||
|
@ -42,7 +52,7 @@ MenuItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
color: MoneroComponents.Style.buttonTextColor
|
color: MoneroComponents.Style.blackTheme ? MoneroComponents.Style.buttonTextColor : MoneroComponents.Style.defaultFontColor
|
||||||
font.family: MoneroComponents.Style.fontRegular.name
|
font.family: MoneroComponents.Style.fontRegular.name
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
|
@ -48,9 +48,16 @@ TextField {
|
||||||
|
|
||||||
MoneroComponents.ContextMenu {
|
MoneroComponents.ContextMenu {
|
||||||
cursorShape: Qt.IBeamCursor
|
cursorShape: Qt.IBeamCursor
|
||||||
|
onCut: textField.cut();
|
||||||
|
onCopy: textField.copy();
|
||||||
onPaste: {
|
onPaste: {
|
||||||
textField.clear();
|
var previoustextFieldLength = textField.length
|
||||||
|
var previousCursorPosition = textField.cursorPosition;
|
||||||
textField.paste();
|
textField.paste();
|
||||||
|
textField.forceActiveFocus()
|
||||||
|
textField.cursorPosition = previousCursorPosition + (textField.length - previoustextFieldLength);
|
||||||
}
|
}
|
||||||
|
onRemove: textField.remove(selectionStart, selectionEnd);
|
||||||
|
onSelectAll: textField.selectAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,9 +71,16 @@ TextArea {
|
||||||
|
|
||||||
MoneroComponents.ContextMenu {
|
MoneroComponents.ContextMenu {
|
||||||
cursorShape: Qt.IBeamCursor
|
cursorShape: Qt.IBeamCursor
|
||||||
|
onCut: textArea.cut();
|
||||||
|
onCopy: textArea.copy();
|
||||||
onPaste: {
|
onPaste: {
|
||||||
textArea.clear();
|
var previoustextFieldLength = textArea.length
|
||||||
|
var previousCursorPosition = textArea.cursorPosition;
|
||||||
textArea.paste();
|
textArea.paste();
|
||||||
|
textArea.forceActiveFocus()
|
||||||
|
textArea.cursorPosition = previousCursorPosition + (textArea.length - previoustextFieldLength);
|
||||||
}
|
}
|
||||||
|
onRemove: textArea.remove(selectionStart, selectionEnd);
|
||||||
|
onSelectAll: textArea.selectAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue