]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Merge branch 'KDE/4.13'
[dolphin.git] / src / dolphinmainwindow.cpp
index d8973053c1ab13bbd96c8aeec1cd8b36cc488cd2..0ad224cbcae2760abcf1559557cbd9cbae4653d0 100644 (file)
@@ -31,7 +31,6 @@
 #include "panels/information/informationpanel.h"
 #include "settings/dolphinsettingsdialog.h"
 #include "statusbar/dolphinstatusbar.h"
-#include "views/dolphinview.h"
 #include "views/dolphinviewactionhandler.h"
 #include "views/dolphinremoteencoding.h"
 #include "views/draganddrophelper.h"
@@ -218,6 +217,7 @@ DolphinMainWindow::DolphinMainWindow() :
         toggleSplitView();
     }
     updateEditActions();
+    updatePasteAction();
     updateViewActions();
     updateGoActions();
 
@@ -248,20 +248,8 @@ void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
         return;
     }
 
-    // dirs could contain URLs that actually point to archives or other files.
-    // Replace them by URLs we can open where possible and filter the rest out.
-    QList<KUrl> urlsToOpen;
-    foreach (const KUrl& rawUrl, dirs) {
-        const KFileItem& item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, rawUrl);
-        item.determineMimeType();
-        const KUrl& url = DolphinView::openItemAsFolderUrl(item);
-        if (!url.isEmpty()) {
-            urlsToOpen.append(url);
-        }
-    }
-
-    if (urlsToOpen.count() == 1) {
-        m_activeViewContainer->setUrl(urlsToOpen.first());
+    if (dirs.count() == 1) {
+        m_activeViewContainer->setUrl(dirs.first());
         return;
     }
 
@@ -271,12 +259,12 @@ void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
 
     // Open each directory inside a new tab. If the "split view" option has been enabled,
     // always show two directories within one tab.
-    QList<KUrl>::const_iterator it = urlsToOpen.constBegin();
-    while (it != urlsToOpen.constEnd()) {
+    QList<KUrl>::const_iterator it = dirs.constBegin();
+    while (it != dirs.constEnd()) {
         openNewTab(*it);
         ++it;
 
-        if (hasSplitView && (it != urlsToOpen.constEnd())) {
+        if (hasSplitView && (it != dirs.constEnd())) {
             const int tabIndex = m_viewTab.count() - 1;
             m_viewTab[tabIndex].secondaryView->setUrl(*it);
             ++it;
@@ -369,6 +357,7 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
     if (view) {
         view->setUrl(url);
         updateEditActions();
+        updatePasteAction();
         updateViewActions();
         updateGoActions();
         setUrlAsCaption(url);
@@ -494,6 +483,8 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
     m_viewTab.append(viewTab);
 
     actionCollection()->action("close_tab")->setEnabled(true);
+    actionCollection()->action("activate_prev_tab")->setEnabled(true);
+    actionCollection()->action("activate_next_tab")->setEnabled(true);
 
     // Provide a split view, if the startup settings are set this way
     if (GeneralSettings::splitView()) {
@@ -690,6 +681,13 @@ void DolphinMainWindow::readProperties(const KConfigGroup& group)
                 Q_ASSERT(cont);
             }
 
+            // The right view must be activated before the URL is set. Changing
+            // the URL in the right view will emit the right URL navigator's
+            // urlChanged(KUrl) signal, which is connected to the changeUrl(KUrl)
+            // slot. That slot will change the URL in the left view if it is still
+            // active. See https://bugs.kde.org/show_bug.cgi?id=330047.
+            setActiveViewContainer(cont);
+
             cont->setUrl(secondaryUrl);
             const bool editable = group.readEntry(tabProperty("Secondary Editable", i), false);
             cont->urlNavigator()->setUrlEditable(editable);
@@ -1161,6 +1159,8 @@ void DolphinMainWindow::closeTab(int index)
     if (m_viewTab.count() == 1) {
         m_tabBar->removeTab(0);
         actionCollection()->action("close_tab")->setEnabled(false);
+        actionCollection()->action("activate_prev_tab")->setEnabled(false);
+        actionCollection()->action("activate_next_tab")->setEnabled(false);
     } else {
         m_tabBar->blockSignals(false);
     }
@@ -1421,6 +1421,19 @@ void DolphinMainWindow::slotPanelErrorMessage(const QString& error)
     activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
 }
 
+void DolphinMainWindow::slotPlaceActivated(const KUrl& url)
+{
+    DolphinViewContainer* view = activeViewContainer();
+
+    if (view->url() == url) {
+        // We can end up here if the user clicked a device in the Places Panel
+        // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
+        reloadView();
+    } else {
+        changeUrl(url);
+    }
+}
+
 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
 {
     Q_ASSERT(viewContainer);
@@ -1444,6 +1457,7 @@ void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContain
 
     updateHistory();
     updateEditActions();
+    updatePasteAction();
     updateViewActions();
     updateGoActions();
 
@@ -1626,12 +1640,16 @@ void DolphinMainWindow::setupActions()
     prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
 
     KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
+    activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
     activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
+    activateNextTab->setEnabled(false);
     connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
     activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
 
     KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
+    activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
     activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
+    activatePrevTab->setEnabled(false);
     connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
     activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
 
@@ -1753,7 +1771,7 @@ void DolphinMainWindow::setupDockWidgets()
 
     addDockWidget(Qt::LeftDockWidgetArea, placesDock);
     connect(placesPanel, SIGNAL(placeActivated(KUrl)),
-            this, SLOT(changeUrl(KUrl)));
+            this, SLOT(slotPlaceActivated(KUrl)));
     connect(placesPanel, SIGNAL(placeMiddleClicked(KUrl)),
             this, SLOT(openNewTab(KUrl)));
     connect(placesPanel, SIGNAL(errorMessage(QString)),
@@ -1804,7 +1822,6 @@ void DolphinMainWindow::updateEditActions()
         deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
         cutAction->setEnabled(capabilities.supportsMoving());
     }
-    updatePasteAction();
 }
 
 void DolphinMainWindow::updateViewActions()