1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00

Add notepad file persistence & overwrite save options

This commit is contained in:
purian23
2025-09-07 15:39:05 -04:00
parent c23088c98a
commit 8abc94fd07
3 changed files with 207 additions and 7 deletions

View File

@@ -41,6 +41,9 @@ Singleton {
property string wallpaperCyclingTime: "06:00" // HH:mm format
property string lastBrightnessDevice: ""
property string notepadContent: ""
property string notepadCurrentFileName: ""
property string notepadCurrentFileUrl: ""
property string notepadLastSavedContent: ""
Component.onCompleted: {
loadSettings()
@@ -96,6 +99,9 @@ Singleton {
wallpaperCyclingTime = settings.wallpaperCyclingTime !== undefined ? settings.wallpaperCyclingTime : "06:00"
lastBrightnessDevice = settings.lastBrightnessDevice !== undefined ? settings.lastBrightnessDevice : ""
notepadContent = settings.notepadContent !== undefined ? settings.notepadContent : ""
notepadCurrentFileName = settings.notepadCurrentFileName !== undefined ? settings.notepadCurrentFileName : ""
notepadCurrentFileUrl = settings.notepadCurrentFileUrl !== undefined ? settings.notepadCurrentFileUrl : ""
notepadLastSavedContent = settings.notepadLastSavedContent !== undefined ? settings.notepadLastSavedContent : ""
}
} catch (e) {
@@ -132,7 +138,10 @@ Singleton {
"wallpaperCyclingInterval": wallpaperCyclingInterval,
"wallpaperCyclingTime": wallpaperCyclingTime,
"lastBrightnessDevice": lastBrightnessDevice,
"notepadContent": notepadContent
"notepadContent": notepadContent,
"notepadCurrentFileName": notepadCurrentFileName,
"notepadCurrentFileUrl": notepadCurrentFileUrl,
"notepadLastSavedContent": notepadLastSavedContent
}, null, 2))
}

View File

@@ -30,6 +30,8 @@ DankModal {
property string selectedFilePath: ""
property string selectedFileName: ""
property bool selectedFileIsDir: false
property bool showOverwriteConfirmation: false
property string pendingFilePath: ""
signal fileSelected(string path)
@@ -97,6 +99,33 @@ DankModal {
keyboardSelectionRequested = true
}
function handleSaveFile(filePath) {
// Ensure the filePath has the correct file:// protocol format
var normalizedPath = filePath
if (!normalizedPath.startsWith("file://")) {
normalizedPath = "file://" + filePath
}
// Check if file exists by looking through the folder model
var exists = false
var fileName = filePath.split('/').pop()
for (var i = 0; i < folderModel.count; i++) {
if (folderModel.get(i, "fileName") === fileName && !folderModel.get(i, "fileIsDir")) {
exists = true
break
}
}
if (exists) {
pendingFilePath = normalizedPath
showOverwriteConfirmation = true
} else {
fileSelected(normalizedPath)
fileBrowserModal.close()
}
}
objectName: "fileBrowserModal"
allowStacking: true
Component.onCompleted: {
@@ -582,9 +611,12 @@ DankModal {
}
onAccepted: {
if (text.trim() !== "") {
var fullPath = currentPath + "/" + text.trim()
fileSelected(fullPath)
fileBrowserModal.close()
// Remove file:// protocol from currentPath if present for proper construction
var basePath = currentPath.replace(/^file:\/\//, '')
var fullPath = basePath + "/" + text.trim()
// Ensure consistent path format - remove any double slashes and normalize
fullPath = fullPath.replace(/\/+/g, '/')
handleSaveFile(fullPath)
}
}
}
@@ -610,9 +642,12 @@ DankModal {
enabled: fileNameInput.text.trim() !== ""
onClicked: {
if (fileNameInput.text.trim() !== "") {
var fullPath = currentPath + "/" + fileNameInput.text.trim()
fileSelected(fullPath)
fileBrowserModal.close()
// Remove file:// protocol from currentPath if present for proper construction
var basePath = currentPath.replace(/^file:\/\//, '')
var fullPath = basePath + "/" + fileNameInput.text.trim()
// Ensure consistent path format - remove any double slashes and normalize
fullPath = fullPath.replace(/\/+/g, '/')
handleSaveFile(fullPath)
}
}
}
@@ -650,6 +685,135 @@ DankModal {
return lastDot > 0 ? fileBrowserModal.selectedFileName.substring(lastDot + 1).toLowerCase() : ""
}
}
// Overwrite confirmation dialog
Item {
id: overwriteDialog
anchors.fill: parent
visible: showOverwriteConfirmation
Keys.onEscapePressed: {
showOverwriteConfirmation = false
pendingFilePath = ""
}
Keys.onReturnPressed: {
showOverwriteConfirmation = false
fileSelected(pendingFilePath)
pendingFilePath = ""
Qt.callLater(() => fileBrowserModal.close())
}
focus: showOverwriteConfirmation
Rectangle {
anchors.fill: parent
color: Theme.shadowStrong
opacity: 0.8
MouseArea {
anchors.fill: parent
onClicked: {
showOverwriteConfirmation = false
pendingFilePath = ""
}
}
}
StyledRect {
anchors.centerIn: parent
width: 400
height: 160
color: Theme.surfaceContainer
radius: Theme.cornerRadius
border.color: Theme.outlineMedium
border.width: 1
Column {
anchors.centerIn: parent
width: parent.width - Theme.spacingL * 2
spacing: Theme.spacingM
StyledText {
text: qsTr("File Already Exists")
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Medium
color: Theme.surfaceText
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: qsTr("A file with this name already exists. Do you want to overwrite it?")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceTextMedium
width: parent.width
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
}
Row {
anchors.horizontalCenter: parent.horizontalCenter
spacing: Theme.spacingM
StyledRect {
width: 80
height: 36
radius: Theme.cornerRadius
color: cancelArea.containsMouse ? Theme.surfaceVariantHover : Theme.surfaceVariant
border.color: Theme.outline
border.width: 1
StyledText {
anchors.centerIn: parent
text: qsTr("Cancel")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
font.weight: Font.Medium
}
MouseArea {
id: cancelArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
showOverwriteConfirmation = false
pendingFilePath = ""
}
}
}
StyledRect {
width: 90
height: 36
radius: Theme.cornerRadius
color: overwriteArea.containsMouse ? Qt.darker(Theme.primary, 1.1) : Theme.primary
StyledText {
anchors.centerIn: parent
text: qsTr("Overwrite")
font.pixelSize: Theme.fontSizeMedium
color: Theme.background
font.weight: Font.Medium
}
MouseArea {
id: overwriteArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
showOverwriteConfirmation = false
fileSelected(pendingFilePath)
pendingFilePath = ""
Qt.callLater(() => fileBrowserModal.close())
}
}
}
}
}
}
}
}
}
}

View File

@@ -177,6 +177,9 @@ PanelWindow {
Component.onCompleted: {
text = SessionData.notepadContent
root.currentFileName = SessionData.notepadCurrentFileName
root.currentFileUrl = SessionData.notepadCurrentFileUrl
root.lastSavedFileContent = SessionData.notepadLastSavedContent
}
Connections {
@@ -237,6 +240,10 @@ PanelWindow {
root.currentFileUrl = ""
root.hasUnsavedChanges = false
root.lastSavedFileContent = ""
SessionData.notepadCurrentFileName = ""
SessionData.notepadCurrentFileUrl = ""
SessionData.notepadLastSavedContent = ""
SessionData.saveSettings()
}
break
case Qt.Key_A:
@@ -326,6 +333,10 @@ PanelWindow {
root.currentFileUrl = ""
root.hasUnsavedChanges = false
root.lastSavedFileContent = ""
SessionData.notepadCurrentFileName = ""
SessionData.notepadCurrentFileUrl = ""
SessionData.notepadLastSavedContent = ""
SessionData.saveSettings()
}
}
}
@@ -408,6 +419,10 @@ PanelWindow {
if (exitCode === 0) {
root.hasUnsavedChanges = false
root.lastSavedFileContent = SessionData.notepadContent
SessionData.notepadCurrentFileName = root.currentFileName
SessionData.notepadCurrentFileUrl = root.currentFileUrl.toString()
SessionData.notepadLastSavedContent = root.lastSavedFileContent
SessionData.saveSettings()
} else {
console.warn("Notepad: Failed to save file, exit code:", exitCode)
}
@@ -422,6 +437,10 @@ PanelWindow {
SessionData.notepadContent = text
root.hasUnsavedChanges = false
root.lastSavedFileContent = text
SessionData.notepadCurrentFileName = root.currentFileName
SessionData.notepadCurrentFileUrl = root.currentFileUrl.toString()
SessionData.notepadLastSavedContent = text
SessionData.saveSettings()
}
}
@@ -465,6 +484,10 @@ PanelWindow {
root.currentFileUrl = ""
root.hasUnsavedChanges = false
root.lastSavedFileContent = ""
SessionData.notepadCurrentFileName = ""
SessionData.notepadCurrentFileUrl = ""
SessionData.notepadLastSavedContent = ""
SessionData.saveSettings()
})
} else if (root.pendingAction === "open") {
Qt.callLater(() => {
@@ -617,6 +640,10 @@ PanelWindow {
root.currentFileUrl = ""
root.hasUnsavedChanges = false
root.lastSavedFileContent = ""
SessionData.notepadCurrentFileName = ""
SessionData.notepadCurrentFileUrl = ""
SessionData.notepadLastSavedContent = ""
SessionData.saveSettings()
} else if (root.pendingAction === "open") {
root.fileDialogOpen = true
loadBrowser.open()