Fix pressing backspace

This commit is contained in:
cutefishd 2021-04-22 01:51:17 +08:00
parent 58357bbb37
commit c7d09c918f
5 changed files with 87 additions and 26 deletions

View file

@ -1,3 +1,27 @@
/***************************************************************************
* Copyright (C) 2006 David Faure <faure@kde.org> *
* Copyright (C) 2008 Fredrik Höglund <fredrik@kde.org> *
* Copyright (C) 2008 Rafael Fernández López <ereslibre@kde.org> *
* Copyright (C) 2011 Marco Martin <mart@kde.org> *
* Copyright (C) 2014 by Eike Hein <hein@kde.org> *
* Copyright (C) 2021 Reven Martin <revenmartin@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "foldermodel.h" #include "foldermodel.h"
#include "dirlister.h" #include "dirlister.h"

View file

@ -1,3 +1,27 @@
/***************************************************************************
* Copyright (C) 2006 David Faure <faure@kde.org> *
* Copyright (C) 2008 Fredrik Höglund <fredrik@kde.org> *
* Copyright (C) 2008 Rafael Fernández López <ereslibre@kde.org> *
* Copyright (C) 2011 Marco Martin <mart@kde.org> *
* Copyright (C) 2014 by Eike Hein <hein@kde.org> *
* Copyright (C) 2021 Reven Martin <revenmartin@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#ifndef FOLDERMODEL_H #ifndef FOLDERMODEL_H
#define FOLDERMODEL_H #define FOLDERMODEL_H

View file

@ -41,7 +41,12 @@ void PathBarModel::setUrl(const QString &url)
if (m_url != url) { if (m_url != url) {
beginResetModel(); beginResetModel();
QUrl _url = QUrl::fromUserInput(url);
if (_url.isValid() && !_url.toLocalFile().isEmpty()) {
m_url = _url.toLocalFile();
} else {
m_url = url; m_url = url;
}
qDeleteAll(m_pathList); qDeleteAll(m_pathList);
m_pathList.clear(); m_pathList.clear();
@ -53,7 +58,8 @@ void PathBarModel::setUrl(const QString &url)
m_pathList.append(item); m_pathList.append(item);
} else { } else {
QDir dir(m_url); QDir dir(m_url);
while (true) {
do {
if (dir.isRoot()) { if (dir.isRoot()) {
PathBarItem *item = new PathBarItem; PathBarItem *item = new PathBarItem;
item->name = "/"; item->name = "/";
@ -66,8 +72,7 @@ void PathBarModel::setUrl(const QString &url)
item->name = dir.dirName(); item->name = dir.dirName();
item->url = QUrl::fromLocalFile(dir.absolutePath()); item->url = QUrl::fromLocalFile(dir.absolutePath());
m_pathList.append(item); m_pathList.append(item);
dir.cdUp(); } while (dir.cdUp());
}
} }
std::reverse(m_pathList.begin(), m_pathList.end()); std::reverse(m_pathList.begin(), m_pathList.end());

View file

@ -155,6 +155,7 @@ GridView {
} }
} }
Keys.onUpPressed: { Keys.onUpPressed: {
if (!editor || !editor.targetItem) {
var newIndex = positioner.nearestItem(currentIndex, var newIndex = positioner.nearestItem(currentIndex,
effectiveNavDirection(control.flow, control.effectiveLayoutDirection, Qt.UpArrow)) effectiveNavDirection(control.flow, control.effectiveLayoutDirection, Qt.UpArrow))
if (newIndex !== -1) { if (newIndex !== -1) {
@ -162,7 +163,9 @@ GridView {
updateSelection(event.modifiers) updateSelection(event.modifiers)
} }
} }
}
Keys.onDownPressed: { Keys.onDownPressed: {
if (!editor || !editor.targetItem) {
var newIndex = positioner.nearestItem(currentIndex, var newIndex = positioner.nearestItem(currentIndex,
effectiveNavDirection(control.flow, control.effectiveLayoutDirection, Qt.DownArrow)) effectiveNavDirection(control.flow, control.effectiveLayoutDirection, Qt.DownArrow))
if (newIndex !== -1) { if (newIndex !== -1) {
@ -170,7 +173,9 @@ GridView {
updateSelection(event.modifiers) updateSelection(event.modifiers)
} }
} }
}
Keys.onLeftPressed: { Keys.onLeftPressed: {
if (!editor || !editor.targetItem) {
var newIndex = positioner.nearestItem(currentIndex, var newIndex = positioner.nearestItem(currentIndex,
effectiveNavDirection(control.flow, control.effectiveLayoutDirection, Qt.LeftArrow)) effectiveNavDirection(control.flow, control.effectiveLayoutDirection, Qt.LeftArrow))
if (newIndex !== -1) { if (newIndex !== -1) {
@ -178,7 +183,9 @@ GridView {
updateSelection(event.modifiers) updateSelection(event.modifiers)
} }
} }
}
Keys.onRightPressed: { Keys.onRightPressed: {
if (!editor || !editor.targetItem) {
var newIndex = positioner.nearestItem(currentIndex, var newIndex = positioner.nearestItem(currentIndex,
effectiveNavDirection(control.flow, control.effectiveLayoutDirection, Qt.RightArrow)) effectiveNavDirection(control.flow, control.effectiveLayoutDirection, Qt.RightArrow))
if (newIndex !== -1) { if (newIndex !== -1) {
@ -186,6 +193,7 @@ GridView {
updateSelection(event.modifiers) updateSelection(event.modifiers)
} }
} }
}
cellHeight: { cellHeight: {
var iconHeight = iconSize + (FishUI.Units.fontMetrics.height * 2) + FishUI.Units.largeSpacing * 2 var iconHeight = iconSize + (FishUI.Units.fontMetrics.height * 2) + FishUI.Units.largeSpacing * 2

View file

@ -79,7 +79,7 @@ Item {
selectByMouse: true selectByMouse: true
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase
text: control.url text: _pathBarModel.url
color: FishUI.Theme.darkMode ? "white" : "black" color: FishUI.Theme.darkMode ? "white" : "black"
background: Rectangle { background: Rectangle {
@ -116,7 +116,7 @@ Item {
} }
function openEditor() { function openEditor() {
_pathEditor.text = control.url _pathEditor.text = _pathBarModel.url
_pathEditor.visible = true _pathEditor.visible = true
_pathEditor.forceActiveFocus() _pathEditor.forceActiveFocus()
_pathEditor.selectAll() _pathEditor.selectAll()