prevent empty sidebar

This commit is contained in:
end-4
2025-10-12 20:17:31 +02:00
parent 4f25572d1d
commit 40fe0bebcf
2 changed files with 49 additions and 39 deletions
@@ -12,12 +12,17 @@ Item {
id: root
required property var scopeRoot
anchors.fill: parent
property bool aiChatEnabled: Config.options.policies.ai !== 0
property bool translatorEnabled: Config.options.sidebar.translator.enable
property bool animeEnabled: Config.options.policies.weeb !== 0
property bool animeCloset: Config.options.policies.weeb === 2
property var tabButtonList: [
...(Config.options.policies.ai !== 0 ? [{"icon": "neurology", "name": Translation.tr("Intelligence")}] : []),
...(Config.options.sidebar.translator.enable ? [{"icon": "translate", "name": Translation.tr("Translator")}] : []),
...(Config.options.policies.weeb === 1 ? [{"icon": "bookmark_heart", "name": Translation.tr("Anime")}] : [])
...(root.aiChatEnabled ? [{"icon": "neurology", "name": Translation.tr("Intelligence")}] : []),
...(root.translatorEnabled ? [{"icon": "translate", "name": Translation.tr("Translator")}] : []),
...((root.animeEnabled && !root.animeCloset) ? [{"icon": "bookmark_heart", "name": Translation.tr("Anime")}] : [])
]
property int selectedTab: 0
property int tabCount: swipeView.count
function focusActiveItem() {
swipeView.currentItem.forceActiveFocus()
@@ -26,7 +31,7 @@ Item {
Keys.onPressed: (event) => {
if (event.modifiers === Qt.ControlModifier) {
if (event.key === Qt.Key_PageDown) {
root.selectedTab = Math.min(root.selectedTab + 1, root.tabButtonList.length - 1)
root.selectedTab = Math.min(root.selectedTab + 1, root.tabCount - 1)
event.accepted = true;
}
else if (event.key === Qt.Key_PageUp) {
@@ -34,11 +39,11 @@ Item {
event.accepted = true;
}
else if (event.key === Qt.Key_Tab) {
root.selectedTab = (root.selectedTab + 1) % root.tabButtonList.length;
root.selectedTab = (root.selectedTab + 1) % root.tabCount;
event.accepted = true;
}
else if (event.key === Qt.Key_Backtab) {
root.selectedTab = (root.selectedTab - 1 + root.tabButtonList.length) % root.tabButtonList.length;
root.selectedTab = (root.selectedTab - 1 + root.tabCount) % root.tabCount;
event.accepted = true;
}
}
@@ -52,6 +57,7 @@ Item {
PrimaryTabBar { // Tab strip
id: tabBar
visible: root.tabButtonList.length > 1
tabButtonList: root.tabButtonList
externalTrackedTab: root.selectedTab
function onCurrentIndexChanged(currentIndex) {
@@ -83,9 +89,9 @@ Item {
}
contentChildren: [
...(Config.options.policies.ai !== 0 ? [aiChat.createObject()] : []),
...(Config.options.sidebar.translator.enable ? [translator.createObject()] : []),
...(Config.options.policies.weeb === 0 ? [] : [anime.createObject()])
...((root.aiChatEnabled || (!root.translatorEnabled && !root.animeEnabled)) ? [aiChat.createObject()] : []),
...(root.translatorEnabled ? [translator.createObject()] : []),
...(root.animeEnabled ? [anime.createObject()] : [])
]
}