mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 16:02:51 -05:00
notepad: use ref system for service
This commit is contained in:
@@ -28,6 +28,10 @@ Item {
|
|||||||
|
|
||||||
signal hideRequested()
|
signal hideRequested()
|
||||||
|
|
||||||
|
Ref {
|
||||||
|
service: NotepadStorageService
|
||||||
|
}
|
||||||
|
|
||||||
function hasUnsavedChanges() {
|
function hasUnsavedChanges() {
|
||||||
return textEditor.hasUnsavedChanges()
|
return textEditor.hasUnsavedChanges()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import qs.Common
|
|||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
property int refCount: 0
|
||||||
|
|
||||||
readonly property string baseDir: Paths.strip(StandardPaths.writableLocation(StandardPaths.GenericStateLocation) + "/DankMaterialShell")
|
readonly property string baseDir: Paths.strip(StandardPaths.writableLocation(StandardPaths.GenericStateLocation) + "/DankMaterialShell")
|
||||||
readonly property string filesDir: baseDir + "/notepad-files"
|
readonly property string filesDir: baseDir + "/notepad-files"
|
||||||
readonly property string metadataPath: baseDir + "/notepad-session.json"
|
readonly property string metadataPath: baseDir + "/notepad-session.json"
|
||||||
@@ -17,10 +19,11 @@ Singleton {
|
|||||||
property var tabs: []
|
property var tabs: []
|
||||||
property int currentTabIndex: 0
|
property int currentTabIndex: 0
|
||||||
property var tabsBeingCreated: ({})
|
property var tabsBeingCreated: ({})
|
||||||
|
property bool metadataLoaded: false
|
||||||
|
|
||||||
FileView {
|
FileView {
|
||||||
id: metadataFile
|
id: metadataFile
|
||||||
path: root.metadataPath
|
path: root.refCount > 0 ? root.metadataPath : ""
|
||||||
blockWrites: true
|
blockWrites: true
|
||||||
atomicWrites: true
|
atomicWrites: true
|
||||||
|
|
||||||
@@ -29,6 +32,7 @@ Singleton {
|
|||||||
var data = JSON.parse(text())
|
var data = JSON.parse(text())
|
||||||
root.tabs = data.tabs || []
|
root.tabs = data.tabs || []
|
||||||
root.currentTabIndex = data.currentTabIndex || 0
|
root.currentTabIndex = data.currentTabIndex || 0
|
||||||
|
root.metadataLoaded = true
|
||||||
validateTabs()
|
validateTabs()
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.warn("Failed to parse notepad metadata:", 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() {
|
function loadMetadata() {
|
||||||
metadataFile.path = ""
|
metadataFile.path = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user