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

Using Command + Backspace as the shortcut to delete torrents on macOS #20668

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 8 additions & 1 deletion src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,12 +851,19 @@ void MainWindow::createKeyboardShortcuts()
{
m_ui->actionCreateTorrent->setShortcut(QKeySequence::New);
m_ui->actionOpen->setShortcut(QKeySequence::Open);
m_ui->actionDelete->setShortcut(QKeySequence::Delete);
m_ui->actionDelete->setShortcut(
#ifdef Q_OS_MACOS
Qt::CTRL | Qt::Key_Backspace
#else
QKeySequence::Delete
#endif
);
m_ui->actionDelete->setShortcutContext(Qt::WidgetShortcut); // nullify its effect: delete key event is handled by respective widgets, not here
m_ui->actionDownloadFromURL->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_O);
m_ui->actionExit->setShortcut(Qt::CTRL | Qt::Key_Q);
#ifdef Q_OS_MACOS
m_ui->actionCloseWindow->setShortcut(QKeySequence::Close);
m_ui->actionDelete->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Backspace));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant cast:

Suggested change
m_ui->actionDelete->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Backspace));
m_ui->actionDelete->setShortcut(Qt::CTRL | Qt::Key_Backspace);

Also shouldn't you use QAction::setShortcuts? otherwise you'll override line 854.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this code style be approved? Or should it be called separately?

m_ui->actionDelete->setShortcut(
    #ifdef Q_OS_MACOS
        Qt::CTRL | Qt::Key_Backspace
    #else
        QKeySequence::Delete
    #endif
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this code style be approved?

I wouldn't use it if there are other ways. Besides that code is still overriding QKeySequence::Delete. Qt::CTRL | Qt::Key_Backspace should be additional to QKeySequence::Delete. They are not mutually exclusive.

Would the following work? Are you able to confirm it?

Suggested change
m_ui->actionDelete->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Backspace));
m_ui->actionDelete->setShortcuts(Qt::CTRL | Qt::Key_Backspace);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setShortcuts(Qt::CTRL | Qt::Key_Backspace) works. Following your suggestion, I pushed a new commit.

#else
m_ui->actionCloseWindow->setVisible(false);
#endif
Expand Down
Loading