Commit cecfffc7 authored by Orgad Shaneh's avatar Orgad Shaneh

VCS: Refresh submit editor status when it might change

Including Git implementation

Task-number: QTCREATORBUG-5644

Change-Id: Ic5dede99d93b84e5d271292b4694216f51e66882
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 6c4c45ba
......@@ -808,8 +808,7 @@ Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const Commit
submitEditor->setCheckScriptWorkingDirectory(m_submitRepository);
const QString title = amend ? tr("Amend %1").arg(cd.amendSHA1) : tr("Git Commit");
submitEditor->setDisplayName(title);
if (amend) // Allow for just correcting the message
submitEditor->setEmptyFileListEnabled(true);
submitEditor->setAmend(amend);
connect(submitEditor, SIGNAL(diff(QStringList,QStringList)), this, SLOT(submitEditorDiff(QStringList,QStringList)));
connect(submitEditor, SIGNAL(merge(QStringList)), this, SLOT(submitEditorMerge(QStringList)));
return editor;
......
......@@ -27,13 +27,16 @@
**
****************************************************************************/
#include "commitdata.h"
#include "gitclient.h"
#include "gitconstants.h"
#include "gitplugin.h"
#include "gitsubmiteditor.h"
#include "gitsubmiteditorwidget.h"
#include "gitconstants.h"
#include "commitdata.h"
#include <utils/qtcassert.h>
#include <vcsbase/submitfilemodel.h>
#include <vcsbase/vcsbaseoutputwindow.h>
#include <QDebug>
#include <QStringList>
......@@ -49,7 +52,8 @@ namespace Internal {
GitSubmitEditor::GitSubmitEditor(const VcsBase::VcsBaseSubmitEditorParameters *parameters, QWidget *parent) :
VcsBaseSubmitEditor(parameters, new GitSubmitEditorWidget(parent)),
m_model(0)
m_model(0),
m_amend(false)
{
connect(this, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(slotDiffSelected(QStringList)));
}
......@@ -59,6 +63,25 @@ GitSubmitEditorWidget *GitSubmitEditor::submitEditorWidget()
return static_cast<GitSubmitEditorWidget *>(widget());
}
static void mergeFileModels(VcsBase::SubmitFileModel *model, const VcsBase::SubmitFileModel *source)
{
int j = 0;
for (int i = 0; i < model->rowCount() && j < source->rowCount(); ++i) {
CommitData::StateFilePair stateFile(
static_cast<FileStates>(model->extraData(i).toInt()), model->file(i));
for (; j < source->rowCount(); ++j) {
CommitData::StateFilePair sourceStateFile(
static_cast<FileStates>(source->extraData(j).toInt()), source->file(j));
if (stateFile == sourceStateFile) {
model->setChecked(i, source->checked(j));
break;
} else if (stateFile < sourceStateFile) {
break;
}
}
}
}
void GitSubmitEditor::setCommitData(const CommitData &d)
{
GitSubmitEditorWidget *w = submitEditorWidget();
......@@ -67,7 +90,9 @@ void GitSubmitEditor::setCommitData(const CommitData &d)
w->setHasUnmerged(false);
m_commitEncoding = d.commitEncoding;
m_workingDirectory = d.panelInfo.repository;
VcsBase::SubmitFileModel *oldModel = m_model;
m_model = new VcsBase::SubmitFileModel(this);
if (!d.files.isEmpty()) {
for (QList<CommitData::StateFilePair>::const_iterator it = d.files.constBegin();
......@@ -87,9 +112,19 @@ void GitSubmitEditor::setCommitData(const CommitData &d)
QVariant(static_cast<int>(state)));
}
}
if (oldModel) {
mergeFileModels(m_model, oldModel);
delete oldModel;
}
setFileModel(m_model, d.panelInfo.repository);
}
void GitSubmitEditor::setAmend(bool amend)
{
m_amend = amend;
setEmptyFileListEnabled(amend); // Allow for just correcting the message
}
void GitSubmitEditor::slotDiffSelected(const QStringList &files)
{
// Sort it apart into unmerged/staged/unstaged files
......@@ -116,6 +151,17 @@ void GitSubmitEditor::slotDiffSelected(const QStringList &files)
emit merge(unmergedFiles);
}
void GitSubmitEditor::updateFileModel()
{
GitClient *client = GitPlugin::instance()->gitClient();
QString errorMessage, commitTemplate;
CommitData data;
if (client->getCommitData(m_workingDirectory, m_amend, &commitTemplate, &data, &errorMessage))
setCommitData(data);
else
VcsBase::VcsBaseOutputWindow::instance()->append(errorMessage);
}
GitSubmitEditorPanelData GitSubmitEditor::panelData() const
{
return const_cast<GitSubmitEditor*>(this)->submitEditorWidget()->panelData();
......
......@@ -52,6 +52,7 @@ public:
explicit GitSubmitEditor(const VcsBase::VcsBaseSubmitEditorParameters *parameters, QWidget *parent);
void setCommitData(const CommitData &);
void setAmend(bool amend);
GitSubmitEditorPanelData panelData() const;
signals:
......@@ -60,6 +61,7 @@ signals:
protected:
QByteArray fileContents() const;
void updateFileModel();
private slots:
void slotDiffSelected(const QStringList &);
......@@ -69,6 +71,8 @@ private:
VcsBase::SubmitFileModel *m_model;
QString m_commitEncoding;
bool m_amend;
QString m_workingDirectory;
};
} // namespace Internal
......
......@@ -117,6 +117,12 @@ bool SubmitFileModel::checked(int row) const
return (item(row)->checkState() == Qt::Checked);
}
void SubmitFileModel::setChecked(int row, bool check)
{
if (row >= 0 || row < rowCount())
item(row)->setCheckState(check ? Qt::Checked : Qt::Unchecked);
}
QVariant SubmitFileModel::extraData(int row) const
{
if (row < 0 || row >= rowCount())
......
......@@ -62,6 +62,7 @@ public:
QString state(int row) const;
QString file(int row) const;
bool checked(int row) const;
void setChecked(int row, bool check);
QVariant extraData(int row) const;
bool hasCheckedFiles() const;
......
......@@ -44,11 +44,12 @@
#include <cplusplus/Symbol.h>
#include <cplusplus/Symbols.h>
#include <cplusplus/TranslationUnit.h>
#include <coreplugin/idocument.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/id.h>
#include <coreplugin/idocument.h>
#include <coreplugin/mainwindow.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <utils/completingtextedit.h>
#include <utils/submiteditorwidget.h>
#include <utils/checkablemessagebox.h>
......@@ -238,6 +239,9 @@ VcsBaseSubmitEditor::VcsBaseSubmitEditor(const VcsBaseSubmitEditorParameters *pa
connect(VcsPlugin::instance(),
SIGNAL(settingsChanged(VcsBase::Internal::CommonVcsSettings)),
this, SLOT(slotUpdateEditorSettings(VcsBase::Internal::CommonVcsSettings)));
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(slotRefreshCommitData()));
connect(Core::ICore::mainWindow(), SIGNAL(windowActivated()), this, SLOT(slotRefreshCommitData()));
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
aggregate->add(new Find::BaseTextFind(d->m_widget->descriptionEdit()));
......@@ -257,6 +261,12 @@ void VcsBaseSubmitEditor::slotUpdateEditorSettings(const CommonVcsSettings &s)
setLineWrap(s.lineWrap);
}
void VcsBaseSubmitEditor::slotRefreshCommitData()
{
if (Core::EditorManager::currentEditor() == this)
updateFileModel();
}
// Return a trimmed list of non-empty field texts
static inline QStringList fieldTexts(const QString &fileContents)
{
......
......@@ -134,6 +134,7 @@ public:
void setFileModel(QAbstractItemModel *m, const QString &repositoryDirectory = QString());
QAbstractItemModel *fileModel() const;
virtual void updateFileModel() { }
// Utilities returning some predefined icons for actions
static QIcon diffIcon();
......@@ -161,6 +162,7 @@ private slots:
void slotInsertNickName();
void slotSetFieldNickName(int);
void slotUpdateEditorSettings(const VcsBase::Internal::CommonVcsSettings &);
void slotRefreshCommitData();
protected:
/* These hooks allow for modifying the contents that goes to
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment