forked from Shinonome/dots-hyprland
make right sidebar tab persistent
This commit is contained in:
@@ -5,8 +5,12 @@ pragma ComponentBehavior: Bound
|
||||
|
||||
Singleton {
|
||||
property QtObject sidebar: QtObject {
|
||||
property QtObject centerGroup: QtObject {
|
||||
property int selectedTab: 0
|
||||
}
|
||||
property QtObject bottomGroup: QtObject {
|
||||
property bool collapsed: false
|
||||
property int selectedTab: 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import Quickshell
|
||||
ColumnLayout {
|
||||
id: root
|
||||
spacing: 0
|
||||
property bool _initialized: false
|
||||
required property var tabButtonList // Something like [{"icon": "notifications", "name": qsTr("Notifications")}, {"icon": "volume_up", "name": qsTr("Volume mixer")}]
|
||||
required property var externalTrackedTab
|
||||
property bool enableIndicatorAnimation: false
|
||||
@@ -16,7 +17,13 @@ ColumnLayout {
|
||||
id: tabBar
|
||||
Layout.fillWidth: true
|
||||
currentIndex: root.externalTrackedTab
|
||||
onCurrentIndexChanged: root.onCurrentIndexChanged(currentIndex)
|
||||
onCurrentIndexChanged: {
|
||||
if (!root._initialized) {
|
||||
root._initialized = true
|
||||
return
|
||||
}
|
||||
root.onCurrentIndexChanged(currentIndex)
|
||||
}
|
||||
|
||||
background: Item {
|
||||
WheelHandler {
|
||||
|
||||
@@ -14,13 +14,17 @@ Rectangle {
|
||||
color: Appearance.colors.colLayer1
|
||||
clip: true
|
||||
implicitHeight: collapsed ? collapsedBottomWidgetGroupRow.implicitHeight : bottomWidgetGroupRow.implicitHeight
|
||||
property int selectedTab: 0
|
||||
property int selectedTab: PersistentStates.sidebar.bottomGroup.selectedTab
|
||||
property bool collapsed: PersistentStates.sidebar.bottomGroup.collapsed
|
||||
property var tabs: [
|
||||
{"type": "calendar", "name": "Calendar", "icon": "calendar_month", "widget": calendarWidget},
|
||||
{"type": "todo", "name": "To Do", "icon": "done_outline", "widget": todoWidget}
|
||||
]
|
||||
|
||||
onSelectedTabChanged: {
|
||||
PersistentStateManager.setState("sidebar.bottomGroup.selectedTab", selectedTab)
|
||||
}
|
||||
|
||||
Behavior on implicitHeight {
|
||||
NumberAnimation {
|
||||
duration: Appearance.animation.elementMove.duration
|
||||
|
||||
@@ -16,23 +16,27 @@ Rectangle {
|
||||
radius: Appearance.rounding.normal
|
||||
color: Appearance.colors.colLayer1
|
||||
|
||||
property int currentTab: 0
|
||||
property int selectedTab: PersistentStates.sidebar.centerGroup.selectedTab
|
||||
property var tabButtonList: [{"icon": "notifications", "name": qsTr("Notifications")}, {"icon": "volume_up", "name": qsTr("Volume mixer")}]
|
||||
|
||||
onSelectedTabChanged: {
|
||||
PersistentStateManager.setState("sidebar.centerGroup.selectedTab", selectedTab)
|
||||
}
|
||||
|
||||
Keys.onPressed: (event) => {
|
||||
if (event.key === Qt.Key_PageDown || event.key === Qt.Key_PageUp) {
|
||||
if (event.key === Qt.Key_PageDown) {
|
||||
root.currentTab = Math.min(root.currentTab + 1, root.tabButtonList.length - 1)
|
||||
PersistentStateManager.setState("sidebar.centerGroup.selectedTab", Math.min(root.selectedTab + 1, root.tabButtonList.length - 1))
|
||||
} else if (event.key === Qt.Key_PageUp) {
|
||||
root.currentTab = Math.max(root.currentTab - 1, 0)
|
||||
PersistentStateManager.setState("sidebar.centerGroup.selectedTab", Math.max(root.selectedTab - 1, 0))
|
||||
}
|
||||
event.accepted = true;
|
||||
}
|
||||
if (event.modifiers === Qt.ControlModifier) {
|
||||
if (event.key === Qt.Key_Tab) {
|
||||
root.currentTab = (root.currentTab + 1) % root.tabButtonList.length;
|
||||
PersistentStateManager.setState("sidebar.centerGroup.selectedTab", (root.selectedTab + 1) % root.tabButtonList.length);
|
||||
} else if (event.key === Qt.Key_Backtab) {
|
||||
root.currentTab = (root.currentTab - 1 + root.tabButtonList.length) % root.tabButtonList.length;
|
||||
PersistentStateManager.setState("sidebar.centerGroup.selectedTab", (root.selectedTab - 1 + root.tabButtonList.length) % root.tabButtonList.length);
|
||||
}
|
||||
event.accepted = true;
|
||||
}
|
||||
@@ -46,9 +50,10 @@ Rectangle {
|
||||
PrimaryTabBar {
|
||||
id: tabBar
|
||||
tabButtonList: root.tabButtonList
|
||||
externalTrackedTab: root.currentTab
|
||||
externalTrackedTab: root.selectedTab
|
||||
|
||||
function onCurrentIndexChanged(currentIndex) {
|
||||
root.currentTab = currentIndex
|
||||
PersistentStateManager.setState("sidebar.centerGroup.selectedTab", currentIndex)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,10 +62,10 @@ Rectangle {
|
||||
Layout.topMargin: 5
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
currentIndex: currentTab
|
||||
currentIndex: root.selectedTab
|
||||
onCurrentIndexChanged: {
|
||||
tabBar.enableIndicatorAnimation = true
|
||||
root.currentTab = currentIndex
|
||||
PersistentStateManager.setState("sidebar.centerGroup.selectedTab", currentIndex)
|
||||
}
|
||||
|
||||
clip: true
|
||||
|
||||
@@ -29,6 +29,7 @@ Singleton {
|
||||
}
|
||||
|
||||
function setState(nestedKey, value) {
|
||||
// console.log(`[PersistentStateManager] Setting state: ${nestedKey} = ${value}`);
|
||||
let keys = nestedKey.split(".");
|
||||
let obj = PersistentStates;
|
||||
let parents = [obj];
|
||||
@@ -53,7 +54,6 @@ Singleton {
|
||||
}
|
||||
|
||||
function saveStates() {
|
||||
console.log("[PersistentStateManager] Saving states to file:", root.filePath)
|
||||
const plainStates = ObjectUtils.toPlainObject(PersistentStates)
|
||||
stateFileView.setText(JSON.stringify(plainStates, null, 2))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user