part of being a good developer involves thinking backwards from the users' and the reviewers' perspective for the ux and the code respectively. there's a really easy thing you can do to make commits less messy.
if you are refactoring a function i.e. creating a new function out of it's body, then you should place the new function "physically away" from the old function in the file. that way git diffs won't be messy. take the following diffs, both do the same thing with the difference being the physical location of the new function in the file.
diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx
index 39afd0963606..1e48e6e04afa 100644
--- a/sc/source/ui/cctrl/checklistmenu.cxx
+++ b/sc/source/ui/cctrl/checklistmenu.cxx
@@ -912,52 +912,12 @@ void ScCheckListMenuControl::MarkCheckedMembers()
IMPL_LINK_NOARG(ScCheckListMenuControl, LockCheckedHdl, weld::Toggleable&, void)
{
- bool bLockCheckedEntries = mxChkLockChecked->get_active();
MarkCheckedMembers();
+ UpdateVisibleMembers(false);
- if (mbHasDates)
- {
- // TODO: flesh this out
- }
- else
- {
- mpChecks->freeze();
- mpChecks->clear();
- mpChecks->thaw();
-
- OUString aSearchText = mxEdSearch->get_text();
- aSearchText = ScGlobal::getCharClass().lowercase(aSearchText);
- if (aSearchText.isEmpty())
- {
- /*
- * when we click on lock, all the checked entries are marked and
- * this `true` tells `initMembers` to check only the currently
- * checked entries.
- *
- * when lock is unchecked we want that the entries which were locked
- * and checked now become unlocked and checked so that we can select
- * or deselect more entries, still we want only the marked (selected)
- * entries to remain selected, thus this `true` is valid even in the
- * uncheck case.
- */
- initMembers(-1, true);
- }
- else
- {
- std::vector<int> aShownIndexes;
- loadSearchedMembers(aShownIndexes, maMembers, aSearchText, true);
- std::vector<int> aFixedWidths { mnCheckWidthReq };
-
- // insert the members, remember whether checked or unchecked.
- mpChecks->bulk_insert_for_each(aShownIndexes.size(), [this, &aShownIndexes, &bLockCheckedEntries](weld::TreeIter& rIter, int i) {
- size_t nIndex = aShownIndexes[i];
- insertMember(*mpChecks, rIter, maMembers[nIndex], maMembers[nIndex].mbMarked, bLockCheckedEntries);
- }, nullptr, &aFixedWidths);
- }
- }
-
- // unmarking should happen after the members are inserted
- if (!bLockCheckedEntries)
+ // unmarking should happen after the members are inserted or updated
+ // (in case there's a hierarchy, in which case we don't clear everything)
+ if (!mxChkLockChecked->get_active())
for (auto& aMember : maMembers)
aMember.mbMarked = false;
}
@@ -1119,6 +1079,54 @@ IMPL_LINK_NOARG(ScCheckListMenuControl, SearchEditTimeoutHdl, Timer*, void)
}
}
+void ScCheckListMenuControl::UpdateVisibleMembers(bool bSearchEditTimeout)
+{
+ // TODO: change it later based on the `SearchEditTimeoutHdl` code
+ bool bLockCheckedEntries = !bSearchEditTimeout && mxChkLockChecked->get_active();
+ OUString aSearchText = mxEdSearch->get_text();
+ aSearchText = ScGlobal::getCharClass().lowercase(aSearchText);
+
+ if (mbHasDates)
+ {
+ // TODO: flesh it out later
+ }
+ else
+ {
+ mpChecks->freeze();
+ mpChecks->clear();
+ mpChecks->thaw();
+
+ if (aSearchText.isEmpty())
+ {
+ /*
+ * when we click on lock, all the checked entries are marked and
+ * this `true` tells `initMembers` to check only the currently
+ * checked entries.
+ *
+ * when lock is unchecked we want that the entries which were locked
+ * and checked now become unlocked and checked so that we can select
+ * or deselect more entries, still we want only the marked (selected)
+ * entries to remain selected, thus this `true` is valid even in the
+ * uncheck case.
+ */
+ initMembers(-1, true);
+ }
+ else
+ {
+ std::vector<int> aShownIndexes;
+ loadSearchedMembers(aShownIndexes, maMembers, aSearchText, true);
+ std::vector<int> aFixedWidths { mnCheckWidthReq };
+
+ // insert the members, remember whether checked or unchecked.
+ mpChecks->bulk_insert_for_each(aShownIndexes.size(), [this, &aShownIndexes, &bLockCheckedEntries](weld::TreeIter& rIter, int i) {
+ size_t nIndex = aShownIndexes[i];
+ insertMember(*mpChecks, rIter, maMembers[nIndex], maMembers[nIndex].mbMarked, bLockCheckedEntries);
+ }, nullptr, &aFixedWidths);
+ }
+ }
+}
+
+
IMPL_LINK_NOARG(ScCheckListMenuControl, EdModifyHdl, weld::Entry&, void)
{
maSearchEditTimer.Start();diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx
index 39afd0963606..a38226336130 100644
--- a/sc/source/ui/cctrl/checklistmenu.cxx
+++ b/sc/source/ui/cctrl/checklistmenu.cxx
@@ -875,49 +875,16 @@ namespace
}
}
-void ScCheckListMenuControl::MarkCheckedMembers()
-{
- if (mbHasDates)
- {
- // TODO: flesh it out later
- }
- else
- {
- // go over the members visible in the popup, and remember which one is
- // checked, and which one is not by setting `mbMarked` to `true`; by default
- // `mbMarked` is `false`, we clear all the marks when lock is unchecked, see
- // at the end of this callback.
- mpChecks->all_foreach([this](weld::TreeIter& rEntry){
- if (mpChecks->get_toggle(rEntry) == TRISTATE_TRUE)
- {
- for (auto& aMember : maMembers)
- {
- if (aMember.maName == mpChecks->get_text(rEntry))
- {
- aMember.mbMarked = true;
- /*
- * if there are multiple entries with the same
- * name in the range, they all show up as a single
- * entry in the autofilter, so we can break
- */
- break;
- }
- }
- }
-
- return false;
- });
- }
-}
-
-IMPL_LINK_NOARG(ScCheckListMenuControl, LockCheckedHdl, weld::Toggleable&, void)
+void ScCheckListMenuControl::UpdateVisibleMembers(bool bSearchEditTimeout)
{
- bool bLockCheckedEntries = mxChkLockChecked->get_active();
- MarkCheckedMembers();
+ // TODO: change it later based on the `SearchEditTimeoutHdl` code
+ bool bLockCheckedEntries = !bSearchEditTimeout && mxChkLockChecked->get_active();
+ OUString aSearchText = mxEdSearch->get_text();
+ aSearchText = ScGlobal::getCharClass().lowercase(aSearchText);
if (mbHasDates)
{
- // TODO: flesh this out
+ // TODO: flesh it out later
}
else
{
@@ -925,8 +892,6 @@ IMPL_LINK_NOARG(ScCheckListMenuControl, LockCheckedHdl, weld::Toggleable&, void)
mpChecks->clear();
mpChecks->thaw();
- OUString aSearchText = mxEdSearch->get_text();
- aSearchText = ScGlobal::getCharClass().lowercase(aSearchText);
if (aSearchText.isEmpty())
{
/*
@@ -955,9 +920,51 @@ IMPL_LINK_NOARG(ScCheckListMenuControl, LockCheckedHdl, weld::Toggleable&, void)
}, nullptr, &aFixedWidths);
}
}
+}
+
+void ScCheckListMenuControl::MarkCheckedMembers()
+{
+ if (mbHasDates)
+ {
+ // TODO: flesh it out later
+ }
+ else
+ {
+ // go over the members visible in the popup, and remember which one is
+ // checked, and which one is not by setting `mbMarked` to `true`; by default
+ // `mbMarked` is `false`, we clear all the marks when lock is unchecked, see
+ // at the end of this callback.
+ mpChecks->all_foreach([this](weld::TreeIter& rEntry){
+ if (mpChecks->get_toggle(rEntry) == TRISTATE_TRUE)
+ {
+ for (auto& aMember : maMembers)
+ {
+ if (aMember.maName == mpChecks->get_text(rEntry))
+ {
+ aMember.mbMarked = true;
+ /*
+ * if there are multiple entries with the same
+ * name in the range, they all show up as a single
+ * entry in the autofilter, so we can break
+ */
+ break;
+ }
+ }
+ }
+
+ return false;
+ });
+ }
+}
+
+IMPL_LINK_NOARG(ScCheckListMenuControl, LockCheckedHdl, weld::Toggleable&, void)
+{
+ MarkCheckedMembers();
+ UpdateVisibleMembers(false);
- // unmarking should happen after the members are inserted
- if (!bLockCheckedEntries)
+ // unmarking should happen after the members are inserted or updated
+ // (in case there's a hierarchy, in which case we don't clear everything)
+ if (!mxChkLockChecked->get_active())
for (auto& aMember : maMembers)
aMember.mbMarked = false;
}