Skip to content

Commit

Permalink
qt: Add Window menu
Browse files Browse the repository at this point in the history
Summary:
Overall this PR does the following:

 - add top level menu Window
 - add Minimize and Zoom actions to Window menu
 - move Sending/Receiving address to Window
 - remove Help->Debug menu and add one menu entry for each debug window tab in the Window menu

The ellipsis in the name of `Sending/Receiving addresses` actions are be removed, according to common practices (https://stackoverflow.com/a/637708).
Ellipsis at the end of the name of menu actions suggest that user input is expected.

Backport of Core [[bitcoin/bitcoin#14573 | PR14573]] and [[bitcoin/bitcoin#16514 | PR16514]]

[[bitcoin/bitcoin#16514 | PR16514]] removes the `RPCConsole::tabFocus` method introduced in the first PR, but never used.

Test Plan:
`ninja && ninja check`

Run `src/qt/bitcoin-qt` and check that all menu actions work.

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, Fabien

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D7892
  • Loading branch information
promag authored and PiRK committed Oct 12, 2020
1 parent 631d110 commit 066a318
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
66 changes: 59 additions & 7 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <QToolBar>
#include <QUrlQuery>
#include <QVBoxLayout>
#include <QWindow>

const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
#if defined(Q_OS_MAC)
Expand Down Expand Up @@ -374,12 +375,12 @@ void BitcoinGUI::createActions() {

usedSendingAddressesAction =
new QAction(platformStyle->TextColorIcon(":/icons/address-book"),
tr("&Sending addresses..."), this);
tr("&Sending addresses"), this);
usedSendingAddressesAction->setStatusTip(
tr("Show the list of used sending addresses and labels"));
usedReceivingAddressesAction =
new QAction(platformStyle->TextColorIcon(":/icons/address-book"),
tr("&Receiving addresses..."), this);
tr("&Receiving addresses"), this);
usedReceivingAddressesAction->setStatusTip(
tr("Show the list of used receiving addresses and labels"));

Expand Down Expand Up @@ -525,9 +526,6 @@ void BitcoinGUI::createMenuBar() {
file->addAction(signMessageAction);
file->addAction(verifyMessageAction);
file->addSeparator();
file->addAction(usedSendingAddressesAction);
file->addAction(usedReceivingAddressesAction);
file->addSeparator();
}
file->addAction(quitAction);

Expand All @@ -539,10 +537,64 @@ void BitcoinGUI::createMenuBar() {
}
settings->addAction(optionsAction);

QMenu *help = appMenuBar->addMenu(tr("&Help"));
QMenu *window_menu = appMenuBar->addMenu(tr("&Window"));

QAction *minimize_action = window_menu->addAction(
tr("Minimize"), [] { qApp->focusWindow()->showMinimized(); },
QKeySequence(Qt::CTRL + Qt::Key_M));

connect(qApp, &QApplication::focusWindowChanged,
[minimize_action](QWindow *window) {
minimize_action->setEnabled(
window != nullptr &&
(window->flags() & Qt::Dialog) != Qt::Dialog &&
window->windowState() != Qt::WindowMinimized);
});

#ifdef Q_OS_MAC
QAction *zoom_action = window_menu->addAction(tr("Zoom"), [] {
QWindow *window = qApp->focusWindow();
if (window->windowState() != Qt::WindowMaximized) {
window->showMaximized();
} else {
window->showNormal();
}
});

connect(qApp, &QApplication::focusWindowChanged,
[zoom_action](QWindow *window) {
zoom_action->setEnabled(window != nullptr);
});
#else
QAction *restore_action = window_menu->addAction(
tr("Restore"), [] { qApp->focusWindow()->showNormal(); });

connect(qApp, &QApplication::focusWindowChanged,
[restore_action](QWindow *window) {
restore_action->setEnabled(window != nullptr);
});
#endif

if (walletFrame) {
help->addAction(openRPCConsoleAction);
window_menu->addSeparator();
window_menu->addAction(tr("Main Window"),
[this] { GUIUtil::bringToFront(this); });

window_menu->addSeparator();
window_menu->addAction(usedSendingAddressesAction);
window_menu->addAction(usedReceivingAddressesAction);
}

window_menu->addSeparator();
for (RPCConsole::TabTypes tab_type : rpcConsole->tabs()) {
window_menu->addAction(rpcConsole->tabTitle(tab_type),
[this, tab_type] {
rpcConsole->setTabFocus(tab_type);
showDebugWindow();
});
}

QMenu *help = appMenuBar->addMenu(tr("&Help"));
help->addAction(showHelpMessageAction);
help->addSeparator();
help->addAction(aboutAction);
Expand Down
4 changes: 4 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,3 +1449,7 @@ void RPCConsole::showOrHideBanTableIfRequired() {
void RPCConsole::setTabFocus(enum TabTypes tabType) {
ui->tabWidget->setCurrentIndex(tabType);
}

QString RPCConsole::tabTitle(TabTypes tab_type) const {
return ui->tabWidget->tabText(tab_type);
}
6 changes: 6 additions & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ class RPCConsole : public QWidget {
TAB_PEERS = 3
};

std::vector<TabTypes> tabs() const {
return {TAB_INFO, TAB_CONSOLE, TAB_GRAPH, TAB_PEERS};
}

QString tabTitle(TabTypes tab_type) const;

protected:
virtual bool eventFilter(QObject *obj, QEvent *event) override;
void keyPressEvent(QKeyEvent *) override;
Expand Down

0 comments on commit 066a318

Please sign in to comment.