diff --git a/src/plugin/ollieplugin.cpp b/src/plugin/ollieplugin.cpp index 76d358e..52db469 100644 --- a/src/plugin/ollieplugin.cpp +++ b/src/plugin/ollieplugin.cpp @@ -408,6 +408,23 @@ QList OllieView::collectActions() const return entries; } +void OllieView::positionPalette(PaletteWidget *palette, bool fullWidth) +{ + QWidget *w = m_mainWindow->window(); + if (!w) { + return; + } + const int margin = 12; + const int y = w->height() / 6; + if (fullWidth) { + palette->resize(w->width() - 2 * margin, 320); + palette->move(w->mapToGlobal(QPoint(margin, y))); + } else { + const QSize sz = palette->size(); + palette->move(w->mapToGlobal(QPoint((w->width() - sz.width()) / 2, y))); + } +} + void OllieView::showCommandPalette() { if (!m_palette) { @@ -465,13 +482,8 @@ void OllieView::showCommandPalette() m_palette->setItems(items); - // Center the palette near the top of the active window. - if (QWidget *w = m_mainWindow->window()) { - const QSize sz = m_palette->size(); - const QPoint topLeft = w->mapToGlobal(QPoint((w->width() - sz.width()) / 2, - w->height() / 6)); - m_palette->move(topLeft); - } + // The command palette keeps its compact centered width. + positionPalette(m_palette, /*fullWidth=*/false); m_palette->activate(); } @@ -600,12 +612,7 @@ void OllieView::showFileSwitcher() m_filePalette->setItems({loading}); } - if (QWidget *w = m_mainWindow->window()) { - const QSize sz = m_filePalette->size(); - const QPoint topLeft = w->mapToGlobal(QPoint((w->width() - sz.width()) / 2, - w->height() / 6)); - m_filePalette->move(topLeft); - } + positionPalette(m_filePalette, /*fullWidth=*/true); m_filePalette->activate(); // Kick off (or serve from cache) the index; filesReady repopulates. @@ -700,12 +707,7 @@ void OllieView::showSymbolSwitcher() m_symbolPalette->setItems({loading}); } - if (QWidget *w = m_mainWindow->window()) { - const QSize sz = m_symbolPalette->size(); - const QPoint topLeft = w->mapToGlobal(QPoint((w->width() - sz.width()) / 2, - w->height() / 6)); - m_symbolPalette->move(topLeft); - } + positionPalette(m_symbolPalette, /*fullWidth=*/true); m_symbolPalette->activate(); m_indexer.requestSymbols(m_symbolSwitcherRoot); diff --git a/src/plugin/ollieplugin.h b/src/plugin/ollieplugin.h index e7258c8..9d31486 100644 --- a/src/plugin/ollieplugin.h +++ b/src/plugin/ollieplugin.h @@ -85,6 +85,11 @@ private: // async-arrival paths). Root is used to project-qualify the frecency key. QList buildFileItems(const QString &root, const QStringList &files) const; QList buildSymbolItems(const QString &root, const QList &symbols) const; + + // Size and place a palette near the top of the active window. When + // \a fullWidth, it spans the window width (minus a small margin); otherwise + // it keeps its own width and is horizontally centered. + void positionPalette(PaletteWidget *palette, bool fullWidth); // One harvested, runnable action with the provenance needed to build a // unique id and to disambiguate labels shared by several commands. struct ActionEntry {