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 @@ -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,32 @@ 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(); + QStringList urlList = QStringList(); + bool hasParent = true; + while (hasParent) { + urlList.append(currentDirectory.path()); + hasParent = (currentDirectory != QUrl(parentDirectory(currentDirectory.path()))); + 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 +469,10 @@ { if (m_editable) { applyUncommittedUrl(); + m_pathBox->removeEventFilter(q); + } else { + m_pathBox->installEventFilter(q); } - switchView(); } @@ -554,11 +604,10 @@ if (m_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 +1279,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; } diff --git a/src/widgets/kurlcombobox.h b/src/widgets/kurlcombobox.h --- a/src/widgets/kurlcombobox.h +++ b/src/widgets/kurlcombobox.h @@ -110,6 +110,7 @@ * will be stripped. */ void setUrls(const QStringList &urls); + void setUrls(const QStringList &urls, bool removeOld); /** * Inserts @p urls into the combobox below the "default urls" (see @@ -119,6 +120,7 @@ * parameter determines whether the first or last items will be stripped. */ void setUrls(const QStringList &urls, OverLoadResolving remove); + void setUrls(const QStringList &urls, OverLoadResolving remove, bool removeOld); /** * @returns a list of all urls currently handled. The list contains at most diff --git a/src/widgets/kurlcombobox.cpp b/src/widgets/kurlcombobox.cpp --- a/src/widgets/kurlcombobox.cpp +++ b/src/widgets/kurlcombobox.cpp @@ -173,10 +173,21 @@ setUrls(urls, RemoveBottom); } -void KUrlComboBox::setUrls(const QStringList &_urls, OverLoadResolving remove) +void KUrlComboBox::setUrls(const QStringList &urls, bool removeOld) +{ + setUrls(urls, RemoveBottom, removeOld); +} + +void KUrlComboBox::setUrls(const QStringList &_urls, OverLoadResolving remove) { + setUrls(_urls, remove, true); +} + +void KUrlComboBox::setUrls(const QStringList &_urls, OverLoadResolving remove, bool removeOld) { setDefaults(); - d->itemList.clear(); + if (removeOld) { + d->itemList.clear(); + } d->urlAdded = false; if (_urls.isEmpty()) {