diff --git a/sublime/container.h b/sublime/container.h --- a/sublime/container.h +++ b/sublime/container.h @@ -111,6 +111,9 @@ Sublime::View* currentView() const; struct ContainerPrivate * const d; + +protected: + void focusInEvent(QFocusEvent*) override; }; } diff --git a/sublime/container.cpp b/sublime/container.cpp --- a/sublime/container.cpp +++ b/sublime/container.cpp @@ -133,6 +133,11 @@ return lhs->document()->title().compare(rhs->document()->title(), Qt::CaseInsensitive) < 0; } +#ifdef Q_OS_MACOS +// only one of these per process: +static QMenu* currentDockMenu = nullptr; +#endif + struct ContainerPrivate { QBoxLayout* layout; QHash viewForWidget; @@ -197,6 +202,28 @@ ///FIXME: push this code somehow into shell, such that we can access the project model for /// icons and also get a neat, short path like the document switcher. } + + setAsDockMenu(); + } + + void setAsDockMenu() + { +#ifdef Q_OS_MACOS + if (documentListMenu != currentDockMenu) { + documentListMenu->setAsDockMenu(); + currentDockMenu = documentListMenu; + } +#endif + } + + ~ContainerPrivate() + { +#ifdef Q_OS_MACOS + if (documentListMenu == currentDockMenu) { + QMenu().setAsDockMenu(); + currentDockMenu = nullptr; + } +#endif } }; @@ -284,6 +311,10 @@ d->documentListButton = new QToolButton(this); d->documentListButton->setIcon(QIcon::fromTheme(QStringLiteral("format-list-unordered"))); d->documentListButton->setMenu(d->documentListMenu); +#ifdef Q_OS_MACOS + // for maintaining the Dock menu: + setFocusPolicy(Qt::StrongFocus); +#endif d->documentListButton->setPopupMode(QToolButton::InstantPopup); d->documentListButton->setAutoRaise(true); d->documentListButton->setToolTip(i18n("Show sorted list of opened documents")); @@ -685,6 +716,12 @@ return d->viewForWidget.value(widget( d->tabBar->currentIndex() )); } +void Container::focusInEvent(QFocusEvent* event) +{ + d->setAsDockMenu(); + QWidget::focusInEvent(event); +} + } #include "container.moc"