Commit 6e3f467a authored by David Redondo's avatar David Redondo 🏎
Browse files

[Cuttlefish] Use the same actions in all menus

Summary:
Defines the actions in one place and uses them for the context menus and
buttons in the two preview panes. This reduces code duplication, adds
actions to the context menu which couldn't be triggered from there before
and makes it easier to add new features with only needing to touch one place
instead of potentially three. Furthermore this also reduces the risk of bugs
caused by copy-pasting, for example the screenshot actions didn't work before
in responsive mode.
The actionsMenu component is based on the one from Kirigami with the same name.

Test Plan: Everything works

Reviewers: #plasma, ngraham, cblack

Reviewed By: ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25846
parent f96f221f
/***************************************************************************
* *
* Copyright 2019 Carson Black <uhhadd@gmail.com> *
* Copyright 2019 David Redondo <kde@david-redondo.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
import QtQuick 2.5
import QtQuick.Dialogs 1.3
import QtQuick.Controls 2.5 as QQC2
import org.kde.kirigami 2.8 as Kirigami
Item {
property QQC2.Action screenshotAction: QQC2.Action {
enabled: !iconPreview.screenshotting
icon.name: "camera-web-symbolic"
text: i18n("Create screenshot of icon")
onTriggered: {
screenshotPopup.popup()
}
}
property list<Kirigami.Action> actions:[
Kirigami.Action {
text: i18n("Open icon with external program")
iconName: "document-open"
onTriggered: Qt.openUrlExternally(preview.fullPath)
},
Kirigami.Action {
text: pickerMode ? i18n("Insert icon name") : i18n("Copy icon name to clipboard")
iconName: "edit-copy"
onTriggered: {
clipboard(preview.iconName)
cuttlefish.showPassiveNotification(i18n("Icon name copied to clipboard"), "short")
}
},
Kirigami.Action {
id: screenshotAction
iconName: "camera-web-symbolic"
text: i18n("Create screenshot of icon with...")
onTriggered: screenshotPopup.popup()
Kirigami.Action {
text: i18n("Breeze Colors")
onTriggered: previewPane.iconPreview.shot("normal")
}
Kirigami.Action {
text: i18n("Breeze Dark Colors")
onTriggered: previewPane.iconPreview.shot("dark")
}
Kirigami.Action {
onTriggered: previewPane.dualMont.shot()
text: i18n("Breeze (Normal) and Breeze Dark")
}
Kirigami.Action {
onTriggered: previewPane.iconPreview.shot("active")
text: i18n("Active Color Scheme")
}
},
Kirigami.Action {
text: i18n("View icon in other themes")
icon.name: "document-equal"
onTriggered: comparison.sheetOpen = true
}
]
QQC2.Menu {
id: screenshotPopup
Repeater {
model: screenshotAction.visibleChildren
delegate: QQC2.MenuItem {
action: modelData
}
}
}
function clipboard(text) {
if (!pickerMode) {
clipboardHelper.text = text;
clipboardHelper.selectAll();
clipboardHelper.copy();
} else {
iconModel.output(text);
}
}
TextEdit {
id: clipboardHelper
visible: false
}
}
/***************************************************************************
* *
* Copyright 2018 Aleix Pol Gonzalez <aleixpol@kde.org> *
* Copyright 2019 Carson Black <uhhadd@gmail.com> *
* Copyright 2019 David Redondo <kde@david-redondo.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......@@ -20,29 +22,63 @@
***************************************************************************/
import QtQuick 2.5
import Qt.labs.platform 1.0
import QtQuick.Controls 2.5 as QQC2
import org.kde.kirigami 2.8 as Kirigami
Menu {
id: root
Connections {
target: cuttlefish
onItemRightClicked: {
root.open()
Item {
Loader {
id:menuLoader
sourceComponent: actionsMenu
onLoaded: {
item.actions = cuttlefish.actions
}
}
MenuItem {
iconName: "edit-copy"
text: pickerMode ? i18n("Insert icon name") : i18n("Copy icon name to clipboard")
onTriggered: {
previewPane.clipboard(preview.iconName)
cuttlefish.showPassiveNotification(i18n("Icon name copied to clipboard"), "short")
Connections {
target: cuttlefish
onItemRightClicked: {
menuLoader.item.popup()
}
}
}
MenuItem {
iconName: "document-open"
text: i18n("Open icon with external program")
onTriggered: {
Qt.openUrlExternally(preview.fullPath)
Component {
id: actionsMenu
QQC2.Menu {
id: theMenu
property Component submenuComponent: actionsMenu
property Component itemDelegate: QQC2.MenuItem { }
property Component seperatorDelegate: Kirigami.Separator {}
property alias actions: actionsInstantiator.model
Item {
id: invisibleItems
visible: false
}
Instantiator {
id: actionsInstantiator
active: theMenu.visible
delegate: QtObject {
readonly property var action: modelData
property QtObject item: null
function create() {
if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) {
item = theMenu.itemDelegate.createObject(null, { action: action });
theMenu.addItem(item)
} else {
item = theMenu.submenuComponent.createObject(null, { actions: action.children, title: action.text});
theMenu.insertMenu(theMenu.count, item)
var menuitem = theMenu.contentData[theMenu.contentData.length-1]
menuitem.icon = action.icon
}
}
function remove() {
if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) {
theMenu.removeItem(item)
} else if (theMenu.submenuComponent) {
theMenu.removeMenu(item)
}
}
}
onObjectAdded: object.create()
onObjectRemoved: object.remove()
}
}
}
}
......@@ -41,21 +41,6 @@ Rectangle {
color: Kirigami.Theme.backgroundColor
function clipboard(text) {
if (!pickerMode) {
clipboardHelper.text = text;
clipboardHelper.selectAll();
clipboardHelper.copy();
} else {
iconModel.output(text);
}
}
TextEdit {
id: clipboardHelper
visible: false
}
FileDialog {
id: ssPicker
selectExisting: false
......@@ -252,65 +237,13 @@ Rectangle {
ssPicker.open()
}
}
QQC2.Button {
Layout.alignment: Qt.AlignHCenter
text: i18n("Open icon with external program")
icon.name: "document-open"
onClicked: Qt.openUrlExternally(preview.fullPath)
}
QQC2.Button {
Layout.alignment: Qt.AlignHCenter
text: pickerMode ? i18n("Insert icon name") : i18n("Copy icon name to clipboard")
icon.name: "edit-copy"
onClicked: {
clipboard(preview.iconName)
cuttlefish.showPassiveNotification(i18n("Icon name copied to clipboard"), "short")
}
}
QQC2.Button {
Layout.alignment: Qt.AlignHCenter
visible: !iconPreview.screenshotting
icon.name: "camera-web-symbolic"
text: i18n("Create screenshot of icon")
onClicked: {
screenshotActions.popup()
}
QQC2.Menu {
id: screenshotActions
QQC2.MenuItem {
text: i18n("Screenshot with Breeze Colors")
onTriggered: {
iconPreview.shot("normal")
}
}
QQC2.MenuItem {
text: i18n("Screenshot with Breeze Dark Colors")
onTriggered: {
iconPreview.shot("dark")
}
}
QQC2.MenuItem {
text: i18n("Screenshot with Breeze (Normal) and Breeze Dark")
onTriggered: {
dualMont.shot()
}
}
QQC2.MenuItem {
text: i18n("Screenshot with Active Color Scheme")
onTriggered: {
iconPreview.shot("active")
}
}
Repeater {
model: cuttlefish.actions
delegate: QQC2.Button {
Layout.alignment: Qt.AlignHCenter
action: modelData
}
}
QQC2.Button {
Layout.alignment: Qt.AlignCenter
text: i18n("View icon in other themes")
icon.name: "document-equal"
onClicked: comparison.sheetOpen = true
}
Item {
Layout.fillHeight: true
}
......
......@@ -42,61 +42,8 @@ Kirigami.GlobalDrawer {
focus: false
function clipboard(text) {
if (!pickerMode) {
clipboardHelper.text = text;
clipboardHelper.selectAll();
clipboardHelper.copy();
} else {
iconModel.output(text);
}
}
actions: cuttlefish.actions
TextEdit {
id: clipboardHelper
visible: false
}
actions: [
Kirigami.Action {
text: i18n("Open icon with external program")
iconName: "document-open"
onTriggered: Qt.openUrlExternally(preview.fullPath)
},
Kirigami.Action {
text: pickerMode ? i18n("Insert icon name") : i18n("Copy icon name to clipboard")
iconName: "edit-copy"
onTriggered: {
root.clipboard(preview.iconName)
cuttlefish.showPassiveNotification(i18n("Icon name copied to clipboard"), "short")
}
},
Kirigami.Action {
iconName: "camera-web-symbolic"
text: i18n("Create screenshot of icon with...")
Kirigami.Action {
text: i18n("Breeze Colors")
onTriggered: iconPreview.shot("normal")
}
Kirigami.Action {
text: i18n("Breeze Dark Colors")
onTriggered: iconPreview.shot("dark")
}
Kirigami.Action {
onTriggered: dualMont.shot()
text: i18n("Breeze (Normal) and Breeze Dark")
}
Kirigami.Action {
onTriggered: iconPreview.shot("active")
text: i18n("Active Color Scheme")
}
},
Kirigami.Action {
text: i18n("View icon in other themes")
icon.name: "document-equal"
onTriggered: comparison.sheetOpen = true
}
]
Kirigami.Heading {
level: 1
Layout.fillWidth: true
......
......@@ -43,6 +43,8 @@ Kirigami.ApplicationWindow {
property bool usesPlasmaTheme: true
property var schemeStash
property alias actions: actions.actions
property color textcolor: Kirigami.Theme.textColor
property color bgcolor: Kirigami.Theme.backgroundColor
property color highlightcolor: Kirigami.Theme.highlightColor
......@@ -59,16 +61,19 @@ Kirigami.ApplicationWindow {
Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor
Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor
Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor
Loader {
// Use a Loader instead of creating a GMB directly,
// so if the GMB errors, it doesn't affect Cuttlefish's operation
id: loader
source: "GlobalMenuBar.qml"
}
Loader {
// Ditto for the right click context menu.
source: "Menu.qml"
Actions {
id: actions
}
Menu {
id: menu
}
Settings {
property alias x: cuttlefish.x
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment