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