Commit 18f93755 authored by Friedemann Kleint's avatar Friedemann Kleint

Add a CVS plugin for use with UNIX cvs or Tortoise CVS.

parent d53129d3
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/vnd.nokia.text.cvs.submit">
<comment>CVS submit template</comment>
<sub-class-of type="text/plain"/>
</mime-type>
</mime-info>
<plugin name="CVS" version="1.2.80" compatVersion="1.2.80">
<vendor>Nokia Corporation</vendor>
<copyright>(C) 2008-2009 Nokia Corporation</copyright>
<license>
Commercial Usage
Licensees holding valid Qt Commercial licenses may use this plugin in
accordance with the Qt Commercial License Agreement provided with the
Software or, alternatively, in accordance with the terms contained in
a written agreement between you and Nokia.
GNU Lesser General Public License Usage
Alternatively, this plugin may be used under the terms of the GNU Lesser
General Public License version 2.1 as published by the Free Software
Foundation. 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.</license>
<description>CVS integration.</description>
<url>http://www.qtsoftware.com</url>
<dependencyList>
<dependency name="TextEditor" version="1.2.80"/>
<dependency name="ProjectExplorer" version="1.2.80"/>
<dependency name="Core" version="1.2.80"/>
<dependency name="VCSBase" version="1.2.80"/>
</dependencyList>
</plugin>
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#include "annotationhighlighter.h"
using namespace CVS;
using namespace CVS::Internal;
CVSAnnotationHighlighter::CVSAnnotationHighlighter(const ChangeNumbers &changeNumbers,
QTextDocument *document) :
VCSBase::BaseAnnotationHighlighter(changeNumbers, document),
m_blank(QLatin1Char(' '))
{
}
QString CVSAnnotationHighlighter::changeNumber(const QString &block) const
{
const int pos = block.indexOf(m_blank);
return pos > 1 ? block.left(pos) : QString();
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#ifndef ANNOTATIONHIGHLIGHTER_H
#define ANNOTATIONHIGHLIGHTER_H
#include <vcsbase/baseannotationhighlighter.h>
namespace CVS {
namespace Internal {
// Annotation highlighter for cvs triggering on 'changenumber '
class CVSAnnotationHighlighter : public VCSBase::BaseAnnotationHighlighter
{
Q_OBJECT
public:
explicit CVSAnnotationHighlighter(const ChangeNumbers &changeNumbers,
QTextDocument *document = 0);
private:
virtual QString changeNumber(const QString &block) const;
const QChar m_blank;
};
} // namespace Internal
} // namespace CVS
#endif // ANNOTATIONHIGHLIGHTER_H
TEMPLATE = lib
TARGET = CVS
include(../../qtcreatorplugin.pri)
include(../../plugins/projectexplorer/projectexplorer.pri)
include(../../plugins/texteditor/texteditor.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/vcsbase/vcsbase.pri)
include(../../libs/utils/utils.pri)
HEADERS += annotationhighlighter.h \
cvsplugin.h \
cvscontrol.h \
cvsoutputwindow.h \
settingspage.h \
cvseditor.h \
cvssubmiteditor.h \
cvssettings.h \
cvsutils.h \
cvsconstants.h
SOURCES += annotationhighlighter.cpp \
cvsplugin.cpp \
cvscontrol.cpp \
cvsoutputwindow.cpp \
settingspage.cpp \
cvseditor.cpp \
cvssubmiteditor.cpp \
cvssettings.cpp \
cvsutils.cpp
FORMS += settingspage.ui
RESOURCES += cvs.qrc
OTHER_FILES += CVS.pluginspec
<RCC>
<qresource prefix="/trolltech.cvs" >
<file>CVS.mimetypes.xml</file>
</qresource>
</RCC>
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#ifndef CVS_CONSTANTS_H
#define CVS_CONSTANTS_H
namespace CVS {
namespace Constants {
const char * const CVS_SUBMIT_MIMETYPE = "application/vnd.nokia.text.cvs.submit";
const char * const CVSEDITOR = "CVS Editor";
const char * const CVSEDITOR_KIND = "CVS Editor";
const char * const CVSCOMMITEDITOR = "CVS Commit Editor";
const char * const CVSCOMMITEDITOR_KIND = "CVS Commit Editor";
const char * const SUBMIT_CURRENT = "CVS.SubmitCurrentLog";
const char * const DIFF_SELECTED = "CVS.DiffSelectedFilesInLog";
enum { debug = 0 };
} // namespace Constants
} // namespace SubVersion
#endif // CVS_CONSTANTS_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#include "cvscontrol.h"
#include "cvsplugin.h"
using namespace CVS;
using namespace CVS::Internal;
CVSControl::CVSControl(CVSPlugin *plugin) :
m_enabled(true),
m_plugin(plugin)
{
}
QString CVSControl::name() const
{
return QLatin1String("cvs");
}
bool CVSControl::isEnabled() const
{
return m_enabled;
}
void CVSControl::setEnabled(bool enabled)
{
if (m_enabled != enabled) {
m_enabled = enabled;
emit enabledChanged(m_enabled);
}
}
bool CVSControl::supportsOperation(Operation operation) const
{
bool rc = true;
switch (operation) {
case AddOperation:
case DeleteOperation:
break;
case OpenOperation:
rc = false;
break;
}
return rc;
}
bool CVSControl::vcsOpen(const QString & /* fileName */)
{
// Open for edit: N/A
return true;
}
bool CVSControl::vcsAdd(const QString &fileName)
{
return m_plugin->vcsAdd(fileName);
}
bool CVSControl::vcsDelete(const QString &fileName)
{
return m_plugin->vcsDelete(fileName);
}
bool CVSControl::managesDirectory(const QString &directory) const
{
return m_plugin->managesDirectory(directory);
}
QString CVSControl::findTopLevelForDirectory(const QString &directory) const
{
return m_plugin->findTopLevelForDirectory(directory);
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#ifndef CVSCONTROL_H
#define CVSCONTROL_H
#include <coreplugin/iversioncontrol.h>
namespace CVS {
namespace Internal {
class CVSPlugin;
// Just a proxy for CVSPlugin
class CVSControl : public Core::IVersionControl
{
Q_OBJECT
public:
explicit CVSControl(CVSPlugin *plugin);
virtual QString name() const;
virtual bool isEnabled() const;
virtual void setEnabled(bool enabled);
virtual bool managesDirectory(const QString &directory) const;
virtual QString findTopLevelForDirectory(const QString &directory) const;
virtual bool supportsOperation(Operation operation) const;
virtual bool vcsOpen(const QString &fileName);
virtual bool vcsAdd(const QString &fileName);
virtual bool vcsDelete(const QString &filename);
signals:
void enabledChanged(bool);
private:
bool m_enabled;
CVSPlugin *m_plugin;
};
} // namespace Internal
} // namespace CVS
#endif // CVSCONTROL_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#include "cvseditor.h"
#include "annotationhighlighter.h"
#include "cvsconstants.h"
#include <utils/qtcassert.h>
#include <vcsbase/diffhighlighter.h>
#include <QtCore/QDebug>
#include <QtGui/QTextCursor>
namespace CVS {
namespace Internal {
// Match a CVS revision ("1.1.1.1")
#define CVS_REVISION_PATTERN "[\\d\\.]+"
#define CVS_REVISION_AT_START_PATTERN "^("CVS_REVISION_PATTERN") "
CVSEditor::CVSEditor(const VCSBase::VCSBaseEditorParameters *type,
QWidget *parent) :
VCSBase::VCSBaseEditor(type, parent),
m_revisionPattern(QLatin1String(CVS_REVISION_AT_START_PATTERN".*$"))
{
QTC_ASSERT(m_revisionPattern.isValid(), return);
}
QSet<QString> CVSEditor::annotationChanges() const
{
QSet<QString> changes;
const QString txt = toPlainText();
if (txt.isEmpty())
return changes;
// Hunt for first change number in annotation: "1.1 (author)"
QRegExp r(QLatin1String(CVS_REVISION_AT_START_PATTERN));
QTC_ASSERT(r.isValid(), return changes);
if (r.indexIn(txt) != -1) {
changes.insert(r.cap(1));
r.setPattern(QLatin1String("\n("CVS_REVISION_PATTERN") "));
QTC_ASSERT(r.isValid(), return changes);
int pos = 0;
while ((pos = r.indexIn(txt, pos)) != -1) {
pos += r.matchedLength();
changes.insert(r.cap(1));
}
}
if (CVS::Constants::debug)
qDebug() << "CVSEditor::annotationChanges() returns #" << changes.size();
return changes;
}
QString CVSEditor::changeUnderCursor(const QTextCursor &c) const
{
// Check for a revision number at the beginning of the line.
// Note that "cursor.select(QTextCursor::WordUnderCursor)" will
// only select the part up until the dot.
// Check if we are at the beginning of a line within a reasonable offset.
const QTextBlock block = c.block();
if (c.atBlockStart() || (c.position() - block.position() < 3)) {
const QString line = block.text();
if (m_revisionPattern.exactMatch(line))
return m_revisionPattern.cap(1);
}
return QString();
}
/* \code
cvs diff -d -u -r1.1 -r1.2:
--- mainwindow.cpp<\t>13 Jul 2009 13:50:15 -0000 <\t>1.1
+++ mainwindow.cpp<\t>14 Jul 2009 07:09:24 -0000<\t>1.2
@@ -6,6 +6,5 @@
\endcode
*/
VCSBase::DiffHighlighter *CVSEditor::createDiffHighlighter() const
{
const QRegExp filePattern(QLatin1String("^[-+][-+][-+] .*1\\.[\\d\\.]+$"));
QTC_ASSERT(filePattern.isValid(), /**/);
return new VCSBase::DiffHighlighter(filePattern);
}
VCSBase::BaseAnnotationHighlighter *CVSEditor::createAnnotationHighlighter(const QSet<QString> &changes) const
{
return new CVSAnnotationHighlighter(changes);
}
QString CVSEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) const
{
// "+++ mainwindow.cpp<\t>13 Jul 2009 13:50:15 -0000 1.1"
// Go back chunks
const QString diffIndicator = QLatin1String("+++ ");
for (QTextBlock block = inBlock; block.isValid() ; block = block.previous()) {
QString diffFileName = block.text();
if (diffFileName.startsWith(diffIndicator)) {
diffFileName.remove(0, diffIndicator.size());
const int tabIndex = diffFileName.indexOf(QLatin1Char('\t'));
if (tabIndex != -1)
diffFileName.truncate(tabIndex);
// Add base dir
if (!m_diffBaseDir.isEmpty()) {
diffFileName.insert(0, QLatin1Char('/'));
diffFileName.insert(0, m_diffBaseDir);
}
if (CVS::Constants::debug)
qDebug() << "fileNameFromDiffSpecification" << m_diffBaseDir << diffFileName;
return diffFileName;
}
}
return QString();
}
QString CVSEditor::diffBaseDir() const
{
return m_diffBaseDir;
}
void CVSEditor::setDiffBaseDir(const QString &d)
{
m_diffBaseDir = d;
}
void CVSEditor::setDiffBaseDir(Core::IEditor *editor, const QString &db)
{
if (CVSEditor *cvsEditor = qobject_cast<CVSEditor*>(editor->widget()))
cvsEditor->setDiffBaseDir(db);
}
}
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#ifndef CVSEDITOR_H
#define CVSEDITOR_H
#include <vcsbase/vcsbaseeditor.h>
#include <QtCore/QRegExp>
namespace CVS {
namespace Internal {
class CVSEditor : public VCSBase::VCSBaseEditor
{
Q_OBJECT
public:
explicit CVSEditor(const VCSBase::VCSBaseEditorParameters *type,
QWidget *parent);
// Diff mode requires a base directory since CVS commands
// are run with relative paths (see plugin).
QString diffBaseDir() const;
void setDiffBaseDir(const QString &d);
static void setDiffBaseDir(Core::IEditor *editor, const QString &db);
private:
virtual QSet<QString> annotationChanges() const;
virtual QString changeUnderCursor(const QTextCursor &) const;
virtual VCSBase::DiffHighlighter *createDiffHighlighter() const;
virtual VCSBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const;
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
const QRegExp m_revisionPattern;
QString m_diffBaseDir;
};
} // namespace Internal
} // namespace CVS
#endif // CVSEDITOR_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**