forked from qt-creator/qt-creator
Implement close all application outputs action
Task-number: QTCREATORBUG-3465 Change-Id: Iff96ece9d6b74199cc3667079b99d587099b85e9 Reviewed-on: http://codereview.qt.nokia.com/2685 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
@@ -56,6 +56,8 @@
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QTabWidget>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QTabBar>
|
||||
#include <QtGui/QMenu>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
@@ -76,6 +78,36 @@ static QString msgAttachDebuggerTooltip(const QString &handleDescription = QStri
|
||||
AppOutputPane::tr("Attach debugger to %1").arg(handleDescription);
|
||||
}
|
||||
|
||||
namespace ProjectExplorer {
|
||||
namespace Internal {
|
||||
|
||||
class TabWidget : public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TabWidget(QWidget *parent = 0);
|
||||
signals:
|
||||
void contextMenuRequested(const QPoint &pos, const int index);
|
||||
private slots:
|
||||
void slotContextMenuRequested(const QPoint &pos);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
TabWidget::TabWidget(QWidget *parent)
|
||||
: QTabWidget(parent)
|
||||
{
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
|
||||
this, SLOT(slotContextMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
void TabWidget::slotContextMenuRequested(const QPoint &pos)
|
||||
{
|
||||
emit contextMenuRequested(pos, tabBar()->tabAt(pos));
|
||||
}
|
||||
|
||||
AppOutputPane::RunControlTab::RunControlTab(RunControl *rc, Core::OutputWindow *w) :
|
||||
runControl(rc), window(w), asyncClosing(false)
|
||||
{
|
||||
@@ -83,8 +115,11 @@ AppOutputPane::RunControlTab::RunControlTab(RunControl *rc, Core::OutputWindow *
|
||||
|
||||
AppOutputPane::AppOutputPane() :
|
||||
m_mainWidget(new QWidget),
|
||||
m_tabWidget(new QTabWidget),
|
||||
m_tabWidget(new TabWidget),
|
||||
m_stopAction(new QAction(tr("Stop"), this)),
|
||||
m_closeCurrentTabAction(new QAction(tr("Close Tab"), this)),
|
||||
m_closeAllTabsAction(new QAction(tr("Close All Tabs"), this)),
|
||||
m_closeOtherTabsAction(new QAction(tr("Close Other Tabs"), this)),
|
||||
m_reRunButton(new QToolButton),
|
||||
m_stopButton(new QToolButton),
|
||||
m_attachButton(new QToolButton)
|
||||
@@ -135,6 +170,7 @@ AppOutputPane::AppOutputPane() :
|
||||
layout->addWidget(m_tabWidget);
|
||||
|
||||
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
|
||||
connect(m_tabWidget, SIGNAL(contextMenuRequested(QPoint,int)), this, SLOT(contextMenuRequested(QPoint,int)));
|
||||
|
||||
m_mainWidget->setLayout(layout);
|
||||
|
||||
@@ -192,6 +228,14 @@ int AppOutputPane::tabWidgetIndexOf(int runControlIndex) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
void AppOutputPane::updateCloseActions()
|
||||
{
|
||||
const int tabCount = m_tabWidget->count();
|
||||
m_closeCurrentTabAction->setEnabled(tabCount > 0);
|
||||
m_closeAllTabsAction->setEnabled(tabCount > 0);
|
||||
m_closeOtherTabsAction->setEnabled(tabCount > 1);
|
||||
}
|
||||
|
||||
bool AppOutputPane::aboutToClose() const
|
||||
{
|
||||
foreach (const RunControlTab &rt, m_runControlTabs)
|
||||
@@ -298,6 +342,7 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
|
||||
m_tabWidget->addTab(ow, rc->displayName());
|
||||
if (debug)
|
||||
qDebug() << "OutputPane::createNewOutputWindow: Adding tab for " << rc;
|
||||
updateCloseActions();
|
||||
}
|
||||
|
||||
void AppOutputPane::handleOldOutput(Core::OutputWindow *window) const
|
||||
@@ -414,6 +459,7 @@ bool AppOutputPane::closeTab(int tabIndex, CloseTabMode closeTabMode)
|
||||
}
|
||||
delete tab.window;
|
||||
m_runControlTabs.removeAt(index);
|
||||
updateCloseActions();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -472,6 +518,23 @@ void AppOutputPane::tabChanged(int i)
|
||||
}
|
||||
}
|
||||
|
||||
void AppOutputPane::contextMenuRequested(const QPoint &pos, int index)
|
||||
{
|
||||
QList<QAction *> actions = QList<QAction *>() << m_closeCurrentTabAction << m_closeAllTabsAction << m_closeOtherTabsAction;
|
||||
QAction *action = QMenu::exec(actions, m_tabWidget->mapToGlobal(pos), 0, m_tabWidget);
|
||||
const int currentIdx = index != -1 ? index : currentIndex();
|
||||
if (action == m_closeCurrentTabAction) {
|
||||
if (currentIdx >= 0)
|
||||
closeTab(currentIdx);
|
||||
} else if (action == m_closeAllTabsAction) {
|
||||
closeTabs(AppOutputPane::CloseTabWithPrompt);
|
||||
} else if (action == m_closeOtherTabsAction) {
|
||||
for (int t = m_tabWidget->count() - 1; t >= 0; t--)
|
||||
if (t != currentIdx)
|
||||
closeTab(t);
|
||||
}
|
||||
}
|
||||
|
||||
void AppOutputPane::runControlStarted()
|
||||
{
|
||||
RunControl *current = currentRunControl();
|
||||
@@ -545,3 +608,5 @@ QList<RunControl *> AppOutputPane::runControls() const
|
||||
return result;
|
||||
}
|
||||
|
||||
#include "appoutputpane.moc"
|
||||
|
||||
|
@@ -102,6 +102,7 @@ private slots:
|
||||
void attachToRunControl();
|
||||
bool closeTab(int index);
|
||||
void tabChanged(int);
|
||||
void contextMenuRequested(const QPoint &pos, int index);
|
||||
void runControlStarted();
|
||||
void runControlFinished();
|
||||
|
||||
@@ -131,11 +132,15 @@ private:
|
||||
RunControl *currentRunControl() const;
|
||||
int tabWidgetIndexOf(int runControlIndex) const;
|
||||
void handleOldOutput(Core::OutputWindow *window) const;
|
||||
void updateCloseActions();
|
||||
|
||||
QWidget *m_mainWidget;
|
||||
QTabWidget *m_tabWidget;
|
||||
class TabWidget *m_tabWidget;
|
||||
QList<RunControlTab> m_runControlTabs;
|
||||
QAction *m_stopAction;
|
||||
QAction *m_closeCurrentTabAction;
|
||||
QAction *m_closeAllTabsAction;
|
||||
QAction *m_closeOtherTabsAction;
|
||||
QToolButton *m_reRunButton;
|
||||
QToolButton *m_stopButton;
|
||||
QToolButton *m_attachButton;
|
||||
|
Reference in New Issue
Block a user