diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2013-10-23 15:45:26 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-30 15:29:18 +0100 |
commit | 5e4fc4b97aa638dc94ae947476684eb4a09ef9d0 (patch) | |
tree | 733193b43ed8918e78bfa6177e35de1ea6d2be14 /src/imports/dialogs/DefaultFileDialog.qml | |
parent | 4a7f1326e3d342148a4a9147505a4d8d531b4a06 (diff) |
QtQuick.Dialogs: handle more keyboard shortcuts
The Back button on Android should close the dialog, but there is a bug
that Qt only receives the release, not the press. Otherwise Esc should
do the same, Enter should accept, it should be possible to copy the
text from the MessageDialog, copy colors to and from the ColorDialog,
etc.
Change-Id: Ib4d4c58cde9f4bb00ce3d46e2f9ea1aad9d52bb0
Reviewed-by: Liang Qi <liang.qi@digia.com>
Diffstat (limited to 'src/imports/dialogs/DefaultFileDialog.qml')
-rw-r--r-- | src/imports/dialogs/DefaultFileDialog.qml | 79 |
1 files changed, 49 insertions, 30 deletions
diff --git a/src/imports/dialogs/DefaultFileDialog.qml b/src/imports/dialogs/DefaultFileDialog.qml index 60928934d8..6ed6697f5a 100644 --- a/src/imports/dialogs/DefaultFileDialog.qml +++ b/src/imports/dialogs/DefaultFileDialog.qml @@ -103,7 +103,7 @@ AbstractFileDialog { clearSelection() if (selectFolder && selectedIndices.length == 0) addSelection(folder) - else { + else if (selectedIndices.length > 0) { selectedIndices.map(function(idx) { if (view.model.isFolder(idx)) { if (selectFolder) @@ -113,17 +113,20 @@ AbstractFileDialog { addSelection(view.model.get(idx, "fileURL")) } }) + } else { + addSelection(pathToUrl(currentPathField.text)) } accept() } Rectangle { + id: content property int maxSize: Math.min(Screen.desktopAvailableWidth, Screen.desktopAvailableHeight) // TODO: QTBUG-29817 geometry from AbstractFileDialog - id: window implicitWidth: Math.min(maxSize, Screen.pixelDensity * 100) implicitHeight: Math.min(maxSize, Screen.pixelDensity * 80) color: palette.window + focus: root.visible && !currentPathField.visible SystemPalette { id: palette } @@ -138,7 +141,7 @@ AbstractFileDialog { root.acceptSelection() } } - width: window.width + width: content.width height: nameText.implicitHeight * 1.5 color: "transparent" Rectangle { @@ -204,6 +207,47 @@ AbstractFileDialog { } } + Keys.onPressed: { + event.accepted = true + switch (event.key) { + case Qt.Key_Up: + root.up(event.modifiers & Qt.ShiftModifier && root.selectMultiple) + break + case Qt.Key_Down: + root.down(event.modifiers & Qt.ShiftModifier && root.selectMultiple) + break + case Qt.Key_Left: + root.dirUp() + break + case Qt.Key_Return: + case Qt.Key_Select: + case Qt.Key_Right: + if (view.currentItem) + view.currentItem.launch() + else + root.acceptSelection() + break + case Qt.Key_Back: + case Qt.Key_Escape: + reject() + break + case Qt.Key_C: + if (event.modifiers & Qt.ControlModifier) + currentPathField.copyAll() + break + case Qt.Key_V: + if (event.modifiers & Qt.ControlModifier) { + currentPathField.visible = true + currentPathField.paste() + } + break + default: + // do nothing + event.accepted = false + break + } + } + ListView { id: view anchors.top: titleBar.bottom @@ -224,33 +268,6 @@ AbstractFileDialog { } highlightMoveDuration: 0 highlightMoveVelocity: -1 - focus: !currentPathField.visible - Keys.onPressed: { - event.accepted = true - switch (event.key) { - case Qt.Key_Up: - root.up(event.modifiers & Qt.ShiftModifier && root.selectMultiple) - break - case Qt.Key_Down: - root.down(event.modifiers & Qt.ShiftModifier && root.selectMultiple) - break - case Qt.Key_Left: - root.dirUp() - break - case Qt.Key_Return: - case Qt.Key_Select: - case Qt.Key_Right: - if (view.currentItem) - view.currentItem.launch() - else - root.acceptSelection() - break - default: - // do nothing - event.accepted = false - break - } - } } MouseArea { @@ -318,6 +335,8 @@ AbstractFileDialog { view.model.folder = root.pathFolder(text) } onDownPressed: currentPathField.visible = false + onBackPressed: reject() + onEscapePressed: reject() } } Rectangle { |