From 3a7586907ed834fb3c09d47e047da305a25374a2 Mon Sep 17 00:00:00 2001 From: Ismael Asensio Date: Sun, 1 Sep 2019 21:59:43 +0200 Subject: [dolphin] Add an action to toggle the searchbar Summary: Make search action toggle the searchbar instead of just launching it. The search action in dolphin did only bring up the search bar, but to close it again you had to go to the closing button on the same searchbar. This behavior in inconsistent with other dolphin actions which toggle panels or tools. BEFORE: {F7256652} AFTER: {F7256862} BUG: 344617 FIXED-IN: 19.12.0 Closes T8473 Depends on D23075 Test Plan: - Enable the search mode: the searchbar appears and the toolbar button gets checked - Press the search button again, and it goes back to normal mode. - The search button state is coherent with the searchbox - Coherence is kept when changing to a split view or different tab - Shorcut does not close the searchbar, but moves the focus to it. Reviewers: #dolphin, ngraham, #vdg, elvisangelaccio Reviewed By: ngraham, #vdg Subscribers: ndavis, felixernst, elvisangelaccio, kfm-devel Tags: #dolphin Maniphest Tasks: T8473 Differential Revision: https://phabricator.kde.org/D23232 --- src/dolphinmainwindow.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index bdf5dbac5..9368a9028 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -617,6 +617,12 @@ void DolphinMainWindow::find() m_activeViewContainer->setSearchModeEnabled(true); } +void DolphinMainWindow::updateSearchAction() +{ + QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); + toggleSearchAction->setChecked(m_activeViewContainer->isSearchModeEnabled()); +} + void DolphinMainWindow::updatePasteAction() { QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); @@ -1084,6 +1090,9 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) m_activeViewContainer = viewContainer; if (oldViewContainer) { + const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); + toggleSearchAction->disconnect(oldViewContainer); + // Disconnect all signals between the old view container (container, // view and url navigator) and main window. oldViewContainer->disconnect(this); @@ -1104,6 +1113,7 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) updatePasteAction(); updateViewActions(); updateGoActions(); + updateSearchAction(); const QUrl url = viewContainer->url(); emit urlChanged(url); @@ -1225,6 +1235,17 @@ void DolphinMainWindow::setupActions() "the find bar so we can have a look at it while the settings are " "explained.")); + // toggle_search acts as a copy of the main searchAction to be used mainly + // in the toolbar, with no default shortcut attached, to avoid messing with + // existing workflows (search bar always open and Ctrl-F to focus) + QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search")); + toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar")); + toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search")); + toggleSearchAction->setIcon(searchAction->icon()); + toggleSearchAction->setToolTip(searchAction->toolTip()); + toggleSearchAction->setWhatsThis(searchAction->whatsThis()); + toggleSearchAction->setCheckable(true); + QAction* selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection()); selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", "This selects all " "files and folders in the current location.")); @@ -1803,6 +1824,11 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container) this, &DolphinMainWindow::updateFilterBarAction); connect(container, &DolphinViewContainer::writeStateChanged, this, &DolphinMainWindow::slotWriteStateChanged); + connect(container, &DolphinViewContainer::searchModeEnabledChanged, + this, &DolphinMainWindow::updateSearchAction); + + const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); + connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled); const DolphinView* view = container->view(); connect(view, &DolphinView::selectionChanged, -- cgit v1.3