From 64597f9d9f86c71dfe2d6e3a9b915a04d60d6032 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Thu, 4 Feb 2016 13:32:52 -0800 Subject: [PATCH] Fixing save dialog issues saving new files --- .../resources/qml/dialogs/FileDialog.qml | 91 ++++++++++--------- libraries/ui/src/FileDialogHelper.cpp | 9 +- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/interface/resources/qml/dialogs/FileDialog.qml b/interface/resources/qml/dialogs/FileDialog.qml index 142ed198c0..a482b76c70 100644 --- a/interface/resources/qml/dialogs/FileDialog.qml +++ b/interface/resources/qml/dialogs/FileDialog.qml @@ -229,55 +229,64 @@ ModalWindow { id: okAction text: root.saveDialog ? "Save" : (root.selectDirectory ? "Choose" : "Open") enabled: currentSelection.text ? true : false + onTriggered: okActionTimer.start(); + } + + Timer { + id: okActionTimer + interval: 50 + running: false + repeat: false onTriggered: { - if (root.saveDialog) { - // Handle the ambiguity between different cases - // * typed name (with or without extension) - // * full path vs relative vs filename only - var selection = helper.saveHelper(currentSelection.text, root.dir, selectionType.currentFilter); + if (!root.saveDialog) { + selectedFile(d.currentSelectionUrl); + root.destroy() + return; + } - if (!selection) { - desktop.messageBox({ icon: OriginalDialogs.StandardIcon.Warning, text: "Unable to parse selection" }) - return; - } - if (helper.urlIsDir(selection)) { - root.dir = selection; - currentSelection.text = ""; - return; - } + // Handle the ambiguity between different cases + // * typed name (with or without extension) + // * full path vs relative vs filename only + var selection = helper.saveHelper(currentSelection.text, root.dir, selectionType.currentFilter); - // Check if the file is a valid target - if (!helper.urlIsWritable(selection)) { - desktop.messageBox({ - icon: OriginalDialogs.StandardIcon.Warning, - buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No, - text: "Unable to write to location " + selection - }) - return; - } + if (!selection) { + desktop.messageBox({ icon: OriginalDialogs.StandardIcon.Warning, text: "Unable to parse 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; - } - } + if (helper.urlIsDir(selection)) { + root.dir = selection; + currentSelection.text = ""; + return; + } - selectedFile(d.currentSelectionUrl); - root.destroy() - } else { - selectedFile(d.currentSelectionUrl); - root.destroy() - } + // Check if the file is a valid target + if (!helper.urlIsWritable(selection)) { + desktop.messageBox({ + icon: OriginalDialogs.StandardIcon.Warning, + 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 { diff --git a/libraries/ui/src/FileDialogHelper.cpp b/libraries/ui/src/FileDialogHelper.cpp index f1cbb22f56..56b9695444 100644 --- a/libraries/ui/src/FileDialogHelper.cpp +++ b/libraries/ui/src/FileDialogHelper.cpp @@ -86,5 +86,12 @@ bool FileDialogHelper::urlExists(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(); }