2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/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
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt 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>
|
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:
|
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
|
|
|
{
|
2010-07-12 14:01:42 +02:00
|
|
|
return m_outputWindow->hasFocus();
|
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-05-19 18:34:53 +03:00
|
|
|
static QColor mix_colors(const QColor &a, const QColor &b)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-27 15:21:51 +02:00
|
|
|
return QColor((a.red() + 2 * b.red()) / 3, (a.green() + 2 * b.green()) / 3,
|
|
|
|
|
(a.blue() + 2* b.blue()) / 3, (a.alpha() + 2 * b.alpha()) / 3);
|
2010-07-15 10:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompileOutputWindow::appendText(const QString &text, ProjectExplorer::BuildStep::OutputFormat format)
|
|
|
|
|
{
|
|
|
|
|
QPalette p = m_outputWindow->palette();
|
|
|
|
|
QTextCharFormat textFormat;
|
|
|
|
|
switch (format) {
|
|
|
|
|
case BuildStep::NormalOutput:
|
|
|
|
|
textFormat.setForeground(p.color(QPalette::Text));
|
|
|
|
|
textFormat.setFontWeight(QFont::Normal);
|
|
|
|
|
break;
|
|
|
|
|
case BuildStep::ErrorOutput:
|
|
|
|
|
textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
|
|
|
|
|
textFormat.setFontWeight(QFont::Normal);
|
|
|
|
|
break;
|
|
|
|
|
case BuildStep::MessageOutput:
|
|
|
|
|
textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::blue)));
|
|
|
|
|
break;
|
|
|
|
|
case BuildStep::ErrorMessageOutput:
|
|
|
|
|
textFormat.setForeground(mix_colors(p.color(QPalette::Text), QColor(Qt::red)));
|
|
|
|
|
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
|
|
|
|
|
|
|
|
void CompileOutputWindow::registerPositionOf(const Task &task)
|
|
|
|
|
{
|
2010-07-12 14:01:42 +02:00
|
|
|
int blocknumber = m_outputWindow->blockCount();
|
2010-07-02 15:54:41 +02:00
|
|
|
if (blocknumber > MAX_LINECOUNT)
|
|
|
|
|
return;
|
2010-06-25 10:41:49 +02:00
|
|
|
|
2010-08-04 14:50:46 +02:00
|
|
|
m_taskPositions.insert(task.taskId, blocknumber);
|
2010-06-25 10:41:49 +02:00
|
|
|
m_outputWindow->addTask(task, blocknumber);
|
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)
|
|
|
|
|
{
|
|
|
|
|
int position = m_taskPositions.value(task.taskId);
|
2010-07-12 14:01:42 +02:00
|
|
|
QTextCursor newCursor(m_outputWindow->document()->findBlockByNumber(position));
|
2010-06-30 16:39:32 +02:00
|
|
|
newCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
2010-07-12 14:01:42 +02:00
|
|
|
m_outputWindow->setTextCursor(newCursor);
|
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"
|