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 <raykowj@gmail.com>
This commit is contained in:
Jim Raykowski
2025-11-17 11:45:54 +01:00
parent 9192f76400
commit 89ffec202e
4 changed files with 70 additions and 22 deletions
+46 -16
View File
@@ -27,6 +27,9 @@
#include <vcl/sysdata.hxx>
#include <swwait.hxx>
#include <svx/srchdlg.hxx>
#include <comphelper/processfactory.hxx>
const int CharactersBeforeAndAfter = 40;
namespace
@@ -97,7 +100,8 @@ IMPL_LINK_NOARG(QuickFindPanel::SearchOptionsDialog, SimilaritySettingsDialogBut
std::unique_ptr<PanelLayout>
QuickFindPanel::Create(weld::Widget* pParent,
const css::uno::Reference<css::frame::XFrame>& rxFrame)
const css::uno::Reference<css::frame::XFrame>& 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<QuickFindPanel>(pParent, rxFrame);
return std::make_unique<QuickFindPanel>(pParent, rxFrame, pBindings);
}
QuickFindPanel::QuickFindPanel(weld::Widget* pParent, const uno::Reference<frame::XFrame>& rxFrame)
QuickFindPanel::QuickFindPanel(weld::Widget* pParent, const uno::Reference<frame::XFrame>& 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::Reference<frame
m_xSearchFindEntry->connect_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)
+12 -4
View File
@@ -12,7 +12,9 @@
#include <sfx2/sidebar/PanelLayout.hxx>
#include <svx/svxdlg.hxx>
#include <wrtsh.hxx>
#include <sfx2/weldutils.hxx>
#include <sfx2/bindings.hxx>
#include <svtools/acceleratorexecute.hxx>
namespace sw::sidebar
{
@@ -45,9 +47,11 @@ class QuickFindPanel : public PanelLayout
public:
static std::unique_ptr<PanelLayout> Create(weld::Widget* pParent,
const uno::Reference<frame::XFrame>& rxFrame);
const uno::Reference<frame::XFrame>& rxFrame,
SfxBindings* pBindings);
QuickFindPanel(weld::Widget* pParent, const uno::Reference<frame::XFrame>& rxFrame);
QuickFindPanel(weld::Widget* pParent, const uno::Reference<frame::XFrame>& rxFrame,
SfxBindings* pBindings);
virtual ~QuickFindPanel() override;
private:
@@ -56,11 +60,13 @@ private:
std::unique_ptr<weld::Entry> m_xSearchFindEntry;
std::unique_ptr<weld::Toolbar> m_xSearchOptionsToolbar;
std::unique_ptr<weld::Toolbar> m_xFindAndReplaceToolbar;
std::unique_ptr<ToolbarUnoDispatcher> m_xFindAndReplaceToolbarDispatch;
std::unique_ptr<weld::TreeView> m_xSearchFindsList;
std::unique_ptr<weld::Label> m_xSearchFindFoundTimesLabel;
SwWrtShell* m_pWrtShell;
std::unique_ptr<svt::AcceleratorExecute> 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: */
+1 -1
View File
@@ -220,7 +220,7 @@ Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement (
else if (rsResourceURL.endsWith("/QuickFindPanel"))
{
std::unique_ptr<PanelLayout> 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));
}
+11 -1
View File
@@ -54,6 +54,7 @@
<child>
<object class="GtkToolButton" id="searchoptions">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes" context="quickfindpanel|moresearchoptions|tooltip_text">Search Options</property>
<property name="icon-name">sw/res/sr20006.png</property>
<child internal-child="accessible">
@@ -82,8 +83,17 @@
<property name="toolbar-style">icons</property>
<property name="show-arrow">False</property>
<child>
<object class="GtkToolButton" id=".uno:SearchDialog">
<object class="GtkToolButton" id="searchdialog">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes" context="quickfindpanel|searchdialog|tooltip_text">Search with Find and Replace</property>
<property name="icon-name">cmd/sc_searchdialog.png</property>
<child internal-child="accessible">
<object class="AtkObject" id="searchdialog-atkobject">
<property name="AtkObject::accessible-name" translatable="yes" context="quickfindpanel|searchdialog|accessible_name">Search with Find and Replace</property>
<property name="AtkObject::accessible-description" translatable="yes" context="quickfindpanel|extended_tip|searchdialog">Click here to transfer the search to the Find and Replace dialog to set more search options.</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>