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
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "messagemanager.h"
#include "coreconstants.h"
#include "coreplugintr.h"
#include "icontext.h"
#include "ioutputpane.h"
#include "outputwindow.h"
#include <utils/qtcassert.h>
#include <utils/shutdownguard.h>
#include <utils/utilsicons.h>
#include <QFont>
#include <QPointer>
/*!
\namespace Core::MessageManager
\inheaderfile coreplugin/messagemanager.h
\ingroup mainclasses
\inmodule QtCreator
\brief The MessageManager namespace is used to post messages in the
\uicontrol{General Messages} pane.
*/
using namespace Core::Internal;
namespace Core::MessageManager {
const char zoomSettingsKey[] = "Core/MessageOutput/Zoom";
class MessageOutputWindow final : public IOutputPane
{
public:
explicit MessageOutputWindow(QObject *parent)
: IOutputPane(parent)
{
setId("GeneralMessages");
setDisplayName(Tr::tr("General Messages"));
setPriorityInStatusBar(-100);
m_widget = new OutputWindow(Context(Constants::C_GENERAL_OUTPUT_PANE), zoomSettingsKey);
m_widget->setReadOnly(true);
connect(this, &IOutputPane::zoomInRequested, m_widget, &Core::OutputWindow::zoomIn);
connect(this, &IOutputPane::zoomOutRequested, m_widget, &Core::OutputWindow::zoomOut);
connect(this, &IOutputPane::resetZoomRequested, m_widget, &Core::OutputWindow::resetZoom);
connect(this, &IOutputPane::fontChanged, m_widget, &OutputWindow::setBaseFont);
connect(this, &IOutputPane::wheelZoomEnabledChanged, m_widget, &OutputWindow::setWheelZoomEnabled);
setupFilterUi("MessageOutputPane.Filter", "Core::Internal::MessageOutputWindow");
setFilteringEnabled(true);
setupContext(Constants::C_GENERAL_OUTPUT_PANE, m_widget);
}
~MessageOutputWindow() final
{
delete m_widget;
}
void append(const QString &text)
{
m_widget->appendMessage(text, Utils::GeneralMessageFormat);
}
void clearLinesPrefixedWith(const QString &prefix, bool deleteTrailingLineBreak)
{
m_widget->clearLinesPrefixedWith(prefix, deleteTrailingLineBreak);
}
private:
QWidget *outputWidget(QWidget *parent) final
{
m_widget->setParent(parent);
return m_widget;
}
void clearContents() final { m_widget->clear(); }
bool canFocus() const final { return true; }
bool hasFocus() const final { return m_widget->window()->focusWidget() == m_widget; }
void setFocus() final { m_widget->setFocus(); }
bool canNext() const final { return false; }
bool canPrevious() const final { return false; }
void goToNext() final {}
void goToPrev() final {}
bool canNavigate() const final { return false; }
bool hasFilterContext() const final { return true; }
void updateFilter() final
{
m_widget->updateFilterProperties(filterText(), filterCaseSensitivity(), filterUsesRegexp(),
filterIsInverted(), beforeContext(), afterContext());
}
OutputWindow *m_widget = nullptr;
};
static MessageOutputWindow *messageOutputWindow()
{
static QPointer<MessageOutputWindow> theMessageOutputWindow
= new MessageOutputWindow(Utils::shutdownGuard());
return theMessageOutputWindow.get();
}
enum class Flag { Silent, Flash, Disrupt };
static void showOutputPane(Flag flags)
{
QTC_ASSERT(messageOutputWindow(), return);
switch (flags) {
case Flag::Silent:
break;
case Flag::Flash:
messageOutputWindow()->flash();
break;
case Flag::Disrupt:
messageOutputWindow()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
break;
}
}
static void writeImpl(const QString &text, Flag flags)
{
// Make sure this end up in the GUI thread.
QMetaObject::invokeMethod(Utils::shutdownGuard(), [text, flags] {
QTC_ASSERT(messageOutputWindow(), return);
showOutputPane(flags);
messageOutputWindow()->append(text + '\n');
});
}
/*!
\internal
*/
void setFont(const QFont &font)
{
QTC_ASSERT(messageOutputWindow(), return);
messageOutputWindow()->setFont(font);
}
/*!
\internal
*/
void setWheelZoomEnabled(bool enabled)
{
QTC_ASSERT(messageOutputWindow(), return);
messageOutputWindow()->setWheelZoomEnabled(enabled);
}
void clearLinesPrefixedWith(const QString &prefix, bool deleteTrailingLineBreak)
{
// Make sure this end up in the GUI thread.
QMetaObject::invokeMethod(Utils::shutdownGuard(), [prefix, deleteTrailingLineBreak] {
QTC_ASSERT(messageOutputWindow(), return);
messageOutputWindow()->clearLinesPrefixedWith(prefix, deleteTrailingLineBreak);
});
}
/*!
Writes the \a message to the \uicontrol{General Messages} pane without
any further action.
This is the preferred method of posting messages, since it does not
interrupt the user.
\sa writeFlashing()
\sa writeDisrupting()
*/
void writeSilently(const QString &message)
{
writeImpl(message, Flag::Silent);
}
/*!
Writes the \a message to the \uicontrol{General Messages} pane and flashes
the output pane button.
This notifies the user that something important has happened that might
require the user's attention. Use sparingly, since continually flashing the
button is annoying, especially if the condition is something the user might
not be able to fix.
\sa writeSilently()
\sa writeDisrupting()
*/
void writeFlashing(const QString &message)
{
writeImpl(message, Flag::Flash);
}
/*!
Writes the \a message to the \uicontrol{General Messages} pane and brings
the pane to the front.
This might interrupt a user's workflow, so only use this as a direct
response to something a user did, like explicitly running a tool.
\sa writeSilently()
\sa writeFlashing()
*/
void writeDisrupting(const QString &message)
{
writeImpl(message, Flag::Disrupt);
}
/*!
\overload writeSilently()
*/
void writeSilently(const QStringList &messages)
{
writeSilently(messages.join('\n'));
}
/*!
\overload writeFlashing()
*/
void writeFlashing(const QStringList &messages)
{
writeFlashing(messages.join('\n'));
}
/*!
\overload writeDisrupting()
*/
void writeDisrupting(const QStringList &messages)
{
writeDisrupting(messages.join('\n'));
}
void popup()
{
messageOutputWindow()->popup(IOutputPane::NoModeSwitch);
}
} // namespace Core::MessageManager
|