@@ -261,21 +261,13 @@ void BitcoinGUI::createActions()
261261 sendCoinsAction->setShortcut (QKeySequence (Qt::ALT + Qt::Key_2));
262262 tabGroup->addAction (sendCoinsAction);
263263
264- sendCoinsMenuAction = new QAction (sendCoinsAction->text (), this );
265- sendCoinsMenuAction->setStatusTip (sendCoinsAction->statusTip ());
266- sendCoinsMenuAction->setToolTip (sendCoinsMenuAction->statusTip ());
267-
268264 receiveCoinsAction = new QAction (platformStyle->SingleColorIcon (" :/icons/receiving_addresses" ), tr (" &Receive" ), this );
269265 receiveCoinsAction->setStatusTip (tr (" Request payments (generates QR codes and bitcoin: URIs)" ));
270266 receiveCoinsAction->setToolTip (receiveCoinsAction->statusTip ());
271267 receiveCoinsAction->setCheckable (true );
272268 receiveCoinsAction->setShortcut (QKeySequence (Qt::ALT + Qt::Key_3));
273269 tabGroup->addAction (receiveCoinsAction);
274270
275- receiveCoinsMenuAction = new QAction (receiveCoinsAction->text (), this );
276- receiveCoinsMenuAction->setStatusTip (receiveCoinsAction->statusTip ());
277- receiveCoinsMenuAction->setToolTip (receiveCoinsMenuAction->statusTip ());
278-
279271 historyAction = new QAction (platformStyle->SingleColorIcon (" :/icons/history" ), tr (" &Transactions" ), this );
280272 historyAction->setStatusTip (tr (" Browse transaction history" ));
281273 historyAction->setToolTip (historyAction->statusTip ());
@@ -290,12 +282,8 @@ void BitcoinGUI::createActions()
290282 connect (overviewAction, &QAction::triggered, this , &BitcoinGUI::gotoOverviewPage);
291283 connect (sendCoinsAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
292284 connect (sendCoinsAction, &QAction::triggered, [this ]{ gotoSendCoinsPage (); });
293- connect (sendCoinsMenuAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
294- connect (sendCoinsMenuAction, &QAction::triggered, [this ]{ gotoSendCoinsPage (); });
295285 connect (receiveCoinsAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
296286 connect (receiveCoinsAction, &QAction::triggered, this , &BitcoinGUI::gotoReceiveCoinsPage);
297- connect (receiveCoinsMenuAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
298- connect (receiveCoinsMenuAction, &QAction::triggered, this , &BitcoinGUI::gotoReceiveCoinsPage);
299287 connect (historyAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
300288 connect (historyAction, &QAction::triggered, this , &BitcoinGUI::gotoHistoryPage);
301289#endif // ENABLE_WALLET
@@ -315,8 +303,6 @@ void BitcoinGUI::createActions()
315303 optionsAction->setStatusTip (tr (" Modify configuration options for %1" ).arg (PACKAGE_NAME));
316304 optionsAction->setMenuRole (QAction::PreferencesRole);
317305 optionsAction->setEnabled (false );
318- toggleHideAction = new QAction (tr (" &Show / Hide" ), this );
319- toggleHideAction->setStatusTip (tr (" Show or hide the main Window" ));
320306
321307 encryptWalletAction = new QAction (tr (" &Encrypt Wallet…" ), this );
322308 encryptWalletAction->setStatusTip (tr (" Encrypt the private keys that belong to your wallet" ));
@@ -376,7 +362,6 @@ void BitcoinGUI::createActions()
376362 connect (aboutAction, &QAction::triggered, this , &BitcoinGUI::aboutClicked);
377363 connect (aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
378364 connect (optionsAction, &QAction::triggered, this , &BitcoinGUI::optionsClicked);
379- connect (toggleHideAction, &QAction::triggered, this , &BitcoinGUI::toggleHidden);
380365 connect (showHelpMessageAction, &QAction::triggered, this , &BitcoinGUI::showHelpMessageClicked);
381366 connect (openRPCConsoleAction, &QAction::triggered, this , &BitcoinGUI::showDebugWindow);
382367 // prevents an open debug window from becoming stuck/unusable on client shutdown
@@ -627,8 +612,6 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
627612 trayIcon->setVisible (optionsModel->getShowTrayIcon ());
628613 }
629614 } else {
630- // Disable possibility to show main window via action
631- toggleHideAction->setEnabled (false );
632615 if (trayIconMenu)
633616 {
634617 // Disable context menu on tray icon
@@ -752,9 +735,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
752735{
753736 overviewAction->setEnabled (enabled);
754737 sendCoinsAction->setEnabled (enabled);
755- sendCoinsMenuAction->setEnabled (enabled);
756738 receiveCoinsAction->setEnabled (enabled);
757- receiveCoinsMenuAction->setEnabled (enabled);
758739 historyAction->setEnabled (enabled);
759740 encryptWalletAction->setEnabled (enabled);
760741 backupWalletAction->setEnabled (enabled);
@@ -784,57 +765,82 @@ void BitcoinGUI::createTrayIcon()
784765void BitcoinGUI::createTrayIconMenu ()
785766{
786767#ifndef Q_OS_MAC
787- // return if trayIcon is unset (only on non-macOSes)
788- if (!trayIcon)
789- return ;
790-
791- trayIcon->setContextMenu (trayIconMenu.get ());
792- connect (trayIcon, &QSystemTrayIcon::activated, this , &BitcoinGUI::trayIconActivated);
793- #else
794- // Note: On macOS, the Dock icon is used to provide the tray's functionality.
795- MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance ();
796- connect (dockIconHandler, &MacDockIconHandler::dockIconClicked, this , &BitcoinGUI::macosDockIconActivated);
797- trayIconMenu->setAsDockMenu ();
798- #endif
768+ if (!trayIcon) return ;
769+ #endif // Q_OS_MAC
799770
800- // Configuration of the tray icon (or Dock icon) menu
771+ // Configuration of the tray icon (or Dock icon) menu.
772+ QAction* show_hide_action{nullptr };
801773#ifndef Q_OS_MAC
802774 // Note: On macOS, the Dock icon's menu already has Show / Hide action.
803- trayIconMenu->addAction (toggleHideAction );
775+ show_hide_action = trayIconMenu->addAction (QString (), this , &BitcoinGUI::toggleHidden );
804776 trayIconMenu->addSeparator ();
805- #endif
777+ #endif // Q_OS_MAC
778+
779+ QAction* send_action{nullptr };
780+ QAction* receive_action{nullptr };
781+ QAction* sign_action{nullptr };
782+ QAction* verify_action{nullptr };
806783 if (enableWallet) {
807- trayIconMenu->addAction (sendCoinsMenuAction );
808- trayIconMenu->addAction (receiveCoinsMenuAction );
784+ send_action = trayIconMenu->addAction (sendCoinsAction-> text (), sendCoinsAction, &QAction::trigger );
785+ receive_action = trayIconMenu->addAction (receiveCoinsAction-> text (), receiveCoinsAction, &QAction::trigger );
809786 trayIconMenu->addSeparator ();
810- trayIconMenu->addAction (signMessageAction);
811- trayIconMenu->addAction (verifyMessageAction);
787+ sign_action = trayIconMenu->addAction (signMessageAction-> text (), signMessageAction, &QAction::trigger );
788+ verify_action = trayIconMenu->addAction (verifyMessageAction-> text (), verifyMessageAction, &QAction::trigger );
812789 trayIconMenu->addSeparator ();
813790 }
814- trayIconMenu->addAction (optionsAction);
815- trayIconMenu->addAction (openRPCConsoleAction);
816- #ifndef Q_OS_MAC // This is built-in on macOS
791+ QAction* options_action = trayIconMenu->addAction (optionsAction->text (), optionsAction, &QAction::trigger);
792+ options_action->setMenuRole (QAction::PreferencesRole);
793+ QAction* node_window_action = trayIconMenu->addAction (openRPCConsoleAction->text (), openRPCConsoleAction, &QAction::trigger);
794+ QAction* quit_action{nullptr };
795+ #ifndef Q_OS_MAC
796+ // Note: On macOS, the Dock icon's menu already has Quit action.
817797 trayIconMenu->addSeparator ();
818- trayIconMenu->addAction (quitAction);
819- #endif
820- }
798+ quit_action = trayIconMenu->addAction (quitAction->text (), quitAction, &QAction::trigger);
821799
822- #ifndef Q_OS_MAC
823- void BitcoinGUI::trayIconActivated (QSystemTrayIcon::ActivationReason reason)
824- {
825- if (reason == QSystemTrayIcon::Trigger)
826- {
827- // Click on system tray icon triggers show/hide of the main window
828- toggleHidden ();
829- }
830- }
800+ trayIcon->setContextMenu (trayIconMenu.get ());
801+ connect (trayIcon, &QSystemTrayIcon::activated, [this ](QSystemTrayIcon::ActivationReason reason) {
802+ if (reason == QSystemTrayIcon::Trigger) {
803+ // Click on system tray icon triggers show/hide of the main window
804+ toggleHidden ();
805+ }
806+ });
831807#else
832- void BitcoinGUI::macosDockIconActivated ()
833- {
834- show ();
835- activateWindow ();
808+ // Note: On macOS, the Dock icon is used to provide the tray's functionality.
809+ MacDockIconHandler* dockIconHandler = MacDockIconHandler::instance ();
810+ connect (dockIconHandler, &MacDockIconHandler::dockIconClicked, [this ] {
811+ show ();
812+ activateWindow ();
813+ });
814+ trayIconMenu->setAsDockMenu ();
815+ #endif // Q_OS_MAC
816+
817+ connect (
818+ // Using QSystemTrayIcon::Context is not reliable.
819+ // See https://bugreports.qt.io/browse/QTBUG-91697
820+ trayIconMenu.get (), &QMenu::aboutToShow,
821+ [this , show_hide_action, send_action, receive_action, sign_action, verify_action, options_action, node_window_action, quit_action] {
822+ if (show_hide_action) show_hide_action->setText (
823+ (!isHidden () && !isMinimized () && !GUIUtil::isObscured (this )) ?
824+ tr (" &Hide" ) :
825+ tr (" S&how" ));
826+ if (QApplication::activeModalWidget ()) {
827+ for (QAction* a : trayIconMenu.get ()->actions ()) {
828+ a->setEnabled (false );
829+ }
830+ } else {
831+ if (show_hide_action) show_hide_action->setEnabled (true );
832+ if (enableWallet) {
833+ send_action->setEnabled (sendCoinsAction->isEnabled ());
834+ receive_action->setEnabled (receiveCoinsAction->isEnabled ());
835+ sign_action->setEnabled (signMessageAction->isEnabled ());
836+ verify_action->setEnabled (verifyMessageAction->isEnabled ());
837+ }
838+ options_action->setEnabled (optionsAction->isEnabled ());
839+ node_window_action->setEnabled (openRPCConsoleAction->isEnabled ());
840+ if (quit_action) quit_action->setEnabled (true );
841+ }
842+ });
836843}
837- #endif
838844
839845void BitcoinGUI::optionsClicked ()
840846{
@@ -847,7 +853,7 @@ void BitcoinGUI::aboutClicked()
847853 return ;
848854
849855 auto dlg = new HelpMessageDialog (this , /* about */ true );
850- GUIUtil::ShowModalDialogAndDeleteOnClose (dlg);
856+ GUIUtil::ShowModalDialogAsynchronously (dlg);
851857}
852858
853859void BitcoinGUI::showDebugWindow ()
@@ -992,7 +998,7 @@ void BitcoinGUI::openOptionsDialogWithTab(OptionsDialog::Tab tab)
992998 connect (dlg, &OptionsDialog::quitOnReset, this , &BitcoinGUI::quitRequested);
993999 dlg->setCurrentTab (tab);
9941000 dlg->setModel (clientModel->getOptionsModel ());
995- GUIUtil::ShowModalDialogAndDeleteOnClose (dlg);
1001+ GUIUtil::ShowModalDialogAsynchronously (dlg);
9961002}
9971003
9981004void BitcoinGUI::setNumBlocks (int count, const QDateTime& blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state)
0 commit comments