forked from qt-creator/qt-creator
Fixes: Make git diff work for staged files, do not launch submit if file list empty, make file model read only, add conveniences
Details: Add a type data field to the git file model
This commit is contained in:
@@ -43,10 +43,22 @@
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
|
||||
enum { FileTypeRole = Qt::UserRole + 1 };
|
||||
enum FileType { StagedFile , UnstagedFile, UntrackedFile };
|
||||
|
||||
/* The problem with git is that no diff can be obtained to for a random
|
||||
* multiselection of staged/unstaged files; it requires the --cached
|
||||
* option for staged files. So, we set the file list to
|
||||
* single selection and sort the files manual according to a type
|
||||
* flag we add to the model. */
|
||||
|
||||
GitSubmitEditor::GitSubmitEditor(const VCSBase::VCSBaseSubmitEditorParameters *parameters, QWidget *parent) :
|
||||
VCSBaseSubmitEditor(parameters, new GitSubmitEditorWidget(parent))
|
||||
VCSBaseSubmitEditor(parameters, new GitSubmitEditorWidget(parent)),
|
||||
m_model(0)
|
||||
{
|
||||
setDisplayName(tr("Git Commit"));
|
||||
setFileListSelectionMode(QAbstractItemView::SingleSelection);
|
||||
connect(this, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(slotDiffSelected(QStringList)));
|
||||
}
|
||||
|
||||
GitSubmitEditorWidget *GitSubmitEditor::submitEditorWidget()
|
||||
@@ -54,14 +66,20 @@ GitSubmitEditorWidget *GitSubmitEditor::submitEditorWidget()
|
||||
return static_cast<GitSubmitEditorWidget *>(widget());
|
||||
}
|
||||
|
||||
static void addStateFileListToModel(const QList<CommitData::StateFilePair> &l,
|
||||
VCSBase::SubmitFileModel *model,
|
||||
bool checked)
|
||||
// Utility to add a list of state/file pairs to the model
|
||||
// setting a file type.
|
||||
static void addStateFileListToModel(const QList<CommitData::StateFilePair> &l,
|
||||
bool checked, FileType ft,
|
||||
VCSBase::SubmitFileModel *model)
|
||||
{
|
||||
|
||||
typedef QList<CommitData::StateFilePair>::const_iterator ConstIterator;
|
||||
const ConstIterator cend = l.constEnd();
|
||||
for (ConstIterator it = l.constBegin(); it != cend; ++it)
|
||||
model->addFile(it->second, it->first, checked);
|
||||
if (!l.empty()) {
|
||||
const ConstIterator cend = l.constEnd();
|
||||
const QVariant fileTypeData(ft);
|
||||
for (ConstIterator it = l.constBegin(); it != cend; ++it)
|
||||
model->addFile(it->second, it->first, checked).front()->setData(fileTypeData, FileTypeRole);
|
||||
}
|
||||
}
|
||||
|
||||
void GitSubmitEditor::setCommitData(const CommitData &d)
|
||||
@@ -69,16 +87,37 @@ void GitSubmitEditor::setCommitData(const CommitData &d)
|
||||
submitEditorWidget()->setPanelData(d.panelData);
|
||||
submitEditorWidget()->setPanelInfo(d.panelInfo);
|
||||
|
||||
VCSBase::SubmitFileModel *model = new VCSBase::SubmitFileModel(this);
|
||||
addStateFileListToModel(d.stagedFiles, model, true);
|
||||
addStateFileListToModel(d.unstagedFiles, model, false);
|
||||
m_model = new VCSBase::SubmitFileModel(this);
|
||||
addStateFileListToModel(d.stagedFiles, true, StagedFile, m_model);
|
||||
addStateFileListToModel(d.unstagedFiles, false, UnstagedFile, m_model);
|
||||
if (!d.untrackedFiles.empty()) {
|
||||
const QString untrackedSpec = QLatin1String("untracked");
|
||||
const QVariant fileTypeData(UntrackedFile);
|
||||
const QStringList::const_iterator cend = d.untrackedFiles.constEnd();
|
||||
for (QStringList::const_iterator it = d.untrackedFiles.constBegin(); it != cend; ++it)
|
||||
model->addFile(*it, untrackedSpec, false);
|
||||
m_model->addFile(*it, untrackedSpec, false).front()->setData(fileTypeData, FileTypeRole);
|
||||
}
|
||||
setFileModel(model);
|
||||
setFileModel(m_model);
|
||||
}
|
||||
|
||||
void GitSubmitEditor::slotDiffSelected(const QStringList &files)
|
||||
{
|
||||
QList<QStandardItem *> fileRow = m_model->findRow(files.front(), fileNameColumn());
|
||||
if (fileRow.empty())
|
||||
return;
|
||||
const FileType ft = static_cast<FileType>(fileRow.front()->data(FileTypeRole).toInt());
|
||||
switch (ft) {
|
||||
case StagedFile:
|
||||
emit diffStaged(files);
|
||||
break;
|
||||
case UnstagedFile:
|
||||
emit diffUnstaged(files);
|
||||
break;
|
||||
case UntrackedFile:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
GitSubmitEditorPanelData GitSubmitEditor::panelData() const
|
||||
|
||||
Reference in New Issue
Block a user