From 89ffec202ee7a21c1f9b1d5deebfceb7357de5cc Mon Sep 17 00:00:00 2001 From: Jim Raykowski Date: Wed, 12 Nov 2025 22:45:33 -0900 Subject: [PATCH] related tdf#162580: copy query text from sidebar Find deck to F&R dialog Makes the query text in the Find&Replace dialog find entry become that of the sidebar Find deck find entry when keyboard focus is in the Find deck find entry and Ctrl+H (or any accelerator assigned to .uno:SearchDialog) is pressed or the F&R button in the Find deck is pressed. Normally these actions make the F&R dialog open or close. Here the F&R dialog is never closed. It either opens the F&R dialog and copies the find text to it or copies the find text to the already open F&R dialog. Reasoning for this behavior: F&R dialog is open. Find deck search finds nothing. Ctrl+H or F&R toolbar button in the Find deck is pressed to upgrade the search using options in the F&R dialog. Without this patch the open F&R dialog closes when Ctrl+H or the F&R button is pressed. Likely what is expected is the F&R dialog remains open and the text in the F&R dialog find entry becomes that of the sidebar Find deck find entry, which is what this patch does. Change-Id: Ic01cbbe6881469349a0756f3837428324f27d5b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193945 Tested-by: Jenkins Reviewed-by: Jim Raykowski --- sw/source/uibase/sidebar/QuickFindPanel.cxx | 62 +++++++++++++++------ sw/source/uibase/sidebar/QuickFindPanel.hxx | 16 ++++-- sw/source/uibase/sidebar/SwPanelFactory.cxx | 2 +- sw/uiconfig/swriter/ui/sidebarquickfind.ui | 12 +++- 4 files changed, 70 insertions(+), 22 deletions(-) diff --git a/sw/source/uibase/sidebar/QuickFindPanel.cxx b/sw/source/uibase/sidebar/QuickFindPanel.cxx index 702c961e77b6..05d29c92ae1c 100644 --- a/sw/source/uibase/sidebar/QuickFindPanel.cxx +++ b/sw/source/uibase/sidebar/QuickFindPanel.cxx @@ -27,6 +27,9 @@ #include #include +#include +#include + const int CharactersBeforeAndAfter = 40; namespace @@ -97,7 +100,8 @@ IMPL_LINK_NOARG(QuickFindPanel::SearchOptionsDialog, SimilaritySettingsDialogBut std::unique_ptr QuickFindPanel::Create(weld::Widget* pParent, - const css::uno::Reference& rxFrame) + const css::uno::Reference& rxFrame, + SfxBindings* pBindings) { if (pParent == nullptr) throw lang::IllegalArgumentException("no parent Window given to QuickFindPanel::Create", @@ -105,20 +109,23 @@ QuickFindPanel::Create(weld::Widget* pParent, if (!rxFrame.is()) throw lang::IllegalArgumentException("no XFrame given to QuickFindPanel::Create", nullptr, 0); - return std::make_unique(pParent, rxFrame); + return std::make_unique(pParent, rxFrame, pBindings); } -QuickFindPanel::QuickFindPanel(weld::Widget* pParent, const uno::Reference& rxFrame) +QuickFindPanel::QuickFindPanel(weld::Widget* pParent, const uno::Reference& rxFrame, + SfxBindings* pBindings) : PanelLayout(pParent, u"QuickFindPanel"_ustr, u"modules/swriter/ui/sidebarquickfind.ui"_ustr) , m_xSearchFindEntry(m_xBuilder->weld_entry(u"Find"_ustr)) , m_xSearchOptionsToolbar(m_xBuilder->weld_toolbar(u"searchoptionstoolbar"_ustr)) , m_xFindAndReplaceToolbar(m_xBuilder->weld_toolbar(u"findandreplacetoolbar"_ustr)) - , m_xFindAndReplaceToolbarDispatch( - new ToolbarUnoDispatcher(*m_xFindAndReplaceToolbar, *m_xBuilder, rxFrame)) , m_xSearchFindsList(m_xBuilder->weld_tree_view(u"searchfinds"_ustr)) , m_xSearchFindFoundTimesLabel(m_xBuilder->weld_label("numberofsearchfinds")) , m_pWrtShell(::GetActiveWrtShell()) + , m_xAcceleratorExecute(svt::AcceleratorExecute::createAcceleratorHelper()) + , m_pBindings(pBindings) { + m_xAcceleratorExecute->init(comphelper::getProcessComponentContext(), rxFrame); + m_nMinimumPanelWidth = m_xBuilder->weld_widget(u"box"_ustr)->get_preferred_size().getWidth() + (6 * 2) + 6; m_xContainer->set_size_request(m_nMinimumPanelWidth, 1); @@ -127,6 +134,8 @@ QuickFindPanel::QuickFindPanel(weld::Widget* pParent, const uno::Referenceconnect_activate( LINK(this, QuickFindPanel, SearchFindEntryActivateHandler)); m_xSearchFindEntry->connect_changed(LINK(this, QuickFindPanel, SearchFindEntryChangedHandler)); + m_xSearchFindEntry->connect_key_press( + LINK(this, QuickFindPanel, SearchFindEntryKeyInputHandler)); m_xSearchOptionsToolbar->connect_clicked( LINK(this, QuickFindPanel, SearchOptionsToolbarClickedHandler)); @@ -181,25 +190,46 @@ IMPL_LINK_NOARG(QuickFindPanel, SearchOptionsToolbarClickedHandler, const OUStri // tdf#162580 related: When upgrading from Find toolbar search to advanced Find and Replace // search dialog, inherit (pre-fill) search field's term from current value of find bar's // focused search entry + +bool QuickFindPanel::UpgradeSearchToSearchDialog() +{ + m_pWrtShell->AssureStdMode(); + SvxSearchDialog* pSearchDialog = SwView::GetSearchDialog(); + if (!pSearchDialog) + { + m_pBindings->ExecuteSynchron(SID_SEARCH_DLG); + pSearchDialog = SwView::GetSearchDialog(); + } + if (pSearchDialog) + { + pSearchDialog->SetSearchLabel(EMPTY_OUSTRING); + pSearchDialog->SetSearchLBEntryTextAndGrabFocus(m_xSearchFindEntry->get_text()); + pSearchDialog->Present(); + return true; + } + return false; +} + IMPL_LINK(QuickFindPanel, FindAndReplaceToolbarClickedHandler, const OUString&, rCommand, void) { - if (!SwView::GetSearchDialog()) - { - SvxSearchItem* pSearchItem = SwView::GetSearchItem(); - if (!pSearchItem) - { - pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM); - SwView::SetSearchItem(pSearchItem); - } - pSearchItem->SetSearchString(m_xSearchFindEntry->get_text()); - } - m_xFindAndReplaceToolbarDispatch->Select(rCommand); + if (rCommand == "searchdialog") + UpgradeSearchToSearchDialog(); +} + +IMPL_LINK(QuickFindPanel, SearchFindEntryKeyInputHandler, const KeyEvent&, rKeyEvent, bool) +{ + const OUString aCommand(m_xAcceleratorExecute->findCommand( + svt::AcceleratorExecute::st_VCLKey2AWTKey(rKeyEvent.GetKeyCode()))); + if (aCommand == ".uno:SearchDialog") + return UpgradeSearchToSearchDialog(); + return false; } QuickFindPanel::~QuickFindPanel() { m_xSearchFindEntry.reset(); m_xSearchFindsList.reset(); + m_xAcceleratorExecute.reset(); } IMPL_LINK_NOARG(QuickFindPanel, SearchFindEntryFocusInHandler, weld::Widget&, void) diff --git a/sw/source/uibase/sidebar/QuickFindPanel.hxx b/sw/source/uibase/sidebar/QuickFindPanel.hxx index ac17e8567ef6..a5c109f090f7 100644 --- a/sw/source/uibase/sidebar/QuickFindPanel.hxx +++ b/sw/source/uibase/sidebar/QuickFindPanel.hxx @@ -12,7 +12,9 @@ #include #include #include -#include + +#include +#include namespace sw::sidebar { @@ -45,9 +47,11 @@ class QuickFindPanel : public PanelLayout public: static std::unique_ptr Create(weld::Widget* pParent, - const uno::Reference& rxFrame); + const uno::Reference& rxFrame, + SfxBindings* pBindings); - QuickFindPanel(weld::Widget* pParent, const uno::Reference& rxFrame); + QuickFindPanel(weld::Widget* pParent, const uno::Reference& rxFrame, + SfxBindings* pBindings); virtual ~QuickFindPanel() override; private: @@ -56,11 +60,13 @@ private: std::unique_ptr m_xSearchFindEntry; std::unique_ptr m_xSearchOptionsToolbar; std::unique_ptr m_xFindAndReplaceToolbar; - std::unique_ptr m_xFindAndReplaceToolbarDispatch; std::unique_ptr m_xSearchFindsList; std::unique_ptr m_xSearchFindFoundTimesLabel; SwWrtShell* m_pWrtShell; + std::unique_ptr m_xAcceleratorExecute; + + SfxBindings* m_pBindings; int m_nMinimumPanelWidth; @@ -75,6 +81,7 @@ private: DECL_LINK(SearchFindEntryFocusInHandler, weld::Widget&, void); DECL_LINK(SearchFindEntryActivateHandler, weld::Entry&, bool); DECL_LINK(SearchFindEntryChangedHandler, weld::Entry&, void); + DECL_LINK(SearchFindEntryKeyInputHandler, const KeyEvent&, bool); DECL_LINK(SearchFindsListCustomGetSizeHandler, weld::TreeView::get_size_args, Size); DECL_LINK(SearchFindsListRender, weld::TreeView::render_args, void); DECL_LINK(SearchFindsListSelectionChangedHandler, weld::TreeView&, void); @@ -84,6 +91,7 @@ private: DECL_LINK(FindAndReplaceToolbarClickedHandler, const OUString&, void); void FillSearchFindsList(); + bool UpgradeSearchToSearchDialog(); }; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/SwPanelFactory.cxx b/sw/source/uibase/sidebar/SwPanelFactory.cxx index cb8c8248bf3f..93873b05014a 100644 --- a/sw/source/uibase/sidebar/SwPanelFactory.cxx +++ b/sw/source/uibase/sidebar/SwPanelFactory.cxx @@ -220,7 +220,7 @@ Reference SAL_CALL SwPanelFactory::createUIElement ( else if (rsResourceURL.endsWith("/QuickFindPanel")) { std::unique_ptr xPanel - = sw::sidebar::QuickFindPanel::Create(pParent, xFrame); + = sw::sidebar::QuickFindPanel::Create(pParent, xFrame, pBindings); xElement = sfx2::sidebar::SidebarPanelBase::Create(rsResourceURL, xFrame, std::move(xPanel), ui::LayoutSize(-1, -1, -1)); } diff --git a/sw/uiconfig/swriter/ui/sidebarquickfind.ui b/sw/uiconfig/swriter/ui/sidebarquickfind.ui index e8eaa19033fe..97951d741afc 100644 --- a/sw/uiconfig/swriter/ui/sidebarquickfind.ui +++ b/sw/uiconfig/swriter/ui/sidebarquickfind.ui @@ -54,6 +54,7 @@ True + False Search Options sw/res/sr20006.png @@ -82,8 +83,17 @@ icons False - + True + False + Search with Find and Replace + cmd/sc_searchdialog.png + + + Search with Find and Replace + Click here to transfer the search to the Find and Replace dialog to set more search options. + + False