]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Added a few things to the "Recently Closed Tabs" menu:
[dolphin.git] / src / dolphinmainwindow.cpp
index 7029e9bc95d37f7ddf2343880a9cbeb59d3a4d12..c0910e2740cf8b01bfea179b5bade8be2c0a5db7 100644 (file)
@@ -85,6 +85,7 @@
 #include <QLineEdit>
 #include <QSplitter>
 #include <QDockWidget>
+#include <kacceleratormanager.h>
 
 /*
  * Remembers the tab configuration if a tab has been closed.
@@ -923,7 +924,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&)));
@@ -1006,7 +1007,7 @@ 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));
     }
 
@@ -1326,7 +1327,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();
@@ -1348,7 +1352,13 @@ void DolphinMainWindow::rememberClosedTab(int index)
     } else {
         tabsMenu->insertAction(tabsMenu->actions().at(2), action);
     }
+    //10 is the limit, remove the oldest one to make room. It's actually 8, since
+    //the separator and the "Empty Recently Closed Tabs" entry count as one
+    if (tabsMenu->actions().size() > 8) {
+        tabsMenu->removeAction(tabsMenu->actions().last());
+    }
     actionCollection()->action("closed_tabs")->setEnabled(true);
+    KAcceleratorManager::manage(tabsMenu);
 }
 
 void DolphinMainWindow::clearStatusBar()