feat: global menu
This adds a global menu to NeoChat, providing a standard and consistent set of File/Edit/View/so on menus.
This commit is contained in:
committed by
Carl Schwan
parent
6bbb4b4985
commit
537416354a
90
imports/NeoChat/Menu/EditMenu.qml
Normal file
90
imports/NeoChat/Menu/EditMenu.qml
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2021 Carson Black <uhhadd@gmail.com>
|
||||||
|
// SPDX-License-Identifier: LGPL-2.0-or-later
|
||||||
|
|
||||||
|
import Qt.labs.platform 1.1 as Labs
|
||||||
|
import QtQuick 2.15
|
||||||
|
import QtQuick.Controls 2.12 as QQC2
|
||||||
|
import QtQuick.Layouts 1.10
|
||||||
|
import org.kde.kirigami 2.15 as Kirigami
|
||||||
|
|
||||||
|
Labs.Menu {
|
||||||
|
id: editMenu
|
||||||
|
|
||||||
|
required property Item field
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
enabled: editMenu.field !== null && editMenu.field.canUndo
|
||||||
|
text: i18nc("text editing menu action", "Undo")
|
||||||
|
shortcut: StandardKey.Undo
|
||||||
|
onTriggered: {
|
||||||
|
editMenu.field.undo()
|
||||||
|
editMenu.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
enabled: editMenu.field !== null && editMenu.field.canRedo
|
||||||
|
text: i18nc("text editing menu action", "Redo")
|
||||||
|
shortcut: StandardKey.Redo
|
||||||
|
onTriggered: {
|
||||||
|
editMenu.field.undo()
|
||||||
|
editMenu.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Labs.MenuSeparator {
|
||||||
|
}
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
enabled: editMenu.field !== null && editMenu.field.selectedText
|
||||||
|
text: i18nc("text editing menu action", "Cut")
|
||||||
|
shortcut: StandardKey.Cut
|
||||||
|
onTriggered: {
|
||||||
|
editMenu.field.cut()
|
||||||
|
editMenu.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
enabled: editMenu.field !== null && editMenu.field.selectedText
|
||||||
|
text: i18nc("text editing menu action", "Copy")
|
||||||
|
shortcut: StandardKey.Copy
|
||||||
|
onTriggered: {
|
||||||
|
editMenu.field.copy()
|
||||||
|
editMenu.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
enabled: editMenu.field !== null && editMenu.field.canPaste
|
||||||
|
text: i18nc("text editing menu action", "Paste")
|
||||||
|
shortcut: StandardKey.Paste
|
||||||
|
onTriggered: {
|
||||||
|
editMenu.field.paste()
|
||||||
|
editMenu.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
enabled: editMenu.field !== null && editMenu.field.selectedText !== ""
|
||||||
|
text: i18nc("text editing menu action", "Delete")
|
||||||
|
shortcut: ""
|
||||||
|
onTriggered: {
|
||||||
|
editMenu.field.remove(editMenu.field.selectionStart, editMenu.field.selectionEnd)
|
||||||
|
editMenu.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Labs.MenuSeparator {
|
||||||
|
}
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
enabled: editMenu.field !== null
|
||||||
|
text: i18nc("text editing menu action", "Select All")
|
||||||
|
shortcut: StandardKey.SelectAll
|
||||||
|
onTriggered: {
|
||||||
|
editMenu.field.selectAll()
|
||||||
|
editMenu.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
96
imports/NeoChat/Menu/GlobalMenu.qml
Normal file
96
imports/NeoChat/Menu/GlobalMenu.qml
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2021 Carson Black <uhhadd@gmail.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import Qt.labs.platform 1.1 as Labs
|
||||||
|
|
||||||
|
import QtQuick 2.15
|
||||||
|
import QtQuick.Window 2.15
|
||||||
|
import QtQuick.Controls 2.12 as QQC2
|
||||||
|
import QtQuick.Layouts 1.10
|
||||||
|
import org.kde.kirigami 2.15 as Kirigami
|
||||||
|
|
||||||
|
import org.kde.neochat 1.0
|
||||||
|
import NeoChat.Component 1.0
|
||||||
|
import NeoChat.Dialog 1.0
|
||||||
|
import NeoChat.Page 1.0
|
||||||
|
import NeoChat.Panel 1.0
|
||||||
|
|
||||||
|
Labs.MenuBar {
|
||||||
|
Labs.Menu {
|
||||||
|
title: i18nc("menu", "NeoChat")
|
||||||
|
|
||||||
|
// TODO: make about page its own thing so we can go to it instead of settings where it's currently at
|
||||||
|
// Labs.MenuItem {
|
||||||
|
// text: i18nc("menu", "About NeoChat")
|
||||||
|
// }
|
||||||
|
Labs.MenuItem {
|
||||||
|
enabled: pageStack.layers.currentItem.title !== i18n("Settings")
|
||||||
|
text: i18nc("menu", "Preferences…")
|
||||||
|
|
||||||
|
shortcut: StandardKey.Preferences
|
||||||
|
onTriggered: pushReplaceLayer("qrc:/imports/NeoChat/Page/SettingsPage.qml")
|
||||||
|
}
|
||||||
|
Labs.MenuItem {
|
||||||
|
text: i18nc("menu", "Quit NeoChat")
|
||||||
|
|
||||||
|
shortcut: StandardKey.Quit
|
||||||
|
onTriggered: Qt.quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Labs.Menu {
|
||||||
|
title: i18nc("menu", "File")
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
text: i18nc("menu", "New Private Chat…")
|
||||||
|
enabled: pageStack.layers.currentItem.title !== i18n("Start a Chat") && Controller.accountCount > 0
|
||||||
|
onTriggered: pushReplaceLayer("qrc:/imports/NeoChat/Page/StartChatPage.qml", {"connection": Controller.activeConnection})
|
||||||
|
}
|
||||||
|
Labs.MenuItem {
|
||||||
|
text: i18nc("menu", "New Group…")
|
||||||
|
enabled: pageStack.layers.currentItem.title !== i18n("Start a Chat") && Controller.accountCount > 0
|
||||||
|
shortcut: StandardKey.New
|
||||||
|
onTriggered: {
|
||||||
|
const dialog = createRoomDialog.createObject(root.overlay)
|
||||||
|
dialog.open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Labs.MenuItem {
|
||||||
|
text: i18nc("menu", "Browse Chats…")
|
||||||
|
onTriggered: pushReplaceLayer("qrc:/imports/NeoChat/Page/JoinRoomPage.qml", {"connection": Controller.activeConnection})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EditMenu {
|
||||||
|
title: i18nc("menu", "Edit")
|
||||||
|
field: (root.activeFocusItem instanceof TextEdit || root.activeFocusItem instanceof TextInput) ? root.activeFocusItem : null
|
||||||
|
}
|
||||||
|
Labs.Menu {
|
||||||
|
title: i18nc("menu", "View")
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
text: i18nc("menu item that opens a UI element called the 'Quick Switcher', which offers a fast keyboard-based interface for switching in between chats.", "Open Quick Switcher")
|
||||||
|
shortcut: "Ctrl+K"
|
||||||
|
onTriggered: quickView.item.open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Labs.Menu {
|
||||||
|
title: i18nc("menu", "Window")
|
||||||
|
|
||||||
|
// Labs.MenuItem {
|
||||||
|
// text: settings.userWantsSidebars ? i18nc("menu", "Hide Sidebar") : i18nc("menu", "Show Sidebar")
|
||||||
|
// onTriggered: settings.userWantsSidebars = !settings.userWantsSidebars
|
||||||
|
// }
|
||||||
|
Labs.MenuItem {
|
||||||
|
text: root.visibility === Window.FullScreen ? i18nc("menu", "Exit Full Screen") : i18nc("menu", "Enter Full Screen")
|
||||||
|
onTriggered: root.visibility === Window.FullScreen ? root.showNormal() : root.showFullScreen()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: offline help system (https://invent.kde.org/network/neochat/-/issues/411)
|
||||||
|
Labs.Menu {
|
||||||
|
title: i18nc("menu", "Help")
|
||||||
|
|
||||||
|
Labs.MenuItem {
|
||||||
|
text: i18nc("menu", "Matrix FAQ")
|
||||||
|
onTriggered: Qt.openUrlExternally("https://matrix.org/faq/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
module NeoChat.Menu
|
module NeoChat.Menu
|
||||||
RoomListContextMenu 1.0 RoomListContextMenu.qml
|
RoomListContextMenu 1.0 RoomListContextMenu.qml
|
||||||
|
GlobalMenu 1.0 GlobalMenu.qml
|
||||||
|
EditMenu 1.0 EditMenu.qml
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ Kirigami.ApplicationWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loader {
|
||||||
|
active: !Kirigami.Settings.isMobile
|
||||||
|
source: Qt.resolvedUrl("qrc:/imports/NeoChat/Menu/GlobalMenu.qml")
|
||||||
|
}
|
||||||
|
|
||||||
// This timer allows to batch update the window size change to reduce
|
// This timer allows to batch update the window size change to reduce
|
||||||
// the io load and also work around the fact that x/y/width/height are
|
// the io load and also work around the fact that x/y/width/height are
|
||||||
// changed when loading the page and overwrite the saved geometry from
|
// changed when loading the page and overwrite the saved geometry from
|
||||||
|
|||||||
2
res.qrc
2
res.qrc
@@ -62,6 +62,8 @@
|
|||||||
<file>imports/NeoChat/Dialog/EmojiDialog.qml</file>
|
<file>imports/NeoChat/Dialog/EmojiDialog.qml</file>
|
||||||
<file>imports/NeoChat/Dialog/OpenFileDialog.qml</file>
|
<file>imports/NeoChat/Dialog/OpenFileDialog.qml</file>
|
||||||
<file>imports/NeoChat/Menu/qmldir</file>
|
<file>imports/NeoChat/Menu/qmldir</file>
|
||||||
|
<file>imports/NeoChat/Menu/GlobalMenu.qml</file>
|
||||||
|
<file>imports/NeoChat/Menu/EditMenu.qml</file>
|
||||||
<file>imports/NeoChat/Menu/Timeline/qmldir</file>
|
<file>imports/NeoChat/Menu/Timeline/qmldir</file>
|
||||||
<file>imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml</file>
|
<file>imports/NeoChat/Menu/Timeline/MessageDelegateContextMenu.qml</file>
|
||||||
<file>imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml</file>
|
<file>imports/NeoChat/Menu/Timeline/FileDelegateContextMenu.qml</file>
|
||||||
|
|||||||
Reference in New Issue
Block a user