vcsbasesubmiteditor.cpp 19.8 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
7
8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
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
26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "vcsbasesubmiteditor.h"
31
32
33
#include "vcsbasesettings.h"
#include "vcsbaseplugin.h"
#include "nicknamedialog.h"
con's avatar
con committed
34
35
#include "submiteditorfile.h"

36
#include <aggregation/aggregate.h>
con's avatar
con committed
37
#include <coreplugin/ifile.h>
38
#include <coreplugin/icore.h>
39
#include <coreplugin/editormanager/editormanager.h>
con's avatar
con committed
40
#include <coreplugin/uniqueidmanager.h>
41
#include <coreplugin/actionmanager/actionmanager.h>
con's avatar
con committed
42
#include <utils/submiteditorwidget.h>
43
#include <utils/submitfieldwidget.h>
con's avatar
con committed
44
#include <find/basetextfind.h>
45
46
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
con's avatar
con committed
47

48
49
50
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>

51
#include <QtCore/QDebug>
52
#include <QtCore/QDir>
53
54
#include <QtCore/QTemporaryFile>
#include <QtCore/QProcess>
55
56
57
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QPointer>
con's avatar
con committed
58
#include <QtCore/QTextStream>
59
60
#include <QtGui/QStyle>
#include <QtGui/QToolBar>
61
62
63
64
65
66
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QMessageBox>
#include <QtGui/QMainWindow>
#include <QtGui/QCompleter>
#include <QtGui/QLineEdit>
con's avatar
con committed
67
68

enum { debug = 0 };
69
enum { wantToolBar = 0 };
con's avatar
con committed
70
71
72

namespace VCSBase {

73
74
75
76
77
static inline QString submitMessageCheckScript()
{
    return Internal::VCSBasePlugin::instance()->settings().submitMessageCheckScript;
}

78
79
struct VCSBaseSubmitEditorPrivate
{
con's avatar
con committed
80
81
82
83
84
85
86
87
88
89
90
91
    VCSBaseSubmitEditorPrivate(const VCSBaseSubmitEditorParameters *parameters,
                               Core::Utils::SubmitEditorWidget *editorWidget,
                               QObject *q);

    Core::Utils::SubmitEditorWidget *m_widget;
    QToolBar *m_toolWidget;
    const VCSBaseSubmitEditorParameters *m_parameters;
    QString m_displayName;
    VCSBase::Internal::SubmitEditorFile *m_file;
    QList<int> m_contexts;

    QPointer<QAction> m_diffAction;
92
    QPointer<QAction> m_submitAction;
93
94

    Internal::NickNameDialog *m_nickNameDialog;
con's avatar
con committed
95
96
97
98
99
100
101
102
};

VCSBaseSubmitEditorPrivate::VCSBaseSubmitEditorPrivate(const VCSBaseSubmitEditorParameters *parameters,
                                                       Core::Utils::SubmitEditorWidget *editorWidget,
                                                       QObject *q) :
    m_widget(editorWidget),
    m_toolWidget(0),
    m_parameters(parameters),
103
104
    m_file(new VCSBase::Internal::SubmitEditorFile(QLatin1String(m_parameters->mimeType), q)),
    m_nickNameDialog(0)
con's avatar
con committed
105
{
106
    m_contexts << Core::UniqueIDManager::instance()->uniqueIdentifier(m_parameters->context);
con's avatar
con committed
107
108
109
110
111
112
}

VCSBaseSubmitEditor::VCSBaseSubmitEditor(const VCSBaseSubmitEditorParameters *parameters,
                                         Core::Utils::SubmitEditorWidget *editorWidget) :
    m_d(new VCSBaseSubmitEditorPrivate(parameters, editorWidget, this))
{
113
    // Message font according to settings
114
115
116
    const TextEditor::FontSettings fs = TextEditor::TextEditorSettings::instance()->fontSettings();
    QFont font = editorWidget->descriptionEdit()->font();
    font.setFamily(fs.family());
117
    font.setPointSize(fs.fontSize());
118
119
    editorWidget->descriptionEdit()->setFont(font);

con's avatar
con committed
120
121
122
123
124
125
126
    m_d->m_file->setModified(false);
    // We are always clean to prevent the editor manager from asking to save.
    connect(m_d->m_file, SIGNAL(saveMe(QString)), this, SLOT(save(QString)));

    connect(m_d->m_widget, SIGNAL(diffSelected(QStringList)), this, SLOT(slotDiffSelectedVCSFiles(QStringList)));
    connect(m_d->m_widget->descriptionEdit(), SIGNAL(textChanged()), this, SLOT(slotDescriptionChanged()));

127
128
    const Internal::VCSBaseSettings settings = Internal::VCSBasePlugin::instance()->settings();
    // Add additional context menu settings
129
    if (!settings.submitMessageCheckScript.isEmpty() || !settings.nickNameMailMap.isEmpty()) {
130
131
132
133
134
135
136
137
138
139
        QAction *sep = new QAction(this);
        sep->setSeparator(true);
        m_d->m_widget->addDescriptionEditContextMenuAction(sep);
        // Run check action
        if (!settings.submitMessageCheckScript.isEmpty()) {
            QAction *checkAction = new QAction(tr("Check message"), this);
            connect(checkAction, SIGNAL(triggered()), this, SLOT(slotCheckSubmitMessage()));
            m_d->m_widget->addDescriptionEditContextMenuAction(checkAction);
        }
        // Insert nick
140
        if (!settings.nickNameMailMap.isEmpty()) {
141
142
143
144
145
146
147
148
            QAction *insertAction = new QAction(tr("Insert name..."), this);
            connect(insertAction, SIGNAL(triggered()), this, SLOT(slotInsertNickName()));
            m_d->m_widget->addDescriptionEditContextMenuAction(insertAction);
        }
    }
    // Do we have user fields?
    if (!settings.nickNameFieldListFile.isEmpty())
        createUserFields(settings.nickNameFieldListFile);
149
150
151
152
153
154
155

    // wrapping. etc
    slotUpdateEditorSettings(settings);
    connect(Internal::VCSBasePlugin::instance(),
            SIGNAL(settingsChanged(VCSBase::Internal::VCSBaseSettings)),
            this, SLOT(slotUpdateEditorSettings(VCSBase::Internal::VCSBaseSettings)));

con's avatar
con committed
156
157
158
159
160
161
162
163
164
165
166
167
    Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
    aggregate->add(new Find::BaseTextFind(m_d->m_widget->descriptionEdit()));
    aggregate->add(this);
}

VCSBaseSubmitEditor::~VCSBaseSubmitEditor()
{
    delete m_d->m_toolWidget;
    delete m_d->m_widget;
    delete m_d;
}

168
169
170
171
172
173
void VCSBaseSubmitEditor::slotUpdateEditorSettings(const Internal::VCSBaseSettings &s)
{
    setLineWrapWidth(s.lineWrapWidth);
    setLineWrap(s.lineWrap);
}

174
175
176
177
178
179
180
181
182
183
184
185
186
// Return a trimmed list of non-empty field texts
static inline QStringList fieldTexts(const QString &fileContents)
{
    QStringList rc;
    const QStringList rawFields = fileContents.trimmed().split(QLatin1Char('\n'));
    foreach(const QString &field, rawFields) {
        const QString trimmedField = field.trimmed();
        if (!trimmedField.isEmpty())
            rc.push_back(trimmedField);
    }
    return rc;
}

187
188
189
190
191
192
193
194
void VCSBaseSubmitEditor::createUserFields(const QString &fieldConfigFile)
{
    QFile fieldFile(fieldConfigFile);
    if (!fieldFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
        qWarning("%s: Unable to open %s: %s", Q_FUNC_INFO, qPrintable(fieldConfigFile), qPrintable(fieldFile.errorString()));
        return;
    }
    // Parse into fields
195
    const QStringList fields = fieldTexts(QString::fromUtf8(fieldFile.readAll()));
196
197
198
    if (fields.empty())
        return;
    // Create a completer on user names
199
200
    const QStandardItemModel *nickNameModel = Internal::VCSBasePlugin::instance()->nickNameModel();
    QCompleter *completer = new QCompleter(Internal::NickNameDialog::nickNameList(nickNameModel), this);
201
202
203
204
205
206
207
208
209

    Core::Utils::SubmitFieldWidget *fieldWidget = new Core::Utils::SubmitFieldWidget;
    connect(fieldWidget, SIGNAL(browseButtonClicked(int,QString)),
            this, SLOT(slotSetFieldNickName(int)));    
    fieldWidget->setCompleter(completer);
    fieldWidget->setAllowDuplicateFields(true);
    fieldWidget->setHasBrowseButton(true);
    fieldWidget->setFields(fields);
    m_d->m_widget->addSubmitFieldWidget(fieldWidget);
210
211
}

212
213
214
215
216
217
218
219
220
221
222
223
224
225
void VCSBaseSubmitEditor::registerActions(QAction *editorUndoAction,  QAction *editorRedoAction,
                                          QAction *submitAction, QAction *diffAction)\
{
    m_d->m_widget->registerActions(editorUndoAction, editorRedoAction, submitAction, diffAction);
    m_d->m_diffAction = diffAction;
    m_d->m_submitAction = submitAction;
}

void VCSBaseSubmitEditor::unregisterActions(QAction *editorUndoAction,  QAction *editorRedoAction,
                           QAction *submitAction, QAction *diffAction)
{
    m_d->m_widget->unregisterActions(editorUndoAction, editorRedoAction, submitAction, diffAction);
    m_d->m_diffAction = m_d->m_submitAction = 0;
}
226
227
228
229
230
231
232
233
234
235
int VCSBaseSubmitEditor::fileNameColumn() const
{
    return m_d->m_widget->fileNameColumn();
}

void VCSBaseSubmitEditor::setFileNameColumn(int c)
{
    m_d->m_widget->setFileNameColumn(c);
}

236
237
238
239
240
241
242
243
244
245
QAbstractItemView::SelectionMode VCSBaseSubmitEditor::fileListSelectionMode() const
{
    return m_d->m_widget->fileListSelectionMode();
}

void VCSBaseSubmitEditor::setFileListSelectionMode(QAbstractItemView::SelectionMode sm)
{
    m_d->m_widget->setFileListSelectionMode(sm);
}

246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
bool VCSBaseSubmitEditor::lineWrap() const
{
    return m_d->m_widget->lineWrap();
}

void VCSBaseSubmitEditor::setLineWrap(bool w)
{
    m_d->m_widget->setLineWrap(w);
}

int VCSBaseSubmitEditor::lineWrapWidth() const
{
    return m_d->m_widget->lineWrapWidth();
}

void VCSBaseSubmitEditor::setLineWrapWidth(int w)
{
    m_d->m_widget->setLineWrapWidth(w);
}

con's avatar
con committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
void VCSBaseSubmitEditor::slotDescriptionChanged()
{
}

bool VCSBaseSubmitEditor::createNew(const QString &contents)
{
    setFileContents(contents);
    return true;
}

bool VCSBaseSubmitEditor::open(const QString &fileName)
{
    if (fileName.isEmpty())
        return false;

    const QFileInfo fi(fileName);
    if (!fi.isFile() || !fi.isReadable())
        return false;

    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
        qWarning("Unable to open %s: %s", qPrintable(fileName), qPrintable(file.errorString()));
        return false;
    }

    const QString text = QString::fromLocal8Bit(file.readAll());
    if (!createNew(text))
        return false;

    m_d->m_file->setFileName(fi.absoluteFilePath());
    return true;
}

Core::IFile *VCSBaseSubmitEditor::file()
{
    return m_d->m_file;
}

QString VCSBaseSubmitEditor::displayName() const
{
    return m_d->m_displayName;
}

void VCSBaseSubmitEditor::setDisplayName(const QString &title)
{
    m_d->m_displayName = title;
}

bool VCSBaseSubmitEditor::duplicateSupported() const
{
    return false;
}

Core::IEditor *VCSBaseSubmitEditor::duplicate(QWidget * /*parent*/)
{
    return 0;
}

const char *VCSBaseSubmitEditor::kind() const
{
    return m_d->m_parameters->kind;
}

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
static QToolBar *createToolBar(const QWidget *someWidget, QAction *submitAction, QAction *diffAction)
{
    // Create
    QToolBar *toolBar = new QToolBar;
    toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    const int size = someWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
    toolBar->setIconSize(QSize(size, size));
    toolBar->addSeparator();

    if (submitAction)
        toolBar->addAction(submitAction);
    if (diffAction)
        toolBar->addAction(diffAction);
    return toolBar;
}

con's avatar
con committed
345
346
QToolBar *VCSBaseSubmitEditor::toolBar()
{
347
348
349
    if (!wantToolBar)
        return 0;

con's avatar
con committed
350
351
352
353
354
355
356
    if (m_d->m_toolWidget)
        return m_d->m_toolWidget;

    if (!m_d->m_diffAction && !m_d->m_submitAction)
        return 0;

    // Create
357
358
    m_d->m_toolWidget = createToolBar(m_d->m_widget, m_d->m_submitAction, m_d->m_diffAction);
    return m_d->m_toolWidget;
con's avatar
con committed
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
}

QList<int> VCSBaseSubmitEditor::context() const
{
    return m_d->m_contexts;
}

QWidget *VCSBaseSubmitEditor::widget()
{
    return m_d->m_widget;
}

QByteArray VCSBaseSubmitEditor::saveState() const
{
    return QByteArray();
}

bool VCSBaseSubmitEditor::restoreState(const QByteArray &/*state*/)
{
    return true;
}

381
QStringList VCSBaseSubmitEditor::checkedFiles() const
con's avatar
con committed
382
{
383
    return m_d->m_widget->checkedFiles();
con's avatar
con committed
384
385
}

386
void VCSBaseSubmitEditor::setFileModel(QAbstractItemModel *m)
con's avatar
con committed
387
{
388
    m_d->m_widget->setFileModel(m);
con's avatar
con committed
389
390
}

391
QAbstractItemModel *VCSBaseSubmitEditor::fileModel() const
con's avatar
con committed
392
{
393
    return m_d->m_widget->fileModel();
con's avatar
con committed
394
395
}

396
void VCSBaseSubmitEditor::slotDiffSelectedVCSFiles(const QStringList &rawList)
con's avatar
con committed
397
{
398
     emit diffSelectedFiles(rawList);
con's avatar
con committed
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
}

bool VCSBaseSubmitEditor::save(const QString &fileName)
{
    const QString fName = fileName.isEmpty() ? m_d->m_file->fileName() : fileName;
    QFile file(fName);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
        qWarning("Unable to open %s: %s", qPrintable(fName), qPrintable(file.errorString()));
        return false;
    }
    file.write(fileContents().toLocal8Bit());
    if (!file.flush())
        return false;
    file.close();
    const QFileInfo fi(fName);
    m_d->m_file->setFileName(fi.absoluteFilePath());
    m_d->m_file->setModified(false);
    return true;
}

QString VCSBaseSubmitEditor::fileContents() const
{
421
    return m_d->m_widget->descriptionText();
con's avatar
con committed
422
423
424
425
426
427
428
429
}

bool VCSBaseSubmitEditor::setFileContents(const QString &contents)
{
    m_d->m_widget->setDescriptionText(contents);
    return true;
}

430
431
432
enum { checkDialogMinimumWidth = 500 };

VCSBaseSubmitEditor::PromptSubmitResult
433
434
435
436
        VCSBaseSubmitEditor::promptSubmit(const QString &title,
                                          const QString &question,
                                          const QString &checkFailureQuestion,
                                          bool forcePrompt) const
437
438
439
440
{
    QString errorMessage;
    QMessageBox::StandardButton answer = QMessageBox::Yes;

441
442
    const bool prompt = forcePrompt || Internal::VCSBasePlugin::instance()->settings().promptForSubmit;

443
444
445
446
447
    QWidget *parent = Core::ICore::instance()->mainWindow();
    // Pop up a message depending on whether the check succeeded and the
    // user wants to be prompted
    if (checkSubmitMessage(&errorMessage)) {
        // Check ok, do prompt?
448
        if (prompt) {
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
            answer = QMessageBox::question(parent, title, question,
                                  QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,
                                  QMessageBox::Yes);
        }
    } else {
        // Check failed.
        QMessageBox msgBox(QMessageBox::Question, title, checkFailureQuestion,
                           QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, parent);
        msgBox.setDefaultButton(QMessageBox::Cancel);
        msgBox.setInformativeText(errorMessage);
        msgBox.setMinimumWidth(checkDialogMinimumWidth);
        answer = static_cast<QMessageBox::StandardButton>(msgBox.exec());
    }
    switch (answer) {
    case QMessageBox::Cancel:
        return SubmitCanceled;
    case QMessageBox::No:
        return SubmitDiscarded;
    default:
        break;
    }
    return SubmitConfirmed;
}

QString VCSBaseSubmitEditor::promptForNickName()
{
    if (!m_d->m_nickNameDialog)
476
        m_d->m_nickNameDialog = new Internal::NickNameDialog(Internal::VCSBasePlugin::instance()->nickNameModel(), m_d->m_widget);
477
478
479
480
481
482
483
484
485
486
487
488
489
490
    if (m_d->m_nickNameDialog->exec() == QDialog::Accepted)
       return m_d->m_nickNameDialog->nickName();
    return QString();
}

void VCSBaseSubmitEditor::slotInsertNickName()
{
    const QString nick = promptForNickName();
    if (!nick.isEmpty())
        m_d->m_widget->descriptionEdit()->textCursor().insertText(nick);
}

void VCSBaseSubmitEditor::slotSetFieldNickName(int i)
{
491
492
493
494
495
    if (Core::Utils::SubmitFieldWidget *sfw  =m_d->m_widget->submitFieldWidgets().front()) {
        const QString nick = promptForNickName();
        if (!nick.isEmpty())
            sfw->setFieldValue(i, nick);
    }
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
}

void VCSBaseSubmitEditor::slotCheckSubmitMessage()
{
    QString errorMessage;
    if (!checkSubmitMessage(&errorMessage)) {
        QMessageBox msgBox(QMessageBox::Warning, tr("Submit Message Check failed"),
                           errorMessage, QMessageBox::Ok, m_d->m_widget);
        msgBox.setMinimumWidth(checkDialogMinimumWidth);
        msgBox.exec();
    }
}

bool VCSBaseSubmitEditor::checkSubmitMessage(QString *errorMessage) const
{
    const QString checkScript = submitMessageCheckScript();
    if (checkScript.isEmpty())
        return true;
514
515
516
517
518
519
520
521
    QApplication::setOverrideCursor(Qt::WaitCursor);
    const bool rc = runSubmitMessageCheckScript(checkScript, errorMessage);
    QApplication::restoreOverrideCursor();
    return rc;
}

bool VCSBaseSubmitEditor::runSubmitMessageCheckScript(const QString &checkScript, QString *errorMessage) const
{
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
    // Write out message
    QString tempFilePattern = QDir::tempPath();
    if (!tempFilePattern.endsWith(QDir::separator()))
        tempFilePattern += QDir::separator();
    tempFilePattern += QLatin1String("msgXXXXXX.txt");
    QTemporaryFile messageFile(tempFilePattern);
    messageFile.setAutoRemove(true);
    if (!messageFile.open()) {
        *errorMessage = tr("Unable to open '%1': %2").arg(messageFile.fileName(), messageFile.errorString());
        return false;
    }
    const QString messageFileName = messageFile.fileName();
    messageFile.write(fileContents().toUtf8());
    messageFile.close();
    // Run check process
    QProcess checkProcess;
    checkProcess.start(checkScript, QStringList(messageFileName));
    if (!checkProcess.waitForStarted()) {
        *errorMessage = tr("The check script '%1' could not be started: %2").arg(checkScript, checkProcess.errorString());
        return false;
    }
    if (!checkProcess.waitForFinished()) {
        *errorMessage = tr("The check script '%1' could not be run: %2").arg(checkScript, checkProcess.errorString());
        return false;
    }    
    const int exitCode = checkProcess.exitCode();
    if (exitCode != 0) {
        *errorMessage = QString::fromLocal8Bit(checkProcess.readAllStandardError());
        if (errorMessage->isEmpty())
            *errorMessage = tr("The check script returned exit code %1.").arg(exitCode);
        return false;
    }
    return true;
}

557
558
559
560
561
562
563
564
565
566
QIcon VCSBaseSubmitEditor::diffIcon()
{
    return QIcon(QLatin1String(":/vcsbase/images/diff.png"));
}

QIcon VCSBaseSubmitEditor::submitIcon()
{
    return QIcon(QLatin1String(":/vcsbase/images/submit.png"));
}

567
568
QStringList VCSBaseSubmitEditor::currentProjectFiles(bool nativeSeparators, QString *name)
{
569
    using namespace ProjectExplorer;
570
571
    if (name)
        name->clear();
572
573
    ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
    if (!pe)
574
575
        return QStringList();
    QStringList files;
576
577
    if (const Project *currentProject = pe->currentProject()) {
        files << currentProject->files(Project::ExcludeGeneratedFiles);
578
579
580
        if (name)
            *name = currentProject->name();
    } else {
581
        if (const SessionManager *session = pe->session()) {
582
583
            if (name)
                *name = session->file()->fileName();
584
585
586
            const QList<Project *> projects = session->projects();
            foreach (Project *project, projects)
                files << project->files(Project::ExcludeGeneratedFiles);
587
588
589
590
591
592
593
594
595
        }
    }
    if (nativeSeparators && !files.empty()) {
        const QStringList::iterator end = files.end();
        for (QStringList::iterator it = files.begin(); it != end; ++it)
            *it = QDir::toNativeSeparators(*it);
    }
    return files;
}
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

// Helper to raise an already open submit editor to prevent opening twice.
bool VCSBaseSubmitEditor::raiseSubmitEditor()
{
    Core::EditorManager *em = Core::EditorManager::instance();
    // Nothing to do?
    if (Core::IEditor *ce = em->currentEditor())
        if (qobject_cast<VCSBaseSubmitEditor*>(ce))
            return true;
    // Try to activate a hidden one
    foreach (Core::IEditor *e, em->openedEditors()) {
        if (qobject_cast<VCSBaseSubmitEditor*>(e)) {
            em->activateEditor(e, Core::EditorManager::IgnoreNavigationHistory);
            return true;
        }
    }
    return false;
}

615
} // namespace VCSBase