Commit 67609e43 authored by Shawn Rutledge's avatar Shawn Rutledge
Browse files

FileDialog: several logic corrections in handling the enter key


A "save as" dialog does not need to validate existence of the file.
When the user presses enter in the text field at the top, and the
text field contains a path to a directory, it usually means enter
the directory; but if the dialog is for choosing a directory, then
pressing enter will mean enter the directory if the dialog is not already
viewing that one, or else accept the current directory as the choice if
the table view does not have focus on some other row.
When the user presses enter in table view, go down into a directory
only if a directory is selected; otherwise accept the current selection.
When the user clicks a row in the table, copy the path of that row
into the text field so that it is possible to edit the path before
pressing Enter or OK (behavior similar to a native dialog that has
an editable path, such as GTK).

Task-number: QTBUG-39435
Change-Id: Ibd5e988624c5b1072a12239d681cbdc812e0a697
Reviewed-by: default avatarLiang Qi <liang.qi@theqtcompany.com>
Showing with 16 additions and 11 deletions
...@@ -316,13 +316,14 @@ AbstractFileDialog { ...@@ -316,13 +316,14 @@ AbstractFileDialog {
sortReversed: view.sortIndicatorOrder === Qt.DescendingOrder sortReversed: view.sortIndicatorOrder === Qt.DescendingOrder
} }
onActivated: { onActivated: if (view.focus) {
if (view.model.isFolder(row)) { if (view.selection.count > 0 && view.model.isFolder(row)) {
dirDown(view.model.get(row, "filePath")) dirDown(view.model.get(row, "filePath"))
} else { } else {
root.acceptSelection() root.acceptSelection()
} }
} }
onClicked: currentPathField.text = view.model.get(row, "filePath")
TableViewColumn { TableViewColumn {
...@@ -398,13 +399,14 @@ AbstractFileDialog { ...@@ -398,13 +399,14 @@ AbstractFileDialog {
TextField { TextField {
id: currentPathField id: currentPathField
Layout.fillWidth: true Layout.fillWidth: true
onAccepted: { function doAccept() {
root.clearSelection() root.clearSelection()
if (root.addSelection(root.pathToUrl(text))) if (root.addSelection(root.pathToUrl(text)))
root.accept() root.accept()
else else
root.folder = root.pathFolder(text) root.folder = root.pathFolder(text)
} }
onAccepted: doAccept()
} }
} }
} }
...@@ -454,6 +456,8 @@ AbstractFileDialog { ...@@ -454,6 +456,8 @@ AbstractFileDialog {
onClicked: { onClicked: {
if (view.model.isFolder(view.currentIndex) && !selectFolder) if (view.model.isFolder(view.currentIndex) && !selectFolder)
dirDown(view.model.get(view.currentIndex, "filePath")) dirDown(view.model.get(view.currentIndex, "filePath"))
else if (!(root.selectExisting))
currentPathField.doAccept()
else else
root.acceptSelection() root.acceptSelection()
} }
......
...@@ -176,14 +176,15 @@ void QQuickFileDialog::clearSelection() ...@@ -176,14 +176,15 @@ void QQuickFileDialog::clearSelection()
bool QQuickFileDialog::addSelection(const QUrl &path) bool QQuickFileDialog::addSelection(const QUrl &path)
{ {
QFileInfo info(path.toLocalFile()); QFileInfo info(path.toLocalFile());
if (info.exists() && ((info.isDir() && m_selectFolder) || !info.isDir())) { if (selectExisting() && !info.exists())
if (m_selectFolder) return false;
m_selections.append(pathFolder(path.toLocalFile())); if (selectFolder() != info.isDir())
else return false;
m_selections.append(path); if (selectFolder())
return true; m_selections.append(pathFolder(path.toLocalFile()));
} else
return false; m_selections.append(path);
return true;
} }
/*! /*!
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment