2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 Brian McGillion
|
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
|
2009-11-02 18:50:06 +01:00
|
|
|
|
2009-09-15 13:03:13 +03:00
|
|
|
#include "mercurialeditor.h"
|
2022-10-06 13:08:30 +02:00
|
|
|
|
2009-09-15 13:03:13 +03:00
|
|
|
#include "annotationhighlighter.h"
|
|
|
|
|
#include "constants.h"
|
2010-01-08 09:44:07 +01:00
|
|
|
#include "mercurialclient.h"
|
2022-10-06 13:08:30 +02:00
|
|
|
#include "mercurialtr.h"
|
2009-09-15 13:03:13 +03:00
|
|
|
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2015-03-25 10:31:55 +02:00
|
|
|
#include <vcsbase/diffandloghighlighter.h>
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QString>
|
|
|
|
|
#include <QTextCursor>
|
|
|
|
|
#include <QTextBlock>
|
|
|
|
|
#include <QDebug>
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2021-07-30 16:46:27 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2022-10-06 13:08:30 +02:00
|
|
|
namespace Mercurial::Internal {
|
2009-09-15 13:03:13 +03:00
|
|
|
|
2020-02-21 14:25:23 +01:00
|
|
|
// use QRegularExpression::anchoredPattern() when minimum Qt is raised to 5.12+
|
2020-01-29 12:50:48 +01:00
|
|
|
MercurialEditorWidget::MercurialEditorWidget(MercurialClient *client) :
|
2020-02-21 14:25:23 +01:00
|
|
|
exactIdentifier12(QString("\\A(?:") + Constants::CHANGEIDEXACT12 + QString(")\\z")),
|
|
|
|
|
exactIdentifier40(QString("\\A(?:") + Constants::CHANGEIDEXACT40 + QString(")\\z")),
|
2020-02-19 23:26:24 +02:00
|
|
|
changesetIdentifier40(Constants::CHANGESETID40),
|
2020-01-29 12:50:48 +01:00
|
|
|
m_client(client)
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2020-02-19 23:26:24 +02:00
|
|
|
setDiffFilePattern(Constants::DIFFIDENTIFIER);
|
|
|
|
|
setLogEntryPattern("^changeset:\\s+(\\S+)$");
|
2022-10-06 13:08:30 +02:00
|
|
|
setAnnotateRevisionTextFormat(Tr::tr("&Annotate %1"));
|
|
|
|
|
setAnnotatePreviousRevisionTextFormat(Tr::tr("Annotate &parent revision %1"));
|
2020-02-19 23:23:36 +02:00
|
|
|
setAnnotationEntryPattern(Constants::CHANGESETID12);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2014-08-21 20:43:33 +02:00
|
|
|
QString MercurialEditorWidget::changeUnderCursor(const QTextCursor &cursorIn) const
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
|
|
|
|
QTextCursor cursor = cursorIn;
|
|
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
|
|
|
|
if (cursor.hasSelection()) {
|
|
|
|
|
const QString change = cursor.selectedText();
|
2020-02-19 23:26:24 +02:00
|
|
|
if (exactIdentifier12.match(change).hasMatch())
|
2009-09-15 13:03:13 +03:00
|
|
|
return change;
|
2020-02-19 23:26:24 +02:00
|
|
|
if (exactIdentifier40.match(change).hasMatch())
|
2009-09-15 13:03:13 +03:00
|
|
|
return change;
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 20:43:33 +02:00
|
|
|
VcsBase::BaseAnnotationHighlighter *MercurialEditorWidget::createAnnotationHighlighter(const QSet<QString> &changes) const
|
2009-09-15 13:03:13 +03:00
|
|
|
{
|
2013-08-13 12:57:31 +02:00
|
|
|
return new MercurialAnnotationHighlighter(changes);
|
2009-09-15 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
2014-08-21 20:43:33 +02:00
|
|
|
QString MercurialEditorWidget::decorateVersion(const QString &revision) const
|
2012-06-04 12:15:54 +03:00
|
|
|
{
|
2023-01-20 10:35:45 +01:00
|
|
|
const FilePath workingDirectory = source().absolutePath();
|
2012-06-04 12:15:54 +03:00
|
|
|
// Format with short summary
|
2023-01-20 10:35:45 +01:00
|
|
|
return m_client->shortDescriptionSync(workingDirectory, revision);
|
2012-06-04 12:15:54 +03:00
|
|
|
}
|
|
|
|
|
|
2014-08-21 20:43:33 +02:00
|
|
|
QStringList MercurialEditorWidget::annotationPreviousVersions(const QString &revision) const
|
2010-01-08 09:44:07 +01:00
|
|
|
{
|
2023-01-20 10:35:45 +01:00
|
|
|
const FilePath filePath = source();
|
|
|
|
|
const FilePath workingDirectory = filePath.absolutePath();
|
2010-01-08 09:44:07 +01:00
|
|
|
// Retrieve parent revisions
|
2023-01-20 10:35:45 +01:00
|
|
|
return m_client->parentRevisionsSync(workingDirectory, filePath.fileName(), revision);
|
2010-01-08 09:44:07 +01:00
|
|
|
}
|
2014-11-04 22:12:40 +02:00
|
|
|
|
2022-10-06 13:08:30 +02:00
|
|
|
} // Mercurial::Internal
|