X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/78e9cc506f90eb862f032154199331b5e5e6dffb..26a75802ebcd74dc9182ff8f2ef9acf8319e0037:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 78e489915..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; } @@ -492,21 +505,21 @@ void DolphinMainWindow::slotUndoAvailable(bool available) void DolphinMainWindow::restoreClosedTab(QAction* action) { - //The Clear Recently Closed Tabs List QAction, has it's data set to true, so we can detect it in here, as it's an exception. - if (action->data().toBool() == true) { - // Lets preserve the separator, and the clear action within this menu. - QList actionlist = m_recentTabsMenu->menu()->actions(); - for (int i = 2; i < actionlist.size(); i++) { - m_recentTabsMenu->menu()->removeAction(actionlist.at(i)); + 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. + // create secondary view toggleSplitView(); m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl); } @@ -724,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) { @@ -798,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; } @@ -808,7 +814,8 @@ void DolphinMainWindow::closeTab(int index) m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1); } rememberClosedTab(index); - //Delete this tab. + + // delete tab m_viewTab[index].primaryView->deleteLater(); if (m_viewTab[index].secondaryView != 0) { m_viewTab[index].secondaryView->deleteLater(); @@ -845,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]; @@ -887,7 +893,6 @@ void DolphinMainWindow::searchItems(const KUrl& url) m_activeViewContainer->setUrl(url); } - void DolphinMainWindow::init() { DolphinSettings& settings = DolphinSettings::instance(); @@ -927,7 +932,7 @@ void DolphinMainWindow::init() 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&))); @@ -1010,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); @@ -1107,13 +1113,13 @@ void DolphinMainWindow::setupActions() backShortcut.setAlternate(Qt::Key_Backspace); backAction->setShortcut(backShortcut); - m_recentTabsMenu = new KActionMenu(i18n("&Recently Closed Tabs"), this); + 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); + 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); @@ -1141,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()); @@ -1340,7 +1342,10 @@ void DolphinMainWindow::rememberClosedTab(int index) const QString primaryPath = m_viewTab[index].primaryView->url().path(); const QString iconName = KMimeType::iconNameForUrl(primaryPath); - QAction* action = new QAction(primaryPath, tabsMenu); + 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(); @@ -1355,13 +1360,20 @@ void DolphinMainWindow::rememberClosedTab(int index) action->setData(QVariant::fromValue(closedTab)); action->setIcon(KIcon(iconName)); - //Add our action at the first element, but only do that if it isn't empty, else just append - if (tabsMenu->actions().isEmpty()) { + // 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().first() + 2, action); + 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()