]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Fix scrolling during inline renaming causes rename of wrong file
[dolphin.git] / src / dolphinmainwindow.cpp
index ff834700bf0bab311ed1f6c24b1f2cda1123c43f..c35de766ccfd717df002025fc61e0df653b65ea3 100644 (file)
@@ -62,6 +62,7 @@
 #include <KProtocolInfo>
 #include <QMenu>
 #include <KMessageBox>
+#include <KFilePlacesModel>
 #include <KFileItemListProperties>
 #include <KRun>
 #include <KShell>
@@ -98,7 +99,12 @@ DolphinMainWindow::DolphinMainWindow() :
     m_settingsDialog(),
     m_controlButton(0),
     m_updateToolBarTimer(0),
-    m_lastHandleUrlStatJob(0)
+    m_lastHandleUrlStatJob(0),
+#ifndef Q_OS_WIN
+    m_terminalPanel(0),
+#endif
+    m_placesPanel(0),
+    m_tearDownFromPlacesRequested(false)
 {
     Q_INIT_RESOURCE(dolphin);
 
@@ -246,6 +252,11 @@ void DolphinMainWindow::changeUrl(const QUrl &url)
 
 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl& url)
 {
+    if (m_tearDownFromPlacesRequested && url == QUrl::fromLocalFile(QDir::homePath())) {
+        m_placesPanel->proceedWithTearDown();
+        m_tearDownFromPlacesRequested = false;
+    }
+
     m_activeViewContainer->setAutoGrabFocus(false);
     changeUrl(url);
     m_activeViewContainer->setAutoGrabFocus(true);
@@ -962,26 +973,58 @@ void DolphinMainWindow::tabCountChanged(int count)
 
 void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
 {
-    QString caption;
+    static KFilePlacesModel s_placesModel;
+
+    QString schemePrefix;
     if (!url.isLocalFile()) {
-        caption.append(url.scheme() + " - ");
+        schemePrefix.append(url.scheme() + " - ");
         if (!url.host().isEmpty()) {
-            caption.append(url.host() + " - ");
+            schemePrefix.append(url.host() + " - ");
         }
     }
 
     if (GeneralSettings::showFullPathInTitlebar()) {
         const QString path = url.adjusted(QUrl::StripTrailingSlash).path();
-        caption.append(path);
+        setWindowTitle(schemePrefix + path);
+        return;
+    }
+
+    const auto& matchedPlaces = s_placesModel.match(s_placesModel.index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
+
+    if (!matchedPlaces.isEmpty()) {
+        setWindowTitle(s_placesModel.text(matchedPlaces.first()));
+        return;
+    }
+
+    QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName();
+    if (fileName.isEmpty()) {
+        fileName = '/';
+    }
+
+    setWindowTitle(schemePrefix + fileName);
+}
+
+void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
+{
+#ifndef Q_OS_WIN
+    if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
+        m_tearDownFromPlacesRequested = true;
+        m_terminalPanel->goHome();
+        // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
     } else {
-        QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName();
-        if (fileName.isEmpty()) {
-            fileName = '/';
-        }
-        caption.append(fileName);
+        m_placesPanel->proceedWithTearDown();
     }
+#endif
+}
 
-    setWindowTitle(caption);
+void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath)
+{
+#ifndef Q_OS_WIN
+    if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
+        m_tearDownFromPlacesRequested = false;
+        m_terminalPanel->goHome();
+    }
+#endif
 }
 
 void DolphinMainWindow::setupActions()
@@ -1053,7 +1096,7 @@ void DolphinMainWindow::setupActions()
     actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
     stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
     stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
-    stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-visiting")));
+    stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
     stashSplit->setCheckable(false);
     stashSplit->setVisible(KProtocolInfo::isKnownProtocol("stash"));
     connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
@@ -1236,21 +1279,21 @@ void DolphinMainWindow::setupDockWidgets()
         terminalDock->setLocked(lock);
         terminalDock->setObjectName(QStringLiteral("terminalDock"));
         terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
-        TerminalPanel* terminalPanel = new TerminalPanel(terminalDock);
-        terminalPanel->setCustomContextMenuActions({lockLayoutAction});
-        terminalDock->setWidget(terminalPanel);
+        m_terminalPanel = new TerminalPanel(terminalDock);
+        m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
+        terminalDock->setWidget(m_terminalPanel);
 
-        connect(terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
-        connect(terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
+        connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
+        connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
         connect(terminalDock, &DolphinDockWidget::visibilityChanged,
-                terminalPanel, &TerminalPanel::dockVisibilityChanged);
+                m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
 
         QAction* terminalAction = terminalDock->toggleViewAction();
         createPanelAction(QIcon::fromTheme(QStringLiteral("utilities-terminal")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel"));
 
         addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
         connect(this, &DolphinMainWindow::urlChanged,
-                terminalPanel, &TerminalPanel::setUrl);
+                m_terminalPanel, &TerminalPanel::setUrl);
 
         if (GeneralSettings::version() < 200) {
             terminalDock->hide();
@@ -1269,28 +1312,31 @@ void DolphinMainWindow::setupDockWidgets()
     placesDock->setObjectName(QStringLiteral("placesDock"));
     placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
 
-    PlacesPanel* placesPanel = new PlacesPanel(placesDock);
-    placesPanel->setCustomContextMenuActions({lockLayoutAction});
-    placesDock->setWidget(placesPanel);
+    m_placesPanel = new PlacesPanel(placesDock);
+    m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
+    placesDock->setWidget(m_placesPanel);
 
-    QActionplacesAction = placesDock->toggleViewAction();
+    QAction *placesAction = placesDock->toggleViewAction();
     createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel"));
 
     addDockWidget(Qt::LeftDockWidgetArea, placesDock);
-    connect(placesPanel, &PlacesPanel::placeActivated,
+    connect(m_placesPanel, &PlacesPanel::placeActivated,
             this, &DolphinMainWindow::slotPlaceActivated);
-    connect(placesPanel, &PlacesPanel::placeMiddleClicked,
+    connect(m_placesPanel, &PlacesPanel::placeMiddleClicked,
             this, &DolphinMainWindow::openNewTab);
-    connect(placesPanel, &PlacesPanel::errorMessage,
+    connect(m_placesPanel, &PlacesPanel::errorMessage,
             this, &DolphinMainWindow::showErrorMessage);
     connect(this, &DolphinMainWindow::urlChanged,
-            placesPanel, &PlacesPanel::setUrl);
+            m_placesPanel, &PlacesPanel::setUrl);
     connect(placesDock, &DolphinDockWidget::visibilityChanged,
             m_tabWidget, &DolphinTabWidget::slotPlacesPanelVisibilityChanged);
     connect(this, &DolphinMainWindow::settingsChanged,
-           placesPanel, &PlacesPanel::readSettings);
-
-    m_tabWidget->slotPlacesPanelVisibilityChanged(placesPanel->isVisible());
+        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());
 
     // Add actions into the "Panels" menu
     KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);