aboutsummaryrefslogtreecommitdiff
path: root/components/ContextMenu.qml
blob: 0b3a37d0e7ec75520f23b70862bd2726c6c8eab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import QtQuick 2.9
import QtQuick.Controls 2.2

import FontAwesome 1.0
import "../components" as MonzeroComponents

MouseArea {
    signal cut()
    signal copy()
    signal paste()
    signal remove()
    signal selectAll()

    id: root
    acceptedButtons: Qt.RightButton
    anchors.fill: parent
    onClicked: {
        if (mouse.button === Qt.RightButton) {
            root.parent.persistentSelection = true;
            contextMenu.open()
            root.parent.cursorVisible = true;
        }
    }

    Menu {
        id: contextMenu

        background: Rectangle {
            border.color: MonzeroComponents.Style.buttonBackgroundColorDisabledHover
            border.width: 1
            radius: 2
            color: MonzeroComponents.Style.blackTheme ? MonzeroComponents.Style.buttonBackgroundColorDisabled : "#E5E5E5"
        }

        padding: 1
        width: 110
        x: root.mouseX
        y: root.mouseY

        onClosed: {
            if (!root.parent.activeFocus) {
                root.parent.cursorVisible = false;
            }
            root.parent.persistentSelection = false;
            root.parent.forceActiveFocus()
        }

        MonzeroComponents.ContextMenuItem {
            enabled: root.parent.selectedText != "" && !root.parent.readOnly
            onTriggered: root.cut()
            text: qsTr("Cut") + translationManager.emptyString
        }

        MonzeroComponents.ContextMenuItem {
            enabled: root.parent.selectedText != ""
            onTriggered: root.copy()
            text: qsTr("Copy") + translationManager.emptyString
        }

        MonzeroComponents.ContextMenuItem {
            enabled: root.parent.canPaste === true
            onTriggered: root.paste()
            text: qsTr("Paste") + translationManager.emptyString
        }

        MonzeroComponents.ContextMenuItem {
            enabled: root.parent.selectedText != "" && !root.parent.readOnly
            onTriggered: root.remove()
            text: qsTr("Delete") + translationManager.emptyString
        }

        MonzeroComponents.ContextMenuItem {
            enabled: root.parent.text != ""
            onTriggered: root.selectAll()
            text: qsTr("Select All") + translationManager.emptyString
        }
    }
}