1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-04-11 08:12:09 -04:00

settings: optimize sidebar bindings

This commit is contained in:
bbedward
2026-02-11 18:42:32 -05:00
parent 1a9d7684b9
commit bd46d29ff0

View File

@@ -17,8 +17,9 @@ Rectangle {
property var parentModal: null property var parentModal: null
signal tabChangeRequested(int tabIndex) signal tabChangeRequested(int tabIndex)
property var expandedCategories: ({}) property string _expandedIds: ","
property var autoExpandedCategories: ({}) property string _collapsedIds: ","
property string _autoExpandedIds: ","
property bool searchActive: searchField.text.length > 0 property bool searchActive: searchField.text.length > 0
property int searchSelectedIndex: 0 property int searchSelectedIndex: 0
property int keyboardHighlightIndex: -1 property int keyboardHighlightIndex: -1
@@ -340,24 +341,46 @@ Rectangle {
return true; return true;
} }
function toggleCategory(categoryId) { function _setExpanded(id, expanded) {
var newExpanded = Object.assign({}, expandedCategories); var marker = "," + id + ",";
newExpanded[categoryId] = !isCategoryExpanded(categoryId); if (expanded) {
expandedCategories = newExpanded; if (_expandedIds.indexOf(marker) < 0)
_expandedIds = _expandedIds + id + ",";
_collapsedIds = _collapsedIds.replace(marker, ",");
} else {
_expandedIds = _expandedIds.replace(marker, ",");
if (_collapsedIds.indexOf(marker) < 0)
_collapsedIds = _collapsedIds + id + ",";
}
}
var newAutoExpanded = Object.assign({}, autoExpandedCategories); function _setAutoExpanded(id, value) {
delete newAutoExpanded[categoryId]; var marker = "," + id + ",";
autoExpandedCategories = newAutoExpanded; if (value) {
if (_autoExpandedIds.indexOf(marker) < 0)
_autoExpandedIds = _autoExpandedIds + id + ",";
} else {
_autoExpandedIds = _autoExpandedIds.replace(marker, ",");
}
}
function _isAutoExpanded(id) {
return _autoExpandedIds.indexOf("," + id + ",") >= 0;
}
function toggleCategory(categoryId) {
_setExpanded(categoryId, !isCategoryExpanded(categoryId));
_setAutoExpanded(categoryId, false);
} }
function isCategoryExpanded(categoryId) { function isCategoryExpanded(categoryId) {
if (expandedCategories[categoryId] !== undefined) { if (_collapsedIds.indexOf("," + categoryId + ",") >= 0)
return expandedCategories[categoryId]; return false;
} if (_expandedIds.indexOf("," + categoryId + ",") >= 0)
var category = categoryStructure.find(cat => cat.id === categoryId); return true;
if (category && category.collapsedByDefault) { var category = categoryStructure.find(cat => cat.id === categoryId);
if (category && category.collapsedByDefault)
return false; return false;
}
return true; return true;
} }
@@ -387,13 +410,8 @@ Rectangle {
return; return;
if (!isCategoryExpanded(parent.id)) { if (!isCategoryExpanded(parent.id)) {
var newExpanded = Object.assign({}, expandedCategories); _setExpanded(parent.id, true);
newExpanded[parent.id] = true; _setAutoExpanded(parent.id, true);
expandedCategories = newExpanded;
var newAutoExpanded = Object.assign({}, autoExpandedCategories);
newAutoExpanded[parent.id] = true;
autoExpandedCategories = newAutoExpanded;
} }
} }
@@ -401,14 +419,9 @@ Rectangle {
var oldParent = findParentCategory(oldTabIndex); var oldParent = findParentCategory(oldTabIndex);
var newParent = findParentCategory(newTabIndex); var newParent = findParentCategory(newTabIndex);
if (oldParent && oldParent !== newParent && autoExpandedCategories[oldParent.id]) { if (oldParent && oldParent !== newParent && _isAutoExpanded(oldParent.id)) {
var newExpanded = Object.assign({}, expandedCategories); _setExpanded(oldParent.id, false);
newExpanded[oldParent.id] = false; _setAutoExpanded(oldParent.id, false);
expandedCategories = newExpanded;
var newAutoExpanded = Object.assign({}, autoExpandedCategories);
delete newAutoExpanded[oldParent.id];
autoExpandedCategories = newAutoExpanded;
} }
} }