[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdevplatform/sublime
From: Milian Wolff <mail () milianw ! de>
Date: 2009-09-10 23:05:03
Message-ID: 1252623903.788067.29044.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1022160 by mwolff:
Add context menu to container tabbar with generic "close tab" and "close other tabs" \
actions.
I eventually want to add more features, like "split view" or "new tab". But the \
latter seems to be out of the scope of sublime as far as I can see. Hence I'll \
eventually have to refactor this code so sublime implementers (like kdevelop shell) \
can provide custom context menu actions.
Imo the two actions alone are far better than no context menu at all. I really wanted \
"close other tabs"...
M +44 -0 container.cpp
M +2 -0 container.h
--- trunk/KDE/kdevplatform/sublime/container.cpp #1022159:1022160
@@ -35,6 +35,8 @@
#include <kglobal.h>
#include <kdeversion.h>
#include <kacceleratormanager.h>
+#include <kmenu.h>
+#include <kicon.h>
#include "view.h"
#include "document.h"
@@ -135,6 +137,7 @@
m_tabBarLayout->setSpacing(0);
d->tabBar = new KTabBar(this);
+ d->tabBar->setContextMenuPolicy(Qt::CustomContextMenu);
m_tabBarLayout->addWidget(d->tabBar);
d->fileStatus = new QLabel( this );
d->fileStatus->setFixedSize( QSize( 16, 16 ) );
@@ -152,6 +155,7 @@
connect(d->tabBar, SIGNAL(closeRequest(int)), this, SLOT(closeRequest(int)));
connect(d->tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(tabMoved(int, int)));
connect(d->tabBar, SIGNAL(wheelDelta(int)), this, SLOT(wheelScroll(int)));
+ connect(d->tabBar, SIGNAL(customContextMenuRequested(QPoint)), this, \
SLOT(contextMenuRequested(QPoint)));
KConfigGroup group = KGlobal::config()->group("UiSettings");
setTabBarHidden(group.readEntry("TabBarVisibility", 1) == 0);
@@ -370,7 +374,47 @@
d->viewForWidget[w]->notifyPositionChanged(to);
}
+void Container::contextMenuRequested( QPoint pos )
+{
+ int currentTab = d->tabBar->tabAt(pos);
+
+ KMenu menu;
+
+// QAction* newFileAction = menu.addAction( KIcon("document-new"), i18n( "New \
File" ) ); + QAction* closeTabAction = menu.addAction( KIcon("document-close"), \
i18n( "Close File" ) ); + menu.addSeparator();
+ QAction* closeOtherTabsAction = menu.addAction( KIcon("document-close"), i18n( \
"Close Other Files" ) ); +
+ QAction* triggered = menu.exec(mapToGlobal(pos));
+
+ if (triggered) {
+ /*if ( triggered == newFileAction ) {
+ kDebug() << "new file";
+ ///TODO
+ } else */
+ if ( triggered == closeTabAction ) {
+ closeRequest(currentTab);
+ } else if ( triggered == closeOtherTabsAction ) {
+ // activate the remaining tab
+ widgetActivated(currentTab);
+ // first get the widgets to be closed since otherwise the indices will \
be wrong + QList<QWidget*> otherTabs;
+ for ( int i = 0; i < count(); ++i ) {
+ if ( i != currentTab ) {
+ otherTabs << widget(i);
+ }
+ }
+ // finally close other tabs
+ foreach( QWidget* tab, otherTabs ) {
+ closeRequest(tab);
+ }
+ } else {
+ kDebug() << "unhandled context menu action triggered:" << triggered;
+ }
+ }
}
+}
+
#include "container.moc"
--- trunk/KDE/kdevplatform/sublime/container.h #1022159:1022160
@@ -78,6 +78,8 @@
void closeRequest(int idx);
void tabMoved(int from, int to);
void wheelScroll(int);
+ void contextMenuRequested( QPoint );
+
private:
struct ContainerPrivate * const d;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic