1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "logwindow.h"
27 
28 #include "debuggeractions.h"
29 #include "debuggercore.h"
30 #include "debuggerengine.h"
31 #include "debuggericons.h"
32 #include "debuggerinternalconstants.h"
33 
34 #include <QDebug>
35 #include <QTime>
36 
37 #include <QHBoxLayout>
38 #include <QLabel>
39 #include <QMenu>
40 #include <QSyntaxHighlighter>
41 #include <QPlainTextEdit>
42 #include <QPushButton>
43 #include <QFileDialog>
44 #include <QToolButton>
45 
46 #include <aggregation/aggregate.h>
47 
48 #include <app/app_version.h>
49 
50 #include <coreplugin/actionmanager/actionmanager.h>
51 #include <coreplugin/findplaceholder.h>
52 #include <coreplugin/minisplitter.h>
53 #include <coreplugin/find/basetextfind.h>
54 
55 #include <utils/fancylineedit.h>
56 #include <utils/fileutils.h>
57 #include <utils/theme/theme.h>
58 
59 namespace Debugger {
60 namespace Internal {
61 
62 GlobalLogWindow *theGlobalLog = nullptr;
63 
channelForChar(QChar c)64 static LogChannel channelForChar(QChar c)
65 {
66     switch (c.unicode()) {
67         case 'd': return LogDebug;
68         case 'w': return LogWarning;
69         case 'e': return LogError;
70         case '<': return LogInput;
71         case '>': return LogOutput;
72         case 's': return LogStatus;
73         case 't': return LogTime;
74         default: return LogMisc;
75     }
76 }
77 
charForChannel(int channel)78 QChar static charForChannel(int channel)
79 {
80     switch (channel) {
81         case LogDebug: return QLatin1Char('d');
82         case LogWarning: return QLatin1Char('w');
83         case LogError: return QLatin1Char('e');
84         case LogInput: return QLatin1Char('<');
85         case LogOutput: return QLatin1Char('>');
86         case LogStatus: return QLatin1Char('s');
87         case LogTime: return QLatin1Char('t');
88         case LogMisc:
89         default: return QLatin1Char(' ');
90     }
91 }
92 
writeLogContents(const QPlainTextEdit * editor,QWidget * parent)93 static bool writeLogContents(const QPlainTextEdit *editor, QWidget *parent)
94 {
95     bool success = false;
96     while (!success) {
97         const QString fileName = QFileDialog::getSaveFileName(parent, LogWindow::tr("Log File"));
98         if (fileName.isEmpty())
99             break;
100         Utils::FileSaver saver(Utils::FilePath::fromString(fileName), QIODevice::Text);
101         saver.write(editor->toPlainText().toUtf8());
102         if (saver.finalize(parent))
103             success = true;
104     }
105     return success;
106 }
107 
108 /////////////////////////////////////////////////////////////////////
109 //
110 // OutputHighlighter
111 //
112 /////////////////////////////////////////////////////////////////////
113 
114 class OutputHighlighter : public QSyntaxHighlighter
115 {
116 public:
OutputHighlighter(QPlainTextEdit * parent)117     OutputHighlighter(QPlainTextEdit *parent)
118         : QSyntaxHighlighter(parent->document()), m_parent(parent)
119     {}
120 
121 private:
highlightBlock(const QString & text)122     void highlightBlock(const QString &text) override
123     {
124         using Utils::Theme;
125         QTextCharFormat format;
126         Theme *theme = Utils::creatorTheme();
127         switch (channelForChar(text.isEmpty() ? QChar() : text.at(0))) {
128             case LogInput:
129                 format.setForeground(theme->color(Theme::Debugger_LogWindow_LogInput));
130                 setFormat(1, text.size(), format);
131                 break;
132             case LogStatus:
133                 format.setForeground(theme->color(Theme::Debugger_LogWindow_LogStatus));
134                 setFormat(1, text.size(), format);
135                 break;
136             case LogWarning:
137                 format.setForeground(theme->color(Theme::OutputPanes_WarningMessageTextColor));
138                 setFormat(1, text.size(), format);
139                 break;
140             case LogError:
141                 format.setForeground(theme->color(Theme::OutputPanes_ErrorMessageTextColor));
142                 setFormat(1, text.size(), format);
143                 break;
144             case LogTime:
145                 format.setForeground(theme->color(Theme::Debugger_LogWindow_LogTime));
146                 setFormat(1, text.size(), format);
147                 break;
148             default:
149                 break;
150         }
151         QColor base = m_parent->palette().color(QPalette::Base);
152         format.setForeground(base);
153         format.setFontPointSize(1);
154         setFormat(0, 1, format);
155     }
156 
157     QPlainTextEdit *m_parent;
158 };
159 
160 
161 /////////////////////////////////////////////////////////////////////
162 //
163 // InputHighlighter
164 //
165 /////////////////////////////////////////////////////////////////////
166 
167 class InputHighlighter : public QSyntaxHighlighter
168 {
169 public:
InputHighlighter(QPlainTextEdit * parent)170     InputHighlighter(QPlainTextEdit *parent)
171         : QSyntaxHighlighter(parent->document())
172     {}
173 
174 private:
highlightBlock(const QString & text)175     void highlightBlock(const QString &text) override
176     {
177         using Utils::Theme;
178         Theme *theme = Utils::creatorTheme();
179         if (text.size() > 3 && text.at(2) == ':') {
180             QTextCharFormat format;
181             format.setForeground(theme->color(Theme::Debugger_LogWindow_LogTime));
182             setFormat(1, text.size(), format);
183         }
184     }
185 };
186 
187 
188 /////////////////////////////////////////////////////////////////////
189 //
190 // DebbuggerPane base class
191 //
192 /////////////////////////////////////////////////////////////////////
193 
194 class DebuggerPane : public QPlainTextEdit
195 {
196     Q_OBJECT
197 
198 public:
DebuggerPane()199     explicit DebuggerPane()
200     {
201         setFrameStyle(QFrame::NoFrame);
202         setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
203 
204         m_clearContentsAction = new QAction(this);
205         m_clearContentsAction->setText(tr("Clear Contents"));
206         m_clearContentsAction->setEnabled(true);
207 
208         m_saveContentsAction = new QAction(this);
209         m_saveContentsAction->setText(tr("Save Contents"));
210         m_saveContentsAction->setEnabled(true);
211         connect(m_saveContentsAction, &QAction::triggered,
212                 this, &DebuggerPane::saveContents);
213     }
214 
contextMenuEvent(QContextMenuEvent * ev)215     void contextMenuEvent(QContextMenuEvent *ev) override
216     {
217         QMenu *menu = createStandardContextMenu();
218         menu->addAction(m_clearContentsAction);
219         menu->addAction(m_saveContentsAction); // X11 clipboard is unreliable for long texts
220         menu->addAction(debuggerSettings()->logTimeStamps.action());
221         menu->addAction(Core::ActionManager::command(Constants::RELOAD_DEBUGGING_HELPERS)->action());
222         menu->addSeparator();
223         menu->addAction(debuggerSettings()->settingsDialog.action());
224         menu->exec(ev->globalPos());
225         delete menu;
226     }
227 
append(const QString & text)228     void append(const QString &text)
229     {
230         const int N = 100000;
231         const int bc = blockCount();
232         if (bc > N) {
233             QTextDocument *doc = document();
234             QTextBlock block = doc->findBlockByLineNumber(bc * 9 / 10);
235             QTextCursor tc(block);
236             tc.movePosition(QTextCursor::Start, QTextCursor::KeepAnchor);
237             tc.removeSelectedText();
238             // Seems to be the only way to force shrinking of the
239             // allocated data.
240             QString contents = doc->toHtml();
241             doc->clear();
242             doc->setHtml(contents);
243         }
244         appendPlainText(text);
245     }
246 
clearUndoRedoStacks()247     void clearUndoRedoStacks()
248     {
249         if (!isUndoRedoEnabled())
250             return;
251         setUndoRedoEnabled(false);
252         setUndoRedoEnabled(true);
253     }
254 
clearContentsAction() const255     QAction *clearContentsAction() const { return m_clearContentsAction; }
256 
257 private:
saveContents()258     void saveContents() { writeLogContents(this, this); }
259 
260     QAction *m_clearContentsAction;
261     QAction *m_saveContentsAction;
262 };
263 
264 
265 
266 /////////////////////////////////////////////////////////////////////
267 //
268 // InputPane
269 //
270 /////////////////////////////////////////////////////////////////////
271 
272 class InputPane : public DebuggerPane
273 {
274     Q_OBJECT
275 public:
InputPane(LogWindow * logWindow)276     InputPane(LogWindow *logWindow)
277     {
278         connect(clearContentsAction(), &QAction::triggered,
279                 logWindow, &LogWindow::clearContents);
280         (void) new InputHighlighter(this);
281     }
282 
283 signals:
284     void executeLineRequested();
285     void clearContentsRequested();
286     void statusMessageRequested(const QString &, int);
287     void commandSelected(int);
288 
289 private:
keyPressEvent(QKeyEvent * ev)290     void keyPressEvent(QKeyEvent *ev) override
291     {
292         if (ev->modifiers() == Qt::ControlModifier && ev->key() == Qt::Key_Return)
293             emit executeLineRequested();
294         else if (ev->modifiers() == Qt::ControlModifier && ev->key() == Qt::Key_R)
295             emit clearContentsRequested();
296         else
297             QPlainTextEdit::keyPressEvent(ev);
298     }
299 
mouseDoubleClickEvent(QMouseEvent * ev)300     void mouseDoubleClickEvent(QMouseEvent *ev) override
301     {
302         QString line = cursorForPosition(ev->pos()).block().text();
303         int n = 0;
304 
305         // cut time string
306         if (line.size() > 18 && line.at(0) == '[')
307             line = line.mid(18);
308         //qDebug() << line;
309 
310         for (int i = 0; i != line.size(); ++i) {
311             QChar c = line.at(i);
312             if (!c.isDigit())
313                 break;
314             n = 10 * n + c.unicode() - '0';
315         }
316         emit commandSelected(n);
317     }
318 
focusInEvent(QFocusEvent * ev)319     void focusInEvent(QFocusEvent *ev) override
320     {
321         emit statusMessageRequested(tr("Type Ctrl-<Return> to execute a line."), -1);
322         QPlainTextEdit::focusInEvent(ev);
323     }
324 
focusOutEvent(QFocusEvent * ev)325     void focusOutEvent(QFocusEvent *ev) override
326     {
327         emit statusMessageRequested(QString(), -1);
328         QPlainTextEdit::focusOutEvent(ev);
329     }
330 };
331 
332 
333 /////////////////////////////////////////////////////////////////////
334 //
335 // CombinedPane
336 //
337 /////////////////////////////////////////////////////////////////////
338 
339 class CombinedPane : public DebuggerPane
340 {
341     Q_OBJECT
342 public:
CombinedPane(LogWindow * logWindow)343     CombinedPane(LogWindow *logWindow)
344     {
345         (void) new OutputHighlighter(this);
346         connect(clearContentsAction(), &QAction::triggered,
347                 logWindow, &LogWindow::clearContents);
348     }
349 
gotoResult(int i)350     void gotoResult(int i)
351     {
352         QString needle = QString::number(i) + '^';
353         QString needle2 = '>' + needle;
354         QString needle3 = QString::fromLatin1("dtoken(\"%1\")@").arg(i);
355         QTextCursor cursor(document());
356         do {
357             QTextCursor newCursor = document()->find(needle, cursor);
358             if (newCursor.isNull()) {
359                 newCursor = document()->find(needle3, cursor);
360                 if (newCursor.isNull())
361                     break; // Not found.
362             }
363             cursor = newCursor;
364             const QString line = cursor.block().text();
365             if (line.startsWith(needle) || line.startsWith(needle2) || line.startsWith(needle3)) {
366                 setFocus();
367                 setTextCursor(cursor);
368                 ensureCursorVisible();
369                 cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor);
370                 setTextCursor(cursor);
371                 break;
372             }
373         } while (cursor.movePosition(QTextCursor::Down));
374     }
375 };
376 
377 
378 /////////////////////////////////////////////////////////////////////
379 //
380 // DebuggerOutputWindow
381 //
382 /////////////////////////////////////////////////////////////////////
383 
LogWindow(DebuggerEngine * engine)384 LogWindow::LogWindow(DebuggerEngine *engine)
385     : m_engine(engine)
386 {
387     setWindowTitle(tr("Debugger &Log"));
388     setObjectName("Log");
389 
390     m_ignoreNextInputEcho = false;
391 
392     auto m_splitter = new Core::MiniSplitter(Qt::Horizontal);
393     m_splitter->setParent(this);
394 
395     // Mixed input/output.
396     m_combinedText = new CombinedPane(this);
397     m_combinedText->setReadOnly(true);
398     m_combinedText->setReadOnly(false);
399 
400     // Input only.
401     m_inputText = new InputPane(this);
402     m_inputText->setReadOnly(false);
403 
404     m_commandEdit = new Utils::FancyLineEdit(this);
405     m_commandEdit->setFrame(false);
406     m_commandEdit->setHistoryCompleter("DebuggerInput");
407 
408     auto repeatButton = new QToolButton(this);
409     repeatButton->setIcon(Icons::STEP_OVER.icon());
410     repeatButton->setFixedSize(QSize(18, 18));
411     repeatButton->setToolTip(tr("Repeat last command for debug reasons."));
412 
413     auto commandBox = new QHBoxLayout;
414     commandBox->addWidget(repeatButton);
415     commandBox->addWidget(new QLabel(tr("Command:"), this));
416     commandBox->addWidget(m_commandEdit);
417     commandBox->setContentsMargins(2, 2, 2, 2);
418     commandBox->setSpacing(6);
419 
420     auto leftBox = new QVBoxLayout;
421     leftBox->addWidget(m_inputText);
422     leftBox->addItem(commandBox);
423     leftBox->setContentsMargins(0, 0, 0, 0);
424     leftBox->setSpacing(0);
425 
426     auto leftDummy = new QWidget;
427     leftDummy->setLayout(leftBox);
428 
429     m_splitter->addWidget(leftDummy);
430     m_splitter->addWidget(m_combinedText);
431     m_splitter->setStretchFactor(0, 1);
432     m_splitter->setStretchFactor(1, 3);
433 
434     auto layout = new QVBoxLayout(this);
435     layout->setContentsMargins(0, 0, 0, 0);
436     layout->setSpacing(0);
437     layout->addWidget(m_splitter);
438     layout->addWidget(new Core::FindToolBarPlaceHolder(this));
439     setLayout(layout);
440 
441     auto aggregate = new Aggregation::Aggregate;
442     aggregate->add(m_combinedText);
443     aggregate->add(new Core::BaseTextFind(m_combinedText));
444 
445     aggregate = new Aggregation::Aggregate;
446     aggregate->add(m_inputText);
447     aggregate->add(new Core::BaseTextFind(m_inputText));
448 
449     connect(m_inputText, &InputPane::statusMessageRequested,
450             this, &LogWindow::statusMessageRequested);
451     connect(m_inputText, &InputPane::commandSelected,
452             m_combinedText, &CombinedPane::gotoResult);
453     connect(m_commandEdit, &QLineEdit::returnPressed,
454             this, &LogWindow::sendCommand);
455     connect(m_inputText, &InputPane::executeLineRequested,
456             this, &LogWindow::executeLine);
457     connect(repeatButton, &QAbstractButton::clicked,
458             this, &LogWindow::repeatLastCommand);
459 
460     connect(&m_outputTimer, &QTimer::timeout,
461             this, &LogWindow::doOutput);
462 
463     setMinimumHeight(60);
464 
465     showOutput(LogWarning,
466         tr("Note: This log contains possibly confidential information about your machine, "
467            "environment variables, in-memory data of the processes you are debugging, and more. "
468            "It is never transferred over the internet by %1, and only stored "
469            "to disk if you manually use the respective option from the context menu, or through "
470            "mechanisms that are not under the control of %1's Debugger plugin, "
471            "for instance in swap files, or other plugins you might use.\n"
472            "You may be asked to share the contents of this log when reporting bugs related "
473            "to debugger operation. In this case, make sure your submission does not "
474            "contain data you do not want to or you are not allowed to share.\n\n")
475                .arg(Core::Constants::IDE_DISPLAY_NAME));
476 }
477 
~LogWindow()478 LogWindow::~LogWindow()
479 {
480     disconnect(&m_outputTimer, &QTimer::timeout, this, &LogWindow::doOutput);
481     m_outputTimer.stop();
482     doOutput();
483 }
484 
executeLine()485 void LogWindow::executeLine()
486 {
487     m_ignoreNextInputEcho = true;
488     m_engine->executeDebuggerCommand(m_inputText->textCursor().block().text());
489 }
490 
repeatLastCommand()491 void LogWindow::repeatLastCommand()
492 {
493     m_engine->debugLastCommand();
494 }
495 
engine() const496 DebuggerEngine *LogWindow::engine() const
497 {
498     return m_engine;
499 }
500 
sendCommand()501 void LogWindow::sendCommand()
502 {
503     if (m_engine->acceptsDebuggerCommands())
504         m_engine->executeDebuggerCommand(m_commandEdit->text());
505     else
506         showOutput(LogError, tr("User commands are not accepted in the current state."));
507 }
508 
showOutput(int channel,const QString & output)509 void LogWindow::showOutput(int channel, const QString &output)
510 {
511     if (output.isEmpty())
512         return;
513 
514     const QChar cchar = charForChannel(channel);
515     const QChar nchar = '\n';
516 
517     QString out;
518     out.reserve(output.size() + 1000);
519 
520     if (output.at(0) != '~' && debuggerSettings()->logTimeStamps.value()) {
521         out.append(charForChannel(LogTime));
522         out.append(logTimeStamp());
523         out.append(nchar);
524     }
525 
526     for (int pos = 0, n = output.size(); pos < n; ) {
527         const int npos = output.indexOf(nchar, pos);
528         const int nnpos = npos == -1 ? n : npos;
529         const int l = nnpos - pos;
530         if (l != 6 || QStringView(output).mid(pos, 6) != QLatin1String("(gdb) ")) {
531             out.append(cchar);
532             if (l > 30000) {
533                 // FIXME: QTextEdit asserts on really long lines...
534                 out.append(output.mid(pos, 30000));
535                 out.append(" [...] <cut off>\n");
536             } else {
537                 out.append(output.mid(pos, l + 1));
538             }
539         }
540         pos = nnpos + 1;
541     }
542     if (!out.endsWith(nchar))
543         out.append(nchar);
544 
545     m_queuedOutput.append(out);
546     // flush the output if it exceeds 16k to prevent out of memory exceptions on regular output
547     if (m_queuedOutput.size() > 16 * 1024) {
548         m_outputTimer.stop();
549         doOutput();
550     } else {
551         m_outputTimer.setSingleShot(true);
552         m_outputTimer.start(80);
553     }
554 }
555 
doOutput()556 void LogWindow::doOutput()
557 {
558     if (m_queuedOutput.isEmpty())
559         return;
560 
561     if (theGlobalLog)
562         theGlobalLog->doOutput(m_queuedOutput);
563 
564     QTextCursor cursor = m_combinedText->textCursor();
565     const bool atEnd = cursor.atEnd();
566 
567     m_combinedText->append(m_queuedOutput);
568     m_queuedOutput.clear();
569 
570     if (atEnd) {
571         cursor.movePosition(QTextCursor::End);
572         m_combinedText->setTextCursor(cursor);
573         m_combinedText->ensureCursorVisible();
574     }
575 }
576 
showInput(int channel,const QString & input)577 void LogWindow::showInput(int channel, const QString &input)
578 {
579     Q_UNUSED(channel)
580     if (m_ignoreNextInputEcho) {
581         m_ignoreNextInputEcho = false;
582         QTextCursor cursor = m_inputText->textCursor();
583         cursor.movePosition(QTextCursor::Down);
584         cursor.movePosition(QTextCursor::EndOfLine);
585         m_inputText->setTextCursor(cursor);
586         return;
587     }
588     if (debuggerSettings()->logTimeStamps.value())
589         m_inputText->append(logTimeStamp());
590     m_inputText->append(input);
591     QTextCursor cursor = m_inputText->textCursor();
592     cursor.movePosition(QTextCursor::End);
593     m_inputText->setTextCursor(cursor);
594     m_inputText->ensureCursorVisible();
595 
596     theGlobalLog->doInput(input);
597 }
598 
clearContents()599 void LogWindow::clearContents()
600 {
601     m_combinedText->clear();
602     m_inputText->clear();
603 }
604 
setCursor(const QCursor & cursor)605 void LogWindow::setCursor(const QCursor &cursor)
606 {
607     m_combinedText->viewport()->setCursor(cursor);
608     m_inputText->viewport()->setCursor(cursor);
609     QWidget::setCursor(cursor);
610 }
611 
combinedContents() const612 QString LogWindow::combinedContents() const
613 {
614     return m_combinedText->toPlainText();
615 }
616 
inputContents() const617 QString LogWindow::inputContents() const
618 {
619     return m_inputText->toPlainText();
620 }
621 
clearUndoRedoStacks()622 void LogWindow::clearUndoRedoStacks()
623 {
624     m_inputText->clearUndoRedoStacks();
625     m_combinedText->clearUndoRedoStacks();
626 }
627 
logTimeStamp()628 QString LogWindow::logTimeStamp()
629 {
630     // Cache the last log time entry by ms. If time progresses,
631     // report the difference to the last time stamp in ms.
632     static const QString logTimeFormat("hh:mm:ss.zzz");
633     static QTime lastTime = QTime::currentTime();
634     static QString lastTimeStamp = lastTime.toString(logTimeFormat);
635 
636     const QTime currentTime = QTime::currentTime();
637     if (currentTime != lastTime) {
638         const int elapsedMS = lastTime.msecsTo(currentTime);
639         lastTime = currentTime;
640         lastTimeStamp = lastTime.toString(logTimeFormat);
641         // Append time elapsed
642         QString rc = lastTimeStamp;
643         rc += " [";
644         rc += QString::number(elapsedMS);
645         rc += "ms]";
646         return rc;
647     }
648     return lastTimeStamp;
649 }
650 
651 /////////////////////////////////////////////////////////////////////
652 //
653 // GlobalLogWindow
654 //
655 /////////////////////////////////////////////////////////////////////
656 
GlobalLogWindow()657 GlobalLogWindow::GlobalLogWindow()
658 {
659     theGlobalLog = this;
660 
661     setWindowTitle(tr("Global Debugger &Log"));
662     setObjectName("GlobalLog");
663 
664     auto m_splitter = new Core::MiniSplitter(Qt::Horizontal);
665     m_splitter->setParent(this);
666 
667     m_rightPane = new DebuggerPane;
668     m_rightPane->setReadOnly(true);
669 
670     m_leftPane = new DebuggerPane;
671     m_leftPane->setReadOnly(true);
672 
673     m_splitter->addWidget(m_leftPane);
674     m_splitter->addWidget(m_rightPane);
675     m_splitter->setStretchFactor(0, 1);
676     m_splitter->setStretchFactor(1, 3);
677 
678     auto layout = new QVBoxLayout(this);
679     layout->setContentsMargins(0, 0, 0, 0);
680     layout->setSpacing(0);
681     layout->addWidget(m_splitter);
682     layout->addWidget(new Core::FindToolBarPlaceHolder(this));
683     setLayout(layout);
684 
685     auto aggregate = new Aggregation::Aggregate;
686     aggregate->add(m_rightPane);
687     aggregate->add(new Core::BaseTextFind(m_rightPane));
688 
689     aggregate = new Aggregation::Aggregate;
690     aggregate->add(m_leftPane);
691     aggregate->add(new Core::BaseTextFind(m_leftPane));
692 
693     connect(m_leftPane->clearContentsAction(), &QAction::triggered,
694             this, &GlobalLogWindow::clearContents);
695     connect(m_rightPane->clearContentsAction(), &QAction::triggered,
696             this, &GlobalLogWindow::clearContents);
697 }
698 
~GlobalLogWindow()699 GlobalLogWindow::~GlobalLogWindow()
700 {
701     theGlobalLog = nullptr;
702 }
703 
doOutput(const QString & output)704 void GlobalLogWindow::doOutput(const QString &output)
705 {
706     QTextCursor cursor = m_rightPane->textCursor();
707     const bool atEnd = cursor.atEnd();
708 
709     m_rightPane->append(output);
710 
711     if (atEnd) {
712         cursor.movePosition(QTextCursor::End);
713         m_rightPane->setTextCursor(cursor);
714         m_rightPane->ensureCursorVisible();
715     }
716 }
717 
doInput(const QString & input)718 void GlobalLogWindow::doInput(const QString &input)
719 {
720     if (debuggerSettings()->logTimeStamps.value())
721         m_leftPane->append(LogWindow::logTimeStamp());
722     m_leftPane->append(input);
723     QTextCursor cursor = m_leftPane->textCursor();
724     cursor.movePosition(QTextCursor::End);
725     m_leftPane->setTextCursor(cursor);
726     m_leftPane->ensureCursorVisible();
727 }
728 
clearContents()729 void GlobalLogWindow::clearContents()
730 {
731     m_rightPane->clear();
732     m_leftPane->clear();
733 }
734 
setCursor(const QCursor & cursor)735 void GlobalLogWindow::setCursor(const QCursor &cursor)
736 {
737     m_rightPane->viewport()->setCursor(cursor);
738     m_leftPane->viewport()->setCursor(cursor);
739     QWidget::setCursor(cursor);
740 }
741 
clearUndoRedoStacks()742 void GlobalLogWindow::clearUndoRedoStacks()
743 {
744     m_leftPane->clearUndoRedoStacks();
745     m_rightPane->clearUndoRedoStacks();
746 }
747 
748 } // namespace Internal
749 } // namespace Debugger
750 
751 #include "logwindow.moc"
752