1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-10 07:25:37 -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,61 +636,80 @@ 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 + "'"] saveFileView.path = ""
saveProcess.running = true pendingSaveContent = content
} saveFileView.path = filePath
function loadFromFile(fileUrl) { // Use Qt.callLater to ensure path is set before calling setText
const cleanPath = fileUrl.toString().replace(/^file:\/\//, '') Qt.callLater(() => {
saveFileView.setText(pendingSaveContent)
loadProcess.command = ["cat", cleanPath] })
loadProcess.running = true } function loadFromFile(fileUrl) {
const filePath = fileUrl.toString().replace(/^file:\/\//, '')
loadFileView.path = ""
loadFileView.path = filePath
// Wait for the file to be loaded before reading
if (loadFileView.waitForJob()) {
Qt.callLater(() => {
const content = loadFileView.text()
if (currentTab && content !== undefined && content !== null) {
updateCurrentTab({
content: content,
hasUnsavedChanges: false,
lastSavedContent: content
}, true)
textArea.text = content
root.lastSavedFileContent = content
}
})
} else {
console.warn("Notepad: Failed to load file - waitForJob returned false")
}
} }
Process { FileView {
id: saveProcess id: saveFileView
blockWrites: true
onExited: (exitCode) => { preload: false
if (exitCode === 0 && currentTab) { atomicWrites: true
printErrors: true
onSaved: {
if (currentTab && saveFileView.path && pendingSaveContent) {
updateCurrentTab({ updateCurrentTab({
hasUnsavedChanges: false, hasUnsavedChanges: false,
lastSavedContent: currentTab.content lastSavedContent: pendingSaveContent
}, true) }, true)
root.lastSavedFileContent = currentTab.content root.lastSavedFileContent = pendingSaveContent
} else { pendingSaveContent = ""
console.warn("Notepad: Failed to save file, exit code:", exitCode)
} }
} }
onSaveFailed: (error) => {
console.warn("Notepad: Failed to save file:", error, "Path:", saveFileView.path)
pendingSaveContent = ""
}
} }
Process { FileView {
id: loadProcess id: loadFileView
blockLoading: true
stdout: StdioCollector { preload: true
onStreamFinished: { atomicWrites: true
if (currentTab) { printErrors: true
updateCurrentTab({
content: text, onLoadFailed: (error) => {
hasUnsavedChanges: false, console.warn("Notepad: Failed to load file:", error)
lastSavedContent: text
}, true)
textArea.text = text
root.lastSavedFileContent = text
}
}
}
onExited: (exitCode) => {
if (exitCode !== 0) {
console.warn("Notepad: Failed to load file, exit code:", exitCode)
}
} }
} }
@@ -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()