subversionplugin.cpp 47.7 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30 31 32 33 34 35 36 37
#include "subversionplugin.h"

#include "settingspage.h"
#include "subversioneditor.h"

#include "subversionsubmiteditor.h"
#include "subversionconstants.h"
#include "subversioncontrol.h"
38
#include "checkoutwizard.h"
con's avatar
con committed
39 40 41 42

#include <vcsbase/basevcseditorfactory.h>
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/basevcssubmiteditorfactory.h>
43
#include <vcsbase/vcsbaseoutputwindow.h>
con's avatar
con committed
44
#include <utils/synchronousprocess.h>
45
#include <utils/parameteraction.h>
con's avatar
con committed
46 47 48 49 50 51 52

#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/filemanager.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/uniqueidmanager.h>
53
#include <coreplugin/actionmanager/actionmanager.h>
54 55
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
con's avatar
con committed
56
#include <coreplugin/editormanager/editormanager.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
57 58 59

#include <locator/commandlocator.h>

hjk's avatar
hjk committed
60
#include <utils/qtcassert.h>
con's avatar
con committed
61 62

#include <QtCore/QDebug>
63
#include <QtCore/QDir>
con's avatar
con committed
64 65
#include <QtCore/QFileInfo>
#include <QtCore/QTemporaryFile>
66 67
#include <QtCore/QTextCodec>
#include <QtCore/QtPlugin>
con's avatar
con committed
68
#include <QtGui/QAction>
69 70
#include <QtGui/QFileDialog>
#include <QtGui/QMainWindow>
con's avatar
con committed
71 72
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
73 74 75
#include <QtGui/QInputDialog>

#include <limits.h>
con's avatar
con committed
76 77 78

using namespace Subversion::Internal;

79 80 81 82 83 84 85 86 87
static const char * const CMD_ID_SUBVERSION_MENU    = "Subversion.Menu";
static const char * const CMD_ID_ADD                = "Subversion.Add";
static const char * const CMD_ID_DELETE_FILE        = "Subversion.Delete";
static const char * const CMD_ID_REVERT             = "Subversion.Revert";
static const char * const CMD_ID_SEPARATOR0         = "Subversion.Separator0";
static const char * const CMD_ID_DIFF_PROJECT       = "Subversion.DiffAll";
static const char * const CMD_ID_DIFF_CURRENT       = "Subversion.DiffCurrent";
static const char * const CMD_ID_SEPARATOR1         = "Subversion.Separator1";
static const char * const CMD_ID_COMMIT_ALL         = "Subversion.CommitAll";
88
static const char * const CMD_ID_REVERT_ALL         = "Subversion.RevertAll";
89 90 91 92 93
static const char * const CMD_ID_COMMIT_CURRENT     = "Subversion.CommitCurrent";
static const char * const CMD_ID_SEPARATOR2         = "Subversion.Separator2";
static const char * const CMD_ID_FILELOG_CURRENT    = "Subversion.FilelogCurrent";
static const char * const CMD_ID_ANNOTATE_CURRENT   = "Subversion.AnnotateCurrent";
static const char * const CMD_ID_SEPARATOR3         = "Subversion.Separator3";
94
static const char * const CMD_ID_SEPARATOR4         = "Subversion.Separator4";
95
static const char * const CMD_ID_STATUS             = "Subversion.Status";
96 97
static const char * const CMD_ID_PROJECTLOG         = "Subversion.ProjectLog";
static const char * const CMD_ID_REPOSITORYLOG      = "Subversion.RepositoryLog";
98 99
static const char * const CMD_ID_UPDATE             = "Subversion.Update";
static const char * const CMD_ID_DESCRIBE           = "Subversion.Describe";
con's avatar
con committed
100

101 102
static const char *nonInteractiveOptionC = "--non-interactive";

con's avatar
con committed
103 104 105
static const VCSBase::VCSBaseEditorParameters editorParameters[] = {
{
    VCSBase::RegularCommandOutput,
106 107
    "Subversion Command Log Editor", // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Command Log Editor"), // display name
108
    "Subversion Command Log Editor", // context
con's avatar
con committed
109 110 111
    "application/vnd.nokia.text.scs_svn_commandlog",
    "scslog"},
{   VCSBase::LogOutput,
112 113
    "Subversion File Log Editor",   // id
    QT_TRANSLATE_NOOP("VCS", "Subversion File Log Editor"),   // display_name
114
    "Subversion File Log Editor",   // context
con's avatar
con committed
115 116 117
    "application/vnd.nokia.text.scs_svn_filelog",
    "scsfilelog"},
{    VCSBase::AnnotateOutput,
118 119
    "Subversion Annotation Editor",  // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Annotation Editor"),   // display_name
120
    "Subversion Annotation Editor",  // context
con's avatar
con committed
121 122 123
    "application/vnd.nokia.text.scs_svn_annotation",
    "scsannotate"},
{   VCSBase::DiffOutput,
124 125
    "Subversion Diff Editor",  // id
    QT_TRANSLATE_NOOP("VCS", "Subversion Diff Editor"),   // display_name
126
    "Subversion Diff Editor",  // context
con's avatar
con committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    "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");
}

hjk's avatar
hjk committed
142
Core::IEditor* locateEditor(const char *property, const QString &entry)
con's avatar
con committed
143
{
144
    foreach (Core::IEditor *ed, Core::EditorManager::instance()->openedEditors())
con's avatar
con committed
145 146 147 148 149
        if (ed->property(property).toString() == entry)
            return ed;
    return 0;
}

150 151 152 153 154 155 156 157 158 159 160 161 162 163
// Parse "svn status" output for added/modified/deleted files
// "M<7blanks>file"
typedef QList<SubversionSubmitEditor::StatusFilePair> StatusList;

StatusList parseStatusOutput(const QString &output)
{
    StatusList changeSet;
    const QString newLine = QString(QLatin1Char('\n'));
    const QStringList list = output.split(newLine, QString::SkipEmptyParts);
    foreach (const QString &l, list) {
        const QString line =l.trimmed();
        if (line.size() > 8) {
            const QChar state = line.at(0);
            if (state == QLatin1Char('A') || state == QLatin1Char('D') || state == QLatin1Char('M')) {
164 165
                const QString fileName = line.mid(7); // Column 8 starting from svn 1.6
                changeSet.push_back(SubversionSubmitEditor::StatusFilePair(QString(state), fileName.trimmed()));
166 167 168 169 170 171 172
            }

        }
    }
    return changeSet;
}

173 174 175 176 177 178 179 180 181 182 183
// Return a list of names for the internal svn directories
static inline QStringList svnDirectories()
{
    QStringList rc(QLatin1String(".svn"));
#ifdef Q_OS_WIN
    // Option on Windows systems to avoid hassle with some IDEs
    rc.push_back(QLatin1String("_svn"));
#endif
    return rc;
}

con's avatar
con committed
184 185 186 187
// ------------- SubversionPlugin
SubversionPlugin *SubversionPlugin::m_subversionPluginInstance = 0;

SubversionPlugin::SubversionPlugin() :
188
    VCSBase::VCSBasePlugin(QLatin1String(Subversion::Constants::SUBVERSIONCOMMITEDITOR_ID)),
189
    m_svnDirectories(svnDirectories()),
Friedemann Kleint's avatar
Friedemann Kleint committed
190
    m_commandLocator(0),
con's avatar
con committed
191 192 193 194 195
    m_addAction(0),
    m_deleteAction(0),
    m_revertAction(0),
    m_diffProjectAction(0),
    m_diffCurrentAction(0),
196 197
    m_logProjectAction(0),
    m_logRepositoryAction(0),
con's avatar
con committed
198
    m_commitAllAction(0),
199
    m_revertRepositoryAction(0),
con's avatar
con committed
200 201 202
    m_commitCurrentAction(0),
    m_filelogCurrentAction(0),
    m_annotateCurrentAction(0),
203
    m_statusProjectAction(0),
con's avatar
con committed
204
    m_updateProjectAction(0),
205
    m_describeAction(0),
con's avatar
con committed
206 207 208
    m_submitCurrentLogAction(0),
    m_submitDiffAction(0),
    m_submitUndoAction(0),
209
    m_submitRedoAction(0),
210
    m_menuAction(0),
211
    m_submitActionTriggered(false)
con's avatar
con committed
212 213 214 215 216
{
}

SubversionPlugin::~SubversionPlugin()
{
217
    cleanCommitMessageFile();
con's avatar
con committed
218 219
}

220
void SubversionPlugin::cleanCommitMessageFile()
con's avatar
con committed
221
{
222 223 224
    if (!m_commitMessageFileName.isEmpty()) {
        QFile::remove(m_commitMessageFileName);
        m_commitMessageFileName.clear();
225
        m_commitRepository.clear();
con's avatar
con committed
226 227 228
    }
}

229 230 231 232 233
bool SubversionPlugin::isCommitEditorOpen() const
{
    return !m_commitMessageFileName.isEmpty();
}

con's avatar
con committed
234 235
static const VCSBase::VCSBaseSubmitEditorParameters submitParameters = {
    Subversion::Constants::SUBVERSION_SUBMIT_MIMETYPE,
236 237
    Subversion::Constants::SUBVERSIONCOMMITEDITOR_ID,
    Subversion::Constants::SUBVERSIONCOMMITEDITOR_DISPLAY_NAME,
238
    Subversion::Constants::SUBVERSIONCOMMITEDITOR
con's avatar
con committed
239 240
};

241 242 243 244 245 246 247 248 249 250
static inline Core::Command *createSeparator(QObject *parent,
                                             Core::ActionManager *ami,
                                             const char*id,
                                             const QList<int> &globalcontext)
{
    QAction *tmpaction = new QAction(parent);
    tmpaction->setSeparator(true);
    return ami->registerAction(tmpaction, id, globalcontext);
}

251
bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *errorMessage)
con's avatar
con committed
252 253 254 255 256 257 258 259
{
    typedef VCSBase::VCSSubmitEditorFactory<SubversionSubmitEditor> SubversionSubmitEditorFactory;
    typedef VCSBase::VCSEditorFactory<SubversionEditor> SubversionEditorFactory;
    using namespace Constants;

    using namespace Core::Constants;
    using namespace ExtensionSystem;

260 261
    VCSBase::VCSBasePlugin::initialize(new SubversionControl(this));

con's avatar
con committed
262
    m_subversionPluginInstance = this;
hjk's avatar
hjk committed
263
    Core::ICore *core = Core::ICore::instance();
con's avatar
con committed
264

hjk's avatar
hjk committed
265
    if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/trolltech.subversion/Subversion.mimetypes.xml"), errorMessage))
con's avatar
con committed
266 267
        return false;

hjk's avatar
hjk committed
268
    if (QSettings *settings = core->settings())
con's avatar
con committed
269 270
        m_settings.fromSettings(settings);

271
    addAutoReleasedObject(new SettingsPage);
con's avatar
con committed
272

273
    addAutoReleasedObject(new SubversionSubmitEditorFactory(&submitParameters));
con's avatar
con committed
274 275 276

    static const char *describeSlot = SLOT(describe(QString,QString));
    const int editorCount = sizeof(editorParameters)/sizeof(VCSBase::VCSBaseEditorParameters);
277 278
    for (int i = 0; i < editorCount; i++)
        addAutoReleasedObject(new SubversionEditorFactory(editorParameters + i, this, describeSlot));
con's avatar
con committed
279

280 281
    addAutoReleasedObject(new CheckoutWizard);

Friedemann Kleint's avatar
Friedemann Kleint committed
282 283 284 285 286
    const QString description = QLatin1String("Subversion");
    const QString prefix = QLatin1String("svn");
    m_commandLocator = new Locator::CommandLocator(description, prefix, prefix);
    addAutoReleasedObject(m_commandLocator);

con's avatar
con committed
287
    //register actions
hjk's avatar
hjk committed
288
    Core::ActionManager *ami = core->actionManager();
289
    Core::ActionContainer *toolsContainer = ami->actionContainer(M_TOOLS);
con's avatar
con committed
290

291
    Core::ActionContainer *subversionMenu =
292
        ami->createMenu(QLatin1String(CMD_ID_SUBVERSION_MENU));
con's avatar
con committed
293 294
    subversionMenu->menu()->setTitle(tr("&Subversion"));
    toolsContainer->addMenu(subversionMenu);
295
    m_menuAction = subversionMenu->menu()->menuAction();
con's avatar
con committed
296
    QList<int> globalcontext;
hjk's avatar
hjk committed
297
    globalcontext << core->uniqueIDManager()->uniqueIdentifier(C_GLOBAL);
con's avatar
con committed
298

con's avatar
con committed
299
    Core::Command *command;
300 301 302 303

    m_diffCurrentAction = new Utils::ParameterAction(tr("Diff Current File"), tr("Diff \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_diffCurrentAction,
        CMD_ID_DIFF_CURRENT, globalcontext);
con's avatar
con committed
304
    command->setAttribute(Core::Command::CA_UpdateText);
305 306
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+D")));
    connect(m_diffCurrentAction, SIGNAL(triggered()), this, SLOT(diffCurrentFile()));
con's avatar
con committed
307
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
308
    m_commandLocator->appendCommand(command);
con's avatar
con committed
309

310 311 312
    m_filelogCurrentAction = new Utils::ParameterAction(tr("Filelog Current File"), tr("Filelog \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_filelogCurrentAction,
        CMD_ID_FILELOG_CURRENT, globalcontext);
con's avatar
con committed
313
    command->setAttribute(Core::Command::CA_UpdateText);
314 315
    connect(m_filelogCurrentAction, SIGNAL(triggered()), this,
        SLOT(filelogCurrentFile()));
con's avatar
con committed
316
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
317
    m_commandLocator->appendCommand(command);
con's avatar
con committed
318

319 320 321
    m_annotateCurrentAction = new Utils::ParameterAction(tr("Annotate Current File"), tr("Annotate \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_annotateCurrentAction,
        CMD_ID_ANNOTATE_CURRENT, globalcontext);
con's avatar
con committed
322
    command->setAttribute(Core::Command::CA_UpdateText);
323 324
    connect(m_annotateCurrentAction, SIGNAL(triggered()), this,
        SLOT(annotateCurrentFile()));
con's avatar
con committed
325
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
326
    m_commandLocator->appendCommand(command);
con's avatar
con committed
327

328
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR0, globalcontext));
con's avatar
con committed
329

330 331
    m_addAction = new Utils::ParameterAction(tr("Add"), tr("Add \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_addAction, CMD_ID_ADD,
con's avatar
con committed
332
        globalcontext);
333
    command->setAttribute(Core::Command::CA_UpdateText);
334 335
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+A")));
    connect(m_addAction, SIGNAL(triggered()), this, SLOT(addCurrentFile()));
con's avatar
con committed
336
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
337
    m_commandLocator->appendCommand(command);
con's avatar
con committed
338

339
    m_commitCurrentAction = new Utils::ParameterAction(tr("Commit Current File"), tr("Commit \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
con's avatar
con committed
340
    command = ami->registerAction(m_commitCurrentAction,
341
        CMD_ID_COMMIT_CURRENT, globalcontext);
con's avatar
con committed
342
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
343 344 345
    command->setDefaultKeySequence(QKeySequence(tr("Alt+S,Alt+C")));
    connect(m_commitCurrentAction, SIGNAL(triggered()), this, SLOT(startCommitCurrentFile()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
346
    m_commandLocator->appendCommand(command);
con's avatar
con committed
347

348 349 350
    m_deleteAction = new Utils::ParameterAction(tr("Delete..."), tr("Delete \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_deleteAction, CMD_ID_DELETE_FILE,
        globalcontext);
con's avatar
con committed
351
    command->setAttribute(Core::Command::CA_UpdateText);
352
    connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(promptToDeleteCurrentFile()));
con's avatar
con committed
353
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
354
    m_commandLocator->appendCommand(command);
con's avatar
con committed
355

356 357 358
    m_revertAction = new Utils::ParameterAction(tr("Revert..."), tr("Revert \"%1\"..."), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_revertAction, CMD_ID_REVERT,
        globalcontext);
con's avatar
con committed
359
    command->setAttribute(Core::Command::CA_UpdateText);
360
    connect(m_revertAction, SIGNAL(triggered()), this, SLOT(revertCurrentFile()));
con's avatar
con committed
361
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
362
    m_commandLocator->appendCommand(command);
con's avatar
con committed
363

364
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR1, globalcontext));
365

366 367 368 369 370 371
    m_diffProjectAction = new Utils::ParameterAction(tr("Diff Project"), tr("Diff Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_diffProjectAction, CMD_ID_DIFF_PROJECT,
        globalcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
    connect(m_diffProjectAction, SIGNAL(triggered()), this, SLOT(diffProject()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
372
    m_commandLocator->appendCommand(command);
con's avatar
con committed
373

374 375
    m_statusProjectAction = new Utils::ParameterAction(tr("Project Status"), tr("Status of Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
    command = ami->registerAction(m_statusProjectAction, CMD_ID_STATUS,
con's avatar
con committed
376
        globalcontext);
377 378
    command->setAttribute(Core::Command::CA_UpdateText);
    connect(m_statusProjectAction, SIGNAL(triggered()), this, SLOT(projectStatus()));
con's avatar
con committed
379
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
380
    m_commandLocator->appendCommand(command);
con's avatar
con committed
381

Friedemann Kleint's avatar
Friedemann Kleint committed
382
    m_logProjectAction = new Utils::ParameterAction(tr("Log Project"), tr("Log Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
383 384 385 386
    command = ami->registerAction(m_logProjectAction, CMD_ID_PROJECTLOG, globalcontext);
    command->setAttribute(Core::Command::CA_UpdateText);
    connect(m_logProjectAction, SIGNAL(triggered()), this, SLOT(logProject()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
387
    m_commandLocator->appendCommand(command);
388

389
    m_updateProjectAction = new Utils::ParameterAction(tr("Update Project"), tr("Update Project \"%1\""), Utils::ParameterAction::EnabledWithParameter, this);
390
    command = ami->registerAction(m_updateProjectAction, CMD_ID_UPDATE, globalcontext);
con's avatar
con committed
391
    connect(m_updateProjectAction, SIGNAL(triggered()), this, SLOT(updateProject()));
392
    command->setAttribute(Core::Command::CA_UpdateText);
con's avatar
con committed
393
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
394
    m_commandLocator->appendCommand(command);
con's avatar
con committed
395

396 397
    subversionMenu->addAction(createSeparator(this, ami, CMD_ID_SEPARATOR2, globalcontext));

398 399 400 401
    m_logRepositoryAction = new QAction(tr("Repository Log"), this);
    command = ami->registerAction(m_logRepositoryAction, CMD_ID_REPOSITORYLOG, globalcontext);
    connect(m_logRepositoryAction, SIGNAL(triggered()), this, SLOT(logRepository()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
402
    m_commandLocator->appendCommand(command);
403

404 405 406 407 408 409 410 411 412 413
    m_describeAction = new QAction(tr("Describe..."), this);
    command = ami->registerAction(m_describeAction, CMD_ID_DESCRIBE, globalcontext);
    connect(m_describeAction, SIGNAL(triggered()), this, SLOT(slotDescribe()));
    subversionMenu->addAction(command);

    m_commitAllAction = new QAction(tr("Commit All Files"), this);
    command = ami->registerAction(m_commitAllAction, CMD_ID_COMMIT_ALL,
        globalcontext);
    connect(m_commitAllAction, SIGNAL(triggered()), this, SLOT(startCommitAll()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
414
    m_commandLocator->appendCommand(command);
415 416 417 418 419 420

    m_revertRepositoryAction = new QAction(tr("Revert Repository..."), this);
    command = ami->registerAction(m_revertRepositoryAction, CMD_ID_REVERT_ALL,
        globalcontext);
    connect(m_revertRepositoryAction, SIGNAL(triggered()), this, SLOT(revertAll()));
    subversionMenu->addAction(command);
Friedemann Kleint's avatar
Friedemann Kleint committed
421
    m_commandLocator->appendCommand(command);
422

con's avatar
con committed
423 424
    // Actions of the submit editor
    QList<int> svncommitcontext;
425
    svncommitcontext << Core::UniqueIDManager::instance()->uniqueIdentifier(Constants::SUBVERSIONCOMMITEDITOR);
con's avatar
con committed
426

427
    m_submitCurrentLogAction = new QAction(VCSBase::VCSBaseSubmitEditor::submitIcon(), tr("Commit"), this);
con's avatar
con committed
428 429 430
    command = ami->registerAction(m_submitCurrentLogAction, Constants::SUBMIT_CURRENT, svncommitcontext);
    connect(m_submitCurrentLogAction, SIGNAL(triggered()), this, SLOT(submitCurrentLog()));

431
    m_submitDiffAction = new QAction(VCSBase::VCSBaseSubmitEditor::diffIcon(), tr("Diff Selected Files"), this);
con's avatar
con committed
432 433 434 435 436 437 438 439 440 441 442
    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);

    return true;
}

443
bool SubversionPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor)
con's avatar
con committed
444
{
445
    if (!isCommitEditorOpen())
con's avatar
con committed
446 447
        return true;

448 449
    Core::IFile *fileIFace = submitEditor->file();
    const SubversionSubmitEditor *editor = qobject_cast<SubversionSubmitEditor *>(submitEditor);
con's avatar
con committed
450 451 452 453 454 455
    if (!fileIFace || !editor)
        return true;

    // Submit editor closing. Make it write out the commit message
    // and retrieve files
    const QFileInfo editorFile(fileIFace->fileName());
456
    const QFileInfo changeFile(m_commitMessageFileName);
con's avatar
con committed
457 458 459
    if (editorFile.absoluteFilePath() != changeFile.absoluteFilePath())
        return true; // Oops?!

460 461
    // Prompt user. Force a prompt unless submit was actually invoked (that
    // is, the editor was closed or shutdown).
462
    SubversionSettings newSettings = m_settings;
463 464 465
    const VCSBase::VCSBaseSubmitEditor::PromptSubmitResult answer =
            editor->promptSubmit(tr("Closing Subversion Editor"),
                                 tr("Do you want to commit the change?"),
466
                                 tr("The commit message check failed. Do you want to commit the change?"),
467
                                 &newSettings.promptToSubmit, !m_submitActionTriggered);
468
    m_submitActionTriggered = false;
con's avatar
con committed
469
    switch (answer) {
470
    case VCSBase::VCSBaseSubmitEditor::SubmitCanceled:
con's avatar
con committed
471
        return false; // Keep editing and change file
472
    case VCSBase::VCSBaseSubmitEditor::SubmitDiscarded:
473
        cleanCommitMessageFile();
con's avatar
con committed
474 475 476 477
        return true; // Cancel all
    default:
        break;
    }
478
    setSettings(newSettings); // in case someone turned prompting off
con's avatar
con committed
479
    const QStringList fileList = editor->checkedFiles();
480
    bool closeEditor = true;
con's avatar
con committed
481 482
    if (!fileList.empty()) {
        // get message & commit
hjk's avatar
hjk committed
483
        Core::ICore::instance()->fileManager()->blockFileChange(fileIFace);
con's avatar
con committed
484
        fileIFace->save();
hjk's avatar
hjk committed
485
        Core::ICore::instance()->fileManager()->unblockFileChange(fileIFace);
486
        closeEditor= commit(m_commitMessageFileName, fileList);
con's avatar
con committed
487
    }
488
    if (closeEditor)
489
        cleanCommitMessageFile();
490
    return closeEditor;
con's avatar
con committed
491 492
}

493
void SubversionPlugin::diffCommitFiles(const QStringList &files)
con's avatar
con committed
494
{
495
    svnDiff(m_commitRepository, files);
con's avatar
con committed
496 497
}

498 499 500 501 502 503
static inline void setDiffBaseDirectory(Core::IEditor *editor, const QString &db)
{
    if (VCSBase::VCSBaseEditor *ve = qobject_cast<VCSBase::VCSBaseEditor*>(editor->widget()))
        ve->setDiffBaseDirectory(db);
}

504
void SubversionPlugin::svnDiff(const QString &workingDir, const QStringList &files, QString diffname)
con's avatar
con committed
505 506 507
{
    if (Subversion::Constants::debug)
        qDebug() << Q_FUNC_INFO << files << diffname;
508
    const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, files);
509
    QTextCodec *codec = source.isEmpty() ? static_cast<QTextCodec *>(0) : VCSBase::VCSBaseEditor::getCodec(source);
con's avatar
con committed
510 511 512 513 514 515 516

    if (files.count() == 1 && diffname.isEmpty())
        diffname = QFileInfo(files.front()).fileName();

    QStringList args(QLatin1String("diff"));
    args << files;

517
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
518 519 520 521 522 523 524
    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
hjk's avatar
hjk committed
525
        if (Core::IEditor *editor = locateEditor("originalFileName", files.front())) {
con's avatar
con committed
526
            editor->createNew(response.stdOut);
527
            Core::EditorManager::instance()->activateEditor(editor);
528
            setDiffBaseDirectory(editor, workingDir);
con's avatar
con committed
529 530 531
            return;
        }
    }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
532
    const QString title = QString::fromLatin1("svn diff %1").arg(diffname);
con's avatar
con committed
533
    Core::IEditor *editor = showOutputInEditor(title, response.stdOut, VCSBase::DiffOutput, source, codec);
534
    setDiffBaseDirectory(editor, workingDir);
con's avatar
con committed
535 536 537 538 539 540
    if (files.count() == 1)
        editor->setProperty("originalFileName", files.front());
}

SubversionSubmitEditor *SubversionPlugin::openSubversionSubmitEditor(const QString &fileName)
{
541
    Core::IEditor *editor = Core::EditorManager::instance()->openEditor(fileName, QLatin1String(Constants::SUBVERSIONCOMMITEDITOR_ID));
con's avatar
con committed
542
    SubversionSubmitEditor *submitEditor = qobject_cast<SubversionSubmitEditor*>(editor);
hjk's avatar
hjk committed
543
    QTC_ASSERT(submitEditor, /**/);
544
    submitEditor->registerActions(m_submitUndoAction, m_submitRedoAction, m_submitCurrentLogAction, m_submitDiffAction);
545
    connect(submitEditor, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(diffCommitFiles(QStringList)));
546
    submitEditor->setCheckScriptWorkingDirectory(m_commitRepository);
con's avatar
con committed
547 548 549
    return submitEditor;
}

550
void SubversionPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
con's avatar
con committed
551
{
Friedemann Kleint's avatar
Friedemann Kleint committed
552 553
    if (!enableMenuAction(as, m_menuAction)) {
        m_commandLocator->setEnabled(false);
554
        return;
Friedemann Kleint's avatar
Friedemann Kleint committed
555 556 557 558
    }
    const bool hasTopLevel = currentState().hasTopLevel();
    m_commandLocator->setEnabled(hasTopLevel);
    m_logRepositoryAction->setEnabled(hasTopLevel);
559

560 561 562 563
    const QString projectName = currentState().currentProjectName();
    m_diffProjectAction->setParameter(projectName);
    m_statusProjectAction->setParameter(projectName);
    m_updateProjectAction->setParameter(projectName);
564
    m_logProjectAction->setParameter(projectName);
565 566 567 568

    const bool repoEnabled = currentState().hasTopLevel();
    m_commitAllAction->setEnabled(repoEnabled);
    m_describeAction->setEnabled(repoEnabled);
569
    m_revertRepositoryAction->setEnabled(repoEnabled);
570 571 572 573 574 575 576 577 578 579

    const QString fileName = currentState().currentFileName();

    m_addAction->setParameter(fileName);
    m_deleteAction->setParameter(fileName);
    m_revertAction->setParameter(fileName);
    m_diffCurrentAction->setParameter(fileName);
    m_commitCurrentAction->setParameter(fileName);
    m_filelogCurrentAction->setParameter(fileName);
    m_annotateCurrentAction->setParameter(fileName);
con's avatar
con committed
580 581 582 583
}

void SubversionPlugin::addCurrentFile()
{
584 585 586
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
587 588
}

589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
void SubversionPlugin::revertAll()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    const QString title = tr("Revert repository");
    if (QMessageBox::warning(0, title, tr("Would you like to revert all changes to the repository?"),
                             QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
        return;
    // NoteL: Svn "revert ." doesn not work.
    QStringList args;
    args << QLatin1String("revert") << QLatin1String("--recursive") << state.topLevel();
    const SubversionResponse revertResponse = runSvn(state.topLevel(), args, m_settings.timeOutMS(), true);
    if (revertResponse.error) {
        QMessageBox::warning(0, title, tr("Revert failed: %1").arg(revertResponse.message), QMessageBox::Ok);
    } else {
        subVersionControl()->emitRepositoryChanged(state.topLevel());
    }
}

con's avatar
con committed
608 609
void SubversionPlugin::revertCurrentFile()
{
610 611
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
con's avatar
con committed
612 613

    QStringList args(QLatin1String("diff"));
614
    args.push_back(state.relativeCurrentFile());
con's avatar
con committed
615

616
    const SubversionResponse diffResponse = runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(), false);
con's avatar
con committed
617 618 619 620 621
    if (diffResponse.error)
        return;

    if (diffResponse.stdOut.isEmpty())
        return;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
622
    if (QMessageBox::warning(0, QLatin1String("svn revert"), tr("The file has been changed. Do you want to revert it?"),
con's avatar
con committed
623 624 625
                             QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
        return;

626

627
    Core::FileChangeBlocker fcb(state.currentFile());
con's avatar
con committed
628 629 630

    // revert
    args.clear();
631
    args << QLatin1String("revert") << state.relativeCurrentFile();
con's avatar
con committed
632

633
    const SubversionResponse revertResponse = runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(), true);
634
    if (!revertResponse.error) {
635
        subVersionControl()->emitFilesChanged(QStringList(state.currentFile()));
con's avatar
con committed
636 637 638 639 640
    }
}

void SubversionPlugin::diffProject()
{
641 642 643
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    svnDiff(state.currentProjectTopLevel(), state.relativeCurrentProject(), state.currentProjectName());
con's avatar
con committed
644 645 646 647
}

void SubversionPlugin::diffCurrentFile()
{
648 649 650
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    svnDiff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
con's avatar
con committed
651 652 653 654
}

void SubversionPlugin::startCommitCurrentFile()
{
655 656 657
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
    startCommit(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
con's avatar
con committed
658 659 660 661
}

void SubversionPlugin::startCommitAll()
{
662 663 664
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return);
    startCommit(state.topLevel());
con's avatar
con committed
665 666 667 668 669
}

/* Start commit of files of a single repository by displaying
 * template and files in a submit editor. On closing, the real
 * commit will start. */
670
void SubversionPlugin::startCommit(const QString &workingDir, const QStringList &files)
con's avatar
con committed
671
{
672 673
    if (VCSBase::VCSBaseSubmitEditor::raiseSubmitEditor())
        return;
674
    if (isCommitEditorOpen()) {
675
        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("Another commit is currently being executed."));
con's avatar
con committed
676 677 678 679 680 681
        return;
    }

    QStringList args(QLatin1String("status"));
    args += files;

682
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false);
con's avatar
con committed
683 684
    if (response.error)
        return;
685

con's avatar
con committed
686
    // Get list of added/modified/deleted files
687
    const StatusList statusOutput = parseStatusOutput(response.stdOut);
con's avatar
con committed
688
    if (statusOutput.empty()) {
689
        VCSBase::VCSBaseOutputWindow::instance()->appendWarning(tr("There are no modified files."));
con's avatar
con committed
690 691
        return;
    }
692
    m_commitRepository = workingDir;
con's avatar
con committed
693
    // Create a new submit change file containing the submit template
694 695 696 697
    QTemporaryFile changeTmpFile;
    changeTmpFile.setAutoRemove(false);
    if (!changeTmpFile.open()) {
        VCSBase::VCSBaseOutputWindow::instance()->appendError(tr("Cannot create temporary file: %1").arg(changeTmpFile.errorString()));
con's avatar
con committed
698 699
        return;
    }
700
    m_commitMessageFileName = changeTmpFile.fileName();
701
    // TODO: Regitctrieve submit template from
con's avatar
con committed
702 703
    const QString submitTemplate;
    // Create a submit
704 705 706
    changeTmpFile.write(submitTemplate.toUtf8());
    changeTmpFile.flush();
    changeTmpFile.close();
con's avatar
con committed
707
    // Create a submit editor and set file list
708
    SubversionSubmitEditor *editor = openSubversionSubmitEditor(m_commitMessageFileName);
709
    editor->setStatusList(statusOutput);
con's avatar
con committed
710 711 712 713 714 715 716 717 718 719 720
}

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"));
721
    args << QLatin1String(nonInteractiveOptionC) << QLatin1String("--file") << messageFile;
con's avatar
con committed
722
    args.append(subVersionFileList);
723
    const SubversionResponse response = runSvn(m_commitRepository, args, m_settings.longTimeOutMS(), true);
con's avatar
con committed
724 725 726 727 728
    return !response.error ;
}

void SubversionPlugin::filelogCurrentFile()
{
729 730
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return)
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
   filelog(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()), true);
}

void SubversionPlugin::logProject()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return)
    filelog(state.currentProjectTopLevel(), state.relativeCurrentProject());
}

void SubversionPlugin::logRepository()
{
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return)
    filelog(state.topLevel());
con's avatar
con committed
746 747
}

748 749 750
void SubversionPlugin::filelog(const QString &workingDir,
                               const QStringList &files,
                               bool enableAnnotationContextMenu)
con's avatar
con committed
751
{
752
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(workingDir, files);
con's avatar
con committed
753 754
    // no need for temp file
    QStringList args(QLatin1String("log"));
755 756
    if (m_settings.logCount > 0)
        args << QLatin1String("-l") << QString::number(m_settings.logCount);
757 758
    foreach(const QString &file, files)
        args.append(QDir::toNativeSeparators(file));
con's avatar
con committed
759

760
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
761 762 763 764 765 766
    if (response.error)
        return;

    // Re-use an existing view if possible to support
    // the common usage pattern of continuously changing and diffing a file

767 768
    const QString id = VCSBase::VCSBaseEditor::getTitleId(workingDir, files);
    if (Core::IEditor *editor = locateEditor("logFileName", id)) {
con's avatar
con committed
769
        editor->createNew(response.stdOut);
770
        Core::EditorManager::instance()->activateEditor(editor);
con's avatar
con committed
771
    } else {
772 773 774 775
        const QString title = QString::fromLatin1("svn log %1").arg(id);
        const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, files);
        Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::LogOutput, source, codec);
        newEditor->setProperty("logFileName", id);
776 777
        if (enableAnnotationContextMenu)
            VCSBase::VCSBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true);
con's avatar
con committed
778 779 780 781 782
    }
}

void SubversionPlugin::updateProject()
{
783 784
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return);
con's avatar
con committed
785 786

    QStringList args(QLatin1String("update"));
787
    args.push_back(QLatin1String(nonInteractiveOptionC));
788
    args.append(state.relativeCurrentProject());
789
    const SubversionResponse response = runSvn(state.currentProjectTopLevel(), args, m_settings.longTimeOutMS(), true);
790 791
    if (!response.error)
        subVersionControl()->emitRepositoryChanged(state.currentProjectTopLevel());
con's avatar
con committed
792 793 794 795
}

void SubversionPlugin::annotateCurrentFile()
{
796 797
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasFile(), return);
798
    vcsAnnotate(state.currentFileTopLevel(), state.relativeCurrentFile());
con's avatar
con committed
799 800
}

801 802 803 804 805
void SubversionPlugin::annotateVersion(const QString &file,
                                       const QString &revision,
                                       int lineNr)
{
    const QFileInfo fi(file);
806
    vcsAnnotate(fi.absolutePath(), fi.fileName(), revision, lineNr);
807 808
}

809
void SubversionPlugin::vcsAnnotate(const QString &workingDir, const QString &file,
810 811
                                const QString &revision /* = QString() */,
                                int lineNumber /* = -1 */)
con's avatar
con committed
812
{
813
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(file);
con's avatar
con committed
814 815

    QStringList args(QLatin1String("annotate"));
816 817
    if (m_settings.spaceIgnorantAnnotation)
        args << QLatin1String("-x") << QLatin1String("-uw");
818 819
    if (!revision.isEmpty())
        args << QLatin1String("-r") << revision;
con's avatar
con committed
820 821 822
    args.push_back(QLatin1String("-v"));
    args.append(QDir::toNativeSeparators(file));

823
    const SubversionResponse response = runSvn(workingDir, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
824 825 826 827 828
    if (response.error)
        return;

    // Re-use an existing view if possible to support
    // the common usage pattern of continuously changing and diffing a file
829
    const QString source = workingDir + QLatin1Char('/') + file;
830 831 832 833
    if (lineNumber <= 0)
        lineNumber = VCSBase::VCSBaseEditor::lineNumberOfCurrentEditor(source);
    // Determine id
    const QString id = VCSBase::VCSBaseEditor::getTitleId(workingDir, QStringList(file), revision);
con's avatar
con committed
834

835
    if (Core::IEditor *editor = locateEditor("annotateFileName", id)) {
con's avatar
con committed
836
        editor->createNew(response.stdOut);
837
        VCSBase::VCSBaseEditor::gotoLineOfEditor(editor, lineNumber);
838
        Core::EditorManager::instance()->activateEditor(editor);
con's avatar
con committed
839
    } else {
840 841 842
        const QString title = QString::fromLatin1("svn annotate %1").arg(id);
        Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::AnnotateOutput, source, codec);
        newEditor->setProperty("annotateFileName", id);
843
        VCSBase::VCSBaseEditor::gotoLineOfEditor(newEditor, lineNumber);
con's avatar
con committed
844 845 846 847 848
    }
}

void SubversionPlugin::projectStatus()
{
849 850
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasProject(), return);
con's avatar
con committed
851
    QStringList args(QLatin1String("status"));
852
    args += state.relativeCurrentProject();
853 854
    VCSBase::VCSBaseOutputWindow *outwin = VCSBase::VCSBaseOutputWindow::instance();
    outwin->setRepository(state.currentProjectTopLevel());
855
    runSvn(state.currentProjectTopLevel(), args, m_settings.timeOutMS(), true);
856
    outwin->clearRepository();
con's avatar
con committed
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
}

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;
874 875 876 877 878
    // Run log to obtain message (local utf8)
    QString description;
    QStringList args(QLatin1String("log"));
    args.push_back(QLatin1String("-r"));
    args.push_back(changeNr);
879
    const SubversionResponse logResponse = runSvn(topLevel, args, m_settings.timeOutMS(), false);
880 881 882 883 884 885 886
    if (logResponse.error)
        return;
    description = logResponse.stdOut;

    // Run diff (encoding via source codec)
    args.clear();
    args.push_back(QLatin1String("diff"));
con's avatar
con committed
887 888 889 890 891
    args.push_back(QLatin1String("-r"));
    QString diffArg;
    QTextStream(&diffArg) << (number - 1) << ':' << number;
    args.push_back(diffArg);

892
    QTextCodec *codec = VCSBase::VCSBaseEditor::getCodec(source);
893
    const SubversionResponse response = runSvn(topLevel, args, m_settings.timeOutMS(), false, codec);
con's avatar
con committed
894 895
    if (response.error)
        return;
896
    description += response.stdOut;
con's avatar
con committed
897 898 899 900

    // 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;
hjk's avatar
hjk committed
901
    if (Core::IEditor *editor = locateEditor("describeChange", id)) {
902
        editor->createNew(description);
hjk's avatar
hjk committed
903
        Core::EditorManager::instance()->activateEditor(editor);
con's avatar
con committed
904
    } else {
905
        const QString title = QString::fromLatin1("svn describe %1#%2").arg(fi.fileName(), changeNr);
906
        Core::IEditor *newEditor = showOutputInEditor(title, description, VCSBase::DiffOutput, source, codec);
con's avatar
con committed
907 908 909 910
        newEditor->setProperty("describeChange", id);
    }
}

911 912
void SubversionPlugin::slotDescribe()
{
913 914
    const VCSBase::VCSBasePluginState state = currentState();
    QTC_ASSERT(state.hasTopLevel(), return);
915 916 917 918 919 920 921 922 923 924 925

    QInputDialog inputDialog(Core::ICore::instance()->mainWindow());
    inputDialog.setWindowFlags(inputDialog.windowFlags() & ~Qt::WindowContextHelpButtonHint);
    inputDialog.setInputMode(QInputDialog::IntInput);
    inputDialog.setIntRange(2, INT_MAX);
    inputDialog.setWindowTitle(tr("Describe"));
    inputDialog.setLabelText(tr("Revision number:"));
    if (inputDialog.exec() != QDialog::Accepted)
        return;

    const int revision = inputDialog.intValue();
926
    describe(state.topLevel(), QString::number(revision));
927 928
}

con's avatar
con committed
929 930
void SubversionPlugin::submitCurrentLog()
{
931
    m_submitActionTriggered = true;
Thorbjørn Lindeijer's avatar