Commit 76f67298 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Tobias Hunger

Git: Pass rows instead of files for diffSelectedFiles

Useful when the same file can appear more than once
(e.g. staged + modified)

Task-number: QTCREATORBUG-5347
Change-Id: I3ce716c22840c149490e00e6948612607ae57159
Reviewed-by: default avatarPetar Perisin <petar.perisin@gmail.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 39e9c5ef
......@@ -108,7 +108,8 @@ static const VcsBase::VcsBaseSubmitEditorParameters submitEditorParameters = {
Constants::COMMITMIMETYPE,
Constants::COMMIT_ID,
Constants::COMMIT_DISPLAY_NAME,
Constants::COMMIT_ID
Constants::COMMIT_ID,
VcsBase::VcsBaseSubmitEditorParameters::DiffFiles
};
......
......@@ -258,7 +258,8 @@ static const VcsBase::VcsBaseSubmitEditorParameters submitParameters = {
ClearCase::Constants::CLEARCASE_SUBMIT_MIMETYPE,
ClearCase::Constants::CLEARCASECHECKINEDITOR_ID,
ClearCase::Constants::CLEARCASECHECKINEDITOR_DISPLAY_NAME,
ClearCase::Constants::CLEARCASECHECKINEDITOR
ClearCase::Constants::CLEARCASECHECKINEDITOR,
VcsBase::VcsBaseSubmitEditorParameters::DiffFiles
};
bool ClearCasePlugin::initialize(const QStringList & /*arguments */, QString *errorMessage)
......
......@@ -213,7 +213,8 @@ static const VcsBaseSubmitEditorParameters submitParameters = {
Constants::CVS_SUBMIT_MIMETYPE,
Constants::CVSCOMMITEDITOR_ID,
Constants::CVSCOMMITEDITOR_DISPLAY_NAME,
Constants::CVSCOMMITEDITOR
Constants::CVSCOMMITEDITOR,
VcsBase::VcsBaseSubmitEditorParameters::DiffFiles
};
bool CvsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
......
......@@ -175,7 +175,8 @@ static const VcsBase::VcsBaseSubmitEditorParameters submitParameters = {
Git::Constants::SUBMIT_MIMETYPE,
Git::Constants::GITSUBMITEDITOR_ID,
Git::Constants::GITSUBMITEDITOR_DISPLAY_NAME,
Git::Constants::C_GITSUBMITEDITOR
Git::Constants::C_GITSUBMITEDITOR,
VcsBase::VcsBaseSubmitEditorParameters::DiffRows
};
// Create a parameter action
......
......@@ -85,7 +85,7 @@ GitSubmitEditor::GitSubmitEditor(const VcsBase::VcsBaseSubmitEditorParameters *p
m_model(0),
m_amend(false)
{
connect(this, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(slotDiffSelected(QStringList)));
connect(this, SIGNAL(diffSelectedFiles(QList<int>)), this, SLOT(slotDiffSelected(QList<int>)));
}
GitSubmitEditorWidget *GitSubmitEditor::submitEditorWidget()
......@@ -131,24 +131,21 @@ void GitSubmitEditor::setAmend(bool amend)
setEmptyFileListEnabled(amend); // Allow for just correcting the message
}
void GitSubmitEditor::slotDiffSelected(const QStringList &files)
void GitSubmitEditor::slotDiffSelected(const QList<int> &rows)
{
// Sort it apart into unmerged/staged/unstaged files
QStringList unmergedFiles;
QStringList unstagedFiles;
QStringList stagedFiles;
const int rowCount = m_model->rowCount();
for (int r = 0; r < rowCount; r++) {
const QString fileName = m_model->file(r);
if (files.contains(fileName)) {
const FileStates state = static_cast<FileStates>(m_model->extraData(r).toInt());
if (state & UnmergedFile)
unmergedFiles.push_back(fileName);
else if (state & StagedFile)
stagedFiles.push_back(fileName);
else if (state != UntrackedFile)
unstagedFiles.push_back(fileName);
}
foreach (int row, rows) {
const QString fileName = m_model->file(row);
const FileStates state = static_cast<FileStates>(m_model->extraData(row).toInt());
if (state & UnmergedFile)
unmergedFiles.push_back(fileName);
else if (state & StagedFile)
stagedFiles.push_back(fileName);
else if (state != UntrackedFile)
unstagedFiles.push_back(fileName);
}
if (!unstagedFiles.empty() || !stagedFiles.empty())
emit diff(unstagedFiles, stagedFiles);
......
......@@ -64,7 +64,7 @@ protected:
void updateFileModel();
private slots:
void slotDiffSelected(const QStringList &);
void slotDiffSelected(const QList<int> &rows);
private:
inline GitSubmitEditorWidget *submitEditorWidget();
......
......@@ -108,7 +108,8 @@ static const VcsBaseSubmitEditorParameters submitEditorParameters = {
Constants::COMMITMIMETYPE,
Constants::COMMIT_ID,
Constants::COMMIT_DISPLAY_NAME,
Constants::COMMIT_ID
Constants::COMMIT_ID,
VcsBase::VcsBaseSubmitEditorParameters::DiffFiles
};
MercurialPlugin *MercurialPlugin::m_instance = 0;
......
......@@ -211,7 +211,8 @@ static const VcsBase::VcsBaseSubmitEditorParameters submitParameters = {
Perforce::Constants::SUBMIT_MIMETYPE,
Perforce::Constants::PERFORCE_SUBMIT_EDITOR_ID,
Perforce::Constants::PERFORCE_SUBMIT_EDITOR_DISPLAY_NAME,
Perforce::Constants::PERFORCESUBMITEDITOR_CONTEXT
Perforce::Constants::PERFORCESUBMITEDITOR_CONTEXT,
VcsBase::VcsBaseSubmitEditorParameters::DiffFiles
};
bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *errorMessage)
......
......@@ -236,7 +236,8 @@ static const VcsBase::VcsBaseSubmitEditorParameters submitParameters = {
Subversion::Constants::SUBVERSION_SUBMIT_MIMETYPE,
Subversion::Constants::SUBVERSIONCOMMITEDITOR_ID,
Subversion::Constants::SUBVERSIONCOMMITEDITOR_DISPLAY_NAME,
Subversion::Constants::SUBVERSIONCOMMITEDITOR
Subversion::Constants::SUBVERSIONCOMMITEDITOR,
VcsBase::VcsBaseSubmitEditorParameters::DiffFiles
};
bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *errorMessage)
......
......@@ -403,20 +403,6 @@ SubmitFileModel *SubmitEditorWidget::fileModel() const
return static_cast<SubmitFileModel *>(d->m_ui.fileView->model());
}
QStringList SubmitEditorWidget::selectedFiles() const
{
const QList<int> selection = selectedRows(d->m_ui.fileView);
if (selection.empty())
return QStringList();
QStringList rc;
const SubmitFileModel *model = fileModel();
const int count = selection.size();
for (int i = 0; i < count; i++)
rc.push_back(model->file(selection.at(i)));
return rc;
}
QStringList SubmitEditorWidget::checkedFiles() const
{
QStringList rc;
......@@ -437,15 +423,14 @@ Utils::CompletingTextEdit *SubmitEditorWidget::descriptionEdit() const
void SubmitEditorWidget::triggerDiffSelected()
{
const QStringList sel = selectedFiles();
const QList<int> sel = selectedRows(d->m_ui.fileView);
if (!sel.empty())
emit diffSelected(sel);
}
void SubmitEditorWidget::diffActivatedDelayed()
{
const QStringList files = QStringList(fileModel()->file(d->m_activatedRow));
emit diffSelected(files);
emit diffSelected(QList<int>() << d->m_activatedRow);
}
void SubmitEditorWidget::diffActivated(const QModelIndex &index)
......
......@@ -95,9 +95,6 @@ public:
// Files to be included in submit
QStringList checkedFiles() const;
// Selected files for diff
QStringList selectedFiles() const;
Utils::CompletingTextEdit *descriptionEdit() const;
void addDescriptionEditContextMenuAction(QAction *a);
......@@ -109,7 +106,7 @@ public:
virtual bool canSubmit() const;
signals:
void diffSelected(const QStringList &);
void diffSelected(const QList<int> &);
void fileSelectionChanged(bool someFileSelected);
void submitActionTextChanged(const QString &);
void submitActionEnabledChanged(bool);
......
......@@ -210,7 +210,7 @@ VcsBaseSubmitEditor::VcsBaseSubmitEditor(const VcsBaseSubmitEditorParameters *pa
connect(d->m_file, SIGNAL(saveMe(QString*,QString,bool)),
this, SLOT(save(QString*,QString,bool)));
connect(d->m_widget, SIGNAL(diffSelected(QStringList)), this, SLOT(slotDiffSelectedVcsFiles(QStringList)));
connect(d->m_widget, SIGNAL(diffSelected(QList<int>)), this, SLOT(slotDiffSelectedVcsFiles(QList<int>)));
connect(d->m_widget->descriptionEdit(), SIGNAL(textChanged()), this, SLOT(slotDescriptionChanged()));
const CommonVcsSettings settings = VcsPlugin::instance()->settings();
......@@ -540,9 +540,25 @@ SubmitFileModel *VcsBaseSubmitEditor::fileModel() const
return d->m_widget->fileModel();
}
void VcsBaseSubmitEditor::slotDiffSelectedVcsFiles(const QStringList &rawList)
QStringList VcsBaseSubmitEditor::rowsToFiles(const QList<int> &rows) const
{
emit diffSelectedFiles(rawList);
if (rows.empty())
return QStringList();
QStringList rc;
const SubmitFileModel *model = fileModel();
const int count = rows.size();
for (int i = 0; i < count; i++)
rc.push_back(model->file(rows.at(i)));
return rc;
}
void VcsBaseSubmitEditor::slotDiffSelectedVcsFiles(const QList<int> &rawList)
{
if (d->m_parameters->diffType == VcsBaseSubmitEditorParameters::DiffRows)
emit diffSelectedFiles(rawList);
else
emit diffSelectedFiles(rowsToFiles(rawList));
}
bool VcsBaseSubmitEditor::save(QString *errorString, const QString &fileName, bool autoSave)
......
......@@ -56,6 +56,7 @@ public:
const char *id;
const char *displayName;
const char *context;
enum DiffType { DiffRows, DiffFiles } diffType;
};
class VCSBASE_EXPORT VcsBaseSubmitEditor : public Core::IEditor
......@@ -130,6 +131,7 @@ public:
void setFileModel(SubmitFileModel *m, const QString &repositoryDirectory = QString());
SubmitFileModel *fileModel() const;
virtual void updateFileModel() { }
QStringList rowsToFiles(const QList<int> &rows) const;
// Utilities returning some predefined icons for actions
static QIcon diffIcon();
......@@ -148,9 +150,10 @@ public:
signals:
void diffSelectedFiles(const QStringList &files);
void diffSelectedFiles(const QList<int> &rows);
private slots:
void slotDiffSelectedVcsFiles(const QStringList &rawList);
void slotDiffSelectedVcsFiles(const QList<int> &rawList);
bool save(QString *errorString, const QString &fileName, bool autoSave);
void slotDescriptionChanged();
void slotCheckSubmitMessage();
......
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