diff --git a/qml/Desktop/main.qml b/qml/Desktop/main.qml index dd85b22..4d406cf 100644 --- a/qml/Desktop/main.qml +++ b/qml/Desktop/main.qml @@ -64,6 +64,16 @@ Item { id: folderModel url: desktopPath() isDesktop: true + viewAdapter: viewAdapter + } + + ItemViewAdapter { + id: viewAdapter + adapterView: _folderView + adapterModel: folderModel + adapterIconSize: 40 + adapterVisibleArea: Qt.rect(_folderView.contentX, _folderView.contentY, + _folderView.contentWidth, _folderView.contentHeight) } FolderGridView { @@ -94,6 +104,10 @@ Item { if (!activeFocus) folderModel.clearSelection() } + + Component.onCompleted: { + folderModel.requestRename.connect(rename) + } } Connections { diff --git a/qml/Dialogs/CreateFolderDialog.qml b/qml/Dialogs/CreateFolderDialog.qml index 971225f..6ba47fe 100644 --- a/qml/Dialogs/CreateFolderDialog.qml +++ b/qml/Dialogs/CreateFolderDialog.qml @@ -7,12 +7,12 @@ import MeuiKit 1.0 as Meui Window { id: control - title: qsTr("New Folder") + title: qsTr("New folder name") flags: Qt.Dialog visible: true width: 400 + Meui.Units.largeSpacing * 2 - height: _mainLayout.implicitHeight + Meui.Units.largeSpacing * 4 + height: _mainLayout.implicitHeight + Meui.Units.largeSpacing * 2 minimumWidth: width minimumHeight: height @@ -31,16 +31,15 @@ Window { anchors.rightMargin: Meui.Units.largeSpacing spacing: 0 - RowLayout { - Label { - text: qsTr("Name") - } + TextField { + id: _textField + Layout.fillWidth: true + Keys.onEscapePressed: control.close() + text: qsTr("New folder") + focus: true - TextField { - id: _textField - Layout.fillWidth: true - Keys.onEscapePressed: control.close() - focus: true + Component.onCompleted: { + _textField.selectAll() } } diff --git a/qml/FolderGridView.qml b/qml/FolderGridView.qml index 1603a32..82c1541 100644 --- a/qml/FolderGridView.qml +++ b/qml/FolderGridView.qml @@ -63,10 +63,20 @@ GridView { } } + function reset() { + currentIndex = -1 + anchorIndex = 0 + previouslySelectedItemIndex = -1 + cancelRename() + hoveredItem = null + pressedItem = null + cPress = null + } + highlightMoveDuration: 0 keyNavigationEnabled : true keyNavigationWraps : true - Keys.onPressed: { + Keys.onPressed: { if (event.key === Qt.Key_Control) { ctrlPressed = true } else if (event.key === Qt.Key_Shift) { @@ -90,6 +100,13 @@ GridView { anchorIndex = 0 } } + Keys.onEscapePressed: { + if (!editor || !editor.targetItem) { + previouslySelectedItemIndex = -1 + folderModel.clearSelection() + event.accepted = false + } + } cellHeight: { var iconHeight = iconSize + (Meui.Units.fontMetrics.height * 2) + Meui.Units.largeSpacing * 2 @@ -269,6 +286,9 @@ GridView { control.dragY = -1 clearPressState() } else { + if (control.editor && control.editor.targetItem) + return; + folderModel.pinSelection() control.rubberBand = rubberBandObject.createObject(control.contentItem, {x: cPress.x, y: cPress.y}) control.interactive = false @@ -429,6 +449,8 @@ GridView { wrapMode: TextEdit.Wrap horizontalAlignment: TextEdit.AlignHCenter z: 999 + topPadding: Meui.Units.smallSpacing + bottomPadding: Meui.Units.smallSpacing property Item targetItem: null @@ -443,12 +465,14 @@ GridView { targetItem.labelArea.visible = false _editor.select(0, folderModel.fileExtensionBoundary(targetItem.index)) visible = true + control.interactive = false } else { x = 0 y = 0 width = 0 height = 0 visible = false + control.interactive = true } } @@ -457,9 +481,11 @@ GridView { case Qt.Key_Return: case Qt.Key_Enter: commit() + event.accepted = true break case Qt.Key_Escape: cancel() + event.accepted = true break } } @@ -477,13 +503,18 @@ GridView { folderModel.rename(targetItem.index, text) control.currentIndex = targetItem.index targetItem = null + + control.editor.destroy() } } function cancel() { if (targetItem) { targetItem.labelArea.visible = true + control.currentIndex = targetItem.index targetItem = null + + control.editor.destroy() } } } diff --git a/qml/FolderListView.qml b/qml/FolderListView.qml index ac54ebd..dcbdd53 100644 --- a/qml/FolderListView.qml +++ b/qml/FolderListView.qml @@ -38,9 +38,39 @@ ListView { ScrollBar.vertical: ScrollBar { } + function rename() { + if (currentIndex !== -1) { + var renameAction = control.model.action("rename") + if (renameAction && !renameAction.enabled) + return + + if (!control.editor) + control.editor = editorComponent.createObject(control) + + control.editor.targetItem = control.currentItem + } + } + + function cancelRename() { + if (control.editor) { + control.editor.cancel() + control.editor.destroy() + control.editor = null + } + } + + function reset() { + currentIndex = -1 + anchorIndex = 0 + previouslySelectedItemIndex = -1 + cancelRename() + hoveredItem = null + pressedItem = null + cPress = null + } + highlightMoveDuration: 0 - keyNavigationEnabled : true - keyNavigationWraps : true + Keys.enabled: true Keys.onPressed: { if (event.key === Qt.Key_Control) { ctrlPressed = true @@ -53,6 +83,7 @@ ListView { control.keyPress(event) } + Keys.onReleased: { if (event.key === Qt.Key_Control) { ctrlPressed = false @@ -62,6 +93,40 @@ ListView { } } + Keys.onEscapePressed: { + if (!editor || !editor.targetItem) { + previouslySelectedItemIndex = -1 + folderModel.clearSelection() + event.accepted = false + } + } + + Keys.onUpPressed: { + if (!editor || !editor.targetItem) { + var newIndex = currentIndex + newIndex--; + + if (newIndex < 0) + newIndex = 0 + + currentIndex = newIndex + updateSelection(event.modifiers) + } + } + + Keys.onDownPressed: { + if (!editor || !editor.targetItem) { + var newIndex = currentIndex + newIndex++ + + if (newIndex >= control.count) + return + + currentIndex = newIndex + updateSelection(event.modifiers) + } + } + onCachedRectangleSelectionChanged: { if (cachedRectangleSelection === null) return @@ -88,26 +153,6 @@ ListView { cPress = mapToItem(control.contentItem, pressX, pressY) } - function rename() { - if (currentIndex !== -1) { - var renameAction = control.model.action("rename") - if (renameAction && !renameAction.enabled) - return - - if (!control.editor) - control.editor = editorComponent.createObject(control) - - control.editor.targetItem = control.currentItem - } - } - - function cancelRename() { - if (control.editor) { - control.editor.cancel() - control.editor = null - } - } - MouseArea { id: _mouseArea anchors.fill: parent @@ -253,6 +298,9 @@ ListView { control.dragY = -1 clearPressState() } else { + if (control.editor && control.editor.targetItem) + return; + folderModel.pinSelection() control.rubberBand = rubberBandObject.createObject(control.contentItem, {x: cPress.x, y: cPress.y}) control.interactive = false @@ -306,9 +354,9 @@ ListView { function updateSelection(modifier) { if (modifier & Qt.ShiftModifier) { - folderModel.setRangeSelected(anchorIndex, hoveredItem) + folderModel.setRangeSelected(anchorIndex, currentIndex) } else { - folderModel.clear() + folderModel.clearSelection() folderModel.setSelected(currentIndex) if (currentIndex == -1) previouslySelectedItemIndex = -1 @@ -319,46 +367,33 @@ ListView { Component { id: editorComponent - TextArea { + TextField { id: _editor visible: false wrapMode: Text.NoWrap - textMargin: 0 verticalAlignment: TextEdit.AlignVCenter - leftPadding: 0 + z: 999 property Item targetItem: null - background: Item {} - onTargetItemChanged: { if (targetItem != null) { var pos = control.mapFromItem(targetItem, targetItem.labelArea.x, targetItem.labelArea.y) width = targetItem.labelArea.width - height = targetItem.height + height = Meui.Units.fontMetrics.height + Meui.Units.largeSpacing * 2 x = control.mapFromItem(targetItem.labelArea, 0, 0).x - y = pos.y + y = pos.y + (targetItem.height - height) / 2 text = targetItem.labelArea.text targetItem.labelArea.visible = false targetItem.labelArea2.visible = false _editor.select(0, folderModel.fileExtensionBoundary(targetItem.index)) visible = true + control.interactive = false } else { x: 0 y: 0 visible = false - } - } - - Keys.onPressed: { - switch (event.key) { - case Qt.Key_Return: - case Qt.Key_Enter: - commit() - break - case Qt.Key_Escape: - cancel() - break + control.interactive = true } } @@ -369,6 +404,20 @@ ListView { control.forceActiveFocus() } + Keys.onPressed: { + switch (event.key) { + case Qt.Key_Return: + case Qt.Key_Enter: + commit() + event.accepted = true + break + case Qt.Key_Escape: + cancel() + event.accepted = true + break + } + } + function commit() { if (targetItem) { targetItem.labelArea.visible = true @@ -376,6 +425,8 @@ ListView { folderModel.rename(targetItem.index, text) control.currentIndex = targetItem.index targetItem = null + + control.editor.destroy() } } @@ -383,7 +434,10 @@ ListView { if (targetItem) { targetItem.labelArea.visible = true targetItem.labelArea2.visible = true + control.currentIndex = targetItem.index targetItem = null + + control.editor.destroy() } } } diff --git a/qml/FolderPage.qml b/qml/FolderPage.qml index e6f9d00..2510dd8 100644 --- a/qml/FolderPage.qml +++ b/qml/FolderPage.qml @@ -17,6 +17,7 @@ Item { signal requestPathEditor() onCurrentUrlChanged: { + _viewLoader.item.reset() _viewLoader.item.forceActiveFocus() } @@ -31,7 +32,8 @@ Item { Label { id: _fileTips - text: qsTr("No files") + text: qsTr("Empty folder") + font.pointSize: 20 anchors.centerIn: parent visible: false } @@ -70,6 +72,11 @@ Item { case 0: return _listViewComponent case 1: return _gridViewComponent } + + onSourceComponentChanged: { + // 焦点 + _viewLoader.item.forceActiveFocus() + } } Loader { diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 36ba2f4..64a6e97 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -5,21 +5,21 @@ CreateFolderDialog - New Folder - 新建文件夹 + New folder name + 新文件夹名 - - Name - 名称 + + New folder + 新文件夹 - + Cancel 取消 - + OK 确定 @@ -27,7 +27,7 @@ DesktopView - + Desktop 桌面 @@ -35,81 +35,77 @@ FolderModel - %1 selected - 选中了 %1 项 - - - + %1 item %1 项 - + %1 items %1 项 - + Select All 全选 - + Open 打开 - + Cut 剪切 - + Copy 复制 - + Paste 粘贴 - + New Folder 新建文件夹 - + Move To Trash 移动到回收站 - + Empty Trash 清空回收站 - + Delete 删除 - + Rename 重命名 - + Open in Terminal 在终端中打开 - + Set as Wallpaper 设置为壁纸 - + Properties 属性 @@ -118,26 +114,26 @@ FolderPage - No files - 无文件 + Empty folder + 空文件夹 - + %1 item %1 项 - + %1 items %1 项 - + %1 selected 选中了 %1 项 - + Empty Trash 清空回收站