1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-11 07:52:50 -05:00

Update to Native fileView

This commit is contained in:
purian23
2025-09-09 00:25:40 -04:00
parent 7105b09dc0
commit 5d4ba8b38a

View File

@@ -636,62 +636,81 @@ PanelWindow {
} }
} }
// File save/load functionality property string pendingSaveContent: ""
function saveToFile(fileUrl) { function saveToFile(fileUrl) {
if (!currentTab) return if (!currentTab) return
const content = currentTab.content const content = currentTab.content
const cleanPath = fileUrl.toString().replace(/^file:\/\//, '') const filePath = fileUrl.toString().replace(/^file:\/\//, '')
const escapedContent = content.replace(/'/g, "'\\''")
saveProcess.command = ["sh", "-c", "printf '%s' '" + escapedContent + "' > '" + cleanPath + "'"]
saveProcess.running = true
}
function loadFromFile(fileUrl) { saveFileView.path = ""
const cleanPath = fileUrl.toString().replace(/^file:\/\//, '') pendingSaveContent = content
saveFileView.path = filePath
loadProcess.command = ["cat", cleanPath] // Use Qt.callLater to ensure path is set before calling setText
loadProcess.running = true Qt.callLater(() => {
} saveFileView.setText(pendingSaveContent)
})
} function loadFromFile(fileUrl) {
const filePath = fileUrl.toString().replace(/^file:\/\//, '')
Process { loadFileView.path = ""
id: saveProcess loadFileView.path = filePath
onExited: (exitCode) => { // Wait for the file to be loaded before reading
if (exitCode === 0 && currentTab) { if (loadFileView.waitForJob()) {
Qt.callLater(() => {
const content = loadFileView.text()
if (currentTab && content !== undefined && content !== null) {
updateCurrentTab({ updateCurrentTab({
content: content,
hasUnsavedChanges: false, hasUnsavedChanges: false,
lastSavedContent: currentTab.content lastSavedContent: content
}, true) }, true)
root.lastSavedFileContent = currentTab.content textArea.text = content
root.lastSavedFileContent = content
}
})
} else { } else {
console.warn("Notepad: Failed to save file, exit code:", exitCode) console.warn("Notepad: Failed to load file - waitForJob returned false")
}
} }
} }
Process { FileView {
id: loadProcess id: saveFileView
blockWrites: true
preload: false
atomicWrites: true
printErrors: true
stdout: StdioCollector { onSaved: {
onStreamFinished: { if (currentTab && saveFileView.path && pendingSaveContent) {
if (currentTab) {
updateCurrentTab({ updateCurrentTab({
content: text,
hasUnsavedChanges: false, hasUnsavedChanges: false,
lastSavedContent: text lastSavedContent: pendingSaveContent
}, true) }, true)
textArea.text = text root.lastSavedFileContent = pendingSaveContent
root.lastSavedFileContent = text pendingSaveContent = ""
}
} }
} }
onExited: (exitCode) => { onSaveFailed: (error) => {
if (exitCode !== 0) { console.warn("Notepad: Failed to save file:", error, "Path:", saveFileView.path)
console.warn("Notepad: Failed to load file, exit code:", exitCode) pendingSaveContent = ""
} }
} }
FileView {
id: loadFileView
blockLoading: true
preload: true
atomicWrites: true
printErrors: true
onLoadFailed: (error) => {
console.warn("Notepad: Failed to load file:", error)
}
} }
FileBrowserModal { FileBrowserModal {
@@ -726,7 +745,6 @@ PanelWindow {
saveToFile(fileUrl) saveToFile(fileUrl)
// Handle pending action after save
if (root.pendingAction === "new") { if (root.pendingAction === "new") {
Qt.callLater(() => { Qt.callLater(() => {
createNewTab() createNewTab()