2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 Hugues Delorme
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2011-02-28 13:40:06 +01:00
|
|
|
#include "bazaareditor.h"
|
2022-09-23 14:25:49 +02:00
|
|
|
|
2011-02-28 13:40:06 +01:00
|
|
|
#include "annotationhighlighter.h"
|
2022-09-23 14:25:49 +02:00
|
|
|
#include "bazaartr.h"
|
2011-02-28 13:40:06 +01:00
|
|
|
#include "constants.h"
|
|
|
|
|
|
2011-03-14 17:52:50 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2011-02-28 13:40:06 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QString>
|
|
|
|
|
#include <QTextCursor>
|
2011-02-28 13:40:06 +01:00
|
|
|
|
2011-11-10 16:06:19 +01:00
|
|
|
#define BZR_CHANGE_PATTERN "[0-9]+"
|
2011-03-14 17:52:50 +01:00
|
|
|
|
2022-09-23 14:25:49 +02:00
|
|
|
namespace Bazaar::Internal {
|
2011-02-28 13:40:06 +01:00
|
|
|
|
2014-08-21 20:43:33 +02:00
|
|
|
BazaarEditorWidget::BazaarEditorWidget() :
|
2016-02-03 17:35:54 +01:00
|
|
|
m_changesetId(QLatin1String(Constants::CHANGESET_ID)),
|
|
|
|
|
m_exactChangesetId(QLatin1String(Constants::CHANGESET_ID_EXACT))
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
2022-09-23 14:25:49 +02:00
|
|
|
setAnnotateRevisionTextFormat(Tr::tr("&Annotate %1"));
|
|
|
|
|
setAnnotatePreviousRevisionTextFormat(Tr::tr("Annotate &parent revision %1"));
|
2013-01-19 23:19:38 +02:00
|
|
|
// Diff format:
|
|
|
|
|
// === <change> <file|dir> 'mainwindow.cpp'
|
2020-02-19 23:26:24 +02:00
|
|
|
setDiffFilePattern("^=== [a-z]+ [a-z]+ '(.+)'\\s*");
|
|
|
|
|
setLogEntryPattern("^revno: (\\d+)");
|
2020-02-19 23:23:36 +02:00
|
|
|
setAnnotationEntryPattern("^(" BZR_CHANGE_PATTERN ") ");
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-21 20:43:33 +02:00
|
|
|
QString BazaarEditorWidget::changeUnderCursor(const QTextCursor &cursorIn) const
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
2012-01-26 14:18:59 +01:00
|
|
|
// The test is done in two steps: first we check if the line contains a
|
|
|
|
|
// changesetId. Then we check if the cursor is over the changesetId itself
|
|
|
|
|
// and not over "revno" or another part of the line.
|
|
|
|
|
// The two steps are necessary because matching only for the changesetId
|
|
|
|
|
// leads to many false-positives (a regex like "[0-9]+" matches a lot of text).
|
|
|
|
|
const int cursorCol = cursorIn.columnNumber();
|
2011-02-28 13:40:06 +01:00
|
|
|
QTextCursor cursor = cursorIn;
|
2012-01-26 14:18:59 +01:00
|
|
|
cursor.select(QTextCursor::LineUnderCursor);
|
2011-02-28 13:40:06 +01:00
|
|
|
if (cursor.hasSelection()) {
|
2012-01-26 14:18:59 +01:00
|
|
|
const QString line = cursor.selectedText();
|
2020-06-23 16:36:59 +02:00
|
|
|
const QRegularExpressionMatch match = m_changesetId.match(line);
|
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
|
const int start = match.capturedStart();
|
|
|
|
|
const int stop = match.capturedEnd();
|
2012-01-26 14:18:59 +01:00
|
|
|
if (start <= cursorCol && cursorCol <= stop) {
|
|
|
|
|
cursor = cursorIn;
|
|
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
|
|
|
|
if (cursor.hasSelection()) {
|
|
|
|
|
const QString change = cursor.selectedText();
|
2020-06-23 16:36:59 +02:00
|
|
|
if (m_exactChangesetId.match(change).hasMatch())
|
2012-01-26 14:18:59 +01:00
|
|
|
return change;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 20:43:33 +02:00
|
|
|
VcsBase::BaseAnnotationHighlighter *BazaarEditorWidget::createAnnotationHighlighter(const QSet<QString> &changes) const
|
2011-02-28 13:40:06 +01:00
|
|
|
{
|
2013-08-13 12:57:31 +02:00
|
|
|
return new BazaarAnnotationHighlighter(changes);
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
2022-09-23 14:25:49 +02:00
|
|
|
|
|
|
|
|
} // Bazaar::Internal
|