]> cloud.milkyroute.net Git - dolphin.git/commitdiff
when clicking with the middle mouse button on a directory, a new tab should be opened
authorPeter Penz <peter.penz19@gmail.com>
Sat, 12 Apr 2008 16:12:57 +0000 (16:12 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 12 Apr 2008 16:12:57 +0000 (16:12 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=796116

src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinview.cpp
src/dolphinview.h

index a0aa1d895ddda92e95c428fd8b9c8dd0b467dbe4..7dd6133f0f8ac8f4c27de0a0d02ee2c513a9f707 100644 (file)
 
 #include <kdirmodel.h>
 #include <QAbstractProxyModel>
+#include <QApplication>
 
 DolphinController::DolphinController(DolphinView* dolphinView) :
     QObject(dolphinView),
     m_zoomInPossible(false),
     m_zoomOutPossible(false),
+    m_openTab(false),
     m_url(),
     m_dolphinView(dolphinView),
     m_itemView(0)
@@ -46,7 +48,16 @@ void DolphinController::setUrl(const KUrl& url)
 
 void DolphinController::setItemView(QAbstractItemView* view)
 {
+    if (m_itemView != 0) {
+        disconnect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
+                   this, SLOT(updateOpenTabState()));
+    }
+
     m_itemView = view;
+
+    // TODO: this is a workaround until  Qt-issue 176832 has been fixed
+    connect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
+            this, SLOT(updateOpenTabState()));
 }
 
 void DolphinController::triggerUrlChangeRequest(const KUrl& url)
@@ -134,12 +145,21 @@ KFileItem DolphinController::itemForIndex(const QModelIndex& index) const
 
 void DolphinController::triggerItem(const QModelIndex& index)
 {
+    const bool openTab = m_openTab;
+    m_openTab = false;
+
     const KFileItem item = itemForIndex(index);
     if (index.isValid() && (index.column() == KDirModel::Name)) {
-        emit itemTriggered(item);
+        if (openTab && item.isDir()) {
+            emit tabRequested(item.url());
+        } else {
+            emit itemTriggered(item);
+        }
     } else {
         m_itemView->clearSelection();
-        emit itemEntered(item);
+        if (!openTab) {
+            emit itemEntered(item);
+        }
     }
 }
 
@@ -156,4 +176,9 @@ void DolphinController::emitViewportEntered()
     emit viewportEntered();
 }
 
+void DolphinController::updateOpenTabState()
+{
+    m_openTab = QApplication::mouseButtons() & Qt::MidButton;
+}
+
 #include "dolphincontroller.moc"
index 9703e5f1b85823673d9a74e13b67e8499006a6f7..191bd1e6339d6bd1c1d329b34a3ef52189159257 100644 (file)
@@ -324,6 +324,11 @@ signals:
      */
     void itemEntered(const KFileItem& item);
 
+    /**
+     * Is emitted if a new tab should be opened for the URL \a url.
+     */
+    void tabRequested(const KUrl& url);
+
     /**
      * Is emitted if the mouse cursor has entered
      * the viewport (see emitViewportEntered().
@@ -343,9 +348,13 @@ signals:
      */
     void zoomOut();
 
+private slots:
+    void updateOpenTabState();
+
 private:
     bool m_zoomInPossible;
     bool m_zoomOutPossible;
+    bool m_openTab; // TODO: this is a workaround until  Qt-issue 176832 has been fixed
     KUrl m_url;
     DolphinView* m_dolphinView;
     QAbstractItemView* m_itemView;
index 623634f9e5851289914e9e1860ca9617b88a53d8..84d22ec4fa00c6fbe68901416df5af97a372fea7 100644 (file)
@@ -262,6 +262,25 @@ void DolphinMainWindow::openNewTab()
     m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
 }
 
+void DolphinMainWindow::openNewTab(const KUrl& url)
+{
+    if (m_viewTab.count() == 1) {
+        // Only one view is open currently and hence no tab is shown at
+        // all. Before creating a tab for 'url', provide a tab for the current URL.
+        m_tabBar->addTab(KIcon("folder"), m_activeViewContainer->url().fileName());
+    }
+
+    m_tabBar->addTab(KIcon("folder"), url.fileName());
+
+    ViewTab viewTab;
+    viewTab.splitter = new QSplitter(this);
+    viewTab.primaryView = new DolphinViewContainer(this, viewTab.splitter, url);
+    connectViewSignals(viewTab.primaryView);
+    viewTab.primaryView->view()->reload();
+
+    m_viewTab.append(viewTab);
+}
+
 void DolphinMainWindow::toggleActiveView()
 {
     if (m_viewTab[m_tabIndex].secondaryView == 0) {
@@ -1058,6 +1077,8 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
             this, SLOT(toggleActiveView()));
     connect(view, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
             this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType)));
+    connect(view, SIGNAL(tabRequested(const KUrl&)),
+            this, SLOT(openNewTab(const KUrl&)));
 
     const KUrlNavigator* navigator = container->urlNavigator();
     connect(navigator, SIGNAL(urlChanged(const KUrl&)),
@@ -1085,25 +1106,6 @@ void DolphinMainWindow::updateSplitAction()
     }
 }
 
-void DolphinMainWindow::openNewTab(const KUrl& url)
-{
-    if (m_viewTab.count() == 1) {
-        // Only one view is open currently and hence no tab is shown at
-        // all. Before creating a tab for 'url', provide a tab for the current URL.
-        m_tabBar->addTab(KIcon("folder"), m_activeViewContainer->url().fileName());
-    }
-
-    m_tabBar->addTab(KIcon("folder"), url.fileName());
-
-    ViewTab viewTab;
-    viewTab.splitter = new QSplitter(this);
-    viewTab.primaryView = new DolphinViewContainer(this, viewTab.splitter, url);
-    connectViewSignals(viewTab.primaryView);
-    viewTab.primaryView->view()->reload();
-
-    m_viewTab.append(viewTab);
-}
-
 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
     KonqFileUndoManager::UiInterface(mainWin),
     m_mainWin(mainWin)
index 5a50f3dbf4cf224ece240787b37847eca004c9b6..2eb282af5353390c315722983d4d8ae6e27dd13f 100644 (file)
@@ -311,9 +311,14 @@ private slots:
     /** Open a new main window. */
     void openNewMainWindow();
 
-    /** Opens a new empty view that is part of a tab. */
+    /** Opens a new view with the current URL that is part of a tab. */
     void openNewTab();
 
+    /**
+     * Opens a new tab showing the URL \a url.
+     */
+    void openNewTab(const KUrl& url);
+
     /** Toggles the active view if two views are shown within the main window. */
     void toggleActiveView();
 
@@ -360,11 +365,6 @@ private:
      */
     void updateSplitAction();
 
-    /**
-     * Opens a new tab showing the URL \a url.
-     */
-    void openNewTab(const KUrl& url);
-
 private:
     /**
      * Implements a custom error handling for the undo manager. This
index a31b67e12b7b62389504dec801f24f5a6ec479f9..d87571c7e79e2e173694fee1ba1851c2f7f29a75 100644 (file)
@@ -114,6 +114,8 @@ DolphinView::DolphinView(QWidget* parent,
             this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList&)));
     connect(m_controller, SIGNAL(itemTriggered(const KFileItem&)),
             this, SLOT(triggerItem(const KFileItem&)));
+    connect(m_controller, SIGNAL(tabRequested(const KUrl&)),
+            this, SIGNAL(tabRequested(const KUrl&)));
     connect(m_controller, SIGNAL(activated()),
             this, SLOT(activate()));
     connect(m_controller, SIGNAL(itemEntered(const KFileItem&)),
index 4ec1f42c8ac1be909118997b898572dc5aa2a0af..048486354b18ff5e684d0b2f361575c83ee0960c 100644 (file)
@@ -412,10 +412,15 @@ signals:
     void urlChanged(const KUrl& url);
 
     /**
-     * Is emitted when clicking on an item
+     * Is emitted when clicking on an item with the left mouse button.
      */
     void itemTriggered(const KFileItem& item);
 
+    /**
+     * Is emitted if a new tab should be opened for the URL \a url.
+     */
+    void tabRequested(const KUrl& url);
+
     /**
      * Is emitted if the view mode (IconsView, DetailsView,
      * PreviewsView) has been changed.