2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "compileoutputwindow.h"
|
|
|
|
|
#include "buildmanager.h"
|
2010-06-30 16:39:32 +02:00
|
|
|
#include "showoutputtaskhandler.h"
|
|
|
|
|
#include "task.h"
|
2011-04-14 10:39:09 +02:00
|
|
|
#include "projectexplorer.h"
|
|
|
|
|
#include "projectexplorersettings.h"
|
2010-06-25 10:41:49 +02:00
|
|
|
#include "taskhub.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-03-25 17:13:18 +01:00
|
|
|
#include <coreplugin/outputwindow.h>
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <coreplugin/find/basetextfind.h>
|
2010-06-30 16:39:32 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2012-05-07 16:32:06 +02:00
|
|
|
#include <texteditor/texteditorsettings.h>
|
|
|
|
|
#include <texteditor/fontsettings.h>
|
2013-09-03 06:47:17 +03:00
|
|
|
#include <utils/ansiescapecodehandler.h>
|
2015-03-19 20:00:15 +01:00
|
|
|
#include <utils/theme/theme.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QIcon>
|
|
|
|
|
#include <QTextCharFormat>
|
|
|
|
|
#include <QTextBlock>
|
|
|
|
|
#include <QTextCursor>
|
|
|
|
|
#include <QPlainTextEdit>
|
2012-03-28 22:23:03 +02:00
|
|
|
#include <QToolButton>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
|
2010-07-02 15:54:41 +02:00
|
|
|
namespace {
|
2012-10-15 15:21:28 +02:00
|
|
|
const int MAX_LINECOUNT = 100000;
|
2010-07-02 15:54:41 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-25 10:41:49 +02:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class CompileOutputTextEdit : public Core::OutputWindow
|
|
|
|
|
{
|
2012-05-07 16:32:06 +02:00
|
|
|
Q_OBJECT
|
2010-06-25 10:41:49 +02:00
|
|
|
public:
|
|
|
|
|
CompileOutputTextEdit(const Core::Context &context) : Core::OutputWindow(context)
|
|
|
|
|
{
|
2012-05-07 16:32:06 +02:00
|
|
|
fontSettingsChanged();
|
|
|
|
|
connect(TextEditor::TextEditorSettings::instance(), SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
|
|
|
|
|
this, SLOT(fontSettingsChanged()));
|
2010-06-25 10:41:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addTask(const Task &task, int blocknumber)
|
|
|
|
|
{
|
|
|
|
|
m_taskids.insert(blocknumber, task.taskId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearTasks()
|
|
|
|
|
{
|
|
|
|
|
m_taskids.clear();
|
|
|
|
|
}
|
2012-05-07 16:32:06 +02:00
|
|
|
private slots:
|
|
|
|
|
void fontSettingsChanged()
|
|
|
|
|
{
|
2013-09-19 17:59:27 +02:00
|
|
|
setFont(TextEditor::TextEditorSettings::fontSettings().font());
|
2012-05-07 16:32:06 +02:00
|
|
|
}
|
2010-06-25 10:41:49 +02:00
|
|
|
|
|
|
|
|
protected:
|
2015-03-17 09:59:17 +01:00
|
|
|
void wheelEvent(QWheelEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
// from QPlainTextEdit, but without scroll wheel zooming
|
|
|
|
|
QAbstractScrollArea::wheelEvent(ev);
|
|
|
|
|
updateMicroFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-25 18:40:14 +02:00
|
|
|
void mouseDoubleClickEvent(QMouseEvent *ev)
|
|
|
|
|
{
|
2010-06-25 10:41:49 +02:00
|
|
|
int line = cursorForPosition(ev->pos()).block().blockNumber();
|
2013-11-11 22:20:47 +02:00
|
|
|
if (unsigned taskid = m_taskids.value(line, 0))
|
2013-08-22 13:25:27 +02:00
|
|
|
TaskHub::showTaskInEditor(taskid);
|
2013-11-11 22:20:47 +02:00
|
|
|
else
|
2010-06-25 10:41:49 +02:00
|
|
|
QPlainTextEdit::mouseDoubleClickEvent(ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QHash<int, unsigned int> m_taskids; //Map blocknumber to taskId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|
|
|
|
|
|
2014-01-27 14:04:03 +01:00
|
|
|
CompileOutputWindow::CompileOutputWindow(QAction *cancelBuildAction) :
|
2013-09-03 06:47:17 +03:00
|
|
|
m_cancelBuildButton(new QToolButton),
|
|
|
|
|
m_escapeCodeHandler(new Utils::AnsiEscapeCodeHandler)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-04-14 10:39:09 +02:00
|
|
|
Core::Context context(Constants::C_COMPILE_OUTPUT);
|
2010-06-25 10:41:49 +02:00
|
|
|
m_outputWindow = new CompileOutputTextEdit(context);
|
2010-07-12 14:01:42 +02:00
|
|
|
m_outputWindow->setWindowTitle(tr("Compile Output"));
|
2011-05-20 19:48:44 +02:00
|
|
|
m_outputWindow->setWindowIcon(QIcon(QLatin1String(Constants::ICON_WINDOW)));
|
2010-07-12 14:01:42 +02:00
|
|
|
m_outputWindow->setReadOnly(true);
|
2011-02-04 14:51:55 +01:00
|
|
|
m_outputWindow->setUndoRedoEnabled(false);
|
2011-04-29 09:36:04 +02:00
|
|
|
m_outputWindow->setMaxLineCount(MAX_LINECOUNT);
|
2010-07-12 14:01:42 +02:00
|
|
|
|
2012-12-20 11:34:00 +01:00
|
|
|
// Let selected text be colored as if the text edit was editable,
|
|
|
|
|
// otherwise the highlight for searching is too light
|
|
|
|
|
QPalette p = m_outputWindow->palette();
|
|
|
|
|
QColor activeHighlight = p.color(QPalette::Active, QPalette::Highlight);
|
|
|
|
|
p.setColor(QPalette::Highlight, activeHighlight);
|
|
|
|
|
QColor activeHighlightedText = p.color(QPalette::Active, QPalette::HighlightedText);
|
|
|
|
|
p.setColor(QPalette::HighlightedText, activeHighlightedText);
|
|
|
|
|
m_outputWindow->setPalette(p);
|
|
|
|
|
|
2012-03-28 22:23:03 +02:00
|
|
|
m_cancelBuildButton->setDefaultAction(cancelBuildAction);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
|
2010-07-12 14:01:42 +02:00
|
|
|
agg->add(m_outputWindow);
|
2014-01-13 16:17:34 +01:00
|
|
|
agg->add(new Core::BaseTextFind(m_outputWindow));
|
2010-06-08 15:04:42 +02:00
|
|
|
|
|
|
|
|
qRegisterMetaType<QTextCharFormat>("QTextCharFormat");
|
2010-06-30 16:39:32 +02:00
|
|
|
|
|
|
|
|
m_handler = new ShowOutputTaskHandler(this);
|
2012-06-18 11:34:15 +02:00
|
|
|
ExtensionSystem::PluginManager::addObject(m_handler);
|
2011-04-14 10:39:09 +02:00
|
|
|
connect(ProjectExplorerPlugin::instance(), SIGNAL(settingsChanged()),
|
|
|
|
|
this, SLOT(updateWordWrapMode()));
|
|
|
|
|
updateWordWrapMode();
|
2010-06-30 16:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CompileOutputWindow::~CompileOutputWindow()
|
|
|
|
|
{
|
2012-06-18 11:34:15 +02:00
|
|
|
ExtensionSystem::PluginManager::removeObject(m_handler);
|
2010-06-30 16:39:32 +02:00
|
|
|
delete m_handler;
|
2012-03-28 22:23:03 +02:00
|
|
|
delete m_cancelBuildButton;
|
2013-09-03 06:47:17 +03:00
|
|
|
delete m_escapeCodeHandler;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 10:39:09 +02:00
|
|
|
void CompileOutputWindow::updateWordWrapMode()
|
|
|
|
|
{
|
2013-09-05 18:30:50 +02:00
|
|
|
m_outputWindow->setWordWrapEnabled(ProjectExplorerPlugin::projectExplorerSettings().wrapAppOutput);
|
2011-04-14 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool CompileOutputWindow::hasFocus() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-11-07 15:48:36 +01:00
|
|
|
return m_outputWindow->window()->focusWidget() == m_outputWindow;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool CompileOutputWindow::canFocus() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompileOutputWindow::setFocus()
|
|
|
|
|
{
|
2010-07-12 14:01:42 +02:00
|
|
|
m_outputWindow->setFocus();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *CompileOutputWindow::outputWidget(QWidget *)
|
|
|
|
|
{
|
2010-07-12 14:01:42 +02:00
|
|
|
return m_outputWindow;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-03-28 22:23:03 +02:00
|
|
|
QList<QWidget *> CompileOutputWindow::toolBarWidgets() const
|
|
|
|
|
{
|
|
|
|
|
return QList<QWidget *>() << m_cancelBuildButton;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 22:37:28 +03:00
|
|
|
void CompileOutputWindow::appendText(const QString &text, BuildStep::OutputFormat format)
|
2010-07-15 10:29:38 +02:00
|
|
|
{
|
2015-03-19 20:00:15 +01:00
|
|
|
using Utils::Theme;
|
2010-07-15 10:29:38 +02:00
|
|
|
QPalette p = m_outputWindow->palette();
|
2015-03-19 20:00:15 +01:00
|
|
|
Theme *theme = Utils::creatorTheme();
|
2010-07-15 10:29:38 +02:00
|
|
|
QTextCharFormat textFormat;
|
|
|
|
|
switch (format) {
|
|
|
|
|
case BuildStep::NormalOutput:
|
2015-03-19 20:00:15 +01:00
|
|
|
textFormat.setForeground(theme->color(Theme::TextColorNormal));
|
2010-07-15 10:29:38 +02:00
|
|
|
textFormat.setFontWeight(QFont::Normal);
|
|
|
|
|
break;
|
|
|
|
|
case BuildStep::ErrorOutput:
|
2015-03-30 10:47:48 +03:00
|
|
|
textFormat.setForeground(theme->color(Theme::OutputPanes_ErrorMessageTextColor));
|
2010-07-15 10:29:38 +02:00
|
|
|
textFormat.setFontWeight(QFont::Normal);
|
|
|
|
|
break;
|
|
|
|
|
case BuildStep::MessageOutput:
|
2015-03-30 10:47:48 +03:00
|
|
|
textFormat.setForeground(theme->color(Theme::OutputPanes_MessageOutput));
|
2010-07-15 10:29:38 +02:00
|
|
|
break;
|
|
|
|
|
case BuildStep::ErrorMessageOutput:
|
2015-03-30 10:47:48 +03:00
|
|
|
textFormat.setForeground(theme->color(Theme::OutputPanes_ErrorMessageTextColor));
|
2010-07-15 10:29:38 +02:00
|
|
|
textFormat.setFontWeight(QFont::Bold);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-17 15:55:27 +01:00
|
|
|
foreach (const Utils::FormattedText &output,
|
|
|
|
|
m_escapeCodeHandler->parseText(Utils::FormattedText(text, textFormat)))
|
|
|
|
|
m_outputWindow->appendText(output.text, output.format);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompileOutputWindow::clearContents()
|
|
|
|
|
{
|
2010-07-12 14:01:42 +02:00
|
|
|
m_outputWindow->clear();
|
2010-06-25 10:41:49 +02:00
|
|
|
m_outputWindow->clearTasks();
|
2010-06-30 16:39:32 +02:00
|
|
|
m_taskPositions.clear();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 14:01:42 +02:00
|
|
|
void CompileOutputWindow::visibilityChanged(bool)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-12 14:01:42 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CompileOutputWindow::priorityInStatusBar() const
|
|
|
|
|
{
|
|
|
|
|
return 50;
|
|
|
|
|
}
|
2009-04-30 12:50:52 +02:00
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool CompileOutputWindow::canNext() const
|
2009-04-30 12:50:52 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool CompileOutputWindow::canPrevious() const
|
2009-04-30 12:50:52 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompileOutputWindow::goToNext()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompileOutputWindow::goToPrev()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:47:06 +02:00
|
|
|
bool CompileOutputWindow::canNavigate() const
|
2009-04-30 12:50:52 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-06-30 16:39:32 +02:00
|
|
|
|
2015-04-20 17:13:45 +02:00
|
|
|
void CompileOutputWindow::registerPositionOf(const Task &task, int linkedOutputLines, int skipLines)
|
2010-06-30 16:39:32 +02:00
|
|
|
{
|
2015-04-20 17:13:45 +02:00
|
|
|
if (linkedOutputLines <= 0)
|
|
|
|
|
return;
|
|
|
|
|
int blocknumber = m_outputWindow->document()->blockCount();
|
2010-07-02 15:54:41 +02:00
|
|
|
if (blocknumber > MAX_LINECOUNT)
|
|
|
|
|
return;
|
2010-06-25 10:41:49 +02:00
|
|
|
|
2015-04-20 17:13:45 +02:00
|
|
|
const int startLine = blocknumber - linkedOutputLines + 1 - skipLines;
|
|
|
|
|
const int endLine = blocknumber - skipLines;
|
|
|
|
|
|
|
|
|
|
m_taskPositions.insert(task.taskId, qMakePair(startLine, endLine));
|
|
|
|
|
|
|
|
|
|
for (int i = startLine; i <= endLine; ++i)
|
|
|
|
|
m_outputWindow->addTask(task, i);
|
2010-06-30 16:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CompileOutputWindow::knowsPositionOf(const Task &task)
|
|
|
|
|
{
|
|
|
|
|
return (m_taskPositions.contains(task.taskId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompileOutputWindow::showPositionOf(const Task &task)
|
|
|
|
|
{
|
2015-04-20 17:13:45 +02:00
|
|
|
QPair<int, int> position = m_taskPositions.value(task.taskId);
|
|
|
|
|
QTextCursor newCursor(m_outputWindow->document()->findBlockByNumber(position.second));
|
|
|
|
|
|
|
|
|
|
// Move cursor to end of last line of interest:
|
|
|
|
|
newCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::MoveAnchor);
|
2010-07-12 14:01:42 +02:00
|
|
|
m_outputWindow->setTextCursor(newCursor);
|
2015-04-20 17:13:45 +02:00
|
|
|
|
|
|
|
|
// Move cursor and select lines:
|
|
|
|
|
newCursor.setPosition(m_outputWindow->document()->findBlockByNumber(position.first).position(),
|
|
|
|
|
QTextCursor::KeepAnchor);
|
|
|
|
|
m_outputWindow->setTextCursor(newCursor);
|
|
|
|
|
|
|
|
|
|
// Center cursor now:
|
|
|
|
|
m_outputWindow->centerCursor();
|
2010-06-30 16:39:32 +02:00
|
|
|
}
|
2012-05-07 16:32:06 +02:00
|
|
|
|
2013-09-03 06:47:17 +03:00
|
|
|
void CompileOutputWindow::flush()
|
|
|
|
|
{
|
|
|
|
|
if (m_escapeCodeHandler)
|
|
|
|
|
m_escapeCodeHandler->endFormatScope();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 16:32:06 +02:00
|
|
|
#include "compileoutputwindow.moc"
|