forked from qt-creator/qt-creator
Mercurial/Bazaar: Make commit work on windows
Do not keep an open file around when passing the file name to the editor. The editor won't be able to save on windows since the file is locked. Task-number: QTCREATORBUG-5972 Change-Id: Ib424c76d2e3e57d43fdc1e1c222dbeb148669038 Reviewed-by: Hugues Delorme <delorme.hugues@fougsys.fr>
This commit is contained in:
@@ -71,8 +71,6 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTemporaryFile>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Bazaar::Internal;
|
using namespace Bazaar::Internal;
|
||||||
using namespace Bazaar;
|
using namespace Bazaar;
|
||||||
@@ -123,10 +121,10 @@ BazaarPlugin::BazaarPlugin()
|
|||||||
m_optionsPage(0),
|
m_optionsPage(0),
|
||||||
m_client(0),
|
m_client(0),
|
||||||
m_commandLocator(0),
|
m_commandLocator(0),
|
||||||
m_changeLog(0),
|
|
||||||
m_addAction(0),
|
m_addAction(0),
|
||||||
m_deleteAction(0),
|
m_deleteAction(0),
|
||||||
m_menuAction(0)
|
m_menuAction(0),
|
||||||
|
m_submitActionTriggered(false)
|
||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
}
|
}
|
||||||
@@ -138,8 +136,6 @@ BazaarPlugin::~BazaarPlugin()
|
|||||||
m_client = 0;
|
m_client = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCommitLog();
|
|
||||||
|
|
||||||
m_instance = 0;
|
m_instance = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,20 +548,16 @@ void BazaarPlugin::showCommitWidget(const QList<VcsBase::VcsBaseClient::StatusIt
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCommitLog();
|
// Start new temp file
|
||||||
|
Utils::TempFileSaver saver;
|
||||||
// Open commit log
|
// Keep the file alive, else it removes self and forgets its name
|
||||||
QString changeLogPattern = QDir::tempPath();
|
saver.setAutoRemove(false);
|
||||||
if (!changeLogPattern.endsWith(QLatin1Char('/')))
|
if (!saver.finalize()) {
|
||||||
changeLogPattern += QLatin1Char('/');
|
VcsBase::VcsBaseOutputWindow::instance()->append(saver.errorString());
|
||||||
changeLogPattern += QLatin1String("qtcreator-bzr-XXXXXX.msg");
|
|
||||||
m_changeLog = new QTemporaryFile(changeLogPattern, this);
|
|
||||||
if (!m_changeLog->open()) {
|
|
||||||
outputWindow->appendError(tr("Unable to generate a temporary file for the commit editor."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IEditor *editor = Core::EditorManager::openEditor(m_changeLog->fileName(),
|
Core::IEditor *editor = Core::EditorManager::openEditor(saver.fileName(),
|
||||||
Constants::COMMIT_ID,
|
Constants::COMMIT_ID,
|
||||||
Core::EditorManager::ModeSwitch);
|
Core::EditorManager::ModeSwitch);
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
@@ -602,17 +594,13 @@ void BazaarPlugin::diffFromEditorSelected(const QStringList &files)
|
|||||||
|
|
||||||
void BazaarPlugin::commitFromEditor()
|
void BazaarPlugin::commitFromEditor()
|
||||||
{
|
{
|
||||||
if (!m_changeLog)
|
// Close the submit editor
|
||||||
return;
|
m_submitActionTriggered = true;
|
||||||
|
Core::ICore::editorManager()->closeEditor();
|
||||||
//use the same functionality than if the user closes the file without completing the commit
|
|
||||||
Core::ICore::editorManager()->closeEditors(Core::ICore::editorManager()->editorsForFileName(m_changeLog->fileName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BazaarPlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *submitEditor)
|
bool BazaarPlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *submitEditor)
|
||||||
{
|
{
|
||||||
if (!m_changeLog)
|
|
||||||
return true;
|
|
||||||
Core::IDocument *editorDocument = submitEditor->document();
|
Core::IDocument *editorDocument = submitEditor->document();
|
||||||
const CommitEditor *commitEditor = qobject_cast<const CommitEditor *>(submitEditor);
|
const CommitEditor *commitEditor = qobject_cast<const CommitEditor *>(submitEditor);
|
||||||
if (!editorDocument || !commitEditor)
|
if (!editorDocument || !commitEditor)
|
||||||
@@ -622,13 +610,13 @@ bool BazaarPlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *submit
|
|||||||
const VcsBase::VcsBaseSubmitEditor::PromptSubmitResult response =
|
const VcsBase::VcsBaseSubmitEditor::PromptSubmitResult response =
|
||||||
commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
|
commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
|
||||||
tr("Message check failed. Do you want to proceed?"),
|
tr("Message check failed. Do you want to proceed?"),
|
||||||
&dummyPrompt, dummyPrompt);
|
&dummyPrompt, !m_submitActionTriggered);
|
||||||
|
m_submitActionTriggered = false;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case VcsBase::VcsBaseSubmitEditor::SubmitCanceled:
|
case VcsBase::VcsBaseSubmitEditor::SubmitCanceled:
|
||||||
return false;
|
return false;
|
||||||
case VcsBase::VcsBaseSubmitEditor::SubmitDiscarded:
|
case VcsBase::VcsBaseSubmitEditor::SubmitDiscarded:
|
||||||
deleteCommitLog();
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -666,14 +654,6 @@ bool BazaarPlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *submit
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BazaarPlugin::deleteCommitLog()
|
|
||||||
{
|
|
||||||
if (m_changeLog) {
|
|
||||||
delete m_changeLog;
|
|
||||||
m_changeLog = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BazaarPlugin::updateActions(VcsBase::VcsBasePlugin::ActionState as)
|
void BazaarPlugin::updateActions(VcsBase::VcsBasePlugin::ActionState as)
|
||||||
{
|
{
|
||||||
if (!enableMenuAction(as, m_menuAction)) {
|
if (!enableMenuAction(as, m_menuAction)) {
|
||||||
|
@@ -44,7 +44,6 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
class QAction;
|
||||||
class QTemporaryFile;
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -127,7 +126,6 @@ private:
|
|||||||
void createFileActions(const Core::Context &context);
|
void createFileActions(const Core::Context &context);
|
||||||
void createDirectoryActions(const Core::Context &context);
|
void createDirectoryActions(const Core::Context &context);
|
||||||
void createRepositoryActions(const Core::Context &context);
|
void createRepositoryActions(const Core::Context &context);
|
||||||
void deleteCommitLog();
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
static BazaarPlugin *m_instance;
|
static BazaarPlugin *m_instance;
|
||||||
@@ -139,7 +137,6 @@ private:
|
|||||||
Core::ActionContainer *m_bazaarContainer;
|
Core::ActionContainer *m_bazaarContainer;
|
||||||
|
|
||||||
QList<QAction *> m_repositoryActionList;
|
QList<QAction *> m_repositoryActionList;
|
||||||
QTemporaryFile *m_changeLog;
|
|
||||||
|
|
||||||
// Menu Items (file actions)
|
// Menu Items (file actions)
|
||||||
Utils::ParameterAction *m_addAction;
|
Utils::ParameterAction *m_addAction;
|
||||||
@@ -159,6 +156,7 @@ private:
|
|||||||
QAction *m_menuAction;
|
QAction *m_menuAction;
|
||||||
|
|
||||||
QString m_submitRepository;
|
QString m_submitRepository;
|
||||||
|
bool m_submitActionTriggered;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -68,8 +68,6 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTemporaryFile>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Mercurial::Internal;
|
using namespace Mercurial::Internal;
|
||||||
using namespace Mercurial;
|
using namespace Mercurial;
|
||||||
@@ -122,11 +120,11 @@ MercurialPlugin::MercurialPlugin() :
|
|||||||
m_client(0),
|
m_client(0),
|
||||||
core(0),
|
core(0),
|
||||||
m_commandLocator(0),
|
m_commandLocator(0),
|
||||||
changeLog(0),
|
|
||||||
m_addAction(0),
|
m_addAction(0),
|
||||||
m_deleteAction(0),
|
m_deleteAction(0),
|
||||||
m_createRepositoryAction(0),
|
m_createRepositoryAction(0),
|
||||||
m_menuAction(0)
|
m_menuAction(0),
|
||||||
|
m_submitActionTriggered(false)
|
||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
}
|
}
|
||||||
@@ -138,8 +136,6 @@ MercurialPlugin::~MercurialPlugin()
|
|||||||
m_client = 0;
|
m_client = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCommitLog();
|
|
||||||
|
|
||||||
m_instance = 0;
|
m_instance = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +549,6 @@ void MercurialPlugin::commit()
|
|||||||
|
|
||||||
void MercurialPlugin::showCommitWidget(const QList<VcsBaseClient::StatusItem> &status)
|
void MercurialPlugin::showCommitWidget(const QList<VcsBaseClient::StatusItem> &status)
|
||||||
{
|
{
|
||||||
|
|
||||||
VcsBaseOutputWindow *outputWindow = VcsBaseOutputWindow::instance();
|
VcsBaseOutputWindow *outputWindow = VcsBaseOutputWindow::instance();
|
||||||
//Once we receive our data release the connection so it can be reused elsewhere
|
//Once we receive our data release the connection so it can be reused elsewhere
|
||||||
disconnect(m_client, SIGNAL(parsedStatus(QList<VcsBase::VcsBaseClient::StatusItem>)),
|
disconnect(m_client, SIGNAL(parsedStatus(QList<VcsBase::VcsBaseClient::StatusItem>)),
|
||||||
@@ -564,20 +559,16 @@ void MercurialPlugin::showCommitWidget(const QList<VcsBaseClient::StatusItem> &s
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCommitLog();
|
// Start new temp file
|
||||||
|
Utils::TempFileSaver saver;
|
||||||
// Open commit log
|
// Keep the file alive, else it removes self and forgets its name
|
||||||
QString changeLogPattern = QDir::tempPath();
|
saver.setAutoRemove(false);
|
||||||
if (!changeLogPattern.endsWith(QLatin1Char('/')))
|
if (!saver.finalize()) {
|
||||||
changeLogPattern += QLatin1Char('/');
|
VcsBase::VcsBaseOutputWindow::instance()->append(saver.errorString());
|
||||||
changeLogPattern += QLatin1String("qtcreator-hg-XXXXXX.msg");
|
|
||||||
changeLog = new QTemporaryFile(changeLogPattern, this);
|
|
||||||
if (!changeLog->open()) {
|
|
||||||
outputWindow->appendError(tr("Unable to generate a temporary file for the commit editor."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IEditor *editor = Core::EditorManager::openEditor(changeLog->fileName(),
|
Core::IEditor *editor = Core::EditorManager::openEditor(saver.fileName(),
|
||||||
Constants::COMMIT_ID,
|
Constants::COMMIT_ID,
|
||||||
Core::EditorManager::ModeSwitch);
|
Core::EditorManager::ModeSwitch);
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
@@ -610,17 +601,13 @@ void MercurialPlugin::diffFromEditorSelected(const QStringList &files)
|
|||||||
|
|
||||||
void MercurialPlugin::commitFromEditor()
|
void MercurialPlugin::commitFromEditor()
|
||||||
{
|
{
|
||||||
if (!changeLog)
|
// Close the submit editor
|
||||||
return;
|
m_submitActionTriggered = true;
|
||||||
|
Core::ICore::editorManager()->closeEditor();
|
||||||
//use the same functionality than if the user closes the file without completing the commit
|
|
||||||
core->editorManager()->closeEditors(core->editorManager()->editorsForFileName(changeLog->fileName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MercurialPlugin::submitEditorAboutToClose(VcsBaseSubmitEditor *submitEditor)
|
bool MercurialPlugin::submitEditorAboutToClose(VcsBaseSubmitEditor *submitEditor)
|
||||||
{
|
{
|
||||||
if (!changeLog)
|
|
||||||
return true;
|
|
||||||
Core::IDocument *editorFile = submitEditor->document();
|
Core::IDocument *editorFile = submitEditor->document();
|
||||||
CommitEditor *commitEditor = qobject_cast<CommitEditor *>(submitEditor);
|
CommitEditor *commitEditor = qobject_cast<CommitEditor *>(submitEditor);
|
||||||
if (!editorFile || !commitEditor)
|
if (!editorFile || !commitEditor)
|
||||||
@@ -630,13 +617,13 @@ bool MercurialPlugin::submitEditorAboutToClose(VcsBaseSubmitEditor *submitEditor
|
|||||||
const VcsBaseSubmitEditor::PromptSubmitResult response =
|
const VcsBaseSubmitEditor::PromptSubmitResult response =
|
||||||
commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
|
commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
|
||||||
tr("Message check failed. Do you want to proceed?"),
|
tr("Message check failed. Do you want to proceed?"),
|
||||||
&dummyPrompt, dummyPrompt);
|
&dummyPrompt, !m_submitActionTriggered);
|
||||||
|
m_submitActionTriggered = false;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case VcsBaseSubmitEditor::SubmitCanceled:
|
case VcsBaseSubmitEditor::SubmitCanceled:
|
||||||
return false;
|
return false;
|
||||||
case VcsBaseSubmitEditor::SubmitDiscarded:
|
case VcsBaseSubmitEditor::SubmitDiscarded:
|
||||||
deleteCommitLog();
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -657,14 +644,6 @@ bool MercurialPlugin::submitEditorAboutToClose(VcsBaseSubmitEditor *submitEditor
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MercurialPlugin::deleteCommitLog()
|
|
||||||
{
|
|
||||||
if (changeLog) {
|
|
||||||
delete changeLog;
|
|
||||||
changeLog = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MercurialPlugin::createRepositoryManagementActions(const Core::Context &context)
|
void MercurialPlugin::createRepositoryManagementActions(const Core::Context &context)
|
||||||
{
|
{
|
||||||
//TODO create menu for these options
|
//TODO create menu for these options
|
||||||
|
@@ -39,7 +39,6 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
class QAction;
|
||||||
class QTemporaryFile;
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -132,7 +131,6 @@ private:
|
|||||||
void createRepositoryActions(const Core::Context &context);
|
void createRepositoryActions(const Core::Context &context);
|
||||||
void createRepositoryManagementActions(const Core::Context &context);
|
void createRepositoryManagementActions(const Core::Context &context);
|
||||||
void createLessUsedActions(const Core::Context &context);
|
void createLessUsedActions(const Core::Context &context);
|
||||||
void deleteCommitLog();
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
static MercurialPlugin *m_instance;
|
static MercurialPlugin *m_instance;
|
||||||
@@ -145,7 +143,6 @@ private:
|
|||||||
Core::ActionContainer *mercurialContainer;
|
Core::ActionContainer *mercurialContainer;
|
||||||
|
|
||||||
QList<QAction *> m_repositoryActionList;
|
QList<QAction *> m_repositoryActionList;
|
||||||
QTemporaryFile *changeLog;
|
|
||||||
|
|
||||||
// Menu items (file actions)
|
// Menu items (file actions)
|
||||||
Utils::ParameterAction *m_addAction;
|
Utils::ParameterAction *m_addAction;
|
||||||
@@ -166,6 +163,8 @@ private:
|
|||||||
QAction *m_menuAction;
|
QAction *m_menuAction;
|
||||||
|
|
||||||
QString m_submitRepository;
|
QString m_submitRepository;
|
||||||
|
|
||||||
|
bool m_submitActionTriggered;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user