mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-08 06:25:37 -05:00
Update Notepad initial services
This commit is contained in:
@@ -21,6 +21,10 @@ Singleton {
|
|||||||
property var tabsBeingCreated: ({})
|
property var tabsBeingCreated: ({})
|
||||||
property bool metadataLoaded: false
|
property bool metadataLoaded: false
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
ensureDirectories()
|
||||||
|
}
|
||||||
|
|
||||||
FileView {
|
FileView {
|
||||||
id: metadataFile
|
id: metadataFile
|
||||||
path: root.refCount > 0 ? root.metadataPath : ""
|
path: root.refCount > 0 ? root.metadataPath : ""
|
||||||
@@ -33,15 +37,15 @@ Singleton {
|
|||||||
root.tabs = data.tabs || []
|
root.tabs = data.tabs || []
|
||||||
root.currentTabIndex = data.currentTabIndex || 0
|
root.currentTabIndex = data.currentTabIndex || 0
|
||||||
root.metadataLoaded = true
|
root.metadataLoaded = true
|
||||||
validateTabs()
|
root.validateTabs()
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.warn("Failed to parse notepad metadata:", e)
|
console.warn("Failed to parse notepad metadata:", e)
|
||||||
createDefaultTab()
|
root.createDefaultTab()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoadFailed: {
|
onLoadFailed: {
|
||||||
createDefaultTab()
|
root.createDefaultTab()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +56,9 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ensureDirectories() {
|
||||||
|
mkdirProcess.running = true
|
||||||
|
}
|
||||||
|
|
||||||
function loadMetadata() {
|
function loadMetadata() {
|
||||||
metadataFile.path = ""
|
metadataFile.path = ""
|
||||||
@@ -67,7 +74,7 @@ Singleton {
|
|||||||
newTabsBeingCreated[id] = true
|
newTabsBeingCreated[id] = true
|
||||||
tabsBeingCreated = newTabsBeingCreated
|
tabsBeingCreated = newTabsBeingCreated
|
||||||
|
|
||||||
createEmptyFile(fullPath, function() {
|
root.createEmptyFile(fullPath, function() {
|
||||||
root.tabs = [{
|
root.tabs = [{
|
||||||
id: id,
|
id: id,
|
||||||
title: I18n.tr("Untitled"),
|
title: I18n.tr("Untitled"),
|
||||||
@@ -82,7 +89,7 @@ Singleton {
|
|||||||
var updatedTabsBeingCreated = Object.assign({}, tabsBeingCreated)
|
var updatedTabsBeingCreated = Object.assign({}, tabsBeingCreated)
|
||||||
delete updatedTabsBeingCreated[id]
|
delete updatedTabsBeingCreated[id]
|
||||||
tabsBeingCreated = updatedTabsBeingCreated
|
tabsBeingCreated = updatedTabsBeingCreated
|
||||||
saveMetadata()
|
root.saveMetadata()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,9 +119,20 @@ Singleton {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var loader = tabFileLoaderComponent.createObject(root, {
|
|
||||||
|
var fileChecker = fileExistsComponent.createObject(root, {
|
||||||
path: fullPath,
|
path: fullPath,
|
||||||
callback: callback
|
callback: (exists) => {
|
||||||
|
if (exists) {
|
||||||
|
var loader = tabFileLoaderComponent.createObject(root, {
|
||||||
|
path: fullPath,
|
||||||
|
callback: callback
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.warn("Tab file does not exist:", fullPath)
|
||||||
|
callback("")
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +286,7 @@ Singleton {
|
|||||||
tabs = validTabs
|
tabs = validTabs
|
||||||
|
|
||||||
if (tabs.length === 0) {
|
if (tabs.length === 0) {
|
||||||
createDefaultTab()
|
root.createDefaultTab()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,6 +309,22 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: fileExistsComponent
|
||||||
|
Process {
|
||||||
|
property string path
|
||||||
|
property var callback
|
||||||
|
command: ["test", "-f", path]
|
||||||
|
|
||||||
|
Component.onCompleted: running = true
|
||||||
|
|
||||||
|
onExited: (exitCode) => {
|
||||||
|
callback(exitCode === 0)
|
||||||
|
destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: tabFileSaverComponent
|
id: tabFileSaverComponent
|
||||||
FileView {
|
FileView {
|
||||||
@@ -305,7 +339,7 @@ Singleton {
|
|||||||
|
|
||||||
onSaved: {
|
onSaved: {
|
||||||
if (tabIndex >= 0) {
|
if (tabIndex >= 0) {
|
||||||
updateTabMetadata(tabIndex, {})
|
root.updateTabMetadata(tabIndex, {})
|
||||||
}
|
}
|
||||||
if (creationCallback) {
|
if (creationCallback) {
|
||||||
creationCallback()
|
creationCallback()
|
||||||
@@ -390,4 +424,9 @@ Singleton {
|
|||||||
property string filePath
|
property string filePath
|
||||||
command: ["rm", "-f", filePath]
|
command: ["rm", "-f", filePath]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: mkdirProcess
|
||||||
|
command: ["mkdir", "-p", root.baseDir, root.filesDir]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user