@@ -261,21 +261,13 @@ void BitcoinGUI::createActions()
261
261
sendCoinsAction->setShortcut (QKeySequence (Qt::ALT + Qt::Key_2));
262
262
tabGroup->addAction (sendCoinsAction);
263
263
264
- sendCoinsMenuAction = new QAction (sendCoinsAction->text (), this );
265
- sendCoinsMenuAction->setStatusTip (sendCoinsAction->statusTip ());
266
- sendCoinsMenuAction->setToolTip (sendCoinsMenuAction->statusTip ());
267
-
268
264
receiveCoinsAction = new QAction (platformStyle->SingleColorIcon (" :/icons/receiving_addresses" ), tr (" &Receive" ), this );
269
265
receiveCoinsAction->setStatusTip (tr (" Request payments (generates QR codes and bitcoin: URIs)" ));
270
266
receiveCoinsAction->setToolTip (receiveCoinsAction->statusTip ());
271
267
receiveCoinsAction->setCheckable (true );
272
268
receiveCoinsAction->setShortcut (QKeySequence (Qt::ALT + Qt::Key_3));
273
269
tabGroup->addAction (receiveCoinsAction);
274
270
275
- receiveCoinsMenuAction = new QAction (receiveCoinsAction->text (), this );
276
- receiveCoinsMenuAction->setStatusTip (receiveCoinsAction->statusTip ());
277
- receiveCoinsMenuAction->setToolTip (receiveCoinsMenuAction->statusTip ());
278
-
279
271
historyAction = new QAction (platformStyle->SingleColorIcon (" :/icons/history" ), tr (" &Transactions" ), this );
280
272
historyAction->setStatusTip (tr (" Browse transaction history" ));
281
273
historyAction->setToolTip (historyAction->statusTip ());
@@ -290,12 +282,8 @@ void BitcoinGUI::createActions()
290
282
connect (overviewAction, &QAction::triggered, this , &BitcoinGUI::gotoOverviewPage);
291
283
connect (sendCoinsAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
292
284
connect (sendCoinsAction, &QAction::triggered, [this ]{ gotoSendCoinsPage (); });
293
- connect (sendCoinsMenuAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
294
- connect (sendCoinsMenuAction, &QAction::triggered, [this ]{ gotoSendCoinsPage (); });
295
285
connect (receiveCoinsAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
296
286
connect (receiveCoinsAction, &QAction::triggered, this , &BitcoinGUI::gotoReceiveCoinsPage);
297
- connect (receiveCoinsMenuAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
298
- connect (receiveCoinsMenuAction, &QAction::triggered, this , &BitcoinGUI::gotoReceiveCoinsPage);
299
287
connect (historyAction, &QAction::triggered, [this ]{ showNormalIfMinimized (); });
300
288
connect (historyAction, &QAction::triggered, this , &BitcoinGUI::gotoHistoryPage);
301
289
#endif // ENABLE_WALLET
@@ -315,8 +303,6 @@ void BitcoinGUI::createActions()
315
303
optionsAction->setStatusTip (tr (" Modify configuration options for %1" ).arg (PACKAGE_NAME));
316
304
optionsAction->setMenuRole (QAction::PreferencesRole);
317
305
optionsAction->setEnabled (false );
318
- toggleHideAction = new QAction (tr (" &Show / Hide" ), this );
319
- toggleHideAction->setStatusTip (tr (" Show or hide the main Window" ));
320
306
321
307
encryptWalletAction = new QAction (tr (" &Encrypt Wallet…" ), this );
322
308
encryptWalletAction->setStatusTip (tr (" Encrypt the private keys that belong to your wallet" ));
@@ -376,7 +362,6 @@ void BitcoinGUI::createActions()
376
362
connect (aboutAction, &QAction::triggered, this , &BitcoinGUI::aboutClicked);
377
363
connect (aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
378
364
connect (optionsAction, &QAction::triggered, this , &BitcoinGUI::optionsClicked);
379
- connect (toggleHideAction, &QAction::triggered, this , &BitcoinGUI::toggleHidden);
380
365
connect (showHelpMessageAction, &QAction::triggered, this , &BitcoinGUI::showHelpMessageClicked);
381
366
connect (openRPCConsoleAction, &QAction::triggered, this , &BitcoinGUI::showDebugWindow);
382
367
// prevents an open debug window from becoming stuck/unusable on client shutdown
@@ -627,8 +612,6 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
627
612
trayIcon->setVisible (optionsModel->getShowTrayIcon ());
628
613
}
629
614
} else {
630
- // Disable possibility to show main window via action
631
- toggleHideAction->setEnabled (false );
632
615
if (trayIconMenu)
633
616
{
634
617
// Disable context menu on tray icon
@@ -752,9 +735,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
752
735
{
753
736
overviewAction->setEnabled (enabled);
754
737
sendCoinsAction->setEnabled (enabled);
755
- sendCoinsMenuAction->setEnabled (enabled);
756
738
receiveCoinsAction->setEnabled (enabled);
757
- receiveCoinsMenuAction->setEnabled (enabled);
758
739
historyAction->setEnabled (enabled);
759
740
encryptWalletAction->setEnabled (enabled);
760
741
backupWalletAction->setEnabled (enabled);
@@ -784,57 +765,82 @@ void BitcoinGUI::createTrayIcon()
784
765
void BitcoinGUI::createTrayIconMenu ()
785
766
{
786
767
#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
799
770
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 };
801
773
#ifndef Q_OS_MAC
802
774
// 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 );
804
776
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 };
806
783
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 );
809
786
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 );
812
789
trayIconMenu->addSeparator ();
813
790
}
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.
817
797
trayIconMenu->addSeparator ();
818
- trayIconMenu->addAction (quitAction);
819
- #endif
820
- }
798
+ quit_action = trayIconMenu->addAction (quitAction->text (), quitAction, &QAction::trigger);
821
799
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
+ });
831
807
#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
+ });
836
843
}
837
- #endif
838
844
839
845
void BitcoinGUI::optionsClicked ()
840
846
{
@@ -847,7 +853,7 @@ void BitcoinGUI::aboutClicked()
847
853
return ;
848
854
849
855
auto dlg = new HelpMessageDialog (this , /* about */ true );
850
- GUIUtil::ShowModalDialogAndDeleteOnClose (dlg);
856
+ GUIUtil::ShowModalDialogAsynchronously (dlg);
851
857
}
852
858
853
859
void BitcoinGUI::showDebugWindow ()
@@ -992,7 +998,7 @@ void BitcoinGUI::openOptionsDialogWithTab(OptionsDialog::Tab tab)
992
998
connect (dlg, &OptionsDialog::quitOnReset, this , &BitcoinGUI::quitRequested);
993
999
dlg->setCurrentTab (tab);
994
1000
dlg->setModel (clientModel->getOptionsModel ());
995
- GUIUtil::ShowModalDialogAndDeleteOnClose (dlg);
1001
+ GUIUtil::ShowModalDialogAsynchronously (dlg);
996
1002
}
997
1003
998
1004
void BitcoinGUI::setNumBlocks (int count, const QDateTime& blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state)
0 commit comments