Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin work on adding editable shortcuts #1568

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@ set(SRC_FILES
src/ui/RoomSettings.cpp
src/ui/RoomSettings.h
src/ui/RoomSummary.cpp
src/ui/RoomSummary.h
src/ui/RoomSummary.h
src/ui/KeySequenceRegistry.cpp
src/ui/KeySequenceRegistry.h
src/ui/Theme.cpp
src/ui/Theme.h
src/ui/UIA.cpp
Expand Down Expand Up @@ -777,6 +779,7 @@ set(QML_SOURCES
resources/qml/dialogs/RoomMembers.qml
resources/qml/dialogs/AllowedRoomsSettingsDialog.qml
resources/qml/dialogs/RoomSettings.qml
resources/qml/dialogs/ShortcutEditor.qml
resources/qml/dialogs/UserProfile.qml
resources/qml/emoji/StickerPicker.qml
resources/qml/pages/LoginPage.qml
Expand Down Expand Up @@ -810,7 +813,7 @@ qt_add_qml_module(nheko
${QML_SOURCES}
SOURCES
src/UserDirectoryModel.cpp
src/UserDirectoryModel.h
src/UserDirectoryModel.h
)
#qt_target_qml_sources(nheko
# #PREFIX "/"
Expand Down
94 changes: 89 additions & 5 deletions resources/qml/Root.qml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ Pane {

onActivated: Qt.quit()
}

EditableKeySequence {
id: quickSwitcherShortcut

name: qsTr("Room search")
defaultKeySequence: "Ctrl+K"
}
Shortcut {
sequence: "Ctrl+K"
sequence: quickSwitcherShortcut.keySequence

onActivated: {
var component = Qt.createComponent("qrc:/resources/qml/QuickSwitcher.qml");
Expand All @@ -125,22 +132,99 @@ Pane {
}
}
}
Shortcut {

EditableKeySequence {
id: nextRoomWithActivityShortcut

name: qsTr("Next room with activity")
// Add alternative shortcut, because sometimes Alt+A is stolen by the TextEdit
sequences: ["Alt+A", "Ctrl+Shift+A"]
defaultKeySequences: ["Alt+A", "Ctrl+Shift+A"]
}
Shortcut {
sequences: nextRoomWithActivityShortcut.keySequence

onActivated: Rooms.nextRoomWithActivity()
}

EditableKeySequence {
id: nextRoomShortcut

name: qsTr("Next room")
defaultKeySequence: "Ctrl+Down"
}
Shortcut {
sequence: "Ctrl+Down"
sequence: nextRoomShortcut.keySequence

onActivated: Rooms.nextRoom()
}

EditableKeySequence {
id: previousRoomShortcut

name: qsTr("Previous room")
defaultKeySequence: "Ctrl+Up"
}
Shortcut {
sequence: "Ctrl+Up"
sequence: previousRoomShortcut.keySequence

onActivated: Rooms.previousRoom()
}

EditableKeySequence {
id: nextSpaceShortcut

name: qsTr("Next space")
}
Shortcut {
sequence: nextSpaceShortcut.keySequence

// onActivated: Communities.setCurrentTagId(model.id)
}

EditableKeySequence {
id: previousSpaceShortcut

name: qsTr("Previous space")
}
Shortcut {
sequence: previousSpaceShortcut.keySequence

// onActivated: Communities.setCurrentTagId(model.id)
}

EditableKeySequence {
id: allRoomsSpaceShortcut

name: qsTr("Show all rooms")
}
Shortcut {
sequence: allRoomsSpaceShortcut.keySequence

onActivated: Communities.setCurrentTagId("global")
}

EditableKeySequence {
id: favoriteRoomsShortcut

name: qsTr("Show favorite rooms")
}
Shortcut {
sequence: favoriteRoomsShortcut.keySequence

onActivated: Communities.setCurrentTagId("m.favourite")
}

EditableKeySequence {
id: directChatsShortcut

name: qsTr("Show direct chats")
}
Shortcut {
sequence: directChatsShortcut.keySequence

onActivated: Communities.setCurrentTagId("dm")
}

Connections {
function onOpenJoinRoomDialog() {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/JoinRoomDialog.qml");
Expand Down
1 change: 1 addition & 0 deletions resources/qml/TopBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ Pane {

onActivated: searchButton.searchActive = !searchButton.searchActive
}

TapHandler {
gesturePolicy: TapHandler.ReleaseWithinBounds

Expand Down
2 changes: 1 addition & 1 deletion resources/qml/dialogs/ImageOverlay.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Window {
Component.onCompleted: Nheko.setWindowRole(imageOverlay, "imageoverlay")

Shortcut {
sequences: [StandardKey.Cancel]
sequence: StandardKey.Cancel
onActivated: imageOverlay.close()
}

Expand Down
83 changes: 83 additions & 0 deletions resources/qml/dialogs/ShortcutEditor.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

import ".."
import "../ui"
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window
import im.nheko

ApplicationWindow {
id: shortcutEditorDialog

minimumWidth: 500
minimumHeight: 450
width: 500
height: 680
color: palette.window
modality: Qt.NonModal
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
title: qsTr("Keyboard shortcuts")

ScrollView {
padding: Nheko.paddingMedium
ScrollBar.horizontal.visible: false
anchors.fill: parent

ListView {
model: KeySequenceRegistry

delegate: RowLayout {
id: del

required property string name
required property string keySequence

spacing: Nheko.paddingMedium
width: ListView.view.width
height: implicitHeight + Nheko.paddingSmall * 2

Label {
text: del.name
}

Item { Layout.fillWidth: true }

Button {
property bool selectingNewKeySequence: false

text: selectingNewKeySequence ? qsTr("Input..") : (del.keySequence === "" ? "None" : del.keySequence)
onClicked: selectingNewKeySequence = !selectingNewKeySequence
Keys.onPressed: event => {
if (!selectingNewKeySequence)
return;
event.accepted = true;

let keySequence = "";
if (event.modifiers & Qt.ControlModifier)
keySequence += "Ctrl+";
if (event.modifiers & Qt.AltModifier)
keySequence += "Alt+";
if (event.modifiers & Qt.MetaModifier)
keySequence += "Meta+";
if (event.modifiers & Qt.ShiftModifier)
keySequence += "Shift+";

if (event.key === 0 || event.key === Qt.Key_unknown || event.key === Qt.Key_Control || event.key === Qt.Key_Alt ||
event.key === Qt.Key_AltGr || event.key === Qt.Key_Meta || event.key === Qt.Key_Super_L || event.key === Qt.Key_Super_R ||
event.key === Qt.Key_Shift)
keySequence += "...";
else {
keySequence += KeySequenceRegistry.keycodeToChar(event.key);
KeySequenceRegistry.changeKeySequence(del.name, keySequence);
selectingNewKeySequence = false;
}
}
}
}
}
}
}
18 changes: 18 additions & 0 deletions resources/qml/pages/UserSettingsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
pragma ComponentBehavior: Bound
import ".."
import "../ui"
import "../dialogs"
import Qt.labs.platform 1.1 as Platform
import QtQuick 2.15
import QtQuick.Controls 2.15
Expand Down Expand Up @@ -215,6 +216,23 @@ Rectangle {
}
}
}
DelegateChoice {
roleValue: UserSettingsModel.ConfigureKeyboardShortcuts
Button {
text: qsTr("CONFIGURE")
onClicked: {
var dialog = keyboardShortcutsDialog.createObject();
dialog.show();
destroyOnClose(dialog);
}

Component {
id: keyboardShortcutsDialog

ShortcutEditor {}
}
}
}
DelegateChoice {
Text {
text: model.value
Expand Down
1 change: 1 addition & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QSharedPointer>
#include <QSystemTrayIcon>

#include "KeySequenceRegistry.h"
#include "UserSettingsPage.h"
#include "dock/Dock.h"

Expand Down
30 changes: 27 additions & 3 deletions src/UserSettingsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ QSharedPointer<UserSettings> UserSettings::instance_;

UserSettings::UserSettings()
{
connect(
QCoreApplication::instance(), &QCoreApplication::aboutToQuit, []() { instance_.clear(); });
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, []() {
instance_->save();
instance_.clear();
});
}

QSharedPointer<UserSettings>
Expand Down Expand Up @@ -164,6 +166,16 @@ UserSettings::load(std::optional<QString> profile)
disableCertificateValidation_ =
settings.value(QStringLiteral("disable_certificate_validation"), false).toBool();

settings.beginGroup(QStringLiteral("user"));
settings.beginGroup(QStringLiteral("shortcuts"));
QMap<QString, QStringList> bindings;
for (const auto &key : settings.childKeys())
bindings[key] = settings.value(key).toStringList();
qDebug() << "restoring with size:" << bindings.size();
KeySequenceRegistry::instance()->restoreBindings(bindings);
settings.endGroup(); // user/shortcuts
settings.endGroup(); // user/shortcuts

applyTheme();
}

Expand Down Expand Up @@ -882,7 +894,7 @@ UserSettings::save()
settings.beginGroup(QStringLiteral("sidebar"));
settings.setValue(QStringLiteral("community_list_width"), communityListWidth_);
settings.setValue(QStringLiteral("room_list_width"), roomListWidth_);
settings.endGroup(); // window
settings.endGroup(); // sidebar

settings.beginGroup(QStringLiteral("timeline"));
settings.setValue(QStringLiteral("buttons"), buttonsInTimeline_);
Expand Down Expand Up @@ -939,6 +951,13 @@ UserSettings::save()
settings.setValue(QStringLiteral("space_background_maintenance"), updateSpaceVias_);
settings.setValue(QStringLiteral("expired_events_background_maintenance"), expireEvents_);

settings.beginGroup(QStringLiteral("shortcuts"));
auto bindings = KeySequenceRegistry::instance()->dumpBindings();
for (const auto &[name, sequences] : bindings.asKeyValueRange())
settings.setValue(name, sequences);
qDebug() << "saved with size:" << bindings.size();
settings.endGroup(); // shortcuts

settings.endGroup(); // user

QString prefix = (profile_ != QLatin1String("") && profile_ != QLatin1String("default"))
Expand Down Expand Up @@ -1145,6 +1164,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
return tr("Periodically update community routing information");
case ExpireEvents:
return tr("Periodically delete expired events");
case KeyboardShortcuts:
return tr("Configure keyboard shortcuts");
}
} else if (role == Value) {
switch (index.row()) {
Expand Down Expand Up @@ -1444,6 +1465,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
case LoginInfoSection:
case SessionKeys:
case CrossSigningSecrets:
case KeyboardShortcuts:
return {};
case OnlineBackupKey:
return tr(
Expand Down Expand Up @@ -1562,6 +1584,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
case UserSigningKey:
case MasterKey:
return KeyStatus;
case KeyboardShortcuts:
return ConfigureKeyboardShortcuts;
}
} else if (role == ValueLowerBound) {
switch (index.row()) {
Expand Down
2 changes: 2 additions & 0 deletions src/UserSettingsPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ class UserSettingsModel : public QAbstractListModel
#endif
UpdateSpaceVias,
ExpireEvents,
KeyboardShortcuts,

AccessibilitySection,
ReducedMotion,
Expand Down Expand Up @@ -562,6 +563,7 @@ class UserSettingsModel : public QAbstractListModel
KeyStatus,
SessionKeyImportExport,
XSignKeysRequestDownload,
ConfigureKeyboardShortcuts,
};
Q_ENUM(Types);

Expand Down
Loading