Resolves: tdf#133780 allow sorting search result treeview columns
Change-Id: I7d5b1ffdaf99fd2e28dfd124db0fbbd4036e2dd6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95896
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx
index 76cffa4..8032a79 100644
--- a/sc/source/ui/dialogs/searchresults.cxx
+++ b/sc/source/ui/dialogs/searchresults.cxx
@@ -24,6 +24,7 @@ SearchResultsDlg::SearchResultsDlg(SfxBindings* _pBindings, weld::Window* pParen
, aSkipped(ScResId(SCSTR_SKIPPED))
, mpBindings(_pBindings)
, mpDoc(nullptr)
, mbSorted(false)
, mxList(m_xBuilder->weld_tree_view("results"))
, mxSearchResults(m_xBuilder->weld_label("lbSearchResults"))
, mxShowDialog(m_xBuilder->weld_check_button("cbShow"))
@@ -35,6 +36,7 @@ SearchResultsDlg::SearchResultsDlg(SfxBindings* _pBindings, weld::Window* pParen
aWidths.push_back(mxList->get_approximate_digit_width() * 10);
mxList->set_column_fixed_widths(aWidths);
mxList->connect_changed(LINK(this, SearchResultsDlg, ListSelectHdl));
mxList->connect_column_clicked(LINK(this, SearchResultsDlg, HeaderBarClick));
}
SearchResultsDlg::~SearchResultsDlg()
@@ -161,6 +163,35 @@ void SearchResultsDlg::Close()
SfxDialogController::Close();
}
IMPL_LINK(SearchResultsDlg, HeaderBarClick, int, nColumn, void)
{
if (!mbSorted)
{
mxList->make_sorted();
mbSorted = true;
}
bool bSortAtoZ = mxList->get_sort_order();
//set new arrow positions in headerbar
if (nColumn == mxList->get_sort_column())
{
bSortAtoZ = !bSortAtoZ;
mxList->set_sort_order(bSortAtoZ);
}
else
{
mxList->set_sort_indicator(TRISTATE_INDET, mxList->get_sort_column());
mxList->set_sort_column(nColumn);
}
if (nColumn != -1)
{
//sort lists
mxList->set_sort_indicator(bSortAtoZ ? TRISTATE_TRUE : TRISTATE_FALSE, nColumn);
}
}
IMPL_LINK_NOARG( SearchResultsDlg, ListSelectHdl, weld::TreeView&, void )
{
if (!mpDoc)
diff --git a/sc/source/ui/inc/searchresults.hxx b/sc/source/ui/inc/searchresults.hxx
index de48e1c..cf48fb23 100644
--- a/sc/source/ui/inc/searchresults.hxx
+++ b/sc/source/ui/inc/searchresults.hxx
@@ -24,11 +24,13 @@ class SearchResultsDlg : public SfxDialogController
OUString aSkipped;
SfxBindings* mpBindings;
ScDocument* mpDoc;
bool mbSorted;
std::unique_ptr<weld::TreeView> mxList;
std::unique_ptr<weld::Label> mxSearchResults;
std::unique_ptr<weld::CheckButton> mxShowDialog;
DECL_LINK(ListSelectHdl, weld::TreeView&, void);
DECL_LINK(HeaderBarClick, int, void);
DECL_STATIC_LINK(SearchResultsDlg, OnShowToggled, weld::ToggleButton&, void);
public:
SearchResultsDlg(SfxBindings* _pBindings, weld::Window* pParent);
diff --git a/sc/uiconfig/scalc/ui/searchresults.ui b/sc/uiconfig/scalc/ui/searchresults.ui
index cb8fbaf..ca56a99 100644
--- a/sc/uiconfig/scalc/ui/searchresults.ui
+++ b/sc/uiconfig/scalc/ui/searchresults.ui
@@ -100,6 +100,7 @@
<property name="resizable">True</property>
<property name="spacing">6</property>
<property name="title" translatable="yes" context="searchresults|sheet">Sheet</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderer1"/>
<attributes>
@@ -113,6 +114,7 @@
<property name="resizable">True</property>
<property name="spacing">6</property>
<property name="title" translatable="yes" context="searchresults|cell">Cell</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderer2"/>
<attributes>
@@ -126,6 +128,7 @@
<property name="resizable">True</property>
<property name="spacing">6</property>
<property name="title" translatable="yes" context="searchresults|content">Content</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderer3"/>
<attributes>