From: Peter Penz Date: Sat, 12 Apr 2008 16:12:57 +0000 (+0000) Subject: when clicking with the middle mouse button on a directory, a new tab should be opened X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/030a5d5433e0ae613f4de32d9d1277ac2405b8f4 when clicking with the middle mouse button on a directory, a new tab should be opened svn path=/trunk/KDE/kdebase/apps/; revision=796116 --- diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index a0aa1d895..7dd6133f0 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -21,11 +21,13 @@ #include #include +#include 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" diff --git a/src/dolphincontroller.h b/src/dolphincontroller.h index 9703e5f1b..191bd1e63 100644 --- a/src/dolphincontroller.h +++ b/src/dolphincontroller.h @@ -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; diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 623634f9e..84d22ec4f 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -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) diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 5a50f3dbf..2eb282af5 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -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 diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index a31b67e12..d87571c7e 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -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&)), diff --git a/src/dolphinview.h b/src/dolphinview.h index 4ec1f42c8..048486354 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -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.