┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2008-04-16 20:03:05 +0000
committerPeter Penz <[email protected]>2008-04-16 20:03:05 +0000
commit12c1feb0c5ac8d402ee03dc9da39f826ae04ce0b (patch)
tree8527191bd0c13be2873fc10f9266bde8ba85e723
parent8f582495f6dcac94d463607341acdebc1016cc2e (diff)
* provide context menu for tabs
* assure that the tab name is set to "/" for the root URL instead of using an empty string svn path=/trunk/KDE/kdebase/apps/; revision=797725
-rw-r--r--src/dolphinmainwindow.cpp63
-rw-r--r--src/dolphinmainwindow.h12
2 files changed, 67 insertions, 8 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index f64f847fe..37fdce75b 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -180,10 +180,9 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
updateEditActions();
updateViewActions();
updateGoActions();
- const QString caption = url.fileName();
- setCaption(caption);
+ setCaption(url.fileName());
if (m_viewTab.count() > 1) {
- m_tabBar->setTabText(m_tabIndex, caption);
+ m_tabBar->setTabText(m_tabIndex, tabName(url));
}
emit urlChanged(url);
}
@@ -267,11 +266,11 @@ 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"), tabName(m_activeViewContainer->url()));
m_tabBar->blockSignals(false);
}
- m_tabBar->addTab(KIcon("folder"), url.fileName());
+ m_tabBar->addTab(KIcon("folder"), tabName(url));
ViewTab viewTab;
viewTab.splitter = new QSplitter(this);
@@ -694,6 +693,11 @@ void DolphinMainWindow::setActiveTab(int index)
viewTab.secondaryView);
}
+void DolphinMainWindow::closeTab()
+{
+ closeTab(m_tabBar->currentIndex());
+}
+
void DolphinMainWindow::closeTab(int index)
{
Q_ASSERT(index >= 0);
@@ -734,6 +738,38 @@ void DolphinMainWindow::closeTab(int index)
}
}
+void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
+{
+ KMenu menu(this);
+
+ QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
+ newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
+
+ QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close"), 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 ViewTab& tab = m_viewTab[index];
+ const KUrl url = tab.primaryView->isActive() ? tab.primaryView->url() :
+ tab.secondaryView->url();
+ openNewTab(url);
+ m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
+ } 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);
+ }
+}
+
void DolphinMainWindow::init()
{
DolphinSettings& settings = DolphinSettings::instance();
@@ -774,6 +810,8 @@ void DolphinMainWindow::init()
this, SLOT(setActiveTab(int)));
connect(m_tabBar, SIGNAL(closeRequest(int)),
this, SLOT(closeTab(int)));
+ connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
+ this, SLOT(openTabContextMenu(int, const QPoint&)));
m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
QWidget* centralWidget = new QWidget(this);
@@ -839,10 +877,9 @@ void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContain
updateGoActions();
const KUrl& url = m_activeViewContainer->url();
- const QString caption = url.fileName();
- setCaption(caption);
+ setCaption(url.fileName());
if (m_viewTab.count() > 1) {
- m_tabBar->setTabText(m_tabIndex, caption);
+ m_tabBar->setTabText(m_tabIndex, tabName(url));
}
emit urlChanged(url);
@@ -870,6 +907,11 @@ void DolphinMainWindow::setupActions()
newTab->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_N);
connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
+ QAction* closeTab = new QAction(KIcon("tab-close"), i18nc("@action:inmenu File", "Close Tab"), this);
+ closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
+ connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
+ actionCollection()->addAction("close_tab", closeTab);
+
KAction* properties = actionCollection()->addAction("properties");
properties->setText(i18nc("@action:inmenu File", "Properties"));
properties->setShortcut(Qt::ALT | Qt::Key_Return);
@@ -1158,6 +1200,11 @@ void DolphinMainWindow::updateSplitAction()
}
}
+QString DolphinMainWindow::tabName(const KUrl& url) const
+{
+ return url.equals(KUrl("file:///")) ? "/" : url.fileName();
+}
+
DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
KonqFileUndoManager::UiInterface(mainWin),
m_mainWin(mainWin)
diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h
index 3ac766d77..2f0fb9589 100644
--- a/src/dolphinmainwindow.h
+++ b/src/dolphinmainwindow.h
@@ -331,11 +331,20 @@ private slots:
*/
void setActiveTab(int index);
+ /** Closes the currently active tab. */
+ void closeTab();
+
/**
* Closes the tab with the index \index and activates the tab with index - 1.
*/
void closeTab(int index);
+ /**
+ * Opens a context menu for the tab with the index \a index
+ * on the position \a pos.
+ */
+ void openTabContextMenu(int index, const QPoint& pos);
+
private:
DolphinMainWindow(int id);
void init();
@@ -370,6 +379,9 @@ private:
*/
void updateSplitAction();
+ /** Returns the name of the tab for the URL \a url. */
+ QString tabName(const KUrl& url) const;
+
private:
/**
* Implements a custom error handling for the undo manager. This