From 18366c147fbcfa3c441409900487147c6aa4bf8c Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 10 May 2025 23:51:33 +0200 Subject: [PATCH] make left sidebar selected tab persistent --- .../modules/common/PersistentStates.qml | 3 +++ .../modules/sidebarLeft/SidebarLeft.qml | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.config/quickshell/modules/common/PersistentStates.qml b/.config/quickshell/modules/common/PersistentStates.qml index eb62219d0..d093786ec 100644 --- a/.config/quickshell/modules/common/PersistentStates.qml +++ b/.config/quickshell/modules/common/PersistentStates.qml @@ -5,6 +5,9 @@ pragma ComponentBehavior: Bound Singleton { property QtObject sidebar: QtObject { + property QtObject leftSide: QtObject { + property int selectedTab: 0 + } property QtObject centerGroup: QtObject { property int selectedTab: 0 } diff --git a/.config/quickshell/modules/sidebarLeft/SidebarLeft.qml b/.config/quickshell/modules/sidebarLeft/SidebarLeft.qml index cdc890dc7..fd0d7a877 100644 --- a/.config/quickshell/modules/sidebarLeft/SidebarLeft.qml +++ b/.config/quickshell/modules/sidebarLeft/SidebarLeft.qml @@ -25,7 +25,7 @@ Scope { // Scope id: sidebarRoot visible: false focusable: true - property int currentTab: 0 + property int selectedTab: PersistentStates.sidebar.leftSide.selectedTab property bool extend: false property real sidebarWidth: sidebarRoot.extend ? Appearance.sizes.sidebarWidthExtended : Appearance.sizes.sidebarWidth @@ -106,16 +106,16 @@ Scope { // Scope } if (event.modifiers === Qt.ControlModifier) { if (event.key === Qt.Key_PageDown) { - sidebarRoot.currentTab = Math.min(sidebarRoot.currentTab + 1, root.tabButtonList.length - 1) + PersistentStateManager.setState("sidebar.leftSide.selectedTab", Math.min(sidebarRoot.selectedTab + 1, root.tabButtonList.length - 1)) } else if (event.key === Qt.Key_PageUp) { - sidebarRoot.currentTab = Math.max(sidebarRoot.currentTab - 1, 0) + PersistentStateManager.setState("sidebar.leftSide.selectedTab", Math.max(sidebarRoot.selectedTab - 1, 0)) } else if (event.key === Qt.Key_Tab) { - sidebarRoot.currentTab = (sidebarRoot.currentTab + 1) % root.tabButtonList.length; + PersistentStateManager.setState("sidebar.leftSide.selectedTab", (sidebarRoot.selectedTab + 1) % root.tabButtonList.length); } else if (event.key === Qt.Key_Backtab) { - sidebarRoot.currentTab = (sidebarRoot.currentTab - 1 + root.tabButtonList.length) % root.tabButtonList.length; + PersistentStateManager.setState("sidebar.leftSide.selectedTab", (sidebarRoot.selectedTab - 1 + root.tabButtonList.length) % root.tabButtonList.length); } else if (event.key === Qt.Key_O) { sidebarRoot.extend = !sidebarRoot.extend; @@ -133,9 +133,9 @@ Scope { // Scope PrimaryTabBar { // Tab strip id: tabBar tabButtonList: root.tabButtonList - externalTrackedTab: sidebarRoot.currentTab + externalTrackedTab: sidebarRoot.selectedTab function onCurrentIndexChanged(currentIndex) { - sidebarRoot.currentTab = currentIndex + PersistentStateManager.setState("sidebar.leftSide.selectedTab", currentIndex) } } @@ -144,10 +144,10 @@ Scope { // Scope Layout.topMargin: 5 Layout.fillWidth: true Layout.fillHeight: true - currentIndex: currentTab + currentIndex: sidebarRoot.selectedTab onCurrentIndexChanged: { tabBar.enableIndicatorAnimation = true - sidebarRoot.currentTab = currentIndex + PersistentStateManager.setState("sidebar.leftSide.selectedTab", currentIndex) } clip: true