2020-09-24 09:57:54 +10:00
|
|
|
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
|
2020-07-10 14:02:43 +10:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
2020-07-16 05:10:34 +10:00
|
|
|
import Clipboard 0.1
|
2020-07-10 14:02:43 +10:00
|
|
|
|
|
|
|
HMenu {
|
2020-07-16 05:10:34 +10:00
|
|
|
id: menu
|
|
|
|
|
2020-07-10 14:02:43 +10:00
|
|
|
property Item control: parent // HTextField or HTextArea
|
|
|
|
|
2020-07-16 05:10:34 +10:00
|
|
|
property bool enableCustomImagePaste: false
|
2020-07-10 14:02:43 +10:00
|
|
|
property bool hadPersistentSelection: false // TODO: use a Qt 5.15 Binding
|
|
|
|
|
2020-07-16 05:10:34 +10:00
|
|
|
signal customImagePaste()
|
|
|
|
|
2020-07-10 14:02:43 +10:00
|
|
|
function spawn(atMousePosition=true) {
|
|
|
|
hadPersistentSelection = control.persistentSelection
|
|
|
|
control.persistentSelection = true
|
|
|
|
|
|
|
|
atMousePosition ?
|
|
|
|
popup() :
|
|
|
|
popup(
|
|
|
|
control.cursorRectangle.right,
|
|
|
|
control.cursorRectangle.bottom + theme.spacing / 4,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onClosed: control.persistentSelection = hadPersistentSelection
|
|
|
|
Component.onDestruction:
|
|
|
|
control.persistentSelection = hadPersistentSelection
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "undo"
|
|
|
|
text: qsTr("Undo")
|
|
|
|
enabled: control.canUndo
|
|
|
|
onTriggered: control.undo()
|
|
|
|
}
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "redo"
|
|
|
|
text: qsTr("Redo")
|
|
|
|
enabled: control.canRedo
|
|
|
|
onTriggered: control.redo()
|
|
|
|
}
|
|
|
|
|
|
|
|
HMenuSeparator {}
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "cut-text"
|
|
|
|
text: qsTr("Cut")
|
2020-10-31 17:59:56 +11:00
|
|
|
enabled: control.selectedPlainText
|
2020-07-10 14:02:43 +10:00
|
|
|
onTriggered: control.cut()
|
|
|
|
}
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "copy-text"
|
|
|
|
text: qsTr("Copy")
|
2020-10-31 17:59:56 +11:00
|
|
|
enabled: control.selectedPlainText
|
2020-07-10 14:02:43 +10:00
|
|
|
onTriggered: control.copy()
|
|
|
|
}
|
|
|
|
|
|
|
|
HMenuItem {
|
2020-07-16 05:10:34 +10:00
|
|
|
property bool pasteImage:
|
|
|
|
menu.enableCustomImagePaste && Clipboard.hasImage
|
|
|
|
|
2020-07-10 14:02:43 +10:00
|
|
|
icon.name: "paste-text"
|
|
|
|
text: qsTr("Paste")
|
2020-07-16 05:10:34 +10:00
|
|
|
enabled: control.canPaste || pasteImage
|
|
|
|
onTriggered: pasteImage ? menu.customImagePaste() : control.paste()
|
2020-07-10 14:02:43 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HMenuSeparator {}
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "select-all-text"
|
|
|
|
text: qsTr("Select all")
|
2020-07-10 17:21:30 +10:00
|
|
|
enabled: control.length > 0
|
2020-07-10 14:02:43 +10:00
|
|
|
onTriggered: control.selectAll()
|
|
|
|
}
|
|
|
|
}
|