2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Hugues Delorme
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-28 13:40:06 +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.
|
2011-02-28 13:40:06 +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.
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2011-02-28 13:40:06 +01:00
|
|
|
#include "bazaareditor.h"
|
|
|
|
|
#include "annotationhighlighter.h"
|
|
|
|
|
#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
|
|
|
|
2011-02-28 13:40:06 +01:00
|
|
|
using namespace Bazaar::Internal;
|
|
|
|
|
using namespace Bazaar;
|
|
|
|
|
|
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
|
|
|
{
|
2015-03-10 12:21:33 +02:00
|
|
|
setAnnotateRevisionTextFormat(tr("&Annotate %1"));
|
|
|
|
|
setAnnotatePreviousRevisionTextFormat(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
|
|
|
}
|