Commit c2809a2c authored by Calvin Buckley's avatar Calvin Buckley 🤔 Committed by Albert Astals Cid
Browse files

Reinstall Mac dock menu if the current window dies

If the top-level window that last installed the dock died, then the
dock menu would be last. When a window dies, it should pass the torch
to another window that's still active.
parent bd658445
......@@ -110,9 +110,34 @@ QCGTopLevel::QCGTopLevel()
QCGTopLevel::~QCGTopLevel()
{
#ifdef Q_OS_MAC
// hacky way to reinstall the dock, since each toplevel has a dock menu,
// we don't do any global menu stuff on mac beyond what qt gives us, and
// when the last window that installed the dock menu dies, it goes away.
// reinstall it into another window if we can.
auto windowList = QApplication::topLevelWidgets();
for (int i = 0; i < windowList.size(); i++) {
QWidget *topLevelRaw = windowList[i];
if (QCGTopLevel *topLevel = qobject_cast<QCGTopLevel*>(topLevelRaw)) {
if (topLevel != this) {
topLevel->reinstallMacDock();
break;
}
}
}
#endif
delete _data;
}
void QCGTopLevel::reinstallMacDock()
{
#ifdef Q_OS_MAC
if (macDockMenu != nullptr) {
this->macDockMenu->setAsDockMenu();
}
#endif
}
// reset the visualization state, e.g. before loading new data
void QCGTopLevel::resetState()
{
......@@ -649,7 +674,7 @@ void QCGTopLevel::createMenu()
connect(this->macDockMenu, &QMenu::aboutToShow, this, &QCGTopLevel::macDockMenuAboutToShow);
// it can reuse the same events, it just needs a diff menu structure
connect(this->macDockMenu, &QMenu::triggered, this, &QCGTopLevel::windowListTriggered);
this->macDockMenu->setAsDockMenu();
reinstallMacDock();
#endif
QMenu* helpMenu = mBar->addMenu(tr("&Help"));
......
......@@ -141,6 +141,7 @@ public Q_SLOTS:
void windowListAboutToShow();
void macDockMenuAboutToShow();
void insertWindowList(QMenu*);
void reinstallMacDock();
bool setEventType(EventType*);
bool setEventType2(EventType*);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment