Skip to content

Commit

Permalink
Allow overriding shortcut keys (#571)
Browse files Browse the repository at this point in the history
Closes #569. Adding a `[Shortcuts]` section in the ini file will override the default shortcuts. https://doc.qt.io/qt-6/qkeysequence.html#QKeySequence-1 is used to parse out the shortcut string. E.g.

[Shortcuts]
New=Ctrl+F1
  • Loading branch information
dail8859 committed Jun 14, 2024
1 parent d43e033 commit fd6040c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/NotepadNext/dialogs/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ MainWindow::MainWindow(NotepadNextApplication *app) :

ui->setupUi(this);

applyCustomShortcuts();

qInfo("setupUi Completed");

connect(this, &MainWindow::aboutToClose, this, &MainWindow::saveSettings);
Expand Down Expand Up @@ -794,6 +796,27 @@ MainWindow::~MainWindow()
delete ui;
}

void MainWindow::applyCustomShortcuts()
{
ApplicationSettings *settings = app->getSettings();

settings->beginGroup("Shortcuts");

for (const QString &actionName : settings->childKeys()) {
QAction *action = findChild<QAction *>(QStringLiteral("action") + actionName, Qt::FindDirectChildrenOnly);
const QString shortcutString = settings->value(actionName).toString();

if (action != Q_NULLPTR) {
action->setShortcut(QKeySequence(shortcutString));
}
else {
qWarning() << "Cannot find action" << actionName;
}
}

settings->endGroup();
}

void MainWindow::setupLanguageMenu()
{
qInfo(Q_FUNC_INFO);
Expand Down
1 change: 1 addition & 0 deletions src/NotepadNext/dialogs/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private slots:

QScopedPointer<SearchResultsCollector> searchResults;

void applyCustomShortcuts();
void initUpdateCheck();
ScintillaNext *getInitialEditor();
void openFileList(const QStringList &fileNames);
Expand Down

0 comments on commit fd6040c

Please sign in to comment.