1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-05 21:15:38 -05:00

notepad: use ref system for service

This commit is contained in:
bbedward
2025-10-16 23:01:48 -04:00
parent 72ad35e1f9
commit ce9ab22ae1
2 changed files with 16 additions and 1 deletions

View File

@@ -28,6 +28,10 @@ Item {
signal hideRequested()
Ref {
service: NotepadStorageService
}
function hasUnsavedChanges() {
return textEditor.hasUnsavedChanges()
}

View File

@@ -10,6 +10,8 @@ import qs.Common
Singleton {
id: root
property int refCount: 0
readonly property string baseDir: Paths.strip(StandardPaths.writableLocation(StandardPaths.GenericStateLocation) + "/DankMaterialShell")
readonly property string filesDir: baseDir + "/notepad-files"
readonly property string metadataPath: baseDir + "/notepad-session.json"
@@ -17,10 +19,11 @@ Singleton {
property var tabs: []
property int currentTabIndex: 0
property var tabsBeingCreated: ({})
property bool metadataLoaded: false
FileView {
id: metadataFile
path: root.metadataPath
path: root.refCount > 0 ? root.metadataPath : ""
blockWrites: true
atomicWrites: true
@@ -29,6 +32,7 @@ Singleton {
var data = JSON.parse(text())
root.tabs = data.tabs || []
root.currentTabIndex = data.currentTabIndex || 0
root.metadataLoaded = true
validateTabs()
} catch(e) {
console.warn("Failed to parse notepad metadata:", e)
@@ -41,6 +45,13 @@ Singleton {
}
}
onRefCountChanged: {
if (refCount === 1 && !metadataLoaded) {
metadataFile.path = ""
metadataFile.path = root.metadataPath
}
}
function loadMetadata() {
metadataFile.path = ""