Skip to content

Commit b51d03b

Browse files
committed
FancyMenu: clear search on hide and category switch
1 parent 146016a commit b51d03b

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

plugin-fancymenu/lxqtfancymenu.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ LXQtFancyMenu::LXQtFancyMenu(const ILXQtPanelPluginStartupInfo &startupInfo):
6262
mWindow = new LXQtFancyMenuWindow(&mButton);
6363
mWindow->setObjectName(QStringLiteral("TopLevelFancyMenu"));
6464
mWindow->installEventFilter(this);
65+
connect(mWindow, &LXQtFancyMenuWindow::aboutToHide, &mHideTimer, QOverload<>::of(&QTimer::start));
66+
connect(mWindow, &LXQtFancyMenuWindow::aboutToShow, &mHideTimer, &QTimer::stop);
6567
connect(mWindow, &LXQtFancyMenuWindow::favoritesChanged, this, &LXQtFancyMenu::saveFavorites);
6668

6769
mDelayedPopup.setSingleShot(true);
@@ -146,6 +148,8 @@ void LXQtFancyMenu::showMenu()
146148
// Just using Qt`s activateWindow() won't work on some WMs like Kwin.
147149
// Solution is to execute menu 1ms later using timer
148150
mWindow->move(calculatePopupWindowPos(mWindow->sizeHint()).topLeft());
151+
152+
emit mWindow->aboutToShow();
149153
mWindow->show();
150154
}
151155

@@ -196,6 +200,7 @@ void LXQtFancyMenu::settingsChanged()
196200

197201
//clear the search to not leaving the menu in wrong state
198202
mFilterClear = settings()->value(QStringLiteral("filterClear"), false).toBool();
203+
mWindow->setFilterClear(mFilterClear);
199204

200205
realign();
201206
}
@@ -207,6 +212,7 @@ void LXQtFancyMenu::buildMenu()
207212
{
208213
mWindow->rebuildMenu(mXdgMenu);
209214

215+
mWindow->doSearch();
210216
setMenuFontSize();
211217
}
212218

plugin-fancymenu/lxqtfancymenuwindow.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ void LXQtFancyMenuWindow::setCurrentCategory(int cat)
275275
mCategoryView->setCurrentIndex(idx);
276276
mCategoryView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
277277
mAppModel->setCurrentCategory(cat);
278-
mAppModel->endSearch();
278+
279+
// If user clicked elsewhere, reset search
280+
if(cat != LXQtFancyMenuAppMap::AllAppsCategory)
281+
setSearchQuery(QString());
279282
}
280283

281284
bool LXQtFancyMenuWindow::eventFilter(QObject *watched, QEvent *e)
@@ -319,6 +322,14 @@ void LXQtFancyMenuWindow::setSearchQuery(const QString &text)
319322
void LXQtFancyMenuWindow::hideEvent(QHideEvent *e)
320323
{
321324
emit aboutToHide();
325+
326+
if(mFilterClear)
327+
setSearchQuery(QString()); // Clear search on hide
328+
329+
// If search is not active, switch to Favorites
330+
if(mSearchEdit->text().isEmpty())
331+
setCurrentCategory(LXQtFancyMenuAppMap::FavoritesCategory);
332+
322333
QWidget::hideEvent(e);
323334
}
324335

@@ -369,6 +380,17 @@ void LXQtFancyMenuWindow::removeFromFavorites(const QString &desktopFile)
369380
emit favoritesChanged();
370381
}
371382

383+
void LXQtFancyMenuWindow::setFilterClear(bool newFilterClear)
384+
{
385+
mFilterClear = newFilterClear;
386+
387+
if(mFilterClear && !isVisible())
388+
{
389+
// Apply immediately
390+
setSearchQuery(QString());
391+
}
392+
}
393+
372394
QStringList LXQtFancyMenuWindow::favorites() const
373395
{
374396
return mFavorites;

plugin-fancymenu/lxqtfancymenuwindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class LXQtFancyMenuWindow : public QWidget
3333
QStringList favorites() const;
3434
void setFavorites(const QStringList &newFavorites);
3535

36+
void setFilterClear(bool newFilterClear);
37+
3638
signals:
3739
void aboutToShow();
3840
void aboutToHide();
@@ -76,6 +78,7 @@ private slots:
7678
LXQtFancyMenuCategoriesModel *mCategoryModel;
7779

7880
QTimer mSearchTimer;
81+
bool mFilterClear = false;
7982
};
8083

8184
#endif // LXQTFANCYMENUWINDOW_H

0 commit comments

Comments
 (0)