1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
diff --git a/src/plugins/projectexplorer/appoutputpane.cpp b/src/plugins/projectexplorer/appoutputpane.cpp
index 6012b7de..cb251799 100644
--- a/src/plugins/projectexplorer/appoutputpane.cpp
+++ b/src/plugins/projectexplorer/appoutputpane.cpp
@@ -56,6 +56,8 @@
#include <QSplitter>
#include <QTabBar>
#include <QTabWidget>
+#include <QStackedWidget>
+#include <QComboBox>
#include <QTextBlock>
#include <QTimer>
#include <QToolButton>
@@ -215,107 +217,6 @@ private:
bool m_filterEnabled = false;
};
-class TabWidget : public QTabWidget
-{
-public:
- TabWidget(QWidget *parent = nullptr);
-
- int addTab(QWidget *ow, QWidget* cv, const QString &label);
-
- QWidget* currentWidget() const;
- void setCurrentWidget(QWidget *widget);
- int indexOf(const QWidget *w) const;
- QWidget *widget(int index) const;
- QWidget *filtersWidget(int index) const;
-
-private:
- bool eventFilter(QObject *object, QEvent *event) override;
- QWidget *getActualWidget(QWidget *w, int splitterIndex) const;
-
- int m_tabIndexForMiddleClick = -1;
-};
-
-TabWidget::TabWidget(QWidget *parent)
- : QTabWidget(parent)
-{
- tabBar()->installEventFilter(this);
- setContextMenuPolicy(Qt::CustomContextMenu);
-}
-
-int TabWidget::addTab(QWidget *ow, QWidget* cv, const QString &label)
-{
- QSplitter * splitter = new QSplitter(Qt::Horizontal);
- splitter->addWidget(ow);
- splitter->setStretchFactor(0, 2);
- splitter->addWidget(cv);
- splitter->setStretchFactor(1, 1);
- return insertTab(-1, splitter, label);
-}
-
-QWidget *TabWidget::currentWidget() const
-{
- return getActualWidget(QTabWidget::currentWidget(), 0);
-}
-
-void TabWidget::setCurrentWidget(QWidget *w)
-{
- for (int i = 0; i < count(); ++i) {
- if (widget(i) == w)
- setCurrentIndex(i);
- }
-}
-
-int TabWidget::indexOf(const QWidget *w) const
-{
- for (int i = 0; i < count(); ++i) {
- if (widget(i) == w)
- return i;
- }
- return -1;
-}
-
-QWidget *TabWidget::widget(int index) const
-{
- return getActualWidget(QTabWidget::widget(index), 0);
-}
-
-QWidget *TabWidget::filtersWidget(int index) const
-{
- return getActualWidget(QTabWidget::widget(index), 1);
-}
-
-bool TabWidget::eventFilter(QObject *object, QEvent *event)
-{
- if (object == tabBar()) {
- if (event->type() == QEvent::MouseButtonPress) {
- auto *me = static_cast<QMouseEvent *>(event);
- if (me->button() == Qt::MiddleButton) {
- m_tabIndexForMiddleClick = tabBar()->tabAt(me->pos());
- event->accept();
- return true;
- }
- } else if (event->type() == QEvent::MouseButtonRelease) {
- auto *me = static_cast<QMouseEvent *>(event);
- if (me->button() == Qt::MiddleButton) {
- int tab = tabBar()->tabAt(me->pos());
- if (tab != -1 && tab == m_tabIndexForMiddleClick)
- emit tabCloseRequested(tab);
- m_tabIndexForMiddleClick = -1;
- event->accept();
- return true;
- }
- }
- }
- return QTabWidget::eventFilter(object, event);
-}
-
-QWidget *TabWidget::getActualWidget(QWidget *w, int splitterIndex) const
-{
- if (const auto splitter = qobject_cast<QSplitter*>(w))
- return splitter->widget(splitterIndex);
- return nullptr;
-}
-
class LoggingCategoryModel : public QAbstractListModel
{
Q_OBJECT
@@ -427,16 +328,15 @@ AppOutputPane::RunControlTab::RunControlTab(RunControl *runControl, Core::Output
}
AppOutputPane::AppOutputPane() :
- m_tabWidget(new TabWidget),
+ m_tabWidget(new QStackedWidget),
m_stopAction(new QAction(Tr::tr("Stop"), this)),
- m_closeCurrentTabAction(new QAction(Tr::tr("Close Tab"), this)),
- m_closeAllTabsAction(new QAction(Tr::tr("Close All Tabs"), this)),
- m_closeOtherTabsAction(new QAction(Tr::tr("Close Other Tabs"), this)),
m_reRunButton(new QToolButton),
m_stopButton(new QToolButton),
m_attachButton(new QToolButton),
m_settingsButton(new QToolButton),
m_formatterWidget(new QWidget),
+ m_tabComboBox(new QComboBox),
+ m_closeCurrentTabButton(new QToolButton),
m_handler(new ShowOutputTaskHandler(this,
Tr::tr("Show &App Output"),
Tr::tr("Show the output that generated this issue in Application Output."),
@@ -494,17 +394,22 @@ AppOutputPane::AppOutputPane() :
m_formatterWidget->setLayout(formatterWidgetsLayout);
// Spacer (?)
-
- m_tabWidget->setDocumentMode(true);
- m_tabWidget->setTabsClosable(true);
- m_tabWidget->setMovable(true);
- connect(m_tabWidget, &QTabWidget::tabCloseRequested,
- this, [this](int index) { closeTab(index); });
-
- connect(m_tabWidget, &QTabWidget::currentChanged,
+ m_closeCurrentTabButton->setToolTip(Tr::tr("Close output configuration."));
+ m_closeCurrentTabButton->setIcon(Utils::Icons::CLOSE_TOOLBAR.icon());
+ m_closeCurrentTabButton->setEnabled(false);
+ connect(m_closeCurrentTabButton, &QToolButton::clicked, this, [this] {
+ closeTab(m_tabWidget->currentIndex());
+ });
+
+ m_tabComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+ m_tabComboBox->addItem(Tr::tr("<no configuration>"));
+ connect(m_tabComboBox, &QComboBox::activated,
+ m_tabWidget, &QStackedWidget::setCurrentIndex);
+ connect(m_tabWidget, &QStackedWidget::currentChanged,
+ m_tabComboBox, &QComboBox::setCurrentIndex);
+
+ connect(m_tabWidget, &QStackedWidget::currentChanged,
this, &AppOutputPane::tabChanged);
- connect(m_tabWidget, &QWidget::customContextMenuRequested,
- this, &AppOutputPane::contextMenuRequested);
connect(SessionManager::instance(), &SessionManager::aboutToUnloadSession,
this, &AppOutputPane::aboutToUnloadSession);
@@ -573,9 +478,7 @@ const AppOutputPane::RunControlTab *AppOutputPane::tabFor(const QWidget *outputW
void AppOutputPane::updateCloseActions()
{
const int tabCount = m_tabWidget->count();
- m_closeCurrentTabAction->setEnabled(tabCount > 0);
- m_closeAllTabsAction->setEnabled(tabCount > 0);
- m_closeOtherTabsAction->setEnabled(tabCount > 1);
+ m_closeCurrentTabButton->setEnabled(tabCount > 0);
}
bool AppOutputPane::aboutToClose() const
@@ -597,8 +500,8 @@ QWidget *AppOutputPane::outputWidget(QWidget *)
QList<QWidget *> AppOutputPane::toolBarWidgets() const
{
- return QList<QWidget *>{m_reRunButton, m_stopButton, m_attachButton, m_settingsButton,
- m_formatterWidget} + IOutputPane::toolBarWidgets();
+ return QList<QWidget *>{m_tabComboBox, m_closeCurrentTabButton, m_reRunButton, m_stopButton,
+ m_attachButton, m_settingsButton, m_formatterWidget} + IOutputPane::toolBarWidgets();
}
void AppOutputPane::clearContents()
@@ -708,7 +611,6 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
const auto updateOutputFiltersWidget = [this](int index, RunControl *rc) {
const auto aspect = rc->aspectData<EnableCategoriesFilterAspect>();
const bool filterEnabled = aspect && aspect->value;
- m_tabWidget->filtersWidget(index)->setVisible(filterEnabled);
qobject_cast<AppOutputWindow *>(m_tabWidget->widget(index))->setFilterEnabled(filterEnabled);
};
if (tab != m_runControlTabs.end()) {
@@ -725,7 +627,7 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
// Update the title.
const int tabIndex = m_tabWidget->indexOf(tab->window);
QTC_ASSERT(tabIndex != -1, return);
- m_tabWidget->setTabText(tabIndex, rc->displayName());
+ m_tabComboBox->setItemText(tabIndex, rc->displayName());
updateOutputFileName(tabIndex, rc);
updateOutputFiltersWidget(tabIndex, rc);
@@ -904,7 +806,12 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
// clang-format on
m_runControlTabs.push_back(RunControlTab(rc, ow));
- m_tabWidget->addTab(ow, cv, rc->displayName());
+ if (m_tabWidget->count() > 0) {
+ m_tabComboBox->addItem(rc->displayName());
+ } else {
+ m_tabComboBox->setItemText(0, rc->displayName());
+ }
+ m_tabWidget->addWidget(ow);
updateOutputFileName(m_tabWidget->count() - 1, rc);
updateOutputFiltersWidget(m_tabWidget->count() - 1, rc);
qCDebug(appOutputLog) << "AppOutputPane::createNewOutputWindow: Adding tab for" << rc;
@@ -1141,7 +1048,13 @@ void AppOutputPane::closeTab(int tabIndex, CloseTabMode closeTabMode)
return;
}
- m_tabWidget->removeTab(tabIndex);
+ m_tabWidget->removeWidget(tabWidget);
+ if (m_tabWidget->count() > 0) {
+ m_tabComboBox->removeItem(tabIndex);
+ } else {
+ m_tabComboBox->setItemText(tabIndex, Tr::tr("<no configuration>"));
+ m_tabComboBox->setCurrentIndex(0);
+ }
delete window;
Utils::erase(m_runControlTabs, [runControl](const RunControlTab &t) {
@@ -1241,27 +1154,6 @@ void AppOutputPane::tabChanged(int i)
}
}
-void AppOutputPane::contextMenuRequested(const QPoint &pos)
-{
- const int index = m_tabWidget->tabBar()->tabAt(pos);
- const QList<QAction *> actions = {m_closeCurrentTabAction, m_closeAllTabsAction, m_closeOtherTabsAction};
- QAction *action = QMenu::exec(actions, m_tabWidget->mapToGlobal(pos), nullptr, m_tabWidget);
- if (action == m_closeAllTabsAction) {
- closeTabs(AppOutputPane::CloseTabWithPrompt);
- return;
- }
-
- const int currentIdx = index != -1 ? index : m_tabWidget->currentIndex();
- if (action == m_closeCurrentTabAction) {
- if (currentIdx >= 0)
- closeTab(currentIdx);
- } else if (action == m_closeOtherTabsAction) {
- for (int t = m_tabWidget->count() - 1; t >= 0; t--)
- if (t != currentIdx)
- closeTab(t);
- }
-}
-
void AppOutputPane::runControlFinished(RunControl *runControl)
{
const RunControlTab * const tab = tabFor(runControl);
diff --git a/src/plugins/projectexplorer/appoutputpane.h b/src/plugins/projectexplorer/appoutputpane.h
index 8d1adde1..2d75b6ce 100644
--- a/src/plugins/projectexplorer/appoutputpane.h
+++ b/src/plugins/projectexplorer/appoutputpane.h
@@ -16,6 +16,8 @@ QT_BEGIN_NAMESPACE
class QToolButton;
class QAction;
class QPoint;
+class QStackedWidget;
+class QComboBox;
QT_END_NAMESPACE
namespace Core { class OutputWindow; }
@@ -27,7 +29,6 @@ class RunControl;
namespace Internal {
class ShowOutputTaskHandler;
-class TabWidget;
enum class AppOutputPaneMode { FlashOnOutput, PopupOnOutput, PopupOnFirstOutput };
@@ -141,17 +142,16 @@ private:
void loadSettings();
void storeSettings() const;
- TabWidget *m_tabWidget;
+ QStackedWidget *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;
QToolButton * const m_settingsButton;
QWidget *m_formatterWidget;
+ QComboBox *m_tabComboBox;
+ QToolButton *m_closeCurrentTabButton;
ShowOutputTaskHandler * const m_handler;
AppOutputSettings m_settings;
};
|