diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 2c043404019ae1203628a3ebfe8b1855b895fef4..5b0249d43c7aa60483bd0daa96e1c15aa9f6214d 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -695,20 +695,22 @@ bool GitPlugin::editorAboutToClose(Core::IEditor *iEditor) const QStringList fileList = editor->checkedFiles(); if (Git::Constants::debug) qDebug() << Q_FUNC_INFO << fileList; + bool closeEditor = true; if (!fileList.empty()) { // get message & commit m_core->fileManager()->blockFileChange(fileIFace); fileIFace->save(); m_core->fileManager()->unblockFileChange(fileIFace); - m_gitClient->addAndCommit(m_submitRepository, - editor->panelData(), - m_changeTmpFile->fileName(), - fileList, - m_submitOrigCommitFiles); + closeEditor = m_gitClient->addAndCommit(m_submitRepository, + editor->panelData(), + m_changeTmpFile->fileName(), + fileList, + m_submitOrigCommitFiles); } - cleanChangeTmpFile(); - return true; + if (closeEditor) + cleanChangeTmpFile(); + return closeEditor; } void GitPlugin::pull() diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp index 25ea4524a6c74c6880f7b331983bd1cb24c5eb45..a3112da078bfbfc6f477c4928ddfa39a62eacc73 100644 --- a/src/plugins/perforce/perforceplugin.cpp +++ b/src/plugins/perforce/perforceplugin.cpp @@ -517,16 +517,14 @@ void PerforcePlugin::submit() m_changeTmpFile = new QTemporaryFile(this); if (!m_changeTmpFile->open()) { showOutput(tr("Cannot create temporary file."), true); - delete m_changeTmpFile; - m_changeTmpFile = 0; + cleanChangeTmpFile(); return; } PerforceResponse result = runP4Cmd(QStringList()<< QLatin1String("change") << QLatin1String("-o"), QStringList(), CommandToWindow|StdErrToWindow|ErrorToWindow); if (result.error) { - delete m_changeTmpFile; - m_changeTmpFile = 0; + cleanChangeTmpFile(); return; } @@ -539,8 +537,7 @@ void PerforcePlugin::submit() PerforceResponse result2 = runP4Cmd(QStringList(QLatin1String("fstat")), nativeFiles, CommandToWindow|StdErrToWindow|ErrorToWindow); if (result2.error) { - delete m_changeTmpFile; - m_changeTmpFile = 0; + cleanChangeTmpFile(); return; } @@ -552,8 +549,7 @@ void PerforcePlugin::submit() } if (depotFileNames.isEmpty()) { showOutput(tr("Project has no files")); - delete m_changeTmpFile; - m_changeTmpFile = 0; + cleanChangeTmpFile(); return; } @@ -959,6 +955,16 @@ void PerforcePlugin::submitCurrentLog() em->closeEditors(QList<Core::IEditor*>() << em->currentEditor()); } +void PerforcePlugin::cleanChangeTmpFile() +{ + if (m_changeTmpFile) { + if (m_changeTmpFile->isOpen()) + m_changeTmpFile->close(); + delete m_changeTmpFile; + m_changeTmpFile = 0; + } +} + bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor) { if (!m_changeTmpFile || !editor) @@ -989,14 +995,13 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor) fileIFace->save(); core->fileManager()->unblockFileChange(fileIFace); if (answer == VCSBase::VCSBaseSubmitEditor::SubmitConfirmed) { + m_changeTmpFile->seek(0); QByteArray change = m_changeTmpFile->readAll(); - m_changeTmpFile->close(); if (!checkP4Command()) { showOutput(tr("No p4 executable specified!"), true); - delete m_changeTmpFile; - m_changeTmpFile = 0; return false; } + QProcess proc; proc.setEnvironment(environment()); @@ -1006,8 +1011,6 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor) if (!proc.waitForStarted(p4Timeout)) { showOutput(tr("Cannot execute p4 submit."), true); QApplication::restoreOverrideCursor(); - delete m_changeTmpFile; - m_changeTmpFile = 0; return false; } proc.write(change); @@ -1016,8 +1019,6 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor) if (!proc.waitForFinished()) { showOutput(tr("Cannot execute p4 submit."), true); QApplication::restoreOverrideCursor(); - delete m_changeTmpFile; - m_changeTmpFile = 0; return false; } const QString output = QString::fromUtf8(proc.readAll()); @@ -1027,9 +1028,7 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor) } QApplication::restoreOverrideCursor(); } - m_changeTmpFile->close(); - delete m_changeTmpFile; - m_changeTmpFile = 0; + cleanChangeTmpFile(); } return true; } diff --git a/src/plugins/perforce/perforceplugin.h b/src/plugins/perforce/perforceplugin.h index 8ac7188994ec5857a5b7d116b608210e9b6a3a54..4191d30e8b2b8f704fa96966d3b11c1c5ab9e928 100644 --- a/src/plugins/perforce/perforceplugin.h +++ b/src/plugins/perforce/perforceplugin.h @@ -167,6 +167,7 @@ private: void showOutput(const QString &output, bool popup = false) const; void annotate(const QString &fileName); void filelog(const QString &fileName); + void cleanChangeTmpFile(); ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer; PerforceOutputWindow *m_perforceOutputWindow; diff --git a/src/plugins/perforce/perforcesubmiteditor.cpp b/src/plugins/perforce/perforcesubmiteditor.cpp index dd3b53d4af328e07394181165b95cb256be9f7c8..ba1aee15aa7c8efaccb65d2543b55cc6fa55536b 100644 --- a/src/plugins/perforce/perforcesubmiteditor.cpp +++ b/src/plugins/perforce/perforcesubmiteditor.cpp @@ -153,8 +153,9 @@ void PerforceSubmitEditor::updateEntries() const QString tab = QString(QLatin1Char('\t')); QStringList lines = submitEditorWidget()->descriptionText().split(newLine); - while (lines.last().isEmpty()) - lines.removeLast(); + + while (!lines.empty() && lines.last().isEmpty()) + lines.removeLast(); // Description lines.replaceInStrings(QRegExp(QLatin1String("^")), tab); m_entries.insert(QLatin1String("Description"), newLine + lines.join(newLine) + QLatin1String("\n\n")); diff --git a/src/plugins/subversion/subversionplugin.cpp b/src/plugins/subversion/subversionplugin.cpp index 064bb086938adfd48dac153f30ee0232900c14d3..11ad9c2531e10d7a05a9c7791bcdc29c46587588 100644 --- a/src/plugins/subversion/subversionplugin.cpp +++ b/src/plugins/subversion/subversionplugin.cpp @@ -483,15 +483,17 @@ bool SubversionPlugin::editorAboutToClose(Core::IEditor *iEditor) } const QStringList fileList = editor->checkedFiles(); + bool closeEditor = true; if (!fileList.empty()) { // get message & commit Core::ICore::instance()->fileManager()->blockFileChange(fileIFace); fileIFace->save(); Core::ICore::instance()->fileManager()->unblockFileChange(fileIFace); - commit(m_changeTmpFile->fileName(), fileList); + closeEditor= commit(m_changeTmpFile->fileName(), fileList); } - cleanChangeTmpFile(); - return true; + if (closeEditor) + cleanChangeTmpFile(); + return closeEditor; } void SubversionPlugin::diffFiles(const QStringList &files)