1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "vcsbasesubmiteditor.h"
#include "commonvcssettings.h"
#include "vcsbaseoutputwindow.h"
#include "vcsplugin.h"
#include "nicknamedialog.h"
#include "submiteditorfile.h"
#include <aggregation/aggregate.h>
#include <coreplugin/ifile.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/id.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <utils/submiteditorwidget.h>
#include <utils/checkablemessagebox.h>
#include <utils/synchronousprocess.h>
#include <utils/submitfieldwidget.h>
#include <utils/fileutils.h>
#include <find/basetextfind.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/project.h>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QTemporaryFile>
#include <QtCore/QProcess>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QPointer>
#include <QtCore/QTextStream>
#include <QtGui/QStyle>
#include <QtGui/QToolBar>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QMessageBox>
#include <QtGui/QMainWindow>
#include <QtGui/QCompleter>
#include <QtGui/QLineEdit>
#include <QtGui/QTextEdit>
enum { debug = 0 };
enum { wantToolBar = 0 };
/*!
\struct VCSBase::VCSBaseSubmitEditorParameters
\brief Utility struct to parametrize a VCSBaseSubmitEditor.
*/
/*!
\class VCSBase::VCSBaseSubmitEditor
\brief Base class for a submit editor based on the Utils::SubmitEditorWidget.
Presents the commit message in a text editor and an
checkable list of modified files in a list window. The user can delete
files from the list by pressing unchecking them or diff the selection
by doubleclicking.
The action matching the the ids (unless 0) of the parameter struct will be
registered with the EditorWidget and submit/diff actions will be added to
a toolbar.
For the given context, there must be only one instance of the editor
active.
To start a submit, set the submit template on the editor and the output
of the VCS status command listing the modified files as fileList and open
it.
The submit process is started by listening on the editor close
signal and then asking the IFile interface of the editor to save the file
within a IFileManager::blockFileChange() section
and to launch the submit process. In addition, the action registered
for submit should be connected to a slot triggering the close of the
current editor in the editor manager.
*/
namespace VCSBase {
static inline QString submitMessageCheckScript()
{
return Internal::VCSPlugin::instance()->settings().submitMessageCheckScript;
}
struct VCSBaseSubmitEditorPrivate
{
VCSBaseSubmitEditorPrivate(const VCSBaseSubmitEditorParameters *parameters,
Utils::SubmitEditorWidget *editorWidget,
QObject *q);
Utils::SubmitEditorWidget *m_widget;
QToolBar *m_toolWidget;
const VCSBaseSubmitEditorParameters *m_parameters;
QString m_displayName;
QString m_checkScriptWorkingDirectory;
VCSBase::Internal::SubmitEditorFile *m_file;
QPointer<QAction> m_diffAction;
QPointer<QAction> m_submitAction;
Internal::NickNameDialog *m_nickNameDialog;
};
VCSBaseSubmitEditorPrivate::VCSBaseSubmitEditorPrivate(const VCSBaseSubmitEditorParameters *parameters,
Utils::SubmitEditorWidget *editorWidget,
QObject *q) :
m_widget(editorWidget),
m_toolWidget(0),
m_parameters(parameters),
m_file(new VCSBase::Internal::SubmitEditorFile(QLatin1String(parameters->mimeType), q)),
m_nickNameDialog(0)
{
}
VCSBaseSubmitEditor::VCSBaseSubmitEditor(const VCSBaseSubmitEditorParameters *parameters,
Utils::SubmitEditorWidget *editorWidget) :
d(new VCSBaseSubmitEditorPrivate(parameters, editorWidget, this))
{
setContext(Core::Context(parameters->context));
setWidget(d->m_widget);
// Message font according to settings
const TextEditor::FontSettings fs = TextEditor::TextEditorSettings::instance()->fontSettings();
QFont font = editorWidget->descriptionEdit()->font();
font.setFamily(fs.family());
font.setPointSize(fs.fontSize());
editorWidget->descriptionEdit()->setFont(font);
d->m_file->setModified(false);
// We are always clean to prevent the editor manager from asking to save.
connect(d->m_file, SIGNAL(saveMe(QString*, QString, bool)),
this, SLOT(save(QString*, QString, bool)));
connect(d->m_widget, SIGNAL(diffSelected(QStringList)), this, SLOT(slotDiffSelectedVCSFiles(QStringList)));
connect(d->m_widget->descriptionEdit(), SIGNAL(textChanged()), this, SLOT(slotDescriptionChanged()));
const Internal::CommonVcsSettings settings = Internal::VCSPlugin::instance()->settings();
// Add additional context menu settings
if (!settings.submitMessageCheckScript.isEmpty() || !settings.nickNameMailMap.isEmpty()) {
QAction *sep = new QAction(this);
sep->setSeparator(true);
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()));
d->m_widget->addDescriptionEditContextMenuAction(checkAction);
}
// Insert nick
if (!settings.nickNameMailMap.isEmpty()) {
QAction *insertAction = new QAction(tr("Insert Name..."), this);
connect(insertAction, SIGNAL(triggered()), this, SLOT(slotInsertNickName()));
d->m_widget->addDescriptionEditContextMenuAction(insertAction);
}
}
// Do we have user fields?
if (!settings.nickNameFieldListFile.isEmpty())
createUserFields(settings.nickNameFieldListFile);
// wrapping. etc
slotUpdateEditorSettings(settings);
connect(Internal::VCSPlugin::instance(),
SIGNAL(settingsChanged(VCSBase::Internal::CommonVcsSettings)),
this, SLOT(slotUpdateEditorSettings(VCSBase::Internal::CommonVcsSettings)));
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
aggregate->add(new Find::BaseTextFind(d->m_widget->descriptionEdit()));
aggregate->add(this);
}
VCSBaseSubmitEditor::~VCSBaseSubmitEditor()
{
delete d->m_toolWidget;
delete d->m_widget;
delete d;
}
void VCSBaseSubmitEditor::slotUpdateEditorSettings(const Internal::CommonVcsSettings &s)
{
setLineWrapWidth(s.lineWrapWidth);
setLineWrap(s.lineWrap);
}
// 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;
}
void VCSBaseSubmitEditor::createUserFields(const QString &fieldConfigFile)
{
Utils::FileReader reader;
if (!reader.fetch(fieldConfigFile, QIODevice::Text, Core::ICore::instance()->mainWindow()))
return;
// Parse into fields
const QStringList fields = fieldTexts(QString::fromUtf8(reader.data()));
if (fields.empty())
return;
// Create a completer on user names
const QStandardItemModel *nickNameModel = Internal::VCSPlugin::instance()->nickNameModel();
QCompleter *completer = new QCompleter(Internal::NickNameDialog::nickNameList(nickNameModel), this);
Utils::SubmitFieldWidget *fieldWidget = new Utils::SubmitFieldWidget;
connect(fieldWidget, SIGNAL(browseButtonClicked(int,QString)),
this, SLOT(slotSetFieldNickName(int)));
fieldWidget->setCompleter(completer);
fieldWidget->setAllowDuplicateFields(true);
fieldWidget->setHasBrowseButton(true);
fieldWidget->setFields(fields);
d->m_widget->addSubmitFieldWidget(fieldWidget);
}
void VCSBaseSubmitEditor::registerActions(QAction *editorUndoAction, QAction *editorRedoAction,
QAction *submitAction, QAction *diffAction)\
{
d->m_widget->registerActions(editorUndoAction, editorRedoAction, submitAction, diffAction);
d->m_diffAction = diffAction;
d->m_submitAction = submitAction;
}
void VCSBaseSubmitEditor::unregisterActions(QAction *editorUndoAction, QAction *editorRedoAction,
QAction *submitAction, QAction *diffAction)
{
d->m_widget->unregisterActions(editorUndoAction, editorRedoAction, submitAction, diffAction);
d->m_diffAction = d->m_submitAction = 0;
}
int VCSBaseSubmitEditor::fileNameColumn() const
{
return d->m_widget->fileNameColumn();
}
void VCSBaseSubmitEditor::setFileNameColumn(int c)
{
d->m_widget->setFileNameColumn(c);
}
QAbstractItemView::SelectionMode VCSBaseSubmitEditor::fileListSelectionMode() const
{
return d->m_widget->fileListSelectionMode();
}
void VCSBaseSubmitEditor::setFileListSelectionMode(QAbstractItemView::SelectionMode sm)
{
d->m_widget->setFileListSelectionMode(sm);
}
bool VCSBaseSubmitEditor::isEmptyFileListEnabled() const
{
return d->m_widget->isEmptyFileListEnabled();
}
void VCSBaseSubmitEditor::setEmptyFileListEnabled(bool e)
{
d->m_widget->setEmptyFileListEnabled(e);
}
bool VCSBaseSubmitEditor::lineWrap() const
{
return d->m_widget->lineWrap();
}
void VCSBaseSubmitEditor::setLineWrap(bool w)
{
d->m_widget->setLineWrap(w);
}
int VCSBaseSubmitEditor::lineWrapWidth() const
{
return d->m_widget->lineWrapWidth();
}
void VCSBaseSubmitEditor::setLineWrapWidth(int w)
{
d->m_widget->setLineWrapWidth(w);
}
void VCSBaseSubmitEditor::slotDescriptionChanged()
{
}
bool VCSBaseSubmitEditor::createNew(const QString &contents)
{
setFileContents(contents);
return true;
}
bool VCSBaseSubmitEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
if (fileName.isEmpty())
return false;
Utils::FileReader reader;
if (!reader.fetch(realFileName, QIODevice::Text, errorString))
return false;
const QString text = QString::fromLocal8Bit(reader.data());
if (!createNew(text))
return false;
d->m_file->setFileName(QFileInfo(fileName).absoluteFilePath());
d->m_file->setModified(fileName != realFileName);
return true;
}
Core::IFile *VCSBaseSubmitEditor::file()
{
return d->m_file;
}
QString VCSBaseSubmitEditor::displayName() const
{
if (d->m_displayName.isEmpty())
d->m_displayName = QCoreApplication::translate("VCS", d->m_parameters->displayName);
return d->m_displayName;
}
void VCSBaseSubmitEditor::setDisplayName(const QString &title)
{
d->m_displayName = title;
emit changed();
}
QString VCSBaseSubmitEditor::checkScriptWorkingDirectory() const
{
return d->m_checkScriptWorkingDirectory;
}
void VCSBaseSubmitEditor::setCheckScriptWorkingDirectory(const QString &s)
{
d->m_checkScriptWorkingDirectory = s;
}
bool VCSBaseSubmitEditor::duplicateSupported() const
{
return false;
}
Core::IEditor *VCSBaseSubmitEditor::duplicate(QWidget * /*parent*/)
{
return 0;
}
Core::Id VCSBaseSubmitEditor::id() const
{
return d->m_parameters->id;
}
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;
}
QWidget *VCSBaseSubmitEditor::toolBar()
{
if (!wantToolBar)
return 0;
if (d->m_toolWidget)
return d->m_toolWidget;
if (!d->m_diffAction && !d->m_submitAction)
return 0;
// Create
d->m_toolWidget = createToolBar(d->m_widget, d->m_submitAction, d->m_diffAction);
return d->m_toolWidget;
}
QByteArray VCSBaseSubmitEditor::saveState() const
{
return QByteArray();
}
bool VCSBaseSubmitEditor::restoreState(const QByteArray &/*state*/)
{
return true;
}
QStringList VCSBaseSubmitEditor::checkedFiles() const
{
return d->m_widget->checkedFiles();
}
void VCSBaseSubmitEditor::setFileModel(QAbstractItemModel *m)
{
d->m_widget->setFileModel(m);
}
QAbstractItemModel *VCSBaseSubmitEditor::fileModel() const
{
return d->m_widget->fileModel();
}
void VCSBaseSubmitEditor::slotDiffSelectedVCSFiles(const QStringList &rawList)
{
emit diffSelectedFiles(rawList);
}
bool VCSBaseSubmitEditor::save(QString *errorString, const QString &fileName, bool autoSave)
{
const QString fName = fileName.isEmpty() ? d->m_file->fileName() : fileName;
Utils::FileSaver saver(fName, QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
saver.write(fileContents());
if (!saver.finalize(errorString))
return false;
if (autoSave)
return true;
const QFileInfo fi(fName);
d->m_file->setFileName(fi.absoluteFilePath());
d->m_file->setModified(false);
return true;
}
QByteArray VCSBaseSubmitEditor::fileContents() const
{
return d->m_widget->descriptionText().toLocal8Bit();
}
bool VCSBaseSubmitEditor::setFileContents(const QString &contents)
{
d->m_widget->setDescriptionText(contents);
return true;
}
enum { checkDialogMinimumWidth = 500 };
VCSBaseSubmitEditor::PromptSubmitResult
VCSBaseSubmitEditor::promptSubmit(const QString &title,
const QString &question,
const QString &checkFailureQuestion,
bool *promptSetting,
bool forcePrompt,
bool canCommitOnFailure) const
{
Utils::SubmitEditorWidget *submitWidget =
static_cast<Utils::SubmitEditorWidget *>(const_cast<VCSBaseSubmitEditor *>(this)->widget());
raiseSubmitEditor();
QString errorMessage;
QMessageBox::StandardButton answer = QMessageBox::Yes;
const bool prompt = forcePrompt || *promptSetting;
QWidget *parent = Core::ICore::instance()->mainWindow();
// Pop up a message depending on whether the check succeeded and the
// user wants to be prompted
bool canCommit = checkSubmitMessage(&errorMessage) && submitWidget->canSubmit();
if (canCommit) {
// Check ok, do prompt?
if (prompt) {
// Provide check box to turn off prompt ONLY if it was not forced
if (*promptSetting && !forcePrompt) {
const QDialogButtonBox::StandardButton danswer =
Utils::CheckableMessageBox::question(parent, title, question,
tr("Prompt to submit"), promptSetting,
QDialogButtonBox::Yes|QDialogButtonBox::No|
QDialogButtonBox::Cancel,
QDialogButtonBox::Yes);
answer = Utils::CheckableMessageBox::dialogButtonBoxToMessageBoxButton(danswer);
} else {
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());
}
if (!canCommit && !canCommitOnFailure) {
switch (answer) {
case QMessageBox::No:
return SubmitDiscarded;
case QMessageBox::Yes:
return SubmitCanceled;
default:
break;
}
} else {
switch (answer) {
case QMessageBox::No:
return SubmitDiscarded;
case QMessageBox::Yes:
return SubmitConfirmed;
default:
break;
}
}
return SubmitCanceled;
}
QString VCSBaseSubmitEditor::promptForNickName()
{
if (!d->m_nickNameDialog)
d->m_nickNameDialog = new Internal::NickNameDialog(Internal::VCSPlugin::instance()->nickNameModel(), d->m_widget);
if (d->m_nickNameDialog->exec() == QDialog::Accepted)
return d->m_nickNameDialog->nickName();
return QString();
}
void VCSBaseSubmitEditor::slotInsertNickName()
{
const QString nick = promptForNickName();
if (!nick.isEmpty())
d->m_widget->descriptionEdit()->textCursor().insertText(nick);
}
void VCSBaseSubmitEditor::slotSetFieldNickName(int i)
{
if (Utils::SubmitFieldWidget *sfw =d->m_widget->submitFieldWidgets().front()) {
const QString nick = promptForNickName();
if (!nick.isEmpty())
sfw->setFieldValue(i, nick);
}
}
void VCSBaseSubmitEditor::slotCheckSubmitMessage()
{
QString errorMessage;
if (!checkSubmitMessage(&errorMessage)) {
QMessageBox msgBox(QMessageBox::Warning, tr("Submit Message Check Failed"),
errorMessage, QMessageBox::Ok, d->m_widget);
msgBox.setMinimumWidth(checkDialogMinimumWidth);
msgBox.exec();
}
}
bool VCSBaseSubmitEditor::checkSubmitMessage(QString *errorMessage) const
{
const QString checkScript = submitMessageCheckScript();
if (checkScript.isEmpty())
return true;
QApplication::setOverrideCursor(Qt::WaitCursor);
const bool rc = runSubmitMessageCheckScript(checkScript, errorMessage);
QApplication::restoreOverrideCursor();
return rc;
}
static inline QString msgCheckScript(const QString &workingDir, const QString &cmd)
{
const QString nativeCmd = QDir::toNativeSeparators(cmd);
return workingDir.isEmpty() ?
VCSBaseSubmitEditor::tr("Executing %1").arg(nativeCmd) :
VCSBaseSubmitEditor::tr("Executing [%1] %2").
arg(QDir::toNativeSeparators(workingDir), nativeCmd);
}
bool VCSBaseSubmitEditor::runSubmitMessageCheckScript(const QString &checkScript, QString *errorMessage) const
{
// Write out message
QString tempFilePattern = QDir::tempPath();
if (!tempFilePattern.endsWith(QDir::separator()))
tempFilePattern += QDir::separator();
tempFilePattern += QLatin1String("msgXXXXXX.txt");
Utils::TempFileSaver saver(tempFilePattern);
saver.write(fileContents());
if (!saver.finalize(errorMessage))
return false;
// Run check process
VCSBaseOutputWindow *outputWindow = VCSBaseOutputWindow::instance();
outputWindow->appendCommand(msgCheckScript(d->m_checkScriptWorkingDirectory, checkScript));
QProcess checkProcess;
if (!d->m_checkScriptWorkingDirectory.isEmpty())
checkProcess.setWorkingDirectory(d->m_checkScriptWorkingDirectory);
checkProcess.start(checkScript, QStringList(saver.fileName()));
checkProcess.closeWriteChannel();
if (!checkProcess.waitForStarted()) {
*errorMessage = tr("The check script '%1' could not be started: %2").arg(checkScript, checkProcess.errorString());
return false;
}
QByteArray stdOutData;
QByteArray stdErrData;
if (!Utils::SynchronousProcess::readDataFromProcess(checkProcess, 30000, &stdOutData, &stdErrData, false)) {
Utils::SynchronousProcess::stopProcess(checkProcess);
*errorMessage = tr("The check script '%1' timed out.").
arg(QDir::toNativeSeparators(checkScript));
return false;
}
if (checkProcess.exitStatus() != QProcess::NormalExit) {
*errorMessage = tr("The check script '%1' crashed.").
arg(QDir::toNativeSeparators(checkScript));
return false;
}
if (!stdOutData.isEmpty())
outputWindow->appendSilently(QString::fromLocal8Bit(stdOutData));
const QString stdErr = QString::fromLocal8Bit(stdErrData);
if (!stdErr.isEmpty())
outputWindow->appendSilently(stdErr);
const int exitCode = checkProcess.exitCode();
if (exitCode != 0) {
const QString exMessage = tr("The check script returned exit code %1.").
arg(exitCode);
outputWindow->appendError(exMessage);
*errorMessage = stdErr;
if (errorMessage->isEmpty())
*errorMessage = exMessage;
return false;
}
return true;
}
QIcon VCSBaseSubmitEditor::diffIcon()
{
return QIcon(QLatin1String(":/vcsbase/images/diff.png"));
}
QIcon VCSBaseSubmitEditor::submitIcon()
{
return QIcon(QLatin1String(":/vcsbase/images/submit.png"));
}
// Compile a list if files in the current projects. TODO: Recurse down qrc files?
QStringList VCSBaseSubmitEditor::currentProjectFiles(bool nativeSeparators, QString *name)
{
if (name)
name->clear();
if (ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance()) {
if (const ProjectExplorer::Project *currentProject = pe->currentProject()) {
QStringList files = currentProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
if (name)
*name = currentProject->displayName();
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;
}
}
return QStringList();
}
// Reduce a list of untracked files reported by a VCS down to the files
// that are actually part of the current project(s).
void VCSBaseSubmitEditor::filterUntrackedFilesOfProject(const QString &repositoryDirectory, QStringList *untrackedFiles)
{
if (untrackedFiles->empty())
return;
const QStringList nativeProjectFiles = VCSBase::VCSBaseSubmitEditor::currentProjectFiles(true);
if (nativeProjectFiles.empty())
return;
const QDir repoDir(repositoryDirectory);
for (QStringList::iterator it = untrackedFiles->begin(); it != untrackedFiles->end(); ) {
const QString path = QDir::toNativeSeparators(repoDir.absoluteFilePath(*it));
if (nativeProjectFiles.contains(path)) {
++it;
} else {
it = untrackedFiles->erase(it);
}
}
}
// 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 | Core::EditorManager::ModeSwitch);
return true;
}
}
return false;
}
} // namespace VCSBase
|