2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2010-12-02 15:18:07 +01:00
|
|
|
|
|
|
|
|
#include "sourceagent.h"
|
|
|
|
|
|
|
|
|
|
#include "debuggerengine.h"
|
2016-06-27 14:38:36 +02:00
|
|
|
#include "debuggericons.h"
|
2011-04-21 15:52:51 +02:00
|
|
|
#include "debuggerinternalconstants.h"
|
2023-01-09 13:14:39 +01:00
|
|
|
#include "debuggertr.h"
|
2010-12-02 15:18:07 +01:00
|
|
|
#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
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
namespace Debugger::Internal {
|
2010-12-02 15:18:07 +01:00
|
|
|
|
|
|
|
|
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;
|
2018-07-23 22:28:49 +02:00
|
|
|
TextMark *locationMark = nullptr;
|
2010-12-02 15:18:07 +01:00
|
|
|
QString path;
|
|
|
|
|
QString producer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SourceAgentPrivate::SourceAgentPrivate()
|
2018-10-07 22:38:47 +03:00
|
|
|
: producer("remote")
|
2010-12-02 15:18:07 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceAgentPrivate::~SourceAgentPrivate()
|
|
|
|
|
{
|
2014-08-15 16:23:32 +02:00
|
|
|
if (editor)
|
2020-09-29 10:24:48 +02:00
|
|
|
EditorManager::closeDocuments({editor->document()});
|
2018-07-23 22:28:49 +02:00
|
|
|
editor = nullptr;
|
2010-12-02 15:18:07 +01:00
|
|
|
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;
|
2017-02-20 16:31:35 +01:00
|
|
|
d = nullptr;
|
2010-12-02 15:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
2018-10-07 22:38:47 +03:00
|
|
|
QString titlePattern = d->producer + ": "
|
2019-05-28 13:49:26 +02:00
|
|
|
+ Utils::FilePath::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;
|
2018-07-23 22:28:49 +02:00
|
|
|
d->locationMark = nullptr;
|
2021-10-26 10:48:43 +02:00
|
|
|
if (d->engine->stackHandler()->currentFrame().file == Utils::FilePath::fromString(d->path)) {
|
2010-12-02 15:18:07 +01:00
|
|
|
int lineNumber = d->engine->stackHandler()->currentFrame().line;
|
2014-09-30 17:35:35 +02:00
|
|
|
|
2023-01-09 13:14:39 +01:00
|
|
|
d->locationMark = new TextMark(Utils::FilePath(),
|
|
|
|
|
lineNumber,
|
|
|
|
|
{Tr::tr("Debugger Location"),
|
|
|
|
|
Constants::TEXT_MARK_CATEGORY_LOCATION});
|
2016-06-27 14:38:36 +02:00
|
|
|
d->locationMark->setIcon(Icons::LOCATION.icon());
|
2014-09-30 17:35:35 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
} // Debugger::Internal
|