]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Fix keyboard navigation issue when Home or End are pressed
[dolphin.git] / src / dolphinmainwindow.cpp
index 203d3249a7c4732663c4dc145adefc5c9b96c982..074185f49764f25461c6f2bd0680ac9942eeb42f 100644 (file)
@@ -41,6 +41,7 @@
 #include "statusbar/dolphinstatusbar.h"
 #include "views/dolphinviewactionhandler.h"
 #include "views/dolphinremoteencoding.h"
+#include "views/draganddrophelper.h"
 #include "views/viewproperties.h"
 
 #ifndef Q_OS_WIN
@@ -156,6 +157,8 @@ DolphinMainWindow::DolphinMainWindow() :
     setObjectName("Dolphin#");
 
     m_viewTab.append(ViewTab());
+    ViewTab& viewTab = m_viewTab[m_tabIndex];
+    viewTab.wasActive = true; // The first opened tab is automatically active
 
     KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
     undoManager->setUiInterface(new UndoUiInterface());
@@ -177,8 +180,8 @@ DolphinMainWindow::DolphinMainWindow() :
 
     setAcceptDrops(true);
 
-    m_viewTab[m_tabIndex].splitter = new QSplitter(this);
-    m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
+    viewTab.splitter = new QSplitter(this);
+    viewTab.splitter->setChildrenCollapsible(false);
 
     setupActions();
 
@@ -188,9 +191,9 @@ DolphinMainWindow::DolphinMainWindow() :
     connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
     connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
 
-    m_viewTab[m_tabIndex].primaryView = createViewContainer(homeUrl, m_viewTab[m_tabIndex].splitter);
+    viewTab.primaryView = createViewContainer(homeUrl, viewTab.splitter);
 
-    m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
+    m_activeViewContainer = viewTab.primaryView;
     connectViewSignals(m_activeViewContainer);
     DolphinView* view = m_activeViewContainer->view();
     m_activeViewContainer->show();
@@ -227,7 +230,7 @@ DolphinMainWindow::DolphinMainWindow() :
     m_centralWidgetLayout->setSpacing(0);
     m_centralWidgetLayout->setMargin(0);
     m_centralWidgetLayout->addWidget(m_tabBar);
-    m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
+    m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
 
     setCentralWidget(centralWidget);
     setupDockWidgets();
@@ -504,16 +507,16 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
     viewTab.primaryView->setActive(false);
     connectViewSignals(viewTab.primaryView);
 
-    const int newTabIndex = m_viewTab.count();
     m_viewTab.append(viewTab);
 
     actionCollection()->action("close_tab")->setEnabled(true);
 
-    // provide a split view, if the startup settings are set this way
+    // Provide a split view, if the startup settings are set this way
     if (GeneralSettings::splitView()) {
+        const int newTabIndex = m_viewTab.count() - 1;
         createSecondaryView(newTabIndex);
-        viewTab.secondaryView->setActive(true);
-        viewTab.isPrimaryViewActive = false;
+        m_viewTab[newTabIndex].secondaryView->setActive(true);
+        m_viewTab[newTabIndex].isPrimaryViewActive = false;
     }
 
     if (focusWidget) {
@@ -521,14 +524,6 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
         // in background, assure that the previous focused widget gets the focus back.
         focusWidget->setFocus();
     }
-
-    // TODO: Temporary switching to the new tab is a workaround/hack to prevent that
-    // the KItemListView from the DolphinView is initialized with a too small size.
-    // The small size results in an unwanted animation of the items when showing the
-    // tab the first time, as the KItemListView size will be adjusted on-the-fly.
-    const int currentTabIndex = m_tabIndex;
-    m_tabBar->setCurrentIndex(newTabIndex);
-    m_tabBar->setCurrentIndex(currentTabIndex);
 }
 
 void DolphinMainWindow::activateNextTab()
@@ -1030,6 +1025,14 @@ void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
     }
 }
 
+void DolphinMainWindow::goHome(Qt::MouseButtons buttons)
+{
+    // The default case (left button pressed) is handled in goHome().
+    if (buttons == Qt::MidButton) {
+        openNewTab(GeneralSettings::self()->homeUrl());
+    }
+}
+
 void DolphinMainWindow::compareFiles()
 {
     // The method is only invoked if exactly 2 files have
@@ -1115,7 +1118,10 @@ void DolphinMainWindow::openTerminal()
 void DolphinMainWindow::editSettings()
 {
     if (!m_settingsDialog) {
-        const KUrl url = activeViewContainer()->url();
+        DolphinViewContainer* container = activeViewContainer();
+        container->view()->writeSettings();
+        
+        const KUrl url = container->url();
         DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
         connect(settingsDialog, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
         settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
@@ -1156,6 +1162,18 @@ void DolphinMainWindow::setActiveTab(int index)
     }
     viewTab.splitter->show();
 
+    if (!viewTab.wasActive) {
+        viewTab.wasActive = true;
+
+        // If the tab has not been activated yet the size of the KItemListView is
+        // undefined and results in an unwanted animation. To prevent this a
+        // reloading of the directory gets triggered.
+        viewTab.primaryView->view()->reload();
+        if (viewTab.secondaryView) {
+            viewTab.secondaryView->view()->reload();
+        }
+    }
+
     setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
                                                          viewTab.secondaryView);
 }
@@ -1313,9 +1331,9 @@ void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
     const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
     if (!urls.isEmpty() && tab != -1) {
         const ViewTab& viewTab = m_viewTab[tab];
-        const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
-        Q_UNUSED(destPath);
-        //DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
+        const DolphinView* view = viewTab.isPrimaryViewActive ? viewTab.primaryView->view()
+                                                              : viewTab.secondaryView->view();
+        DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event);
     }
 }
 
@@ -1684,7 +1702,8 @@ void DolphinMainWindow::setupActions()
     KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
     connect(upAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
 
-    KStandardAction::home(this, SLOT(goHome()), actionCollection());
+    KAction* homeAction = KStandardAction::home(this, SLOT(goHome()), actionCollection());
+    connect(homeAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goHome(Qt::MouseButtons)));
 
     // setup 'Tools' menu
     KAction* showFilterBar = actionCollection()->addAction("show_filter_bar");
@@ -2050,9 +2069,9 @@ void DolphinMainWindow::refreshViews()
 
     const int tabCount = m_viewTab.count();
     for (int i = 0; i < tabCount; ++i) {
-        m_viewTab[i].primaryView->refresh();
+        m_viewTab[i].primaryView->readSettings();
         if (m_viewTab[i].secondaryView) {
-            m_viewTab[i].secondaryView->refresh();
+            m_viewTab[i].secondaryView->readSettings();
         }
     }