diff options
-rw-r--r-- | src/plugins/git/gitplugin.cpp | 3 | ||||
-rw-r--r-- | src/plugins/git/gitsubmiteditor.cpp | 52 | ||||
-rw-r--r-- | src/plugins/git/gitsubmiteditor.h | 4 | ||||
-rw-r--r-- | src/plugins/vcsbase/submitfilemodel.cpp | 6 | ||||
-rw-r--r-- | src/plugins/vcsbase/submitfilemodel.h | 1 | ||||
-rw-r--r-- | src/plugins/vcsbase/vcsbasesubmiteditor.cpp | 14 | ||||
-rw-r--r-- | src/plugins/vcsbase/vcsbasesubmiteditor.h | 2 |
7 files changed, 75 insertions, 7 deletions
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index b82818a163..850553992c 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -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; diff --git a/src/plugins/git/gitsubmiteditor.cpp b/src/plugins/git/gitsubmiteditor.cpp index 2bb63d50e7..606ca9fb05 100644 --- a/src/plugins/git/gitsubmiteditor.cpp +++ b/src/plugins/git/gitsubmiteditor.cpp @@ -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(); diff --git a/src/plugins/git/gitsubmiteditor.h b/src/plugins/git/gitsubmiteditor.h index 2cacaecc2e..79c4347328 100644 --- a/src/plugins/git/gitsubmiteditor.h +++ b/src/plugins/git/gitsubmiteditor.h @@ -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 diff --git a/src/plugins/vcsbase/submitfilemodel.cpp b/src/plugins/vcsbase/submitfilemodel.cpp index dd24b0eaab..4045407513 100644 --- a/src/plugins/vcsbase/submitfilemodel.cpp +++ b/src/plugins/vcsbase/submitfilemodel.cpp @@ -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()) diff --git a/src/plugins/vcsbase/submitfilemodel.h b/src/plugins/vcsbase/submitfilemodel.h index 74579c0fc3..8d3e03e694 100644 --- a/src/plugins/vcsbase/submitfilemodel.h +++ b/src/plugins/vcsbase/submitfilemodel.h @@ -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; diff --git a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp index c41f984cbb..ae6d2bedd2 100644 --- a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp +++ b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp @@ -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) { diff --git a/src/plugins/vcsbase/vcsbasesubmiteditor.h b/src/plugins/vcsbase/vcsbasesubmiteditor.h index 7f608cef82..90b9f58f8c 100644 --- a/src/plugins/vcsbase/vcsbasesubmiteditor.h +++ b/src/plugins/vcsbase/vcsbasesubmiteditor.h @@ -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 |