2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-12-02 15:18:07 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-12-02 15:18:07 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-12-02 15:18:07 +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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-12-02 15:18:07 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 17:14:20 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-12-02 15:18:07 +01:00
|
|
|
|
|
|
|
|
#include "sourceagent.h"
|
|
|
|
|
|
|
|
|
|
#include "debuggerengine.h"
|
2011-04-21 15:52:51 +02:00
|
|
|
#include "debuggerinternalconstants.h"
|
2010-12-02 15:18:07 +01:00
|
|
|
#include "debuggercore.h"
|
|
|
|
|
#include "stackhandler.h"
|
|
|
|
|
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/idocument.h>
|
|
|
|
|
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <texteditor/textdocument.h>
|
2014-07-19 11:27:28 +02:00
|
|
|
#include <texteditor/textmark.h>
|
2010-12-02 15:18:07 +01:00
|
|
|
|
|
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
|
|
|
|
|
2015-01-10 23:40:32 +02:00
|
|
|
#include <utils/fileutils.h>
|
2010-12-02 15:18:07 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QTextBlock>
|
2010-12-02 15:18:07 +01:00
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
|
|
using namespace Core;
|
2014-09-30 17:35:35 +02:00
|
|
|
using namespace TextEditor;
|
2010-12-02 15:18:07 +01:00
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class SourceAgentPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SourceAgentPrivate();
|
|
|
|
|
~SourceAgentPrivate();
|
|
|
|
|
|
|
|
|
|
public:
|
2014-09-30 17:35:35 +02:00
|
|
|
QPointer<BaseTextEditor> editor;
|
2010-12-02 15:18:07 +01:00
|
|
|
QPointer<DebuggerEngine> engine;
|
2014-09-30 17:35:35 +02:00
|
|
|
TextMark *locationMark;
|
2010-12-02 15:18:07 +01:00
|
|
|
QString path;
|
|
|
|
|
QString producer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SourceAgentPrivate::SourceAgentPrivate()
|
|
|
|
|
: editor(0)
|
2012-02-21 16:27:04 +01:00
|
|
|
, locationMark(0)
|
2011-12-21 14:02:52 +01:00
|
|
|
, producer(QLatin1String("remote"))
|
2010-12-02 15:18:07 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceAgentPrivate::~SourceAgentPrivate()
|
|
|
|
|
{
|
2014-08-15 16:23:32 +02:00
|
|
|
if (editor)
|
|
|
|
|
EditorManager::closeDocument(editor->document());
|
2010-12-02 15:18:07 +01:00
|
|
|
editor = 0;
|
|
|
|
|
delete locationMark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceAgent::SourceAgent(DebuggerEngine *engine)
|
2012-03-14 12:42:09 +01:00
|
|
|
: d(new SourceAgentPrivate)
|
2010-12-02 15:18:07 +01:00
|
|
|
{
|
|
|
|
|
d->engine = engine;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceAgent::~SourceAgent()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
d = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourceAgent::setSourceProducerName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
d->producer = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourceAgent::setContent(const QString &filePath, const QString &content)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d, return);
|
|
|
|
|
d->path = filePath;
|
|
|
|
|
|
|
|
|
|
if (!d->editor) {
|
|
|
|
|
QString titlePattern = d->producer + QLatin1String(": ")
|
2015-01-10 23:40:32 +02:00
|
|
|
+ Utils::FileName::fromString(filePath).fileName();
|
2014-07-18 15:29:04 +02:00
|
|
|
d->editor = qobject_cast<BaseTextEditor *>(
|
2012-05-08 09:43:14 +02:00
|
|
|
EditorManager::openEditorWithContents(
|
2010-12-02 15:18:07 +01:00
|
|
|
CppEditor::Constants::CPPEDITOR_ID,
|
2013-07-15 15:14:10 +02:00
|
|
|
&titlePattern, content.toUtf8()));
|
2010-12-02 15:18:07 +01:00
|
|
|
QTC_ASSERT(d->editor, return);
|
2013-07-09 12:14:33 +02:00
|
|
|
d->editor->document()->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
|
2010-12-02 15:18:07 +01:00
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *baseTextEdit = d->editor->editorWidget();
|
2010-12-02 15:18:07 +01:00
|
|
|
if (baseTextEdit)
|
|
|
|
|
baseTextEdit->setRequestMarkEnabled(true);
|
2014-03-06 15:44:13 +01:00
|
|
|
} else {
|
|
|
|
|
EditorManager::activateEditor(d->editor);
|
2010-12-02 15:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-18 15:29:04 +02:00
|
|
|
QPlainTextEdit *plainTextEdit = d->editor->editorWidget();
|
2010-12-02 15:18:07 +01:00
|
|
|
QTC_ASSERT(plainTextEdit, return);
|
|
|
|
|
plainTextEdit->setReadOnly(true);
|
|
|
|
|
|
|
|
|
|
updateLocationMarker();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SourceAgent::updateLocationMarker()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->editor, return);
|
|
|
|
|
|
2012-02-21 16:27:04 +01:00
|
|
|
if (d->locationMark)
|
2014-08-01 23:31:56 +02:00
|
|
|
d->editor->textDocument()->removeMark(d->locationMark);
|
2012-02-21 16:27:04 +01:00
|
|
|
delete d->locationMark;
|
|
|
|
|
d->locationMark = 0;
|
2010-12-02 15:18:07 +01:00
|
|
|
if (d->engine->stackHandler()->currentFrame().file == d->path) {
|
|
|
|
|
int lineNumber = d->engine->stackHandler()->currentFrame().line;
|
2014-09-30 17:35:35 +02:00
|
|
|
|
2015-04-17 12:46:28 +02:00
|
|
|
d->locationMark = new TextMark(QString(), lineNumber,
|
|
|
|
|
Constants::TEXT_MARK_CATEGORY_LOCATION);
|
2014-09-30 17:35:35 +02:00
|
|
|
d->locationMark->setIcon(locationMarkIcon());
|
|
|
|
|
d->locationMark->setPriority(TextMark::HighPriority);
|
|
|
|
|
|
2014-08-01 23:31:56 +02:00
|
|
|
d->editor->textDocument()->addMark(d->locationMark);
|
2014-08-27 11:57:32 +02:00
|
|
|
QTextCursor tc = d->editor->textCursor();
|
2010-12-02 15:18:07 +01:00
|
|
|
QTextBlock block = tc.document()->findBlockByNumber(lineNumber - 1);
|
|
|
|
|
tc.setPosition(block.position());
|
2014-08-27 11:57:32 +02:00
|
|
|
d->editor->setTextCursor(tc);
|
2012-05-08 09:43:14 +02:00
|
|
|
EditorManager::activateEditor(d->editor);
|
2010-12-02 15:18:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|