mirror of
https://github.com/lubosz/overte.git
synced 2025-08-04 18:48:59 +02:00
Fixing save dialog issues saving new files
This commit is contained in:
parent
60d97c45af
commit
64597f9d9f
2 changed files with 58 additions and 42 deletions
|
@ -229,55 +229,64 @@ ModalWindow {
|
||||||
id: okAction
|
id: okAction
|
||||||
text: root.saveDialog ? "Save" : (root.selectDirectory ? "Choose" : "Open")
|
text: root.saveDialog ? "Save" : (root.selectDirectory ? "Choose" : "Open")
|
||||||
enabled: currentSelection.text ? true : false
|
enabled: currentSelection.text ? true : false
|
||||||
|
onTriggered: okActionTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: okActionTimer
|
||||||
|
interval: 50
|
||||||
|
running: false
|
||||||
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
if (root.saveDialog) {
|
if (!root.saveDialog) {
|
||||||
// Handle the ambiguity between different cases
|
selectedFile(d.currentSelectionUrl);
|
||||||
// * typed name (with or without extension)
|
root.destroy()
|
||||||
// * full path vs relative vs filename only
|
return;
|
||||||
var selection = helper.saveHelper(currentSelection.text, root.dir, selectionType.currentFilter);
|
}
|
||||||
|
|
||||||
if (!selection) {
|
|
||||||
desktop.messageBox({ icon: OriginalDialogs.StandardIcon.Warning, text: "Unable to parse selection" })
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (helper.urlIsDir(selection)) {
|
// Handle the ambiguity between different cases
|
||||||
root.dir = selection;
|
// * typed name (with or without extension)
|
||||||
currentSelection.text = "";
|
// * full path vs relative vs filename only
|
||||||
return;
|
var selection = helper.saveHelper(currentSelection.text, root.dir, selectionType.currentFilter);
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the file is a valid target
|
if (!selection) {
|
||||||
if (!helper.urlIsWritable(selection)) {
|
desktop.messageBox({ icon: OriginalDialogs.StandardIcon.Warning, text: "Unable to parse selection" })
|
||||||
desktop.messageBox({
|
return;
|
||||||
icon: OriginalDialogs.StandardIcon.Warning,
|
}
|
||||||
buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No,
|
|
||||||
text: "Unable to write to location " + selection
|
|
||||||
})
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (helper.urlExists(selection)) {
|
if (helper.urlIsDir(selection)) {
|
||||||
var messageBox = desktop.messageBox({
|
root.dir = selection;
|
||||||
icon: OriginalDialogs.StandardIcon.Question,
|
currentSelection.text = "";
|
||||||
buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No,
|
return;
|
||||||
text: "Do you wish to overwrite " + selection + "?",
|
}
|
||||||
});
|
|
||||||
var result = messageBox.exec();
|
|
||||||
if (OriginalDialogs.StandardButton.Yes !== result) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
selectedFile(d.currentSelectionUrl);
|
// Check if the file is a valid target
|
||||||
root.destroy()
|
if (!helper.urlIsWritable(selection)) {
|
||||||
} else {
|
desktop.messageBox({
|
||||||
selectedFile(d.currentSelectionUrl);
|
icon: OriginalDialogs.StandardIcon.Warning,
|
||||||
root.destroy()
|
buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No,
|
||||||
}
|
text: "Unable to write to location " + selection
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (helper.urlExists(selection)) {
|
||||||
|
var messageBox = desktop.messageBox({
|
||||||
|
icon: OriginalDialogs.StandardIcon.Question,
|
||||||
|
buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No,
|
||||||
|
text: "Do you wish to overwrite " + selection + "?",
|
||||||
|
});
|
||||||
|
var result = messageBox.exec();
|
||||||
|
if (OriginalDialogs.StandardButton.Yes !== result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Selecting " + selection)
|
||||||
|
selectedFile(selection);
|
||||||
|
root.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
|
|
|
@ -86,5 +86,12 @@ bool FileDialogHelper::urlExists(const QUrl& url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDialogHelper::urlIsWritable(const QUrl& url) {
|
bool FileDialogHelper::urlIsWritable(const QUrl& url) {
|
||||||
return QFileInfo(url.toLocalFile()).isWritable();
|
QFileInfo fileInfo(url.toLocalFile());
|
||||||
|
// Is the file writable?
|
||||||
|
if (fileInfo.exists()) {
|
||||||
|
return fileInfo.isWritable();
|
||||||
|
}
|
||||||
|
|
||||||
|
// No file, get the parent directory and check if writable
|
||||||
|
return QFileInfo(fileInfo.absoluteDir().absolutePath()).isWritable();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue