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:
@@ -28,6 +28,10 @@ Item {
|
||||
|
||||
signal hideRequested()
|
||||
|
||||
Ref {
|
||||
service: NotepadStorageService
|
||||
}
|
||||
|
||||
function hasUnsavedChanges() {
|
||||
return textEditor.hasUnsavedChanges()
|
||||
}
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
Reference in New Issue
Block a user