From 2dfd7349a3a86035e9ddb4b1b2353f5a5bf1b267 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint <Friedemann.Kleint@nokia.com> Date: Fri, 20 Mar 2009 16:52:22 +0100 Subject: [PATCH] Make VCS plugins keep the submit editor open if the submit fails. --- src/plugins/git/gitplugin.cpp | 16 +++++---- src/plugins/perforce/perforceplugin.cpp | 35 +++++++++---------- src/plugins/perforce/perforceplugin.h | 1 + src/plugins/perforce/perforcesubmiteditor.cpp | 5 +-- src/plugins/subversion/subversionplugin.cpp | 8 +++-- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 2c043404019..5b0249d43c7 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 25ea4524a6c..a3112da078b 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 8ac7188994e..4191d30e8b2 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 dd3b53d4af3..ba1aee15aa7 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 064bb086938..11ad9c2531e 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) -- GitLab