include/sfx2/devtools/ObjectInspectorTreeHandler.hxx | 8 ++++ sfx2/source/devtools/ObjectInspectorTreeHandler.cxx | 31 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-)
New commits: commit 66d8951df3c11ead0b9415eb292c3ae88689edf1 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu May 19 00:33:37 2022 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Fri May 20 06:19:16 2022 +0200 sfx2: use natural string sort for sorting in object inspector Use a natural string sort for all strings in the object inspector tree view. This is more useful for properties as those can have indices, which are shown as numbers, so having them in natural order makes the tree view easier to digest. Change-Id: I7d036cd755f6595fa302c7a28a005684897f2963 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134541 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx b/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx index 03188276a4b4..b6fa678de366 100644 --- a/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx +++ b/include/sfx2/devtools/ObjectInspectorTreeHandler.hxx @@ -12,6 +12,7 @@ #include <vcl/weld.hxx> #include <vcl/commandevent.hxx> +#include <comphelper/string.hxx> #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/XInterface.hpp> @@ -40,6 +41,13 @@ private: // just the current context css::uno::Reference<css::uno::XComponentContext> mxContext; + // treeview sort and compare + comphelper::string::NaturalStringSorter mxSorter; + void setSortFunction(std::unique_ptr<weld::TreeView>& pTreeView); + sal_Int32 compare(std::unique_ptr<weld::TreeView>& pTreeView, const weld::TreeIter& rLeft, + const weld::TreeIter& rRight); + + // treeview manipulation static void clearObjectInspectorChildren(std::unique_ptr<weld::TreeView>& pTreeView, weld::TreeIter const& rParent); static void handleExpanding(std::unique_ptr<weld::TreeView>& pTreeView, diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx index 79b69d612b79..18c4206e0730 100644 --- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx +++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx @@ -44,6 +44,9 @@ #include <comphelper/processfactory.hxx> #include <comphelper/extract.hxx> +#include <vcl/settings.hxx> +#include <i18nlangtag/languagetag.hxx> + using namespace css; namespace @@ -928,6 +931,7 @@ ObjectInspectorTreeHandler::ObjectInspectorTreeHandler( std::unique_ptr<ObjectInspectorWidgets>& pObjectInspectorWidgets) : mpObjectInspectorWidgets(pObjectInspectorWidgets) , mxContext(comphelper::getProcessComponentContext()) + , mxSorter(mxContext, Application::GetSettings().GetLanguageTag().getLocale()) { mpObjectInspectorWidgets->mpInterfacesTreeView->connect_expanding( LINK(this, ObjectInspectorTreeHandler, ExpandingHandlerInterfaces)); @@ -955,6 +959,11 @@ ObjectInspectorTreeHandler::ObjectInspectorTreeHandler( mpObjectInspectorWidgets->mpPropertiesTreeView->make_sorted(); mpObjectInspectorWidgets->mpMethodsTreeView->make_sorted(); + setSortFunction(mpObjectInspectorWidgets->mpInterfacesTreeView); + setSortFunction(mpObjectInspectorWidgets->mpServicesTreeView); + setSortFunction(mpObjectInspectorWidgets->mpPropertiesTreeView); + setSortFunction(mpObjectInspectorWidgets->mpMethodsTreeView); + mpObjectInspectorWidgets->mpInterfacesTreeView->connect_column_clicked( LINK(this, ObjectInspectorTreeHandler, HeaderBarClick)); mpObjectInspectorWidgets->mpServicesTreeView->connect_column_clicked( @@ -987,7 +996,27 @@ ObjectInspectorTreeHandler::ObjectInspectorTreeHandler( static_cast<int>(nMethodsDigitWidth * 50) }; mpObjectInspectorWidgets->mpMethodsTreeView->set_column_fixed_widths(aMethodsWidths); - pObjectInspectorWidgets->mpPaned->set_position(160); + mpObjectInspectorWidgets->mpPaned->set_position(160); +} + +void ObjectInspectorTreeHandler::setSortFunction(std::unique_ptr<weld::TreeView>& pTreeView) +{ + pTreeView->set_sort_func( + [this, &pTreeView](const weld::TreeIter& rLeft, const weld::TreeIter& rRight) { + return compare(pTreeView, rLeft, rRight); + }); +} + +sal_Int32 ObjectInspectorTreeHandler::compare(std::unique_ptr<weld::TreeView>& pTreeView, + const weld::TreeIter& rLeft, + const weld::TreeIter& rRight) +{ + int nSortColumn = pTreeView->get_sort_column(); + + OUString sLeft = pTreeView->get_text(rLeft, nSortColumn); + OUString sRight = pTreeView->get_text(rRight, nSortColumn); + sal_Int32 nCompare = mxSorter.compare(sLeft, sRight); + return nCompare; } void ObjectInspectorTreeHandler::handleExpanding(std::unique_ptr<weld::TreeView>& pTreeView,