forked from qt-creator/qt-creator
VCS[cvs,subversion]: Add diff options and enable reverting chunks.
Create VCSBaseEditorParameterWidget as a base class for setting the diff arguments lists and wire it up to trigger a re-run of diff on reverting. Enable reverting of chunks for cvs, subversion.
This commit is contained in:
@@ -43,9 +43,11 @@
|
||||
#include <vcsbase/vcsbaseeditor.h>
|
||||
#include <vcsbase/basevcssubmiteditorfactory.h>
|
||||
#include <vcsbase/vcsbaseoutputwindow.h>
|
||||
#include <vcsbase/vcsbaseeditorparameterwidget.h>
|
||||
#include <locator/commandlocator.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
#include <utils/parameteraction.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
@@ -529,22 +531,79 @@ static inline void setDiffBaseDirectory(Core::IEditor *editor, const QString &db
|
||||
ve->setDiffBaseDirectory(db);
|
||||
}
|
||||
|
||||
// Collect all parameters required for a diff to be able to associate them
|
||||
// with a diff editor and re-run the diff with parameters.
|
||||
struct CvsDiffParameters
|
||||
{
|
||||
CvsDiffParameters() : reUseEditor(false) {}
|
||||
|
||||
QString workingDir;
|
||||
QStringList arguments;
|
||||
QStringList files;
|
||||
bool reUseEditor;
|
||||
};
|
||||
|
||||
// Parameter widget controlling whitespace diff mode, associated with a parameter
|
||||
// struct.
|
||||
class CvsDiffParameterWidget : public VCSBase::VCSBaseEditorParameterWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CvsDiffParameterWidget(const CvsDiffParameters &p, QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void reRunDiff(const CVS::Internal::CvsDiffParameters &);
|
||||
|
||||
public slots:
|
||||
void triggerReRun();
|
||||
|
||||
private:
|
||||
const CvsDiffParameters m_parameters;
|
||||
};
|
||||
|
||||
CvsDiffParameterWidget::CvsDiffParameterWidget(const CvsDiffParameters &p, QWidget *parent) :
|
||||
VCSBase::VCSBaseEditorParameterWidget(parent), m_parameters(p)
|
||||
{
|
||||
setBaseArguments(p.arguments);
|
||||
addIgnoreWhiteSpaceButton(QLatin1String("-w"));
|
||||
addIgnoreBlankLinesButton(QLatin1String("-B"));
|
||||
connect(this, SIGNAL(argumentsChanged()),
|
||||
this, SLOT(triggerReRun()));
|
||||
}
|
||||
|
||||
void CvsDiffParameterWidget::triggerReRun()
|
||||
{
|
||||
CvsDiffParameters effectiveParameters = m_parameters;
|
||||
effectiveParameters.reUseEditor = true;
|
||||
effectiveParameters.arguments = arguments();
|
||||
emit reRunDiff(effectiveParameters);
|
||||
}
|
||||
|
||||
void CVSPlugin::cvsDiff(const QString &workingDir, const QStringList &files)
|
||||
{
|
||||
CvsDiffParameters p;
|
||||
p.workingDir = workingDir;
|
||||
p.files = files;
|
||||
p.arguments = m_settings.cvsDiffOptions.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
||||
cvsDiff(p);
|
||||
}
|
||||
|
||||
void CVSPlugin::cvsDiff(const CvsDiffParameters &p)
|
||||
{
|
||||
if (CVS::Constants::debug)
|
||||
qDebug() << Q_FUNC_INFO << files;
|
||||
const QString source = VCSBase::VCSBaseEditorWidget::getSource(workingDir, files);
|
||||
QTextCodec *codec = VCSBase::VCSBaseEditorWidget::getCodec(workingDir, files);
|
||||
const QString id = VCSBase::VCSBaseEditorWidget::getTitleId(workingDir, files);
|
||||
qDebug() << Q_FUNC_INFO << p.files;
|
||||
const QString source = VCSBase::VCSBaseEditorWidget::getSource(p.workingDir, p.files);
|
||||
QTextCodec *codec = VCSBase::VCSBaseEditorWidget::getCodec(p.workingDir, p.files);
|
||||
const QString id = VCSBase::VCSBaseEditorWidget::getTitleId(p.workingDir, p.files);
|
||||
|
||||
QStringList args(QLatin1String("diff"));
|
||||
args << m_settings.cvsDiffOptions;
|
||||
args.append(files);
|
||||
args.append(p.arguments);
|
||||
args.append(p.files);
|
||||
|
||||
// CVS returns the diff exit code (1 if files differ), which is
|
||||
// undistinguishable from a "file not found" error, unfortunately.
|
||||
const CVSResponse response =
|
||||
runCVS(workingDir, args, m_settings.timeOutMS(), 0, codec);
|
||||
runCVS(p.workingDir, args, m_settings.timeOutMS(), 0, codec);
|
||||
switch (response.result) {
|
||||
case CVSResponse::NonNullExitCode:
|
||||
case CVSResponse::Ok:
|
||||
@@ -558,20 +617,31 @@ void CVSPlugin::cvsDiff(const QString &workingDir, const QStringList &files)
|
||||
output = tr("The files do not differ.");
|
||||
// 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) {
|
||||
if (p.files.count() == 1 || p.reUseEditor) {
|
||||
// Show in the same editor if diff has been executed before
|
||||
if (Core::IEditor *editor = locateEditor("originalFileName", id)) {
|
||||
editor->createNew(output);
|
||||
Core::EditorManager::instance()->activateEditor(editor, Core::EditorManager::ModeSwitch);
|
||||
setDiffBaseDirectory(editor, workingDir);
|
||||
setDiffBaseDirectory(editor, p.workingDir);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const QString title = QString::fromLatin1("cvs diff %1").arg(id);
|
||||
Core::IEditor *editor = showOutputInEditor(title, output, VCSBase::DiffOutput, source, codec);
|
||||
if (files.count() == 1)
|
||||
editor->setProperty("originalFileName", id);
|
||||
setDiffBaseDirectory(editor, workingDir);
|
||||
editor->setProperty("originalFileName", id);
|
||||
setDiffBaseDirectory(editor, p.workingDir);
|
||||
CVSEditor *diffEditorWidget = qobject_cast<CVSEditor*>(editor->widget());
|
||||
QTC_ASSERT(diffEditorWidget, return ; )
|
||||
|
||||
// Wire up the parameter widget to trigger a re-run on
|
||||
// parameter change and 'revert' from inside the diff editor.
|
||||
diffEditorWidget->setRevertDiffChunkEnabled(true);
|
||||
CvsDiffParameterWidget *pw = new CvsDiffParameterWidget(p);
|
||||
connect(pw, SIGNAL(reRunDiff(CVS::Internal::CvsDiffParameters)),
|
||||
this, SLOT(cvsDiff(CVS::Internal::CvsDiffParameters)));
|
||||
connect(diffEditorWidget, SIGNAL(diffChunkReverted(VCSBase::DiffChunk)),
|
||||
pw, SLOT(triggerReRun()));
|
||||
diffEditorWidget->setConfigurationWidget(pw);
|
||||
}
|
||||
|
||||
CVSSubmitEditor *CVSPlugin::openCVSSubmitEditor(const QString &fileName)
|
||||
@@ -1339,3 +1409,5 @@ CVSControl *CVSPlugin::cvsVersionControl() const
|
||||
}
|
||||
}
|
||||
Q_EXPORT_PLUGIN(CVS::Internal::CVSPlugin)
|
||||
|
||||
#include "cvsplugin.moc"
|
||||
|
Reference in New Issue
Block a user