2011-02-28 13:40:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (c) 2014 Hugues Delorme
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-02-28 13:40:06 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-02-28 13:40:06 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02: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 <QRegExp>
|
|
|
|
|
#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;
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
BazaarEditor::BazaarEditor(const VcsBase::VcsBaseEditorParameters *type, QWidget *parent)
|
|
|
|
|
: VcsBase::VcsBaseEditorWidget(type, parent),
|
2012-01-26 14:18:59 +01:00
|
|
|
m_changesetId(QLatin1String(Constants::CHANGESET_ID)),
|
2013-01-19 23:19:38 +02:00
|
|
|
m_exactChangesetId(QLatin1String(Constants::CHANGESET_ID_EXACT))
|
2011-02-28 13:40:06 +01: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'
|
|
|
|
|
setDiffFilePattern(QRegExp(QLatin1String("^=== [a-z]+ [a-z]+ '(.+)'\\s*")));
|
2013-01-28 22:02:35 +02:00
|
|
|
setLogEntryPattern(QRegExp(QLatin1String("^revno: (\\d+)")));
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSet<QString> BazaarEditor::annotationChanges() const
|
|
|
|
|
{
|
|
|
|
|
QSet<QString> changes;
|
2011-03-14 17:52:50 +01:00
|
|
|
const QString txt = toPlainText();
|
|
|
|
|
if (txt.isEmpty())
|
2011-02-28 13:40:06 +01:00
|
|
|
return changes;
|
|
|
|
|
|
2011-11-22 15:50:49 +01:00
|
|
|
QRegExp changeNumRx(QLatin1String("^(" BZR_CHANGE_PATTERN ") "));
|
2011-03-14 17:52:50 +01:00
|
|
|
QTC_ASSERT(changeNumRx.isValid(), return changes);
|
|
|
|
|
if (changeNumRx.indexIn(txt) != -1) {
|
|
|
|
|
changes.insert(changeNumRx.cap(1));
|
2011-11-22 15:50:49 +01:00
|
|
|
changeNumRx.setPattern(QLatin1String("\n(" BZR_CHANGE_PATTERN ") "));
|
2011-03-14 17:52:50 +01:00
|
|
|
QTC_ASSERT(changeNumRx.isValid(), return changes);
|
|
|
|
|
int pos = 0;
|
|
|
|
|
while ((pos = changeNumRx.indexIn(txt, pos)) != -1) {
|
|
|
|
|
pos += changeNumRx.matchedLength();
|
|
|
|
|
changes.insert(changeNumRx.cap(1));
|
|
|
|
|
}
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
return changes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BazaarEditor::changeUnderCursor(const QTextCursor &cursorIn) const
|
|
|
|
|
{
|
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();
|
|
|
|
|
const int start = m_changesetId.indexIn(line);
|
|
|
|
|
if (start > -1) {
|
|
|
|
|
const QString match = m_changesetId.cap(0);
|
|
|
|
|
const int stop = start + match.length();
|
|
|
|
|
if (start <= cursorCol && cursorCol <= stop) {
|
|
|
|
|
cursor = cursorIn;
|
|
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
|
|
|
|
if (cursor.hasSelection()) {
|
|
|
|
|
const QString change = cursor.selectedText();
|
|
|
|
|
if (m_exactChangesetId.exactMatch(change))
|
|
|
|
|
return change;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-28 13:40:06 +01:00
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 12:57:31 +02:00
|
|
|
VcsBase::BaseAnnotationHighlighter *BazaarEditor::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
|
|
|
}
|