X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/7cb193de1074e226b6fb3fe0f71da577b54f3589..ec6d53e70e01aaa4fe25ab78622631cd9105e3c8:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index db4ad0765..d321d3b4a 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -26,6 +26,7 @@ #include "dolphincontextmenu.h" #include "dolphinnewfilemenu.h" #include "dolphinrecenttabsmenu.h" +#include "dolphintabbar.h" #include "dolphinviewcontainer.h" #include "dolphintabpage.h" #include "panels/folders/folderspanel.h" @@ -75,7 +76,6 @@ #include #include #include -#include #include #include #include @@ -144,25 +144,19 @@ DolphinMainWindow::DolphinMainWindow() : connect(this, SIGNAL(urlChanged(KUrl)), m_remoteEncoding, SLOT(slotAboutToOpenUrl())); - m_tabBar = new KTabBar(this); - m_tabBar->setMovable(true); - m_tabBar->setTabsClosable(true); + m_tabBar = new DolphinTabBar(this); connect(m_tabBar, SIGNAL(currentChanged(int)), this, SLOT(setActiveTab(int))); connect(m_tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); - connect(m_tabBar, SIGNAL(contextMenu(int,QPoint)), - this, SLOT(openTabContextMenu(int,QPoint))); - connect(m_tabBar, SIGNAL(newTabRequest()), - this, SLOT(openNewTab())); - connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*,bool&)), - this, SLOT(slotTestCanDecode(const QDragMoveEvent*,bool&))); - connect(m_tabBar, SIGNAL(mouseMiddleClick(int)), - this, SLOT(closeTab(int))); + connect(m_tabBar, SIGNAL(openNewActivatedTab(int)), + this, SLOT(openNewActivatedTab(int))); connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(slotTabMoved(int,int))); - connect(m_tabBar, SIGNAL(receivedDropEvent(int,QDropEvent*)), + connect(m_tabBar, SIGNAL(tabDropEvent(int,QDropEvent*)), this, SLOT(tabDropEvent(int,QDropEvent*))); + connect(m_tabBar, SIGNAL(tabDetachRequested(int)), + this, SLOT(detachTab(int))); m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open m_tabBar->hide(); @@ -443,6 +437,13 @@ void DolphinMainWindow::openNewActivatedTab(const KUrl& primaryUrl, const KUrl& setActiveTab(m_viewTab.count() - 1); } +void DolphinMainWindow::openNewActivatedTab(int index) +{ + Q_ASSERT(index >= 0); + const DolphinTabPage* tabPage = m_viewTab.at(index); + openNewActivatedTab(tabPage->activeViewContainer()->url()); +} + void DolphinMainWindow::activateNextTab() { if (m_viewTab.count() >= 2) { @@ -982,50 +983,23 @@ void DolphinMainWindow::closeTab(int index) } } -void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos) +void DolphinMainWindow::detachTab(int index) { - KMenu menu(this); - - QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab")); - newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut()); - - QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab")); - - QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs")); - - QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab")); - closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut()); - QAction* selectedAction = menu.exec(pos); - if (selectedAction == newTabAction) { - const KUrl url = m_viewTab.at(index)->activeViewContainer()->url(); - openNewTab(url); - m_tabBar->setCurrentIndex(m_viewTab.count() - 1); - } else if (selectedAction == detachTabAction) { - const QString separator(QLatin1Char(' ')); - QString command = QLatin1String("dolphin"); + Q_ASSERT(index >= 0); - const DolphinTabPage* tabPage = m_viewTab.at(index); + const QString separator(QLatin1Char(' ')); + QString command = QLatin1String("dolphin"); - command += separator + tabPage->primaryViewContainer()->url().url(); - if (tabPage->splitViewEnabled()) { - command += separator + tabPage->secondaryViewContainer()->url().url(); - command += separator + QLatin1String("-split"); - } + const DolphinTabPage* tabPage = m_viewTab.at(index); + command += separator + tabPage->primaryViewContainer()->url().url(); + if (tabPage->splitViewEnabled()) { + command += separator + tabPage->secondaryViewContainer()->url().url(); + command += separator + QLatin1String("-split"); + } - KRun::runCommand(command, this); + KRun::runCommand(command, this); - closeTab(index); - } else if (selectedAction == closeOtherTabsAction) { - const int count = m_tabBar->count(); - for (int i = 0; i < index; ++i) { - closeTab(0); - } - for (int i = index + 1; i < count; ++i) { - closeTab(1); - } - } else if (selectedAction == closeTabAction) { - closeTab(index); - } + closeTab(index); } void DolphinMainWindow::slotTabMoved(int from, int to) @@ -1034,11 +1008,6 @@ void DolphinMainWindow::slotTabMoved(int from, int to) m_tabIndex = m_tabBar->currentIndex(); } -void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode) -{ - canDecode = KUrl::List::canDecode(event->mimeData()); -} - void DolphinMainWindow::handleUrl(const KUrl& url) { delete m_lastHandleUrlStatJob; @@ -1251,6 +1220,11 @@ void DolphinMainWindow::activeViewChanged() setActiveViewContainer(tabPage->activeViewContainer()); } +void DolphinMainWindow::closedTabsCountChanged(unsigned int count) +{ + actionCollection()->action("undo_close_tab")->setEnabled(count > 0); +} + void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer) { Q_ASSERT(viewContainer); @@ -1381,6 +1355,15 @@ void DolphinMainWindow::setupActions() recentTabsMenu, SLOT(rememberClosedTab(KUrl,KUrl))); connect(recentTabsMenu, SIGNAL(restoreClosedTab(KUrl,KUrl)), this, SLOT(openNewActivatedTab(KUrl,KUrl))); + connect(recentTabsMenu, SIGNAL(closedTabsCountChanged(uint)), + this, SLOT(closedTabsCountChanged(uint))); + + KAction* undoCloseTab = actionCollection()->addAction("undo_close_tab"); + undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab")); + undoCloseTab->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_T); + undoCloseTab->setIcon(KIcon("edit-undo")); + undoCloseTab->setEnabled(false); + connect(undoCloseTab, SIGNAL(triggered()), recentTabsMenu, SLOT(undoCloseTab())); KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection()); connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));