diff options
author | con <qtc-commiter@nokia.com> | 2008-12-02 12:01:29 +0100 |
---|---|---|
committer | con <qtc-commiter@nokia.com> | 2008-12-02 12:01:29 +0100 |
commit | 05c35356abc31549c5db6eba31fb608c0365c2a0 (patch) | |
tree | be044530104267afaff13f8943889cb97f8c8bad /src/plugins/subversion | |
download | qt-creator-05c35356abc31549c5db6eba31fb608c0365c2a0.tar.gz |
Initial import
Diffstat (limited to 'src/plugins/subversion')
27 files changed, 2887 insertions, 0 deletions
diff --git a/src/plugins/subversion/Subversion.mimetypes.xml b/src/plugins/subversion/Subversion.mimetypes.xml new file mode 100644 index 0000000000..6aa0c3eda9 --- /dev/null +++ b/src/plugins/subversion/Subversion.mimetypes.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> + <mime-type type="application/vnd.nokia.text.subversion.submit"> + <comment>Subversion submit template</comment> + <sub-class-of type="text/plain"/> + </mime-type> +</mime-info> diff --git a/src/plugins/subversion/Subversion.pluginspec b/src/plugins/subversion/Subversion.pluginspec new file mode 100644 index 0000000000..f503ff1340 --- /dev/null +++ b/src/plugins/subversion/Subversion.pluginspec @@ -0,0 +1,13 @@ +<plugin name="Subversion" version="0.9.1" compatVersion="0.9.1"> + <vendor>Nokia Corporation</vendor> + <copyright>(C) 2008 Nokia Corporation</copyright> + <license>Nokia Technology Preview License Agreement</license> + <description>Subversion integration.</description> + <url>http://www.trolltech.com/</url> + <dependencyList> + <dependency name="TextEditor" version="0.9.1"/> + <dependency name="ProjectExplorer" version="0.9.1"/> + <dependency name="Core" version="0.9.1"/> + <dependency name="VCSBase" version="0.9.1"/> + </dependencyList> +</plugin> diff --git a/src/plugins/subversion/annotationhighlighter.cpp b/src/plugins/subversion/annotationhighlighter.cpp new file mode 100644 index 0000000000..e6269ef061 --- /dev/null +++ b/src/plugins/subversion/annotationhighlighter.cpp @@ -0,0 +1,52 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "annotationhighlighter.h" + +namespace Subversion { +namespace Internal { + +SubversionAnnotationHighlighter::SubversionAnnotationHighlighter(const ChangeNumbers &changeNumbers, + QTextDocument *document) : + VCSBase::BaseAnnotationHighlighter(changeNumbers, document), + m_blank(QLatin1Char(' ')) +{ +} + +QString SubversionAnnotationHighlighter::changeNumber(const QString &block) const +{ + const int pos = block.indexOf(m_blank); + return pos > 1 ? block.left(pos) : QString(); +} + +} +} diff --git a/src/plugins/subversion/annotationhighlighter.h b/src/plugins/subversion/annotationhighlighter.h new file mode 100644 index 0000000000..4078ea477e --- /dev/null +++ b/src/plugins/subversion/annotationhighlighter.h @@ -0,0 +1,58 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef ANNOTATIONHIGHLIGHTER_H +#define ANNOTATIONHIGHLIGHTER_H + +#include <vcsbase/baseannotationhighlighter.h> + +namespace Subversion { +namespace Internal { + +// Annotation highlighter for subversion triggering on 'changenumber ' +class SubversionAnnotationHighlighter : public VCSBase::BaseAnnotationHighlighter +{ + Q_OBJECT +public: + explicit SubversionAnnotationHighlighter(const ChangeNumbers &changeNumbers, + QTextDocument *document = 0); + +private: + virtual QString changeNumber(const QString &block) const; + + const QChar m_blank; +}; + +} //namespace Subversion +} //namespace Internal + +#endif diff --git a/src/plugins/subversion/changenumberdialog.cpp b/src/plugins/subversion/changenumberdialog.cpp new file mode 100644 index 0000000000..4cdb6b05e1 --- /dev/null +++ b/src/plugins/subversion/changenumberdialog.cpp @@ -0,0 +1,52 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtGui/QIntValidator> + +#include "changenumberdialog.h" + +using namespace Subversion::Internal; + +ChangeNumberDialog::ChangeNumberDialog(QWidget *parent) + : QDialog(parent) +{ + m_ui.setupUi(this); + m_ui.numberLineEdit->setValidator(new QIntValidator(0, 1000000, this)); +} + +int ChangeNumberDialog::number() const +{ + if (m_ui.numberLineEdit->text().isEmpty()) + return -1; + bool ok; + return m_ui.numberLineEdit->text().toInt(&ok); +} diff --git a/src/plugins/subversion/changenumberdialog.h b/src/plugins/subversion/changenumberdialog.h new file mode 100644 index 0000000000..ebc2d87cb8 --- /dev/null +++ b/src/plugins/subversion/changenumberdialog.h @@ -0,0 +1,60 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef CHANGENUMBERDIALOG_H +#define CHANGENUMBERDIALOG_H + +#include <QtGui/QDialog> + +#include "ui_changenumberdialog.h" + +namespace Subversion { +namespace Internal { + +class ChangeNumberDialog : public QDialog +{ + Q_OBJECT +public: + ChangeNumberDialog(QWidget *parent = 0); + int number() const; + +private: + Ui::ChangeNumberDialog m_ui; + +}; + +} //namespace Subversion +} //namespace Internal + +#endif + + diff --git a/src/plugins/subversion/changenumberdialog.ui b/src/plugins/subversion/changenumberdialog.ui new file mode 100644 index 0000000000..ff3e651750 --- /dev/null +++ b/src/plugins/subversion/changenumberdialog.ui @@ -0,0 +1,79 @@ +<ui version="4.0" > + <class>Subversion::Internal::ChangeNumberDialog</class> + <widget class="QDialog" name="Subversion::Internal::ChangeNumberDialog" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>319</width> + <height>76</height> + </rect> + </property> + <property name="windowTitle" > + <string>Change Number</string> + </property> + <layout class="QGridLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="1" > + <widget class="QLineEdit" name="numberLineEdit" /> + </item> + <item row="0" column="0" > + <widget class="QLabel" name="label" > + <property name="text" > + <string>Change Number:</string> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2" > + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons" > + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>Subversion::Internal::ChangeNumberDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel" > + <x>59</x> + <y>24</y> + </hint> + <hint type="destinationlabel" > + <x>160</x> + <y>38</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>Subversion::Internal::ChangeNumberDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel" > + <x>59</x> + <y>24</y> + </hint> + <hint type="destinationlabel" > + <x>160</x> + <y>38</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/plugins/subversion/images/diff.png b/src/plugins/subversion/images/diff.png Binary files differnew file mode 100644 index 0000000000..b3597f9ff8 --- /dev/null +++ b/src/plugins/subversion/images/diff.png diff --git a/src/plugins/subversion/images/submit.png b/src/plugins/subversion/images/submit.png Binary files differnew file mode 100644 index 0000000000..4f302302b9 --- /dev/null +++ b/src/plugins/subversion/images/submit.png diff --git a/src/plugins/subversion/settingspage.cpp b/src/plugins/subversion/settingspage.cpp new file mode 100644 index 0000000000..16ed648483 --- /dev/null +++ b/src/plugins/subversion/settingspage.cpp @@ -0,0 +1,110 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "settingspage.h" +#include "subversionsettings.h" +#include "subversionplugin.h" + +#include <coreplugin/icore.h> +#include <extensionsystem/pluginmanager.h> + +#include <QtGui/QFileDialog> + +using namespace Subversion::Internal; + +SettingsPageWidget::SettingsPageWidget(QWidget *parent) : + QWidget(parent) +{ + m_ui.setupUi(this); + connect(m_ui.browseButton, SIGNAL(clicked()), this, SLOT(browseForCommand())); +} + +SubversionSettings SettingsPageWidget::settings() const +{ + SubversionSettings rc; + rc.svnCommand = m_ui.svnCmdLineEdit->text(); + rc.useAuthentication = m_ui.userGroupBox->isChecked(); + rc.user = m_ui.usernameLineEdit->text(); + rc.password = m_ui.passwordLineEdit->text(); + if (rc.user.isEmpty()) + rc.useAuthentication = false; + return rc; +} + +void SettingsPageWidget::setSettings(const SubversionSettings &s) +{ + m_ui.svnCmdLineEdit->setText(s.svnCommand); + m_ui.usernameLineEdit->setText(s.user); + m_ui.passwordLineEdit->setText(s.password); + m_ui.userGroupBox->setChecked(s.useAuthentication); +} + +void SettingsPageWidget::browseForCommand() +{ + QString cmd = QFileDialog::getOpenFileName(window(), tr("Subversion Command")); + if (!cmd.isEmpty()) + m_ui.svnCmdLineEdit->setText(cmd); +} + +SettingsPage::SettingsPage() +{ +} + +QString SettingsPage::name() const +{ + return tr("General"); +} + +QString SettingsPage::category() const +{ + return QLatin1String("Subversion"); +} + +QString SettingsPage::trCategory() const +{ + return tr("Subversion"); +} + +QWidget *SettingsPage::createPage(QWidget *parent) +{ + if (!m_widget) + m_widget = new SettingsPageWidget(parent); + m_widget->setSettings(SubversionPlugin::subversionPluginInstance()->settings()); + return m_widget; +} + +void SettingsPage::finished(bool accepted) +{ + if (!accepted || !m_widget) + return; + SubversionPlugin::subversionPluginInstance()->setSettings(m_widget->settings()); +} diff --git a/src/plugins/subversion/settingspage.h b/src/plugins/subversion/settingspage.h new file mode 100644 index 0000000000..6bed2236b0 --- /dev/null +++ b/src/plugins/subversion/settingspage.h @@ -0,0 +1,90 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef SETTINGSPAGE_H +#define SETTINGSPAGE_H + +#include <QtGui/QWidget> +#include <QtCore/QPointer> +#include <QtCore/QString> + +#include <coreplugin/dialogs/ioptionspage.h> + +#include "ui_settingspage.h" + +QT_BEGIN_NAMESPACE +class QSettings; +QT_END_NAMESPACE + +namespace Subversion { + namespace Internal { + +struct SubversionSettings; + +class SettingsPageWidget : public QWidget { + Q_OBJECT +public: + explicit SettingsPageWidget(QWidget *parent = 0); + + SubversionSettings settings() const; + void setSettings(const SubversionSettings &); + +private slots:; + void browseForCommand(); + +private: + Ui::SettingsPage m_ui; +}; + + +class SettingsPage : public Core::IOptionsPage +{ + Q_OBJECT + +public: + SettingsPage(); + + QString name() const; + QString category() const; + QString trCategory() const; + + QWidget *createPage(QWidget *parent); + void finished(bool accepted); + +private: + QPointer<SettingsPageWidget> m_widget; +}; + + } //namespace Subversion +} //namespace Internal + +#endif // SETTINGSPAGE_H diff --git a/src/plugins/subversion/settingspage.ui b/src/plugins/subversion/settingspage.ui new file mode 100644 index 0000000000..14e5ebce87 --- /dev/null +++ b/src/plugins/subversion/settingspage.ui @@ -0,0 +1,117 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Subversion::Internal::SettingsPage</class> + <widget class="QWidget" name="Subversion::Internal::SettingsPage"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>427</width> + <height>280</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="commandHBox"> + <property name="spacing"> + <number>6</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="commandLabel"> + <property name="text"> + <string>Subversion Command:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="svnCmdLineEdit"/> + </item> + <item> + <widget class="QToolButton" name="browseButton"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="userGroupBox"> + <property name="title"> + <string>Authentication</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="usernameLabel"> + <property name="text"> + <string>User name:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="usernameLineEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="passwordLabel"> + <property name="text"> + <string>Password:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="passwordLineEdit"> + <property name="echoMode"> + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>105</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <tabstops> + <tabstop>svnCmdLineEdit</tabstop> + </tabstops> + <resources/> + <connections/> +</ui> diff --git a/src/plugins/subversion/subversion.pro b/src/plugins/subversion/subversion.pro new file mode 100644 index 0000000000..7de5499fa7 --- /dev/null +++ b/src/plugins/subversion/subversion.pro @@ -0,0 +1,34 @@ +TEMPLATE = lib +TARGET = Subversion + +include(../../qworkbenchplugin.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 \ + subversionplugin.h \ + subversioncontrol.h \ + subversionoutputwindow.h \ + settingspage.h \ + subversioneditor.h \ + changenumberdialog.h \ + subversionsubmiteditor.h \ + subversionsettings.h + +SOURCES += annotationhighlighter.cpp \ + subversionplugin.cpp \ + subversioncontrol.cpp \ + subversionoutputwindow.cpp \ + settingspage.cpp \ + subversioneditor.cpp \ + changenumberdialog.cpp \ + subversionsubmiteditor.cpp \ + subversionsettings.cpp + +FORMS += settingspage.ui \ + changenumberdialog.ui + +RESOURCES += subversion.qrc diff --git a/src/plugins/subversion/subversion.qrc b/src/plugins/subversion/subversion.qrc new file mode 100644 index 0000000000..7fa3a2a31e --- /dev/null +++ b/src/plugins/subversion/subversion.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/trolltech.subversion" > + <file>images/diff.png</file> + <file>images/submit.png</file> + <file>Subversion.mimetypes.xml</file> + </qresource> +</RCC> diff --git a/src/plugins/subversion/subversionconstants.h b/src/plugins/subversion/subversionconstants.h new file mode 100644 index 0000000000..eaf2575508 --- /dev/null +++ b/src/plugins/subversion/subversionconstants.h @@ -0,0 +1,51 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef SUBVERSION_CONSTANTS_H +#define SUBVERSION_CONSTANTS_H + +namespace Subversion { + namespace Constants { + const char * const SUBVERSION_SUBMIT_MIMETYPE = "application/vnd.nokia.text.subversion.submit"; + const char * const SUBVERSIONEDITOR = "Subversion Editor"; + const char * const SUBVERSIONEDITOR_KIND = "Subversion Editor"; + const char * const SUBVERSIONCOMMITEDITOR = "Subversion Commit Editor"; + const char * const SUBVERSIONCOMMITEDITOR_KIND = "Subversion Commit Editor"; + const char * const ICON_SUBMIT = ":/trolltech.subversion/images/submit.png"; + const char * const ICON_DIFF = ":/trolltech.subversion/images/diff.png"; + const char * const SUBMIT_CURRENT = "Nokia.Subversion.SubmitCurrentLog"; + const char * const DIFF_SELECTED = "Nokia.Subversion.DiffSelectedFilesInLog"; + enum { debug = 0 }; + } +} + +#endif diff --git a/src/plugins/subversion/subversioncontrol.cpp b/src/plugins/subversion/subversioncontrol.cpp new file mode 100644 index 0000000000..0357eccf5b --- /dev/null +++ b/src/plugins/subversion/subversioncontrol.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "subversioncontrol.h" +#include "subversionplugin.h" + +namespace Subversion { +namespace Internal { + +SubversionControl::SubversionControl(SubversionPlugin *plugin) : + m_plugin(plugin) +{ +} + +bool SubversionControl::vcsOpen(const QString & /* fileName */) +{ + // Open for edit: N/A + return true; +} + +bool SubversionControl::vcsAdd(const QString &fileName) +{ + return m_plugin->vcsAdd(fileName); +} + +bool SubversionControl::vcsDelete(const QString &fileName) +{ + return m_plugin->vcsDelete(fileName); +} + +bool SubversionControl::managesDirectory(const QString &directory) const +{ + return m_plugin->managesDirectory(directory); +} + +QString SubversionControl::findTopLevelForDirectory(const QString &directory) const +{ + return m_plugin->findTopLevelForDirectory(directory); +} +} +} diff --git a/src/plugins/subversion/subversioncontrol.h b/src/plugins/subversion/subversioncontrol.h new file mode 100644 index 0000000000..7be525275f --- /dev/null +++ b/src/plugins/subversion/subversioncontrol.h @@ -0,0 +1,60 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef SUBVERSIONCONTROL_H +#define SUBVERSIONCONTROL_H + +#include <coreplugin/iversioncontrol.h> + +namespace Subversion { +namespace Internal { +class SubversionPlugin; + +// Just a proxy for SubversionPlugin +class SubversionControl : public Core::IVersionControl +{ + Q_OBJECT +public: + explicit SubversionControl(SubversionPlugin *plugin); + virtual bool managesDirectory(const QString &directory) const; + virtual QString findTopLevelForDirectory(const QString &directory) const; + virtual bool vcsOpen(const QString &fileName); + virtual bool vcsAdd(const QString &fileName); + virtual bool vcsDelete(const QString &filename); + +private: + SubversionPlugin *m_plugin; +}; + +} +} +#endif diff --git a/src/plugins/subversion/subversioneditor.cpp b/src/plugins/subversion/subversioneditor.cpp new file mode 100644 index 0000000000..d87138aae1 --- /dev/null +++ b/src/plugins/subversion/subversioneditor.cpp @@ -0,0 +1,140 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "subversioneditor.h" +#include "annotationhighlighter.h" +#include "subversionconstants.h" + +#include <vcsbase/diffhighlighter.h> + +#include <QtCore/QDebug> +#include <QtGui/QTextCursor> + +namespace Subversion { +namespace Internal { + +SubversionEditor::SubversionEditor(const VCSBase::VCSBaseEditorParameters *type, + QWidget *parent) : + VCSBase::VCSBaseEditor(type, parent), + m_changeNumberPattern(QLatin1String("^\\d+$")), + m_revisionNumberPattern(QLatin1String("^r\\d+$")) +{ + Q_ASSERT(m_changeNumberPattern.isValid()); + Q_ASSERT(m_revisionNumberPattern.isValid()); +} + +QSet<QString> SubversionEditor::annotationChanges() const +{ + QSet<QString> changes; + const QString txt = toPlainText(); + if (txt.isEmpty()) + return changes; + // Hunt for first change number in annotation: "<change>:" + QRegExp r(QLatin1String("^(\\d+):")); + Q_ASSERT(r.isValid()); + if (r.indexIn(txt) != -1) { + changes.insert(r.cap(1)); + r.setPattern(QLatin1String("\n(\\d+):")); + Q_ASSERT(r.isValid()); + int pos = 0; + while ((pos = r.indexIn(txt, pos)) != -1) { + pos += r.matchedLength(); + changes.insert(r.cap(1)); + } + } + if (Subversion::Constants::debug) + qDebug() << "SubversionEditor::annotationChanges() returns #" << changes.size(); + return changes; +} + +QString SubversionEditor::changeUnderCursor(const QTextCursor &c) const +{ + QTextCursor cursor = c; + // Any number is regarded as change number. + cursor.select(QTextCursor::WordUnderCursor); + if (!cursor.hasSelection()) + return QString(); + QString change = cursor.selectedText(); + // Annotation output has number, log output has revision numbers + // as r1, r2... + if (m_changeNumberPattern.exactMatch(change)) + return change; + if (m_revisionNumberPattern.exactMatch(change)) { + change.remove(0, 1); + return change; + } + return QString(); +} + +/* code: + Index: main.cpp +=================================================================== +--- main.cpp (revision 2) ++++ main.cpp (working copy) +@@ -6,6 +6,5 @@ +\endcode +*/ + +VCSBase::DiffHighlighter *SubversionEditor::createDiffHighlighter() const +{ + const QRegExp filePattern(QLatin1String("^[-+][-+][-+] .*|^Index: .*|^==*$")); + Q_ASSERT(filePattern.isValid()); + return new VCSBase::DiffHighlighter(filePattern); +} + +VCSBase::BaseAnnotationHighlighter *SubversionEditor::createAnnotationHighlighter(const QSet<QString> &changes) const +{ + return new SubversionAnnotationHighlighter(changes); +} + +QString SubversionEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) const +{ + // "+++ /depot/.../mainwindow.cpp<tab>(revision 3)" + // 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.lastIndexOf(QLatin1Char('\t')); + if (tabIndex != -1) + diffFileName.truncate(tabIndex); + if (Subversion::Constants::debug) + qDebug() << Q_FUNC_INFO << diffFileName; + return diffFileName; + } + } + return QString(); +} + +} +} diff --git a/src/plugins/subversion/subversioneditor.h b/src/plugins/subversion/subversioneditor.h new file mode 100644 index 0000000000..9dee4a9d5a --- /dev/null +++ b/src/plugins/subversion/subversioneditor.h @@ -0,0 +1,65 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef SUBVERSIONEDITOR_H +#define SUBVERSIONEDITOR_H + +#include <vcsbase/vcsbaseeditor.h> + +#include <QtCore/QRegExp> + +namespace Subversion { +namespace Internal { + +class SubversionEditor : public VCSBase::VCSBaseEditor +{ + Q_OBJECT + +public: + explicit SubversionEditor(const VCSBase::VCSBaseEditorParameters *type, + QWidget *parent); + +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_changeNumberPattern; + const QRegExp m_revisionNumberPattern; +}; + +} // namespace Internal +} // namespace Subversion + +#endif // SUBVERSIONEDITOR_H diff --git a/src/plugins/subversion/subversionoutputwindow.cpp b/src/plugins/subversion/subversionoutputwindow.cpp new file mode 100644 index 0000000000..f3d8fd8ac1 --- /dev/null +++ b/src/plugins/subversion/subversionoutputwindow.cpp @@ -0,0 +1,105 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "subversionoutputwindow.h" +#include "subversionplugin.h" + +#include <QtGui/QListWidget> +#include <QtCore/QDebug> + +using namespace Subversion::Internal; + +SubversionOutputWindow::SubversionOutputWindow(SubversionPlugin *svnPlugin) + : m_svnPlugin(svnPlugin) +{ + m_outputListWidget = new QListWidget; + m_outputListWidget->setFrameStyle(QFrame::NoFrame); + m_outputListWidget->setWindowTitle(tr("Subversion Output")); + m_outputListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); +} + +SubversionOutputWindow::~SubversionOutputWindow() +{ + delete m_outputListWidget; +} + +QWidget *SubversionOutputWindow::outputWidget(QWidget *parent) +{ + m_outputListWidget->setParent(parent); + return m_outputListWidget; +} + +QString SubversionOutputWindow::name() const +{ + return tr("Subversion"); +} + +void SubversionOutputWindow::clearContents() +{ + m_outputListWidget->clear(); +} + +int SubversionOutputWindow::priorityInStatusBar() const +{ + return -1; +} + +void SubversionOutputWindow::visibilityChanged(bool b) +{ + if (b) + m_outputListWidget->setFocus(); +} + +void SubversionOutputWindow::append(const QString &txt, bool doPopup) +{ + const QStringList lines = txt.split(QLatin1Char('\n')); + foreach (const QString &s, lines) + m_outputListWidget->addItem(s); + m_outputListWidget->scrollToBottom(); + + if (doPopup) + popup(); +} + +bool SubversionOutputWindow::canFocus() +{ + return false; +} + +bool SubversionOutputWindow::hasFocus() +{ + return m_outputListWidget->hasFocus(); +} + +void SubversionOutputWindow::setFocus() +{ +} diff --git a/src/plugins/subversion/subversionoutputwindow.h b/src/plugins/subversion/subversionoutputwindow.h new file mode 100644 index 0000000000..cd1bda5e9d --- /dev/null +++ b/src/plugins/subversion/subversionoutputwindow.h @@ -0,0 +1,81 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef SUBVERSIONOUTPUTWINDOW_H +#define SUBVERSIONOUTPUTWINDOW_H + +#include <coreplugin/ioutputpane.h> + +QT_BEGIN_NAMESPACE +class QListWidget; +QT_END_NAMESPACE + +namespace Subversion { + namespace Internal { + +class SubversionPlugin; + +class SubversionOutputWindow : public Core::IOutputPane +{ + Q_OBJECT + +public: + SubversionOutputWindow(SubversionPlugin *svnPlugin); + ~SubversionOutputWindow(); + + QWidget *outputWidget(QWidget *parent); + QList<QWidget*> toolBarWidgets(void) const { + return QList<QWidget *>(); + } + + QString name() const; + void clearContents(); + int priorityInStatusBar() const; + void visibilityChanged(bool visible); + + virtual bool canFocus(); + virtual bool hasFocus(); + virtual void setFocus(); + +public slots: + void append(const QString &txt, bool popup = false); + +private: + + SubversionPlugin *m_svnPlugin; + QListWidget *m_outputListWidget; +}; + +} // namespace Subversion +} // namespace Internal + +#endif diff --git a/src/plugins/subversion/subversionplugin.cpp b/src/plugins/subversion/subversionplugin.cpp new file mode 100644 index 0000000000..7c44e87fea --- /dev/null +++ b/src/plugins/subversion/subversionplugin.cpp @@ -0,0 +1,1087 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "subversionplugin.h" + +#include "settingspage.h" +#include "subversioneditor.h" + +#include "subversionoutputwindow.h" +#include "subversionsubmiteditor.h" +#include "changenumberdialog.h" +#include "subversionconstants.h" +#include "subversioncontrol.h" + +#include <vcsbase/basevcseditorfactory.h> +#include <vcsbase/vcsbaseeditor.h> +#include <vcsbase/basevcssubmiteditorfactory.h> +#include <utils/synchronousprocess.h> + +#include <coreplugin/icore.h> +#include <coreplugin/coreconstants.h> +#include <coreplugin/filemanager.h> +#include <coreplugin/messagemanager.h> +#include <coreplugin/mimedatabase.h> +#include <coreplugin/uniqueidmanager.h> +#include <coreplugin/actionmanager/actionmanagerinterface.h> +#include <coreplugin/editormanager/editormanager.h> +#include <projectexplorer/ProjectExplorerInterfaces> + +#include <QtCore/qplugin.h> +#include <QtCore/QDebug> +#include <QtCore/QTextCodec> +#include <QtCore/QFileInfo> +#include <QtCore/QTemporaryFile> +#include <QtCore/QDir> +#include <QtGui/QAction> +#include <QtGui/QMenu> +#include <QtGui/QMessageBox> +#include <QtGui/QMainWindow> +#include <QtGui/QFileDialog> + +using namespace Subversion::Internal; + +// Timeout for normal output commands +enum { subversionShortTimeOut = 10000 }; +// Timeout for submit, update +enum { subversionLongTimeOut = 120000 }; + +// #pragma mark -- SubversionPlugin + +const char * const SubversionPlugin::SUBVERSION_MENU = "Subversion.Menu"; +const char * const SubversionPlugin::ADD = "Subversion.Add"; +const char * const SubversionPlugin::DELETE_FILE = "Subversion.Delete"; +const char * const SubversionPlugin::REVERT = "Subversion.Revert"; +const char * const SubversionPlugin::SEPARATOR0 = "Subversion.Separator0"; +const char * const SubversionPlugin::DIFF_PROJECT = "Subversion.DiffAll"; +const char * const SubversionPlugin::DIFF_CURRENT = "Subversion.DiffCurrent"; +const char * const SubversionPlugin::SEPARATOR1 = "Subversion.Separator1"; +const char * const SubversionPlugin::COMMIT_ALL = "Subversion.CommitAll"; +const char * const SubversionPlugin::COMMIT_CURRENT = "Subversion.CommitCurrent"; +const char * const SubversionPlugin::SEPARATOR2 = "Subversion.Separator2"; +const char * const SubversionPlugin::FILELOG_CURRENT = "Subversion.FilelogCurrent"; +const char * const SubversionPlugin::ANNOTATE_CURRENT = "Subversion.AnnotateCurrent"; +const char * const SubversionPlugin::SEPARATOR3 = "Subversion.Separator3"; +const char * const SubversionPlugin::STATUS = "Subversion.Status"; +const char * const SubversionPlugin::UPDATE = "Subversion.Update"; + +static const VCSBase::VCSBaseEditorParameters editorParameters[] = { +{ + VCSBase::RegularCommandOutput, + "Subversion Command Log Editor", + Core::Constants::C_GLOBAL, + "application/vnd.nokia.text.scs_svn_commandlog", + "scslog"}, +{ VCSBase::LogOutput, + "Subversion File Log Editor", + Core::Constants::C_GLOBAL, + "application/vnd.nokia.text.scs_svn_filelog", + "scsfilelog"}, +{ VCSBase::AnnotateOutput, + "Subversion Annotation Editor", + Core::Constants::C_GLOBAL, + "application/vnd.nokia.text.scs_svn_annotation", + "scsannotate"}, +{ VCSBase::DiffOutput, + "Subversion Diff Editor", + Core::Constants::C_GLOBAL, + "text/x-patch","diff"} +}; + +// Utility to find a parameter set by type +static inline const VCSBase::VCSBaseEditorParameters *findType(int ie) +{ + const VCSBase::EditorContentType et = static_cast<VCSBase::EditorContentType>(ie); + return VCSBase::VCSBaseEditor::findType(editorParameters, sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters), et); +} + +static inline QString debugCodec(const QTextCodec *c) +{ + return c ? QString::fromAscii(c->name()) : QString::fromAscii("Null codec"); +} + +inline Core::IEditor* locateEditor(const Core::ICore *core, const char *property, const QString &entry) +{ + foreach (Core::IEditor *ed, core->editorManager()->openedEditors()) + if (ed->property(property).toString() == entry) + return ed; + return 0; +} + +// ------------- SubversionPlugin +Core::ICore *SubversionPlugin::m_coreInstance = 0; +SubversionPlugin *SubversionPlugin::m_subversionPluginInstance = 0; + +SubversionPlugin::SubversionPlugin() : + m_svnDotDirectory(QLatin1String(".svn")), + m_versionControl(0), + m_coreListener(0), + m_settingsPage(0), + m_changeTmpFile(0), + m_submitEditorFactory(0), + m_subversionOutputWindow(0), + m_projectExplorer(0), + m_addAction(0), + m_deleteAction(0), + m_revertAction(0), + m_diffProjectAction(0), + m_diffCurrentAction(0), + m_commitAllAction(0), + m_commitCurrentAction(0), + m_filelogCurrentAction(0), + m_annotateCurrentAction(0), + m_statusAction(0), + m_updateProjectAction(0), + m_submitCurrentLogAction(0), + m_submitDiffAction(0), + m_submitUndoAction(0), + m_submitRedoAction(0) +{ +} + +SubversionPlugin::~SubversionPlugin() +{ + if (m_versionControl) { + removeObject(m_versionControl); + delete m_versionControl; + m_versionControl = 0; + } + + if (m_settingsPage) { + removeObject(m_settingsPage); + delete m_settingsPage; + m_settingsPage = 0; + } + if (m_subversionOutputWindow) { + removeObject(m_subversionOutputWindow); + delete m_subversionOutputWindow; + m_subversionOutputWindow = 0; + } + if (m_submitEditorFactory) { + removeObject(m_submitEditorFactory); + delete m_submitEditorFactory; + m_submitEditorFactory = 0; + } + + if (!m_editorFactories.empty()) { + foreach(Core::IEditorFactory* pf, m_editorFactories) + removeObject(pf); + qDeleteAll(m_editorFactories); + m_editorFactories.clear(); + } + + if (m_coreListener) { + removeObject(m_coreListener); + delete m_coreListener; + m_coreListener = 0; + } + cleanChangeTmpFile(); +} + +void SubversionPlugin::cleanChangeTmpFile() +{ + if (m_changeTmpFile) { + if (m_changeTmpFile->isOpen()) + m_changeTmpFile->close(); + delete m_changeTmpFile; + m_changeTmpFile = 0; + } +} + +static const VCSBase::VCSBaseSubmitEditorParameters submitParameters = { + Subversion::Constants::SUBVERSION_SUBMIT_MIMETYPE, + Subversion::Constants::SUBVERSIONCOMMITEDITOR_KIND, + Subversion::Constants::SUBVERSIONCOMMITEDITOR, + Core::Constants::UNDO, + Core::Constants::REDO, + Subversion::Constants::SUBMIT_CURRENT, + Subversion::Constants::DIFF_SELECTED +}; + +bool SubversionPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage) +{ + typedef VCSBase::VCSSubmitEditorFactory<SubversionSubmitEditor> SubversionSubmitEditorFactory; + typedef VCSBase::VCSEditorFactory<SubversionEditor> SubversionEditorFactory; + using namespace Constants; + + using namespace Core::Constants; + using namespace ExtensionSystem; + + m_subversionPluginInstance = this; + m_coreInstance = PluginManager::instance()->getObject<Core::ICore>(); + + if (!m_coreInstance->mimeDatabase()->addMimeTypes(QLatin1String(":/trolltech.subversion/Subversion.mimetypes.xml"), errorMessage)) + return false; + + m_versionControl = new SubversionControl(this); + addObject(m_versionControl); + + if (QSettings *settings = m_coreInstance->settings()) + m_settings.fromSettings(settings); + + m_coreListener = new CoreListener(this); + addObject(m_coreListener); + + m_settingsPage = new SettingsPage; + addObject(m_settingsPage); + + m_submitEditorFactory = new SubversionSubmitEditorFactory(&submitParameters); + addObject(m_submitEditorFactory); + + static const char *describeSlot = SLOT(describe(QString,QString)); + const int editorCount = sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters); + for (int i = 0; i < editorCount; i++) { + m_editorFactories.push_back(new SubversionEditorFactory(editorParameters + i, m_coreInstance, this, describeSlot)); + addObject(m_editorFactories.back()); + } + + m_subversionOutputWindow = new SubversionOutputWindow(this); + addObject(m_subversionOutputWindow); + + //register actions + Core::ActionManagerInterface *ami = m_coreInstance->actionManager(); + Core::IActionContainer *toolsContainer = ami->actionContainer(M_TOOLS); + + Core::IActionContainer *subversionMenu = + ami->createMenu(QLatin1String(SUBVERSION_MENU)); + subversionMenu->menu()->setTitle(tr("&Subversion")); + toolsContainer->addMenu(subversionMenu); + + QList<int> globalcontext; + globalcontext << m_coreInstance->uniqueIDManager()->uniqueIdentifier(C_GLOBAL); + + Core::ICommand *command; + m_addAction = new QAction(tr("Add"), this); + command = ami->registerAction(m_addAction, SubversionPlugin::ADD, + globalcontext); + command->setAttribute(Core::ICommand::CA_UpdateText); + command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+A"))); + connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile())); + subversionMenu->addAction(command); + + m_deleteAction = new QAction(tr("Delete"), this); + command = ami->registerAction(m_deleteAction, SubversionPlugin::DELETE_FILE, + globalcontext); + command->setAttribute(Core::ICommand::CA_UpdateText); + connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deleteCurrentFile())); + subversionMenu->addAction(command); + + m_revertAction = new QAction(tr("Revert"), this); + command = ami->registerAction(m_revertAction, SubversionPlugin::REVERT, + globalcontext); + command->setAttribute(Core::ICommand::CA_UpdateText); + connect(m_revertAction, SIGNAL(triggered()), this, SLOT(revertCurrentFile())); + subversionMenu->addAction(command); + + QAction *tmpaction = new QAction(this); + tmpaction->setSeparator(true); + subversionMenu->addAction(ami->registerAction(tmpaction, + SubversionPlugin::SEPARATOR0, globalcontext)); + + m_diffProjectAction = new QAction(tr("Diff Project"), this); + command = ami->registerAction(m_diffProjectAction, SubversionPlugin::DIFF_PROJECT, + globalcontext); + connect(m_diffProjectAction, SIGNAL(triggered()), this, SLOT(diffProject())); + subversionMenu->addAction(command); + + m_diffCurrentAction = new QAction(tr("Diff Current File"), this); + command = ami->registerAction(m_diffCurrentAction, + SubversionPlugin::DIFF_CURRENT, globalcontext); + command->setAttribute(Core::ICommand::CA_UpdateText); + command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+D"))); + connect(m_diffCurrentAction, SIGNAL(triggered()), this, SLOT(diffCurrentFile())); + subversionMenu->addAction(command); + + tmpaction = new QAction(this); + tmpaction->setSeparator(true); + subversionMenu->addAction(ami->registerAction(tmpaction, + SubversionPlugin::SEPARATOR1, globalcontext)); + + m_commitAllAction = new QAction(tr("Commit All Files"), this); + command = ami->registerAction(m_commitAllAction, SubversionPlugin::COMMIT_ALL, + globalcontext); + connect(m_commitAllAction, SIGNAL(triggered()), this, SLOT(startCommitAll())); + subversionMenu->addAction(command); + + m_commitCurrentAction = new QAction(tr("Commit Current File"), this); + command = ami->registerAction(m_commitCurrentAction, + SubversionPlugin::COMMIT_CURRENT, globalcontext); + command->setAttribute(Core::ICommand::CA_UpdateText); + command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+C"))); + connect(m_commitCurrentAction, SIGNAL(triggered()), this, SLOT(startCommitCurrentFile())); + subversionMenu->addAction(command); + + tmpaction = new QAction(this); + tmpaction->setSeparator(true); + subversionMenu->addAction(ami->registerAction(tmpaction, + SubversionPlugin::SEPARATOR2, globalcontext)); + + m_filelogCurrentAction = new QAction(tr("Filelog Current File"), this); + command = ami->registerAction(m_filelogCurrentAction, + SubversionPlugin::FILELOG_CURRENT, globalcontext); + command->setAttribute(Core::ICommand::CA_UpdateText); + connect(m_filelogCurrentAction, SIGNAL(triggered()), this, + SLOT(filelogCurrentFile())); + subversionMenu->addAction(command); + + m_annotateCurrentAction = new QAction(tr("Annotate Current File"), this); + command = ami->registerAction(m_annotateCurrentAction, + SubversionPlugin::ANNOTATE_CURRENT, globalcontext); + command->setAttribute(Core::ICommand::CA_UpdateText); + connect(m_annotateCurrentAction, SIGNAL(triggered()), this, + SLOT(annotateCurrentFile())); + subversionMenu->addAction(command); + + tmpaction = new QAction(this); + tmpaction->setSeparator(true); + subversionMenu->addAction(ami->registerAction(tmpaction, + SubversionPlugin::SEPARATOR3, globalcontext)); + + m_statusAction = new QAction(tr("Project Status"), this); + command = ami->registerAction(m_statusAction, SubversionPlugin::STATUS, + globalcontext); + connect(m_statusAction, SIGNAL(triggered()), this, SLOT(projectStatus())); + subversionMenu->addAction(command); + + m_updateProjectAction = new QAction(tr("Update Project"), this); + command = ami->registerAction(m_updateProjectAction, SubversionPlugin::UPDATE, globalcontext); + connect(m_updateProjectAction, SIGNAL(triggered()), this, SLOT(updateProject())); + subversionMenu->addAction(command); + + // Actions of the submit editor + QList<int> svncommitcontext; + svncommitcontext << m_coreInstance->uniqueIDManager()->uniqueIdentifier(Constants::SUBVERSIONCOMMITEDITOR); + + m_submitCurrentLogAction = new QAction(QIcon(Constants::ICON_SUBMIT), tr("Commit"), this); + command = ami->registerAction(m_submitCurrentLogAction, Constants::SUBMIT_CURRENT, svncommitcontext); + connect(m_submitCurrentLogAction, SIGNAL(triggered()), this, SLOT(submitCurrentLog())); + + m_submitDiffAction = new QAction(QIcon(Constants::ICON_DIFF), tr("Diff Selected Files"), this); + command = ami->registerAction(m_submitDiffAction , Constants::DIFF_SELECTED, svncommitcontext); + + m_submitUndoAction = new QAction(tr("&Undo"), this); + command = ami->registerAction(m_submitUndoAction, Core::Constants::UNDO, svncommitcontext); + + m_submitRedoAction = new QAction(tr("&Redo"), this); + command = ami->registerAction(m_submitRedoAction, Core::Constants::REDO, svncommitcontext); + + connect(m_coreInstance, SIGNAL(contextChanged(Core::IContext *)), this, SLOT(updateActions())); + + return true; +} + +void SubversionPlugin::extensionsInitialized() +{ + using namespace ExtensionSystem; + using namespace ProjectExplorer; + + m_projectExplorer = PluginManager::instance()->getObject<ProjectExplorerPlugin>(); + if (m_projectExplorer) { + connect(m_projectExplorer, + SIGNAL(currentProjectChanged(ProjectExplorer::Project*)), + m_subversionPluginInstance, SLOT(updateActions())); + } + updateActions(); +} + +bool SubversionPlugin::editorAboutToClose(Core::IEditor *iEditor) +{ + if (!m_changeTmpFile || !iEditor || qstrcmp(Constants::SUBVERSIONCOMMITEDITOR, iEditor->kind())) + return true; + + Core::IFile *fileIFace = iEditor->file(); + const SubversionSubmitEditor *editor = qobject_cast<SubversionSubmitEditor *>(iEditor); + if (!fileIFace || !editor) + return true; + + // Submit editor closing. Make it write out the commit message + // and retrieve files + const QFileInfo editorFile(fileIFace->fileName()); + const QFileInfo changeFile(m_changeTmpFile->fileName()); + if (editorFile.absoluteFilePath() != changeFile.absoluteFilePath()) + return true; // Oops?! + + // Prompt user. + const QMessageBox::StandardButton answer = QMessageBox::question( + m_coreInstance->mainWindow(), tr("Closing Subversion Editor"), + tr("Do you want to commit the change?"), + QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, QMessageBox::Yes); + switch (answer) { + case QMessageBox::Cancel: + return false; // Keep editing and change file + case QMessageBox::No: + cleanChangeTmpFile(); + return true; // Cancel all + default: + break; + } + + const QStringList fileList = editor->checkedFiles(); + if (!fileList.empty()) { + // get message & commit + m_coreInstance->fileManager()->blockFileChange(fileIFace); + fileIFace->save(); + m_coreInstance->fileManager()->unblockFileChange(fileIFace); + commit(m_changeTmpFile->fileName(), fileList); + } + cleanChangeTmpFile(); + return true; +} + +void SubversionPlugin::diffFiles(const QStringList &files) +{ + svnDiff(files); +} + +void SubversionPlugin::svnDiff(const QStringList &files, QString diffname) +{ + if (Subversion::Constants::debug) + qDebug() << Q_FUNC_INFO << files << diffname; + const QString source = files.empty() ? QString() : files.front(); + QTextCodec *codec = source.isEmpty() ? static_cast<QTextCodec *>(0) : VCSBase::VCSBaseEditor::getCodec(m_coreInstance, source); + + if (files.count() == 1 && diffname.isEmpty()) + diffname = QFileInfo(files.front()).fileName(); + + QStringList args(QLatin1String("diff")); + args << files; + + const SubversionResponse response = runSvn(args, subversionShortTimeOut, false, codec); + if (response.error) + return; + + // diff of a single file? re-use an existing view if possible to support + // the common usage pattern of continuously changing and diffing a file + if (files.count() == 1) { + // Show in the same editor if diff has been executed before + if (Core::IEditor *editor = locateEditor(m_coreInstance, "originalFileName", files.front())) { + editor->createNew(response.stdOut); + m_coreInstance->editorManager()->setCurrentEditor(editor); + return; + } + } + const QString title = tr("svn diff %1").arg(diffname); + Core::IEditor *editor = showOutputInEditor(title, response.stdOut, VCSBase::DiffOutput, source, codec); + if (files.count() == 1) + editor->setProperty("originalFileName", files.front()); +} + +SubversionSubmitEditor *SubversionPlugin::openSubversionSubmitEditor(const QString &fileName) +{ + Core::IEditor *editor = m_coreInstance->editorManager()->openEditor(fileName, QLatin1String(Constants::SUBVERSIONCOMMITEDITOR_KIND)); + SubversionSubmitEditor *submitEditor = qobject_cast<SubversionSubmitEditor*>(editor); + Q_ASSERT(submitEditor); + // The actions are for some reason enabled by the context switching + // mechanism. Disable them correctly. + m_submitDiffAction->setEnabled(false); + m_submitUndoAction->setEnabled(false); + m_submitRedoAction->setEnabled(false); + connect(submitEditor, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(diffFiles(QStringList))); + + return submitEditor; +} + +void SubversionPlugin::updateActions() +{ + QString fileName = currentFileName(); + const bool hasFile = !fileName.isEmpty(); + + m_addAction->setEnabled(hasFile); + m_deleteAction->setEnabled(hasFile); + m_revertAction->setEnabled(hasFile); + m_diffProjectAction->setEnabled(true); + m_diffCurrentAction->setEnabled(hasFile); + m_commitAllAction->setEnabled(true); + m_commitCurrentAction->setEnabled(hasFile); + m_filelogCurrentAction->setEnabled(hasFile); + m_annotateCurrentAction->setEnabled(hasFile); + m_statusAction->setEnabled(true); + + QString baseName; + if (hasFile) + baseName = QFileInfo(fileName).fileName(); + + m_addAction->setText(tr("Add %1").arg(baseName)); + m_deleteAction->setText(tr("Delete %1").arg(baseName)); + m_revertAction->setText(tr("Revert %1").arg(baseName)); + m_diffCurrentAction->setText(tr("Diff %1").arg(baseName)); + m_commitCurrentAction->setText(tr("Commit %1").arg(baseName)); + m_filelogCurrentAction->setText(tr("Filelog %1").arg(baseName)); + m_annotateCurrentAction->setText(tr("Annotate %1").arg(baseName)); +} + +void SubversionPlugin::addCurrentFile() +{ + const QString file = currentFileName(); + if (!file.isEmpty()) + vcsAdd(file); +} + +void SubversionPlugin::deleteCurrentFile() +{ + const QString file = currentFileName(); + if (!file.isEmpty()) + vcsDelete(file); +} + +void SubversionPlugin::revertCurrentFile() +{ + const QString file = QDir::toNativeSeparators(currentFileName()); + if (file.isEmpty()) + return; + + QStringList args(QLatin1String("diff")); + args.push_back(file); + + const SubversionResponse diffResponse = runSvn(args, subversionShortTimeOut, false); + if (diffResponse.error) + return; + + if (diffResponse.stdOut.isEmpty()) + return; + if (QMessageBox::warning(0, tr("svn revert"), tr("The file has been changed. Do you want to revert it?"), + QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) + return; + + Core::FileManager *fm = m_coreInstance->fileManager(); + QList<Core::IFile *> files = fm->managedFiles(file); + foreach (Core::IFile *file, files) { + fm->blockFileChange(file); + } + + // revert + args.clear(); + args.push_back(QLatin1String("revert")); + args.append(file); + + const SubversionResponse revertResponse = runSvn(args, subversionShortTimeOut, true); + if (revertResponse.error) { + foreach (Core::IFile *file, files) + fm->unblockFileChange(file); + return; + } + + Core::IFile::ReloadBehavior tempBehavior = Core::IFile::ReloadAll; + foreach (Core::IFile *file, files) { + file->modified(&tempBehavior); + fm->unblockFileChange(file); + } +} + +// Get a unique set of toplevel directories for the current projects. +// To be used for "diff all" or "commit all". +QStringList SubversionPlugin::currentProjectsTopLevels(QString *name) const +{ + typedef QList<ProjectExplorer::Project *> ProjectList; + ProjectList projects; + // Compile list of projects + if (ProjectExplorer::Project *currentProject = m_projectExplorer->currentProject()) { + projects.push_back(currentProject); + } else { + if (const ProjectExplorer::SessionManager *session = m_projectExplorer->session()) + projects.append(session->projects()); + } + // Get unique set of toplevels and concat project names + QStringList toplevels; + const QChar blank(QLatin1Char(' ')); + foreach (const ProjectExplorer::Project *p, projects) { + if (name) { + if (!name->isEmpty()) + name->append(blank); + name->append(p->name()); + } + + const QString projectPath = QFileInfo(p->file()->fileName()).absolutePath(); + const QString topLevel = findTopLevelForDirectory(projectPath); + if (!topLevel.isEmpty() && !toplevels.contains(topLevel)) + toplevels.push_back(topLevel); + } + return toplevels; +} + +void SubversionPlugin::diffProject() +{ + QString diffName; + const QStringList topLevels = currentProjectsTopLevels(&diffName); + if (!topLevels.isEmpty()) + svnDiff(topLevels, diffName); +} + +void SubversionPlugin::diffCurrentFile() +{ + svnDiff(QStringList(currentFileName())); +} + +void SubversionPlugin::startCommitCurrentFile() +{ + const QString file = QDir::toNativeSeparators(currentFileName()); + if (!file.isEmpty()) + startCommit(QStringList(file)); +} + +void SubversionPlugin::startCommitAll() +{ + // Make sure we have only repository for commit + const QStringList files = currentProjectsTopLevels(); + switch (files.size()) { + case 0: + break; + case 1: + startCommit(files); + break; + default: { + const QString msg = tr("The commit list spans several respositories (%1). Please commit them one by one."). + arg(files.join(QString(QLatin1Char(' ')))); + QMessageBox::warning(0, tr("svn commit"), msg, QMessageBox::Ok); + } + break; + } +} + +/* Start commit of files of a single repository by displaying + * template and files in a submit editor. On closing, the real + * commit will start. */ +void SubversionPlugin::startCommit(const QStringList &files) +{ + if (files.empty()) + return; + + if (m_changeTmpFile) { + showOutput(tr("Another commit is currently being executed.")); + return; + } + + QStringList args(QLatin1String("status")); + args += files; + if (args.size() == 1) + return; + + const SubversionResponse response = runSvn(args, subversionShortTimeOut, false); + if (response.error) + return; + // Get list of added/modified/deleted files + const QStringList statusOutput = parseStatusOutput(response.stdOut); + if (statusOutput.empty()) { + showOutput(tr("There are no modified files."), true); + return; + } + + // Create a new submit change file containing the submit template + QTemporaryFile *changeTmpFile = new QTemporaryFile(this); + changeTmpFile->setAutoRemove(true); + if (!changeTmpFile->open()) { + showOutput(tr("Cannot create temporary file: %1").arg(changeTmpFile->errorString())); + delete changeTmpFile; + return; + } + m_changeTmpFile = changeTmpFile; + // TODO: Retrieve submit template from + const QString submitTemplate; + // Create a submit + m_changeTmpFile->write(submitTemplate.toUtf8()); + m_changeTmpFile->flush(); + m_changeTmpFile->seek(0); + // Create a submit editor and set file list + SubversionSubmitEditor *editor = openSubversionSubmitEditor(m_changeTmpFile->fileName()); + editor->setFileList(statusOutput); +} + +// Parse "status" output for added/modified/deleted files +QStringList SubversionPlugin::parseStatusOutput(const QString &output) const +{ + QStringList changeSet; + const QString newLine = QString(QLatin1Char('\n')); + const QStringList list = output.split(newLine, QString::SkipEmptyParts); + foreach (const QString& l, list) { + QString line(l.trimmed()); + if (line.startsWith(QLatin1Char('A')) || line.startsWith(QLatin1Char('D')) + || line.startsWith(QLatin1Char('M'))) + changeSet.append(line); + } + return changeSet; +} + +bool SubversionPlugin::commit(const QString &messageFile, + const QStringList &subVersionFileList) +{ + if (Subversion::Constants::debug) + qDebug() << Q_FUNC_INFO << messageFile << subVersionFileList; + // Transform the status list which is sth + // "[ADM]<blanks>file" into an args list. The files of the status log + // can be relative or absolute depending on where the command was run. + QStringList args = QStringList(QLatin1String("commit")); + args << QLatin1String("--non-interactive") << QLatin1String("--file") << messageFile; + args.append(subVersionFileList); + const SubversionResponse response = runSvn(args, subversionLongTimeOut, true); + return !response.error ; +} + +void SubversionPlugin::filelogCurrentFile() +{ + const QString file = currentFileName(); + if (!file.isEmpty()) + filelog(file); +} + +void SubversionPlugin::filelog(const QString &file) +{ + QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(m_coreInstance, file); + // no need for temp file + QStringList args(QLatin1String("log")); + args.append(QDir::toNativeSeparators(file)); + + const SubversionResponse response = runSvn(args, subversionShortTimeOut, false, codec); + if (response.error) + return; + + // Re-use an existing view if possible to support + // the common usage pattern of continuously changing and diffing a file + + if (Core::IEditor *editor = locateEditor(m_coreInstance, "logFileName", file)) { + editor->createNew(response.stdOut); + m_coreInstance->editorManager()->setCurrentEditor(editor); + } else { + const QString title = tr("svn log %1").arg(QFileInfo(file).fileName()); + Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::LogOutput, file, codec); + newEditor->setProperty("logFileName", file); + } +} + +void SubversionPlugin::updateProject() +{ + const QStringList topLevels = currentProjectsTopLevels(); + if (topLevels.empty()) + return; + + QStringList args(QLatin1String("update")); + args.append(topLevels); + runSvn(args, subversionLongTimeOut, false); +} + +void SubversionPlugin::annotateCurrentFile() +{ + const QString file = currentFileName(); + if (!file.isEmpty()) + annotate(file); +} + +void SubversionPlugin::annotate(const QString &file) +{ + QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(m_coreInstance, file); + + QStringList args(QLatin1String("annotate")); + args.push_back(QLatin1String("-v")); + args.append(QDir::toNativeSeparators(file)); + + const SubversionResponse response = runSvn(args, subversionShortTimeOut, false, codec); + if (response.error) + return; + + // Re-use an existing view if possible to support + // the common usage pattern of continuously changing and diffing a file + + if (Core::IEditor *editor = locateEditor(m_coreInstance, "annotateFileName", file)) { + editor->createNew(response.stdOut); + m_coreInstance->editorManager()->setCurrentEditor(editor); + } else { + const QString title = tr("svn annotate %1").arg(QFileInfo(file).fileName()); + Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::AnnotateOutput, file, codec); + newEditor->setProperty("annotateFileName", file); + } +} + +void SubversionPlugin::projectStatus() +{ + if (!m_projectExplorer) + return; + + QStringList args(QLatin1String("status")); + args += currentProjectsTopLevels(); + + if (args.size() == 1) + return; + + runSvn(args, subversionShortTimeOut, true); +} + +void SubversionPlugin::describe(const QString &source, const QString &changeNr) +{ + // To describe a complete change, find the top level and then do + //svn diff -r 472958:472959 <top level> + const QFileInfo fi(source); + const QString topLevel = findTopLevelForDirectory(fi.isDir() ? source : fi.absolutePath()); + if (topLevel.isEmpty()) + return; + if (Subversion::Constants::debug) + qDebug() << Q_FUNC_INFO << source << topLevel << changeNr; + // Number must be > 1 + bool ok; + const int number = changeNr.toInt(&ok); + if (!ok || number < 2) + return; + QStringList args(QLatin1String("diff")); + args.push_back(QLatin1String("-r")); + QString diffArg; + QTextStream(&diffArg) << (number - 1) << ':' << number; + args.push_back(diffArg); + args.push_back(topLevel); + + QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(m_coreInstance, source); + const SubversionResponse response = runSvn(args, subversionShortTimeOut, false, codec); + if (response.error) + return; + + // Re-use an existing view if possible to support + // the common usage pattern of continuously changing and diffing a file + const QString id = diffArg + source; + if (Core::IEditor *editor = locateEditor(m_coreInstance, "describeChange", id)) { + editor->createNew(response.stdOut); + m_coreInstance->editorManager()->setCurrentEditor(editor); + } else { + const QString title = tr("svn describe %1#%2").arg(QFileInfo(source).fileName(), changeNr); + Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::DiffOutput, source, codec); + newEditor->setProperty("describeChange", id); + } +} + +void SubversionPlugin::submitCurrentLog() +{ + m_coreInstance->editorManager()->closeEditors(QList<Core::IEditor*>() + << m_coreInstance->editorManager()->currentEditor()); +} + +QString SubversionPlugin::currentFileName() const +{ + const QString fileName = m_coreInstance->fileManager()->currentFile(); + if (!fileName.isEmpty()) { + const QFileInfo fi(fileName); + if (fi.exists()) + return fi.canonicalFilePath(); + } + return QString(); +} + +static inline QString processStdErr(QProcess &proc) +{ + return QString::fromLocal8Bit(proc.readAllStandardError()).remove(QLatin1Char('\r')); +} + +static inline QString processStdOut(QProcess &proc, QTextCodec *outputCodec = 0) +{ + const QByteArray stdOutData = proc.readAllStandardOutput(); + QString stdOut = outputCodec ? outputCodec->toUnicode(stdOutData) : QString::fromLocal8Bit(stdOutData); + return stdOut.remove(QLatin1Char('\r')); +} + +SubversionResponse SubversionPlugin::runSvn(const QStringList &arguments, + int timeOut, + bool showStdOutInOutputWindow, + QTextCodec *outputCodec) +{ + const QString executable = m_settings.svnCommand; + SubversionResponse response; + if (executable.isEmpty()) { + response.error = true; + response.message =tr("No subversion executable specified!"); + return response; + } + const QStringList allArgs = m_settings.addOptions(arguments); + + // Hide passwords, etc in the log window + const QString timeStamp = QTime::currentTime().toString(QLatin1String("HH:mm")); + const QString outputText = tr("%1 Executing: %2 %3\n").arg(timeStamp, executable, SubversionSettings::formatArguments(allArgs)); + showOutput(outputText, false); + + if (Subversion::Constants::debug) + qDebug() << "runSvn" << timeOut << outputText; + + // Run, connect stderr to the output window + Core::Utils::SynchronousProcess process; + process.setTimeout(timeOut); + process.setStdOutCodec(outputCodec); + + process.setStdErrBufferedSignalsEnabled(true); + connect(&process, SIGNAL(stdErrBuffered(QString,bool)), m_subversionOutputWindow, SLOT(append(QString,bool))); + + // connect stdout to the output window if desired + if (showStdOutInOutputWindow) { + process.setStdOutBufferedSignalsEnabled(true); + connect(&process, SIGNAL(stdOutBuffered(QString,bool)), m_subversionOutputWindow, SLOT(append(QString,bool))); + } + + const Core::Utils::SynchronousProcessResponse sp_resp = process.run(executable, allArgs); + response.error = true; + response.stdErr = sp_resp.stdErr; + response.stdOut = sp_resp.stdOut; + switch (sp_resp.result) { + case Core::Utils::SynchronousProcessResponse::Finished: + response.error = false; + break; + case Core::Utils::SynchronousProcessResponse::FinishedError: + response.message = tr("The process terminated with exit code %1.").arg(sp_resp.exitCode); + break; + case Core::Utils::SynchronousProcessResponse::TerminatedAbnormally: + response.message = tr("The process terminated abnormally."); + break; + case Core::Utils::SynchronousProcessResponse::StartFailed: + response.message = tr("Could not start subversion '%1'. Please check your settings in the preferences.").arg(executable); + break; + case Core::Utils::SynchronousProcessResponse::Hang: + response.message = tr("Subversion did not respond within timeout limit (%1 ms).").arg(timeOut); + break; + } + if (response.error) + m_subversionOutputWindow->append(response.message, true); + + return response; +} + +void SubversionPlugin::showOutput(const QString &output, bool bringToForeground) +{ + m_subversionOutputWindow->append(output); + if (bringToForeground) + m_subversionOutputWindow->popup(); +} + +Core::IEditor * SubversionPlugin::showOutputInEditor(const QString& title, const QString &output, + int editorType, const QString &source, + QTextCodec *codec) +{ + const VCSBase::VCSBaseEditorParameters *params = findType(editorType); + Q_ASSERT(params); + const QString kind = QLatin1String(params->kind); + if (Subversion::Constants::debug) + qDebug() << "SubversionPlugin::showOutputInEditor" << title << kind << "Size= " << output.size() << " Type=" << editorType << debugCodec(codec); + QString s = title; + Core::IEditor *ediface = m_coreInstance->editorManager()->newFile(kind, &s, output.toLocal8Bit()); + SubversionEditor *e = qobject_cast<SubversionEditor*>(ediface->widget()); + if (!e) + return 0; + s.replace(QLatin1Char(' '), QLatin1Char('_')); + e->setSuggestedFileName(s); + if (!source.isEmpty()) + e->setSource(source); + if (codec) + e->setCodec(codec); + return e->editableInterface(); +} + +SubversionSettings SubversionPlugin::settings() const +{ + return m_settings; +} + +void SubversionPlugin::setSettings(const SubversionSettings &s) +{ + if (s != m_settings) { + m_settings = s; + if (QSettings *settings = m_coreInstance->settings()) + m_settings.toSettings(settings); + } +} + +Core::ICore *SubversionPlugin::coreInstance() +{ + Q_ASSERT(m_coreInstance); + return m_coreInstance; +} + +SubversionPlugin *SubversionPlugin::subversionPluginInstance() +{ + Q_ASSERT(m_subversionPluginInstance); + return m_subversionPluginInstance; +} + +bool SubversionPlugin::vcsAdd(const QString &rawFileName) +{ + const QString file = QDir::toNativeSeparators(rawFileName); + QStringList args(QLatin1String("add")); + args.push_back(file); + + const SubversionResponse response = runSvn(args, subversionShortTimeOut, true); + return !response.error; +} + +bool SubversionPlugin::vcsDelete(const QString &rawFileName) +{ + const QString file = QDir::toNativeSeparators(rawFileName); + + QStringList args(QLatin1String("delete")); + args.push_back(file); + + const SubversionResponse response = runSvn(args, subversionShortTimeOut, true); + return !response.error; +} + +/* Subversion has ".svn" directory in each directory + * it manages. The top level is the first directory + * under the directory that does not have a ".svn". */ +bool SubversionPlugin::managesDirectory(const QString &directory) const +{ + const QDir dir(directory); + const bool rc = dir.exists() && managesDirectory(dir); + if (Subversion::Constants::debug) + qDebug() << "SubversionPlugin::managesDirectory" << directory << rc; + return rc; +} + +bool SubversionPlugin::managesDirectory(const QDir &directory) const +{ + const QString svnDir = directory.absoluteFilePath(m_svnDotDirectory); + return QFileInfo(svnDir).isDir(); +} + +QString SubversionPlugin::findTopLevelForDirectory(const QString &directory) const +{ + // Debug wrapper + const QString rc = findTopLevelForDirectoryI(directory); + if (Subversion::Constants::debug) + qDebug() << "SubversionPlugin::findTopLevelForDirectory" << directory << rc; + return rc; +} + +QString SubversionPlugin::findTopLevelForDirectoryI(const QString &directory) const +{ + /* Recursing up, the top level is a child of the first directory that does + * not have a ".svn" directory. The starting directory must be a managed + * one. Go up and try to find the first unmanaged parent dir. */ + QDir lastDirectory = QDir(directory); + if (!lastDirectory.exists() || !managesDirectory(lastDirectory)) + return QString(); + for (QDir parentDir = lastDirectory; parentDir.cdUp() ; lastDirectory = parentDir) { + if (!managesDirectory(parentDir)) + return QDir::toNativeSeparators(lastDirectory.absolutePath()); + } + return QString(); +} + +Q_EXPORT_PLUGIN(SubversionPlugin) diff --git a/src/plugins/subversion/subversionplugin.h b/src/plugins/subversion/subversionplugin.h new file mode 100644 index 0000000000..d01d0a05bb --- /dev/null +++ b/src/plugins/subversion/subversionplugin.h @@ -0,0 +1,223 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef SUBVERSIONPLUGIN_H +#define SUBVERSIONPLUGIN_H + +#include "subversionsettings.h" + +#include <coreplugin/editormanager/ieditorfactory.h> +#include <coreplugin/iversioncontrol.h> +#include <coreplugin/icorelistener.h> +#include <extensionsystem/iplugin.h> +#include <coreplugin/icorelistener.h> + +#include <QtCore/QObject> +#include <QtCore/QProcess> + +QT_BEGIN_NAMESPACE +class QFile; +class QDir; +class QAction; +class QTemporaryFile; +class QTextCodec; +QT_END_NAMESPACE + +namespace Core { + class ICore; + class IEditorFactory; + class IVersionControl; +} + +namespace ProjectExplorer { + class ProjectExplorerPlugin; +} + +namespace Subversion { +namespace Internal { + +class CoreListener; +class SettingsPage; +class SubversionOutputWindow; +class SubversionSubmitEditor; + +struct SubversionResponse +{ + SubversionResponse() : error(false) {} + bool error; + QString stdOut; + QString stdErr; + QString message; +}; + +class SubversionPlugin : public ExtensionSystem::IPlugin +{ + Q_OBJECT + +public: + SubversionPlugin(); + ~SubversionPlugin(); + + bool initialize(const QStringList &arguments, QString *error_message); + void extensionsInitialized(); + bool editorAboutToClose(Core::IEditor *editor); + + void svnDiff(const QStringList &files, QString diffname = QString()); + + SubversionSubmitEditor *openSubversionSubmitEditor(const QString &fileName); + + SubversionSettings settings() const; + void setSettings(const SubversionSettings &s); + + // IVersionControl + bool vcsAdd(const QString &fileName); + bool vcsDelete(const QString &fileName); + bool managesDirectory(const QString &directory) const; + QString findTopLevelForDirectory(const QString &directory) const; + + static Core::ICore *coreInstance(); + static SubversionPlugin *subversionPluginInstance(); + +private slots: + void updateActions(); + void addCurrentFile(); + void deleteCurrentFile(); + void revertCurrentFile(); + void diffProject(); + void diffCurrentFile(); + void startCommitAll(); + void startCommitCurrentFile(); + void filelogCurrentFile(); + void annotateCurrentFile(); + void projectStatus(); + void describe(const QString &source, const QString &changeNr); + void updateProject(); + void submitCurrentLog(); + void diffFiles(const QStringList &); + +private: + QString currentFileName() const; + Core::IEditor * showOutputInEditor(const QString& title, const QString &output, + int editorType, const QString &source, + QTextCodec *codec); + SubversionResponse runSvn(const QStringList &arguments, int timeOut, + bool showStdOutInOutputWindow, QTextCodec *outputCodec = 0); + void showOutput(const QString &output, bool bringToForeground = true); + QStringList parseStatusOutput(const QString &output) const; + void annotate(const QString &file); + void filelog(const QString &file); + bool managesDirectory(const QDir &directory) const; + QString findTopLevelForDirectoryI(const QString &directory) const; + QStringList currentProjectsTopLevels(QString *name = 0) const; + void startCommit(const QStringList &files); + bool commit(const QString &messageFile, const QStringList &subVersionFileList); + void cleanChangeTmpFile(); + + const QString m_svnDotDirectory; + + SubversionSettings m_settings; + Core::IVersionControl *m_versionControl; + CoreListener *m_coreListener; + SettingsPage *m_settingsPage; + QTemporaryFile *m_changeTmpFile; + + Core::IEditorFactory *m_submitEditorFactory; + QList<Core::IEditorFactory*> m_editorFactories; + + SubversionOutputWindow *m_subversionOutputWindow; + ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer; + + QAction *m_addAction; + QAction *m_deleteAction; + QAction *m_revertAction; + QAction *m_diffProjectAction; + QAction *m_diffCurrentAction; + QAction *m_commitAllAction; + QAction *m_commitCurrentAction; + QAction *m_filelogCurrentAction; + QAction *m_annotateCurrentAction; + QAction *m_statusAction; + QAction *m_updateProjectAction; + + QAction *m_submitCurrentLogAction; + QAction *m_submitDiffAction; + QAction *m_submitUndoAction; + QAction *m_submitRedoAction; + + static const char * const SUBVERSION_MENU; + static const char * const ADD; + static const char * const DELETE_FILE; + static const char * const REVERT; + static const char * const SEPARATOR0; + static const char * const DIFF_PROJECT; + static const char * const DIFF_CURRENT; + static const char * const SEPARATOR1; + static const char * const COMMIT_ALL; + static const char * const COMMIT_CURRENT; + static const char * const SEPARATOR2; + static const char * const FILELOG_CURRENT; + static const char * const ANNOTATE_CURRENT; + static const char * const SEPARATOR3; + static const char * const STATUS; + static const char * const UPDATE; + + static Core::ICore *m_coreInstance; + static SubversionPlugin *m_subversionPluginInstance; + + friend class SubversionOutputWindow; +}; + +// Just a proxy for SubversionPlugin +class CoreListener : public Core::ICoreListener +{ + Q_OBJECT +public: + CoreListener(SubversionPlugin *plugin) : m_plugin(plugin) { } + + // Start commit when submit editor closes + bool editorAboutToClose(Core::IEditor *editor) { + return m_plugin->editorAboutToClose(editor); + } + + // TODO: how to handle that ??? + bool coreAboutToClose() { + return true; + } + +private: + SubversionPlugin *m_plugin; +}; + +} // namespace Subversion +} // namespace Internal + +#endif // SUBVERSIONPLUGIN_H diff --git a/src/plugins/subversion/subversionsettings.cpp b/src/plugins/subversion/subversionsettings.cpp new file mode 100644 index 0000000000..ca4a946c7c --- /dev/null +++ b/src/plugins/subversion/subversionsettings.cpp @@ -0,0 +1,133 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "subversionsettings.h" + +#include <QtCore/QSettings> +#include <QtCore/QTextStream> + +static const char *groupC = "Subversion"; +static const char *commandKeyC = "Command"; +static const char *userKeyC = "User"; +static const char *passwordKeyC = "Password"; +static const char *authenticationKeyC = "Authentication"; + +static const char *userNameOptionC = "--username"; +static const char *passwordOptionC = "--password"; + +static QString defaultCommand() +{ + QString rc; + rc = QLatin1String("svn"); +#if defined(Q_OS_WIN32) + rc.append(QLatin1String(".exe")); +#endif + return rc; +} + +namespace Subversion { +namespace Internal { + +SubversionSettings::SubversionSettings() : + svnCommand(defaultCommand()), + useAuthentication(false) +{ +} + +void SubversionSettings::fromSettings(QSettings *settings) +{ + settings->beginGroup(QLatin1String(groupC)); + svnCommand = settings->value(QLatin1String(commandKeyC), defaultCommand()).toString(); + useAuthentication = settings->value(QLatin1String(authenticationKeyC), QVariant(false)).toBool(); + user = settings->value(QLatin1String(userKeyC), QString()).toString(); + password = settings->value(QLatin1String(passwordKeyC), QString()).toString(); + settings->endGroup(); +} + +void SubversionSettings::toSettings(QSettings *settings) const +{ + settings->beginGroup(QLatin1String(groupC)); + settings->setValue(QLatin1String(commandKeyC), svnCommand); + settings->setValue(QLatin1String(authenticationKeyC), QVariant(useAuthentication)); + settings->setValue(QLatin1String(userKeyC), user); + settings->setValue(QLatin1String(passwordKeyC), password); + settings->endGroup(); +} + +bool SubversionSettings::equals(const SubversionSettings &s) const +{ + return svnCommand == s.svnCommand + && useAuthentication == s.useAuthentication + && user == s.user + && password == s.password; +} + +QStringList SubversionSettings::addOptions(const QStringList &args) const +{ + if (!useAuthentication || user.isEmpty()) + return args; + + QStringList rc; + rc.push_back(QLatin1String(userNameOptionC)); + rc.push_back(user); + if (!password.isEmpty()) { + rc.push_back(QLatin1String(passwordOptionC)); + rc.push_back(password); + } + rc.append(args); + return rc; +} + +// Format arguments for log windows hiding passwords, etc. +QString SubversionSettings::formatArguments(const QStringList &args) +{ + QString rc; + QTextStream str(&rc); + const int size = args.size(); + // Skip authentication options + for (int i = 0; i < size; i++) { + const QString &arg = args.at(i); + if (i) + str << ' '; + str << arg; + if (arg == QLatin1String(userNameOptionC) || arg == QLatin1String(passwordOptionC)) { + str << " ********"; + i++; + } + } + return rc; +} + + +} +} + diff --git a/src/plugins/subversion/subversionsettings.h b/src/plugins/subversion/subversionsettings.h new file mode 100644 index 0000000000..32c0c301ff --- /dev/null +++ b/src/plugins/subversion/subversionsettings.h @@ -0,0 +1,73 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef SUBVERSIONSETTINGS_H +#define SUBVERSIONSETTINGS_H + +#include <QtCore/QStringList> + +QT_BEGIN_NAMESPACE +class QSettings; +QT_END_NAMESPACE + +namespace Subversion { +namespace Internal { + +// Todo: Add user name and password? +struct SubversionSettings { + SubversionSettings(); + + void fromSettings(QSettings *); + void toSettings(QSettings *) const; + + // Add authentication and (maybe future) options to the + // command line + QStringList addOptions(const QStringList &args) const; + // Format arguments for log windows hiding passwords, etc. + static QString formatArguments(const QStringList &args); + + bool equals(const SubversionSettings &s) const; + + QString svnCommand; + bool useAuthentication; + QString user; + QString password; +}; + +inline bool operator==(const SubversionSettings &p1, const SubversionSettings &p2) + { return p1.equals(p2); } +inline bool operator!=(const SubversionSettings &p1, const SubversionSettings &p2) + { return !p1.equals(p2); } +} +} + +#endif diff --git a/src/plugins/subversion/subversionsubmiteditor.cpp b/src/plugins/subversion/subversionsubmiteditor.cpp new file mode 100644 index 0000000000..1301041378 --- /dev/null +++ b/src/plugins/subversion/subversionsubmiteditor.cpp @@ -0,0 +1,63 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "subversionsubmiteditor.h" + +#include <utils/submiteditorwidget.h> + +namespace Subversion { +namespace Internal { + +SubversionSubmitEditor::SubversionSubmitEditor(const VCSBase::VCSBaseSubmitEditorParameters *parameters, + QWidget *parentWidget) : + VCSBase::VCSBaseSubmitEditor(parameters, new Core::Utils::SubmitEditorWidget(parentWidget)) +{ + setDisplayName(tr("Subversion Submit")); +} + +QStringList SubversionSubmitEditor::vcsFileListToFileList(const QStringList &rl) const +{ + QStringList files; + const QStringList::const_iterator cend = rl.constEnd(); + for (QStringList::const_iterator it = rl.constBegin(); it != cend; ++it) + files.push_back(SubversionSubmitEditor::fileFromStatusLine(*it)); + return files; +} + +QString SubversionSubmitEditor::fileFromStatusLine(const QString &statusLine) +{ + enum { filePos = 7 }; + return statusLine.mid(filePos, statusLine.size() - filePos); +} + +} +} diff --git a/src/plugins/subversion/subversionsubmiteditor.h b/src/plugins/subversion/subversionsubmiteditor.h new file mode 100644 index 0000000000..3ba3335e49 --- /dev/null +++ b/src/plugins/subversion/subversionsubmiteditor.h @@ -0,0 +1,57 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef SUBVERSIONSUBMITEDITOR_H +#define SUBVERSIONSUBMITEDITOR_H + +#include <vcsbase/vcsbasesubmiteditor.h> + +namespace Subversion { +namespace Internal { + +class SubversionSubmitEditor : public VCSBase::VCSBaseSubmitEditor +{ + Q_OBJECT +public: + SubversionSubmitEditor(const VCSBase::VCSBaseSubmitEditorParameters *parameters, + QWidget *parentWidget = 0); + + static QString fileFromStatusLine(const QString &statusLine); + +private: + virtual QStringList vcsFileListToFileList(const QStringList &) const; +}; + +} // namespace Internal +} // namespace Subversion + +#endif // SUBVERSIONSUBMITEDITOR_H |