diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,7 @@ set(NON_KIOCORE_LINK_QCHS Qt5Widgets_QCH Qt5Network_QCH + Qt5Core_QCH KF5Completion_QCH KF5WidgetsAddons_QCH KF5JobWidgets_QCH diff --git a/src/filewidgets/CMakeLists.txt b/src/filewidgets/CMakeLists.txt --- a/src/filewidgets/CMakeLists.txt +++ b/src/filewidgets/CMakeLists.txt @@ -12,7 +12,6 @@ kpreviewwidgetbase.cpp krecentdirs.cpp defaultviewadapter.cpp - kdiroperator.cpp kdiroperatordetailview.cpp kdirsortfilterproxymodel.cpp #used in combination with kdirmodel.cpp @@ -39,8 +38,6 @@ kurlnavigator.cpp kurlnavigatormenu.cpp kurlnavigatorpathselectoreventfilter.cpp - - ) qt5_add_resources(kiofilewidgets_SRCS ../new_file_templates/templates.qrc) diff --git a/src/filewidgets/kurlnavigator.h b/src/filewidgets/kurlnavigator.h --- a/src/filewidgets/kurlnavigator.h +++ b/src/filewidgets/kurlnavigator.h @@ -443,6 +443,9 @@ */ void urlSelectionRequested(const QUrl &url); + void keyUpPressed(); + void keyDownPressed(); + protected: #if !defined(DOXYGEN_SHOULD_SKIP_THIS) /** @@ -483,16 +486,18 @@ Q_PRIVATE_SLOT(d, void dropUrls(const QUrl &destination, QDropEvent *)) Q_PRIVATE_SLOT(d, void slotNavigatorButtonClicked(const QUrl &url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)) Q_PRIVATE_SLOT(d, void openContextMenu(QPoint)) + Q_PRIVATE_SLOT(d, void openHierarchyMenu()) Q_PRIVATE_SLOT(d, void openPathSelectorMenu()) Q_PRIVATE_SLOT(d, void updateButtonVisibility()) Q_PRIVATE_SLOT(d, void switchToBreadcrumbMode()) Q_PRIVATE_SLOT(d, void slotPathBoxChanged(const QString &text)) Q_PRIVATE_SLOT(d, void updateContent()) + Q_PRIVATE_SLOT(d, void slotKeyUpPressed()) + private: class Private; Private *const d; - Q_DISABLE_COPY(KUrlNavigator) }; diff --git a/src/filewidgets/kurlnavigator.cpp b/src/filewidgets/kurlnavigator.cpp --- a/src/filewidgets/kurlnavigator.cpp +++ b/src/filewidgets/kurlnavigator.cpp @@ -51,7 +51,9 @@ #include #include #include +#include #include +#include using namespace KDEPrivate; @@ -77,6 +79,8 @@ void slotReturnPressed(); void slotProtocolChanged(const QString &); void openPathSelectorMenu(); + void openHierarchyMenu(); + QString parentDirectory(const QString ¤tPath) const; /** * Appends the widget at the end of the URL navigator. It is assured @@ -107,11 +111,16 @@ */ void slotNavigatorButtonClicked(const QUrl &url, Qt::MouseButton button, Qt::KeyboardModifiers modifiers); + void slotKeyUpPressed(); + void keyUpPressed(); + void keyDownPressed(); + void openContextMenu(const QPoint &p); void slotPathBoxChanged(const QString &text); void updateContent(); + /** * Updates all buttons to have one button for each part of the @@ -164,7 +173,7 @@ bool isCompressedPath(const QUrl &path) const; void removeTrailingSlash(QString &url) const; - + /** * Returns the current history index, if \a historyIndex is * smaller than 0. If \a historyIndex is greater or equal than @@ -251,7 +260,7 @@ m_pathBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); m_pathBox->installEventFilter(q); - KUrlCompletion *kurlCompletion = new KUrlCompletion(KUrlCompletion::DirCompletion); + KUrlCompletion *kurlCompletion = new KUrlCompletion(KUrlCompletion::DirCompletionWithParents); m_pathBox->setCompletionObject(kurlCompletion); m_pathBox->setAutoDeleteCompletionObject(true); @@ -281,6 +290,9 @@ q->setContextMenuPolicy(Qt::CustomContextMenu); connect(q, SIGNAL(customContextMenuRequested(QPoint)), q, SLOT(openContextMenu(QPoint))); + connect(q, SIGNAL(keyUpPressed()), q, SLOT(slotKeyUpPressed())); + connect(q, SIGNAL(keyDownPressed()), + q, SLOT(openHierarchyMenu())); } void KUrlNavigator::Private::initialize(const QUrl &url) @@ -327,6 +339,16 @@ m_pathBox->setUrl(currentUrl); } +void KUrlNavigator::Private::slotKeyUpPressed() +{ + emit q->goUp(); + /* + * Ugly hack to get focus back + */ + slotToggleEditableButtonPressed(); + QTimer::singleShot(10, q->editor()->lineEdit(), SLOT(setFocus())); +} + void KUrlNavigator::Private::slotReturnPressed() { applyUncommittedUrl(); @@ -358,6 +380,33 @@ m_pathBox->setEditUrl(url); } + QString KUrlNavigator::Private::parentDirectory(const QString ¤tPath) const + { + const int slash = currentPath.lastIndexOf(QLatin1Char('/')); + if (slash == -1) + return QString(); + else if (slash == 0) + return QString(QLatin1Char('/')); + else if (slash == currentPath.length()-1) + return parentDirectory(currentPath.left(slash)); + return currentPath.left(slash); + } + +void KUrlNavigator::Private::openHierarchyMenu() { + QUrl currentDirectory = q->locationUrl(); + QUrl levelUp(QStringLiteral("/../")); + QStringList urlList = QStringList(); + bool hasParent = true; + while (hasParent) { + urlList.append(currentDirectory.path()); + hasParent = (currentDirectory != currentDirectory.resolved(levelUp)); + qInfo() << currentDirectory.path(); + currentDirectory = QUrl(parentDirectory(currentDirectory.path())); + } + m_pathBox->setUrls(urlList, false); + m_pathBox->showPopup(); +} + void KUrlNavigator::Private::openPathSelectorMenu() { if (m_navButtons.count() <= 0) { @@ -421,8 +470,10 @@ { if (m_editable) { applyUncommittedUrl(); + m_pathBox->removeEventFilter(q); + } else { + m_pathBox->installEventFilter(q); } - switchView(); } @@ -552,13 +603,13 @@ } if (m_editable) { + qDebug() << "is editable"; m_protocols->hide(); m_dropDownButton->hide(); - + deleteButtons(); m_toggleEditableMode->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); q->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); - m_pathBox->show(); m_pathBox->setUrl(currentUrl); } else { @@ -1230,7 +1281,18 @@ button->setShowMnemonic(false); } break; - + case QEvent::KeyRelease: + { + QKeyEvent *actualEvent = static_cast(event); + if (actualEvent->key() == Qt::Key_Up) { + emit keyUpPressed(); + return true; + } else if (actualEvent->key() == Qt::Key_Down) { + emit keyDownPressed(); + return true; + } + break; + } default: break; }