Commit ad5d3367 authored by Felix Ernst's avatar Felix Ernst Committed by Elvis Angelaccio
Browse files

Add an option to use an UrlNavigator in the toolbar instead

This commit adds a locationInToolbar KToggleAction to switch between
using a location bar to navigate or using a new custom QWidgetAction
in the toolbar.

A big portion of this MR is refactoring because until now the
UrlNavigator was tightly intertwined with the DolphinViewContainer.
With this MR an UrlNavigator for controlling a View can be freely
connected or disconnected with a single method call.

A DolphinUrlNavigator class is created in the process which contains all
Dolphin-specific UrlNavigator code which did previously reside in the
DolphinViewContainer class. Other application parts that belong to
UrlNavigator-management are also moved here.
parent 880766bd
......@@ -208,6 +208,7 @@ set(dolphinstatic_SRCS
dolphinrecenttabsmenu.cpp
dolphintabpage.cpp
dolphintabwidget.cpp
dolphinurlnavigator.cpp
trash/dolphintrash.cpp
filterbar/filterbar.cpp
panels/places/placespanel.cpp
......@@ -248,6 +249,7 @@ set(dolphinstatic_SRCS
statusbar/mountpointobservercache.cpp
statusbar/spaceinfoobserver.cpp
statusbar/statusbarspaceinfo.cpp
views/dolphinurlnavigatorwidgetaction.cpp
views/zoomlevelinfo.cpp
dolphindebug.cpp
global.cpp
......
......@@ -68,7 +68,7 @@ bool DolphinBookmarkHandler::supportsTabs() const
QList<KBookmarkOwner::FutureBookmark> DolphinBookmarkHandler::currentBookmarkList() const
{
const auto viewContainers = m_mainWindow->viewContainers();
const auto viewContainers = m_mainWindow->viewContainers(false);
QList<FutureBookmark> bookmarks;
bookmarks.reserve(viewContainers.size());
for (const auto viewContainer : viewContainers) {
......
......@@ -31,6 +31,7 @@
#include "views/draganddrophelper.h"
#include "views/viewproperties.h"
#include "views/dolphinnewfilemenuobserver.h"
#include "views/dolphinurlnavigatorwidgetaction.h"
#include "dolphin_generalsettings.h"
#include <KActionCollection>
......@@ -201,7 +202,7 @@ DolphinMainWindow::~DolphinMainWindow()
{
}
QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers() const
QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers(bool includeInactive) const
{
QVector<DolphinViewContainer*> viewContainers;
......@@ -356,7 +357,7 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
void DolphinMainWindow::updateHistory()
{
const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternal();
const int index = urlNavigator->historyIndex();
QAction* backAction = actionCollection()->action(KStandardAction::name(KStandardAction::Back));
......@@ -727,7 +728,7 @@ void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction *action)
void DolphinMainWindow::slotAboutToShowBackPopupMenu()
{
KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternal();
int entries = 0;
m_backAction->menu()->clear();
for (int i = urlNavigator->historyIndex() + 1; i < urlNavigator->historySize() && entries < MaxNumberOfNavigationentries; ++i, ++entries) {
......@@ -740,7 +741,7 @@ void DolphinMainWindow::slotAboutToShowBackPopupMenu()
void DolphinMainWindow::slotGoBack(QAction* action)
{
int gotoIndex = action->data().value<int>();
KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternal();
for (int i = gotoIndex - urlNavigator->historyIndex(); i > 0; --i) {
goBack();
}
......@@ -749,14 +750,14 @@ void DolphinMainWindow::slotGoBack(QAction* action)
void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction* action)
{
if (action) {
KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternal();
openNewTabAfterCurrentTab(urlNavigator->locationUrl(action->data().value<int>()));
}
}
void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
{
KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternal();
int entries = 0;
m_forwardAction->menu()->clear();
for (int i = urlNavigator->historyIndex() - 1; i >= 0 && entries < MaxNumberOfNavigationentries; --i, ++entries) {
......@@ -769,7 +770,7 @@ void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
void DolphinMainWindow::slotGoForward(QAction* action)
{
int gotoIndex = action->data().value<int>();
KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternal();
for (int i = urlNavigator->historyIndex() - gotoIndex; i > 0; --i) {
goForward();
}
......@@ -841,6 +842,47 @@ void DolphinMainWindow::showFilterBar()
m_activeViewContainer->setFilterBarVisible(true);
}
void DolphinMainWindow::toggleLocationInToolbar()
{
// collect needed variables
const bool locationInToolbar = actionCollection()->action(QStringLiteral("location_in_toolbar"))->isChecked();
auto viewContainers = this->viewContainers();
auto urlNavigatorWidgetAction = static_cast<DolphinUrlNavigatorWidgetAction *>
(actionCollection()->action(QStringLiteral("url_navigator")));
const bool isEditable = m_activeViewContainer->urlNavigator()->isUrlEditable();
const QLineEdit *lineEdit = m_activeViewContainer->urlNavigator()->editor()->lineEdit();
const bool hasFocus = lineEdit->hasFocus();
const int cursorPosition = lineEdit->cursorPosition();
const int selectionStart = lineEdit->selectionStart();
const int selectionLength = lineEdit->selectionLength();
// do the switching
GeneralSettings::setLocationInToolbar(locationInToolbar);
if (locationInToolbar) {
for (const auto viewContainer : viewContainers) {
viewContainer->disconnectUrlNavigator();
}
m_activeViewContainer->connectUrlNavigator(urlNavigatorWidgetAction->urlNavigator());
} else {
m_activeViewContainer->disconnectUrlNavigator();
for (const auto viewContainer : viewContainers) {
viewContainer->connectToInternalUrlNavigator();
}
}
urlNavigatorWidgetAction->setUrlNavigatorVisible(!locationInToolbar);
m_activeViewContainer->urlNavigator()->setUrlEditable(isEditable);
if (hasFocus) { // the rest of this method is unneeded perfectionism
m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setText(lineEdit->text());
m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setFocus();
m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setCursorPosition(cursorPosition);
if (selectionStart != -1) {
m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setSelection(selectionStart, selectionLength);
}
}
}
void DolphinMainWindow::toggleEditLocation()
{
clearStatusBar();
......@@ -891,7 +933,7 @@ void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
void DolphinMainWindow::goBack()
{
KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
DolphinUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternal();
urlNavigator->goBack();
if (urlNavigator->locationState().isEmpty()) {
......@@ -918,14 +960,14 @@ void DolphinMainWindow::goHome()
void DolphinMainWindow::goBackInNewTab()
{
KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternal();
const int index = urlNavigator->historyIndex() + 1;
openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
}
void DolphinMainWindow::goForwardInNewTab()
{
KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternal();
const int index = urlNavigator->historyIndex() - 1;
openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
}
......@@ -1057,6 +1099,7 @@ void DolphinMainWindow::editSettings()
const QUrl url = container->url();
DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews);
connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, &DolphinUrlNavigator::slotReadSettings);
settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
settingsDialog->show();
m_settingsDialog = settingsDialog;
......@@ -1254,12 +1297,19 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
oldViewContainer->disconnect(this);
oldViewContainer->view()->disconnect(this);
oldViewContainer->urlNavigator()->disconnect(this);
if (GeneralSettings::locationInToolbar()) {
oldViewContainer->disconnectUrlNavigator();
}
// except the requestItemInfo so that on hover the information panel can still be updated
connect(oldViewContainer->view(), &DolphinView::requestItemInfo,
this, &DolphinMainWindow::requestItemInfo);
}
if (GeneralSettings::locationInToolbar()) {
viewContainer->connectUrlNavigator(static_cast<DolphinUrlNavigatorWidgetAction *>
(actionCollection()->action(QStringLiteral("url_navigator")))->urlNavigator());
}
connectViewSignals(viewContainer);
m_actionHandler->setCurrentView(viewContainer->view());
......@@ -1491,6 +1541,16 @@ void DolphinMainWindow::setupActions()
stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
KToggleAction* locationInToolbar = actionCollection()->add<KToggleAction>(QStringLiteral("location_in_toolbar"));
locationInToolbar->setText(i18nc("@action:inmenu Navigation Bar", "Location in Toolbar"));
locationInToolbar->setWhatsThis(xi18nc("@info:whatsthis",
"This toggles between showing the <emphasis>path</emphasis> in the "
"<emphasis>Location Bar</emphasis> and in the <emphasis>Toolbar</emphasis>."));
actionCollection()->setDefaultShortcut(locationInToolbar, Qt::Key_F12);
locationInToolbar->setChecked(GeneralSettings::locationInToolbar());
connect(locationInToolbar, &KToggleAction::triggered, this, &DolphinMainWindow::toggleLocationInToolbar);
DolphinUrlNavigator::addToContextMenu(locationInToolbar);
KToggleAction* editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
......@@ -1692,6 +1752,14 @@ void DolphinMainWindow::setupActions()
connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
auto *urlNavigatorWidgetAction = new DolphinUrlNavigatorWidgetAction(this);
urlNavigatorWidgetAction->setText(i18nc("@action:inmenu auto-hide: "
"Depending on the settings this Widget is blank/invisible.",
"Url Navigator (auto-hide)"));
actionCollection()->addAction(QStringLiteral("url_navigator"), urlNavigatorWidgetAction);
connect(locationInToolbar, &KToggleAction::triggered,
urlNavigatorWidgetAction, &DolphinUrlNavigatorWidgetAction::setUrlNavigatorVisible);
// for context menu
QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
showTarget->setText(i18nc("@action:inmenu", "Show Target"));
......@@ -1883,14 +1951,14 @@ void DolphinMainWindow::setupDockWidgets()
connect(this, &DolphinMainWindow::urlChanged,
m_placesPanel, &PlacesPanel::setUrl);
connect(placesDock, &DolphinDockWidget::visibilityChanged,
m_tabWidget, &DolphinTabWidget::slotPlacesPanelVisibilityChanged);
&DolphinUrlNavigator::slotPlacesPanelVisibilityChanged);
connect(this, &DolphinMainWindow::settingsChanged,
m_placesPanel, &PlacesPanel::readSettings);
connect(m_placesPanel, &PlacesPanel::storageTearDownRequested,
this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested,
this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
m_tabWidget->slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
DolphinUrlNavigator::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
actionShowAllPlaces->setCheckable(true);
......@@ -2165,12 +2233,13 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
const KUrlNavigator* navigator = container->urlNavigator();
connect(navigator, &KUrlNavigator::urlChanged,
this, &DolphinMainWindow::changeUrl);
connect(navigator, &KUrlNavigator::historyChanged,
this, &DolphinMainWindow::updateHistory);
connect(navigator, &KUrlNavigator::editableStateChanged,
this, &DolphinMainWindow::slotEditableStateChanged);
connect(navigator, &KUrlNavigator::tabRequested,
this, &DolphinMainWindow::openNewTabAfterLastTab);
connect(container->urlNavigatorInternal(), &KUrlNavigator::historyChanged,
this, &DolphinMainWindow::updateHistory);
}
void DolphinMainWindow::updateSplitAction()
......
......@@ -68,9 +68,14 @@ public:
DolphinViewContainer* activeViewContainer() const;
/**
* Returns view container for all tabs
* Returns view containers for all tabs
* @param includeInactive When true all view containers available in
* this window are returned. When false the
* view containers of split views that are not
* currently active are ignored.
* Default is true.
*/
QVector<DolphinViewContainer*> viewContainers() const;
QVector<DolphinViewContainer*> viewContainers(bool includeInactive = true) const;
/**
* Opens each directory in \p dirs in a separate tab. If \a splitView is set,
......@@ -305,6 +310,12 @@ private slots:
void showFilterBar();
/**
* Toggle between either using an UrlNavigator in the toolbar or the
* ones in the location bar for navigating.
*/
void toggleLocationInToolbar();
/**
* Toggles between edit and browse mode of the navigation bar.
*/
......
......@@ -68,9 +68,6 @@ void DolphinTabPage::setSplitViewEnabled(bool enabled, const QUrl &secondaryUrl)
const QUrl& url = (secondaryUrl.isEmpty()) ? m_primaryViewContainer->url() : secondaryUrl;
m_secondaryViewContainer = createViewContainer(url);
const bool placesSelectorVisible = m_primaryViewContainer->urlNavigator()->isPlacesSelectorVisible();
m_secondaryViewContainer->urlNavigator()->setPlacesSelectorVisible(placesSelectorVisible);
m_splitter->addWidget(m_secondaryViewContainer);
m_secondaryViewContainer->show();
m_secondaryViewContainer->setActive(true);
......@@ -150,14 +147,6 @@ void DolphinTabPage::markUrlAsCurrent(const QUrl& url)
}
}
void DolphinTabPage::setPlacesSelectorVisible(bool visible)
{
m_primaryViewContainer->urlNavigator()->setPlacesSelectorVisible(visible);
if (m_splitViewEnabled) {
m_secondaryViewContainer->urlNavigator()->setPlacesSelectorVisible(visible);
}
}
void DolphinTabPage::refreshViews()
{
m_primaryViewContainer->readSettings();
......@@ -176,12 +165,12 @@ QByteArray DolphinTabPage::saveState() const
stream << m_splitViewEnabled;
stream << m_primaryViewContainer->url();
stream << m_primaryViewContainer->urlNavigator()->isUrlEditable();
stream << m_primaryViewContainer->urlNavigatorInternal()->isUrlEditable();
m_primaryViewContainer->view()->saveState(stream);
if (m_splitViewEnabled) {
stream << m_secondaryViewContainer->url();
stream << m_secondaryViewContainer->urlNavigator()->isUrlEditable();
stream << m_secondaryViewContainer->urlNavigatorInternal()->isUrlEditable();
m_secondaryViewContainer->view()->saveState(stream);
}
......@@ -217,7 +206,7 @@ void DolphinTabPage::restoreState(const QByteArray& state)
m_primaryViewContainer->setUrl(primaryUrl);
bool primaryUrlEditable;
stream >> primaryUrlEditable;
m_primaryViewContainer->urlNavigator()->setUrlEditable(primaryUrlEditable);
m_primaryViewContainer->urlNavigatorInternal()->setUrlEditable(primaryUrlEditable);
m_primaryViewContainer->view()->restoreState(stream);
if (isSplitViewEnabled) {
......@@ -226,7 +215,7 @@ void DolphinTabPage::restoreState(const QByteArray& state)
m_secondaryViewContainer->setUrl(secondaryUrl);
bool secondaryUrlEditable;
stream >> secondaryUrlEditable;
m_secondaryViewContainer->urlNavigator()->setUrlEditable(secondaryUrlEditable);
m_secondaryViewContainer->urlNavigatorInternal()->setUrlEditable(secondaryUrlEditable);
m_secondaryViewContainer->view()->restoreState(stream);
}
......@@ -261,7 +250,7 @@ void DolphinTabPage::restoreStateV1(const QByteArray& state)
m_primaryViewContainer->setUrl(primaryUrl);
bool primaryUrlEditable;
stream >> primaryUrlEditable;
m_primaryViewContainer->urlNavigator()->setUrlEditable(primaryUrlEditable);
m_primaryViewContainer->urlNavigatorInternal()->setUrlEditable(primaryUrlEditable);
if (isSplitViewEnabled) {
QUrl secondaryUrl;
......@@ -269,7 +258,7 @@ void DolphinTabPage::restoreStateV1(const QByteArray& state)
m_secondaryViewContainer->setUrl(secondaryUrl);
bool secondaryUrlEditable;
stream >> secondaryUrlEditable;
m_secondaryViewContainer->urlNavigator()->setUrlEditable(secondaryUrlEditable);
m_secondaryViewContainer->urlNavigatorInternal()->setUrlEditable(secondaryUrlEditable);
}
stream >> m_primaryViewActive;
......
......@@ -22,7 +22,6 @@
DolphinTabWidget::DolphinTabWidget(QWidget* parent) :
QTabWidget(parent),
m_placesSelectorVisible(true),
m_lastViewedTab(0)
{
KAcceleratorManager::setNoAccel(this);
......@@ -157,7 +156,6 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU
DolphinTabPage* tabPage = new DolphinTabPage(primaryUrl, secondaryUrl, this);
tabPage->setActive(false);
tabPage->setPlacesSelectorVisible(m_placesSelectorVisible);
connect(tabPage, &DolphinTabPage::activeViewChanged,
this, &DolphinTabWidget::activeViewChanged);
connect(tabPage, &DolphinTabPage::activeViewUrlChanged,
......@@ -288,19 +286,6 @@ void DolphinTabWidget::activatePrevTab()
setCurrentIndex(index >= 0 ? index : (count() - 1));
}
void DolphinTabWidget::slotPlacesPanelVisibilityChanged(bool visible)
{
// The places-selector from the URL navigator should only be shown
// if the places dock is invisible
m_placesSelectorVisible = !visible;
const int tabCount = count();
for (int i = 0; i < tabCount; ++i) {
DolphinTabPage* tabPage = tabPageAt(i);
tabPage->setPlacesSelectorVisible(m_placesSelectorVisible);
}
}
void DolphinTabWidget::restoreClosedTab(const QByteArray& state)
{
openNewActivatedTab();
......
......@@ -163,13 +163,6 @@ public slots:
*/
void activatePrevTab();
/**
* Is invoked if the Places panel got visible/invisible and takes care
* that the places-selector of all views is only shown if the Places panel
* is invisible.
*/
void slotPlacesPanelVisibilityChanged(bool visible);
/**
* Is called when the user wants to reopen a previously closed tab from
* the recent tabs menu.
......@@ -231,9 +224,6 @@ private:
QPair<int, bool> indexByUrl(const QUrl& url) const;
private:
/** Caches the (negated) places panel visibility */
bool m_placesSelectorVisible;
int m_lastViewedTab;
};
......
......@@ -56,6 +56,7 @@
<text context="@title:menu">Location Bar</text>
<Action name="editable_location" />
<Action name="replace_location" />
<Action name="location_in_toolbar" />
</Menu>
<Separator/>
<Action name="view_properties" />
......@@ -121,7 +122,7 @@
<Action name="details" />
<Separator name="separator_0" />
<Action name="sort" />
<Spacer name="spacer_0" />
<Action name="url_navigator" />
<Action name="split_view" />
<Action name="split_stash" />
<Action name="toggle_search" />
......
/*
* Copyright 2020 Felix Ernst <fe.a.ernst@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <https://www.gnu.org/licenses/>.
*/
#include "dolphinurlnavigator.h"
#include "dolphin_generalsettings.h"
#include "dolphinplacesmodelsingleton.h"
#include "global.h"
#include <KToggleAction>
#include <KUrlComboBox>
#include <KLocalizedString>
#include <QLineEdit>
#include <QMenu>
DolphinUrlNavigator::DolphinUrlNavigator(QWidget *parent) :
KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), QUrl(), parent)
{
init();
}
DolphinUrlNavigator::DolphinUrlNavigator(const QUrl &url, QWidget *parent) :
KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url, parent)
{
init();
}
void DolphinUrlNavigator::init()
{
const GeneralSettings* settings = GeneralSettings::self();
setUrlEditable(settings->editableUrl());
setShowFullPath(settings->showFullPath());
setHomeUrl(Dolphin::homeUrl());
setPlacesSelectorVisible(s_placesSelectorVisible);
editor()->setCompletionMode(KCompletion::CompletionMode(settings->urlCompletionMode()));
editor()->lineEdit()->installEventFilter(this);
installEventFilter(this);
setWhatsThis(xi18nc("@info:whatsthis location bar",
"<para>This line describes the location of the files and folders "
"displayed below.</para><para>The name of the currently viewed "
"folder can be read at the very right. To the left of it is the "
"name of the folder that contains it. The whole line is called "
"the <emphasis>path</emphasis> to the current location because "
"following these folders from left to right leads here.</para>"
"<para>This interactive path "
"is more powerful than one would expect. To learn more "
"about the basic and advanced features of the location bar "
"<link url='help:/dolphin/location-bar.html'>click here</link>. "
"This will open the dedicated page in the Handbook.</para>"));
s_instances.push_front(this);
connect(this, &DolphinUrlNavigator::returnPressed,
this, &DolphinUrlNavigator::slotReturnPressed);
connect(editor(), &KUrlComboBox::completionModeChanged,
this, DolphinUrlNavigator::setCompletionMode);
}
DolphinUrlNavigator::~DolphinUrlNavigator()
{
s_instances.remove(this);
}
bool DolphinUrlNavigator::eventFilter(QObject* watched, QEvent* event)
{
Q_UNUSED(watched)
if (event->type() == QEvent::ChildPolished) {
QChildEvent *childEvent = static_cast<QChildEvent *>(event);
QMenu *popup = qobject_cast<QMenu *>(childEvent->child());
if (popup) {
// The popups of the "breadcrumb mode" navigation buttons
// should not get the action added. They can currently be
// identified by their number of separators: 0 or 1
// The popups we are interested in have 2 or more separators.
int separatorCount = 0;
for (QAction *action : popup->actions()) {
if (action->isSeparator()) {
separatorCount++;
}
}
if (separatorCount > 1) {
q_check_ptr(s_ActionForContextMenu);
popup->addAction(s_ActionForContextMenu);
}
}
}
return false;
}
void DolphinUrlNavigator::slotReadSettings()
{
// The startup settings should (only) get applied if they have been
// modified by the user. Otherwise keep the (possibly) different current
// settings of the URL navigators and split view.
if (GeneralSettings::modifiedStartupSettings()) {
for (DolphinUrlNavigator *urlNavigator : s_instances) {
urlNavigator->setUrlEditable(GeneralSettings::editableUrl());
urlNavigator->setShowFullPath(GeneralSettings::showFullPath());
urlNavigator->setHomeUrl(Dolphin::homeUrl());
}
}
}
void DolphinUrlNavigator::slotReturnPressed()
{
if (!GeneralSettings::editableUrl()) {
setUrlEditable(false);
}
}
void DolphinUrlNavigator::addToContextMenu(QAction* action)
{
s_ActionForContextMenu = action;
}
void DolphinUrlNavigator::slotPlacesPanelVisibilityChanged(bool visible)
{
// The places-selector from the URL navigator should only be shown
// if the places dock is invisible
s_placesSelectorVisible = !visible;
for (DolphinUrlNavigator *urlNavigator : s_instances) {
urlNavigator->setPlacesSelectorVisible(s_placesSelectorVisible);
}
}
void DolphinUrlNavigator::setCompletionMode(const KCompletion::CompletionMode completionMode)
{
if (completionMode != GeneralSettings::urlCompletionMode())
{
GeneralSettings::setUrlCompletionMode(completionMode);
for (const DolphinUrlNavigator *urlNavigator : s_instances)
{
urlNavigator->editor()->setCompletionMode(completionMode);
}
}
}
std::forward_list<DolphinUrlNavigator *> DolphinUrlNavigator::s_instances;
bool DolphinUrlNavigator::s_placesSelectorVisible = true;
QAction *DolphinUrlNavigator::s_ActionForContextMenu = nullptr;
/*
* Copyright 2020 Felix Ernst <fe.a.ernst@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of