Commit b6fc58c3 authored by Felix Ernst's avatar Felix Ernst Committed by Elvis Angelaccio

Adress the first round of Angelaccio's review comments

- Split the viewContainers(bool includeInActive) into two methods
    without parameters
- Prevent users from accidently hiding all Url Navigators by
    preventing the dangerous action and then displaying a helpful
    message instead
Unrelated to review comments: Remove a useless line of code
parent 00abc6d2
...@@ -68,7 +68,7 @@ bool DolphinBookmarkHandler::supportsTabs() const ...@@ -68,7 +68,7 @@ bool DolphinBookmarkHandler::supportsTabs() const
QList<KBookmarkOwner::FutureBookmark> DolphinBookmarkHandler::currentBookmarkList() const QList<KBookmarkOwner::FutureBookmark> DolphinBookmarkHandler::currentBookmarkList() const
{ {
const auto viewContainers = m_mainWindow->viewContainers(false); const auto viewContainers = m_mainWindow->activeViewContainers();
QList<FutureBookmark> bookmarks; QList<FutureBookmark> bookmarks;
bookmarks.reserve(viewContainers.size()); bookmarks.reserve(viewContainers.size());
for (const auto viewContainer : viewContainers) { for (const auto viewContainer : viewContainers) {
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <KJobWidgets> #include <KJobWidgets>
#include <KLocalizedString> #include <KLocalizedString>
#include <KMessageBox> #include <KMessageBox>
#include <KMessageWidget>
#include <KNS3/KMoreToolsMenuFactory> #include <KNS3/KMoreToolsMenuFactory>
#include <KProtocolInfo> #include <KProtocolInfo>
#include <KProtocolManager> #include <KProtocolManager>
...@@ -202,7 +203,7 @@ DolphinMainWindow::~DolphinMainWindow() ...@@ -202,7 +203,7 @@ DolphinMainWindow::~DolphinMainWindow()
{ {
} }
QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers(bool includeInactive) const QVector<DolphinViewContainer *> DolphinMainWindow::activeViewContainers() const
{ {
QVector<DolphinViewContainer*> viewContainers; QVector<DolphinViewContainer*> viewContainers;
...@@ -845,7 +846,8 @@ void DolphinMainWindow::showFilterBar() ...@@ -845,7 +846,8 @@ void DolphinMainWindow::showFilterBar()
void DolphinMainWindow::toggleLocationInToolbar() void DolphinMainWindow::toggleLocationInToolbar()
{ {
// collect needed variables // collect needed variables
const bool locationInToolbar = actionCollection()->action(QStringLiteral("location_in_toolbar"))->isChecked(); QAction *locationInToolbarAction = actionCollection()->action(QStringLiteral("location_in_toolbar"));
const bool locationInToolbar = locationInToolbarAction->isChecked();
auto viewContainers = this->viewContainers(); auto viewContainers = this->viewContainers();
auto urlNavigatorWidgetAction = static_cast<DolphinUrlNavigatorWidgetAction *> auto urlNavigatorWidgetAction = static_cast<DolphinUrlNavigatorWidgetAction *>
(actionCollection()->action(QStringLiteral("url_navigator"))); (actionCollection()->action(QStringLiteral("url_navigator")));
...@@ -856,6 +858,21 @@ void DolphinMainWindow::toggleLocationInToolbar() ...@@ -856,6 +858,21 @@ void DolphinMainWindow::toggleLocationInToolbar()
const int selectionStart = lineEdit->selectionStart(); const int selectionStart = lineEdit->selectionStart();
const int selectionLength = lineEdit->selectionLength(); const int selectionLength = lineEdit->selectionLength();
// prevent the switching if it would leave the user without a visible UrlNavigator
if (locationInToolbar && !toolBar()->actions().contains(urlNavigatorWidgetAction)) {
QAction *configureToolbars = actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars));
KMessageWidget *messageWidget = m_activeViewContainer->showMessage(
xi18nc("@info 2 is the visible text on a button just below the message",
"The location could not be moved onto the toolbar because there is currently "
"no \"%1\" item on the toolbar. Select <interface>%2</interface> and add the "
"\"%1\" item. Then this will work.", urlNavigatorWidgetAction->iconText(),
configureToolbars->iconText()), DolphinViewContainer::Information);
messageWidget->addAction(configureToolbars);
messageWidget->addAction(locationInToolbarAction);
locationInToolbarAction->setChecked(false);
return;
}
// do the switching // do the switching
GeneralSettings::setLocationInToolbar(locationInToolbar); GeneralSettings::setLocationInToolbar(locationInToolbar);
if (locationInToolbar) { if (locationInToolbar) {
...@@ -870,7 +887,7 @@ void DolphinMainWindow::toggleLocationInToolbar() ...@@ -870,7 +887,7 @@ void DolphinMainWindow::toggleLocationInToolbar()
} }
} }
urlNavigatorWidgetAction->setUrlNavigatorVisible(!locationInToolbar); urlNavigatorWidgetAction->setUrlNavigatorVisible(locationInToolbar);
m_activeViewContainer->urlNavigator()->setUrlEditable(isEditable); m_activeViewContainer->urlNavigator()->setUrlEditable(isEditable);
if (hasFocus) { // the rest of this method is unneeded perfectionism if (hasFocus) { // the rest of this method is unneeded perfectionism
m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setText(lineEdit->text()); m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setText(lineEdit->text());
...@@ -1756,8 +1773,6 @@ void DolphinMainWindow::setupActions() ...@@ -1756,8 +1773,6 @@ void DolphinMainWindow::setupActions()
"Depending on the settings this Widget is blank/invisible.", "Depending on the settings this Widget is blank/invisible.",
"Url Navigator (auto-hide)")); "Url Navigator (auto-hide)"));
actionCollection()->addAction(QStringLiteral("url_navigator"), urlNavigatorWidgetAction); actionCollection()->addAction(QStringLiteral("url_navigator"), urlNavigatorWidgetAction);
connect(locationInToolbar, &KToggleAction::triggered,
urlNavigatorWidgetAction, &DolphinUrlNavigatorWidgetAction::setUrlNavigatorVisible);
// for context menu // for context menu
QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target")); QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
......
...@@ -65,17 +65,19 @@ public: ...@@ -65,17 +65,19 @@ public:
* having a split view setup, the nonactive view * having a split view setup, the nonactive view
* is usually shown in darker colors. * is usually shown in darker colors.
*/ */
DolphinViewContainer* activeViewContainer() const; DolphinViewContainer *activeViewContainer() const;
/** /**
* Returns view containers for all tabs * Returns the active view containers of all tabs.
* @param includeInactive When true all view containers available in * @see activeViewContainer()
* this window are returned. When false the * Use viewContainers() to also include the inactive ones.
* view containers of split views that are not
* currently active are ignored.
* Default is true.
*/ */
QVector<DolphinViewContainer*> viewContainers(bool includeInactive = true) const; QVector<DolphinViewContainer *> activeViewContainers() const;
/**
* Returns all view containers.
*/
QVector<DolphinViewContainer *> viewContainers() const;
/** /**
* Opens each directory in \p dirs in a separate tab. If \a splitView is set, * Opens each directory in \p dirs in a separate tab. If \a splitView is set,
......
...@@ -367,10 +367,13 @@ void DolphinViewContainer::disconnectUrlNavigator() ...@@ -367,10 +367,13 @@ void DolphinViewContainer::disconnectUrlNavigator()
updateNavigatorWidgetVisibility(); updateNavigatorWidgetVisibility();
} }
void DolphinViewContainer::showMessage(const QString& msg, MessageType type) KMessageWidget *DolphinViewContainer::showMessage(const QString& msg, MessageType type)
{ {
if (msg.isEmpty()) { if (msg.isEmpty()) {
return; return m_messageWidget;
}
for (auto action : m_messageWidget->actions()) {
m_messageWidget->removeAction(action);
} }
m_messageWidget->setText(msg); m_messageWidget->setText(msg);
...@@ -396,6 +399,7 @@ void DolphinViewContainer::showMessage(const QString& msg, MessageType type) ...@@ -396,6 +399,7 @@ void DolphinViewContainer::showMessage(const QString& msg, MessageType type)
m_messageWidget->hide(); m_messageWidget->hide();
} }
m_messageWidget->animatedShow(); m_messageWidget->animatedShow();
return m_messageWidget;
} }
void DolphinViewContainer::readSettings() void DolphinViewContainer::readSettings()
......
...@@ -140,8 +140,9 @@ public: ...@@ -140,8 +140,9 @@ public:
/** /**
* Shows the message \msg with the given type non-modal above * Shows the message \msg with the given type non-modal above
* the view-content. * the view-content.
* @return the KMessageWidget used to show the message
*/ */
void showMessage(const QString& msg, MessageType type); KMessageWidget *showMessage(const QString& msg, MessageType type);
/** /**
* Refreshes the view container to get synchronized with the (updated) Dolphin settings. * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment