X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/5cec8a2dd95d6ccbc0d425c449df70cd645e3d29..26a75802ebcd74dc9182ff8f2ef9acf8319e0037:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 697fba85f..0151d48b1 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -78,6 +78,7 @@ #include #include #include +#include #include #include @@ -85,6 +86,20 @@ #include #include #include +#include + +/* + * Remembers the tab configuration if a tab has been closed. + * Each closed tab can be restored by the menu + * "Go -> Recently Closed Tabs". + */ +struct ClosedTab +{ + KUrl primaryUrl; + KUrl secondaryUrl; + bool isSplit; +}; +Q_DECLARE_METATYPE(ClosedTab) DolphinMainWindow::DolphinMainWindow(int id) : KXmlGuiWindow(0), @@ -223,6 +238,8 @@ void DolphinMainWindow::changeUrl(const KUrl& url) if (m_viewTab.count() > 1) { m_tabBar->setTabText(m_tabIndex, tabName(url)); } + const QString iconName = KMimeType::iconNameForUrl(url); + m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName)); emit urlChanged(url); } } @@ -256,11 +273,6 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) compareFilesAction->setEnabled(false); } -#if defined(QUICK_VIEW) - const bool activeViewHasSelection = (activeViewContainer()->view()->selectedItemsCount() > 0); - actionCollection()->action("quick_view")->setEnabled(activeViewHasSelection); -#endif - m_activeViewContainer->updateStatusBar(); emit selectionChanged(selection); @@ -322,14 +334,15 @@ void DolphinMainWindow::openNewTab() void DolphinMainWindow::openNewTab(const KUrl& url) { + const KIcon icon = KIcon(KMimeType::iconNameForUrl(m_activeViewContainer->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"), tabName(m_activeViewContainer->url())); + m_tabBar->addTab(icon, tabName(m_activeViewContainer->url())); m_tabBar->blockSignals(false); } - m_tabBar->addTab(KIcon("folder"), tabName(url)); + m_tabBar->addTab(icon, tabName(url)); ViewTab viewTab; viewTab.splitter = new QSplitter(this); @@ -354,7 +367,7 @@ void DolphinMainWindow::openNewTab(const KUrl& url) void DolphinMainWindow::activateNextTab() { - if (m_viewTab.count() == 1 || m_tabBar->count() < 2) { + if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) { return; } @@ -364,7 +377,7 @@ void DolphinMainWindow::activateNextTab() void DolphinMainWindow::activatePrevTab() { - if (m_viewTab.count() == 1 || m_tabBar->count() < 2) { + if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) { return; } @@ -490,6 +503,35 @@ void DolphinMainWindow::slotUndoAvailable(bool available) } } +void DolphinMainWindow::restoreClosedTab(QAction* action) +{ + if (action->data().toBool()) { + // clear all actions except the "Empty Recently Closed Tabs" + // action and the separator + QList actions = m_recentTabsMenu->menu()->actions(); + const int count = actions.size(); + for (int i = 2; i < count; ++i) { + m_recentTabsMenu->menu()->removeAction(actions.at(i)); + } + } else { + const ClosedTab closedTab = action->data().value(); + openNewTab(closedTab.primaryUrl); + m_tabBar->setCurrentIndex(m_viewTab.count() - 1); + + if (closedTab.isSplit) { + // create secondary view + toggleSplitView(); + m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl); + } + + m_recentTabsMenu->removeAction(action); + } + + if (m_recentTabsMenu->menu()->actions().count() == 2) { + m_recentTabsMenu->setEnabled(false); + } +} + void DolphinMainWindow::slotUndoTextChanged(const QString& text) { QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo)); @@ -695,24 +737,17 @@ void DolphinMainWindow::compareFiles() KRun::runCommand(command, "Kompare", "kompare", this); } -void DolphinMainWindow::quickView() -{ - const KUrl::List urls = activeViewContainer()->view()->selectedUrls(); - Q_ASSERT(urls.count() > 0); - - QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.plasma", "/Previewer", "", "openFile"); - foreach (const KUrl& url, urls) { - msg.setArguments(QList() << url.prettyUrl()); - QDBusConnection::sessionBus().send(msg); - } -} - void DolphinMainWindow::toggleShowMenuBar() { const bool visible = menuBar()->isVisible(); menuBar()->setVisible(!visible); } +void DolphinMainWindow::openTerminal() +{ + KToolInvocation::invokeTerminal(QString(), m_activeViewContainer->url().path()); +} + void DolphinMainWindow::editSettings() { if (m_settingsDialog == 0) { @@ -769,7 +804,7 @@ void DolphinMainWindow::closeTab(int index) Q_ASSERT(index >= 0); Q_ASSERT(index < m_viewTab.count()); if (m_viewTab.count() == 1) { - // the last tab may never get closed + // the last tab may never get closed return; } @@ -778,6 +813,7 @@ void DolphinMainWindow::closeTab(int index) // previous tab before closing the tab. m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1); } + rememberClosedTab(index); // delete tab m_viewTab[index].primaryView->deleteLater(); @@ -816,7 +852,6 @@ void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos) 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 ViewTab& tab = m_viewTab[index]; @@ -858,7 +893,6 @@ void DolphinMainWindow::searchItems(const KUrl& url) m_activeViewContainer->setUrl(url); } - void DolphinMainWindow::init() { DolphinSettings& settings = DolphinSettings::instance(); @@ -894,10 +928,11 @@ void DolphinMainWindow::init() m_actionHandler->setCurrentView(view); m_tabBar = new KTabBar(this); - m_tabBar->setCloseButtonEnabled(true); + m_tabBar->setMovable(true); + m_tabBar->setTabsClosable(true); connect(m_tabBar, SIGNAL(currentChanged(int)), this, SLOT(setActiveTab(int))); - connect(m_tabBar, SIGNAL(closeRequest(int)), + connect(m_tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)), this, SLOT(openTabContextMenu(int, const QPoint&))); @@ -980,8 +1015,9 @@ void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContain const KUrl& url = m_activeViewContainer->url(); setCaption(url.fileName()); - if (m_viewTab.count() > 1) { + if (m_viewTab.count() > 1 && m_viewTab[m_tabIndex].secondaryView != 0) { m_tabBar->setTabText(m_tabIndex, tabName(url)); + m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url))); } emit urlChanged(url); @@ -1009,7 +1045,7 @@ void DolphinMainWindow::setupActions() newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N)); connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab())); - QAction* closeTab = actionCollection()->addAction("close_tab"); + KAction* closeTab = actionCollection()->addAction("close_tab"); closeTab->setIcon(KIcon("tab-close")); closeTab->setText(i18nc("@action:inmenu File", "Close Tab")); closeTab->setShortcut(Qt::CTRL | Qt::Key_W); @@ -1077,6 +1113,19 @@ void DolphinMainWindow::setupActions() backShortcut.setAlternate(Qt::Key_Backspace); backAction->setShortcut(backShortcut); + m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this); + m_recentTabsMenu->setIcon(KIcon("edit-undo")); + actionCollection()->addAction("closed_tabs", m_recentTabsMenu); + connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)), + this, SLOT(restoreClosedTab(QAction *))); + + QAction* action = new QAction("Empty Recently Closed Tabs", m_recentTabsMenu); + action->setIcon(KIcon("edit-clear-list")); + action->setData(QVariant::fromValue(true)); + m_recentTabsMenu->addAction(action); + m_recentTabsMenu->addSeparator(); + m_recentTabsMenu->setEnabled(false); + KStandardAction::forward(this, SLOT(goForward()), actionCollection()); KStandardAction::up(this, SLOT(goUp()), actionCollection()); KStandardAction::home(this, SLOT(goHome()), actionCollection()); @@ -1098,15 +1147,11 @@ void DolphinMainWindow::setupActions() compareFiles->setEnabled(false); connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles())); - // disabled Quick View -#if defined(QUICK_VIEW) - KAction* quickView = actionCollection()->addAction("quick_view"); - quickView->setText(i18nc("@action:inmenu Tools", "Quick View")); - quickView->setIcon(KIcon("view-preview")); - quickView->setShortcut(Qt::CTRL + Qt::Key_Return); - quickView->setEnabled(false); - connect(quickView, SIGNAL(triggered()), this, SLOT(quickView())); -#endif + KAction* openTerminal = actionCollection()->addAction("open_terminal"); + openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal")); + openTerminal->setIcon(KIcon("terminal")); + openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4); + connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal())); // setup 'Settings' menu m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection()); @@ -1290,6 +1335,47 @@ void DolphinMainWindow::updateGoActions() goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); } +void DolphinMainWindow::rememberClosedTab(int index) +{ + KMenu* tabsMenu = m_recentTabsMenu->menu(); + + const QString primaryPath = m_viewTab[index].primaryView->url().path(); + const QString iconName = KMimeType::iconNameForUrl(primaryPath); + + const QFontMetrics fm = fontMetrics(); + const QString actionText = fm.elidedText(primaryPath, Qt::ElideMiddle, fm.maxWidth() * 20); + + QAction* action = new QAction(actionText, tabsMenu); + + ClosedTab closedTab; + closedTab.primaryUrl = m_viewTab[index].primaryView->url(); + + if (m_viewTab[index].secondaryView != 0) { + closedTab.secondaryUrl = m_viewTab[index].secondaryView->url(); + closedTab.isSplit = true; + } else { + closedTab.isSplit = false; + } + + action->setData(QVariant::fromValue(closedTab)); + action->setIcon(KIcon(iconName)); + + // add the closed tab menu entry after the separator and + // "Empty Recently Closed Tabs" entry + if (tabsMenu->actions().size() == 2) { + tabsMenu->addAction(action); + } else { + tabsMenu->insertAction(tabsMenu->actions().at(2), action); + } + + // assure that only up to 8 closed tabs are shown in the menu + if (tabsMenu->actions().size() > 8) { + tabsMenu->removeAction(tabsMenu->actions().last()); + } + actionCollection()->action("closed_tabs")->setEnabled(true); + KAcceleratorManager::manage(tabsMenu); +} + void DolphinMainWindow::clearStatusBar() { m_activeViewContainer->statusBar()->clear();