Commit 9ef8d71e authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: Indicate affected commits for range operations



* Reset: Strikethrough discarded commits
* Interactive Rebase: Mark included commits
* Push to Gerrit: Mark pushed commits

Change-Id: I5599a72055fd94b88c55b74b3a1116c07e35c113
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 4e32babc
......@@ -33,12 +33,31 @@
#include "../gitplugin.h"
#include "../gitclient.h"
#include <coreplugin/coreconstants.h>
#include <QDateTime>
#include <QDir>
namespace Gerrit {
namespace Internal {
class PushItemDelegate : public Git::Internal::IconItemDelegate
{
public:
PushItemDelegate(Git::Internal::LogChangeWidget *widget)
: IconItemDelegate(widget, QLatin1String(Core::Constants::ICON_PLUS))
{
}
protected:
bool hasIcon(int row) const
{
return row >= currentRow();
}
};
GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &reviewerList, QWidget *parent) :
QDialog(parent),
m_workingDir(workingDir),
......@@ -54,6 +73,8 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev
if (!m_ui->commitView->init(workingDir, QString(), false))
return;
PushItemDelegate *delegate = new PushItemDelegate(m_ui->commitView);
delegate->setParent(this);
QString earliestCommit = m_ui->commitView->earliestCommit();
if (earliestCommit.isEmpty())
return;
......
......@@ -60,6 +60,7 @@
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/coreconstants.h>
#include <utils/qtcassert.h>
#include <utils/parameteraction.h>
......@@ -802,6 +803,34 @@ void GitPlugin::undoUnstagedFileChanges()
undoFileChanges(false);
}
class ResetItemDelegate : public LogItemDelegate
{
public:
ResetItemDelegate(LogChangeWidget *widget) : LogItemDelegate(widget) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem o = option;
if (index.row() < currentRow())
o.font.setStrikeOut(true);
QStyledItemDelegate::paint(painter, o, index);
}
};
class RebaseItemDelegate : public IconItemDelegate
{
public:
RebaseItemDelegate(LogChangeWidget *widget)
: IconItemDelegate(widget, QLatin1String(Core::Constants::ICON_UNDO))
{
}
protected:
bool hasIcon(int row) const
{
return row <= currentRow();
}
};
void GitPlugin::resetRepository()
{
if (!ensureAllDocumentsSaved())
......@@ -811,6 +840,7 @@ void GitPlugin::resetRepository()
QString topLevel = state.topLevel();
LogChangeDialog dialog(true);
ResetItemDelegate delegate(dialog.widget());
dialog.setWindowTitle(tr("Undo Changes to %1").arg(QDir::toNativeSeparators(topLevel)));
if (dialog.runDialog(topLevel))
m_gitClient->reset(topLevel, dialog.resetFlag(), dialog.commit());
......@@ -828,6 +858,7 @@ void GitPlugin::startRebase()
if (!m_gitClient->beginStashScope(topLevel, QLatin1String("Rebase-i")))
return;
LogChangeDialog dialog(false);
RebaseItemDelegate delegate(dialog.widget());
dialog.setWindowTitle(tr("Interactive Rebase"));
if (dialog.runDialog(topLevel, QString(), false))
m_gitClient->interactiveRebase(topLevel, dialog.commit(), false);
......
......@@ -33,6 +33,8 @@
#include <vcsbase/vcsbaseoutputwindow.h>
#include <utils/qtcassert.h>
#include <QTreeView>
#include <QLabel>
#include <QPushButton>
......@@ -41,6 +43,7 @@
#include <QItemSelectionModel>
#include <QVBoxLayout>
#include <QComboBox>
#include <QPainter>
namespace Git {
namespace Internal {
......@@ -55,6 +58,7 @@ enum Columns
LogChangeWidget::LogChangeWidget(QWidget *parent)
: QTreeView(parent)
, m_model(new QStandardItemModel(0, ColumnCount, this))
, m_hasCustomDelegate(false)
{
QStringList headers;
headers << tr("Sha1")<< tr("Subject");
......@@ -104,6 +108,12 @@ QString LogChangeWidget::earliestCommit() const
return QString();
}
void LogChangeWidget::setItemDelegate(QAbstractItemDelegate *delegate)
{
QTreeView::setItemDelegate(delegate);
m_hasCustomDelegate = true;
}
void LogChangeWidget::emitDoubleClicked(const QModelIndex &index)
{
if (index.isValid()) {
......@@ -113,6 +123,25 @@ void LogChangeWidget::emitDoubleClicked(const QModelIndex &index)
}
}
void LogChangeWidget::selectionChanged(const QItemSelection &selected,
const QItemSelection &deselected)
{
QTreeView::selectionChanged(selected, deselected);
if (!m_hasCustomDelegate)
return;
const QModelIndexList previousIndexes = deselected.indexes();
QTC_ASSERT(!previousIndexes.isEmpty(), return);
const QModelIndex current = currentIndex();
int row = current.row();
int previousRow = previousIndexes.first().row();
if (row < previousRow)
qSwap(row, previousRow);
for (int r = previousRow; r <= row; ++r) {
update(current.sibling(r, 0));
update(current.sibling(r, 1));
}
}
bool LogChangeWidget::populateLog(const QString &repository, const QString &commit, bool includeRemote)
{
const QString currentCommit = this->commit();
......@@ -234,5 +263,40 @@ QString LogChangeDialog::resetFlag() const
return m_resetTypeComboBox->itemData(m_resetTypeComboBox->currentIndex()).toString();
}
LogChangeWidget *LogChangeDialog::widget() const
{
return m_widget;
}
LogItemDelegate::LogItemDelegate(LogChangeWidget *widget) : m_widget(widget)
{
m_widget->setItemDelegate(this);
}
int LogItemDelegate::currentRow() const
{
return m_widget->commitIndex();
}
IconItemDelegate::IconItemDelegate(LogChangeWidget *widget, const QString &icon)
: LogItemDelegate(widget)
, m_icon(icon)
{
}
void IconItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyleOptionViewItem o = option;
if (index.column() == 0 && hasIcon(index.row())) {
const QSize size = option.decorationSize;
painter->save();
painter->drawPixmap(o.rect.x(), o.rect.y(), m_icon.pixmap(size.width(), size.height()));
painter->restore();
o.rect.translate(size.width(), 0);
}
QStyledItemDelegate::paint(painter, o, index);
}
} // namespace Internal
} // namespace Git
......@@ -31,6 +31,8 @@
#define LOGCHANGEDDIALOG_H
#include <QDialog>
#include <QIcon>
#include <QStyledItemDelegate>
#include <QTreeView>
QT_BEGIN_NAMESPACE
......@@ -57,6 +59,7 @@ public:
QString commit() const;
int commitIndex() const;
QString earliestCommit() const;
void setItemDelegate(QAbstractItemDelegate *delegate);
signals:
void doubleClicked(const QString &commit);
......@@ -65,10 +68,12 @@ private slots:
void emitDoubleClicked(const QModelIndex &index);
private:
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
bool populateLog(const QString &repository, const QString &commit, bool includeRemote);
const QStandardItem *currentItem(int column = 0) const;
QStandardItemModel *m_model;
bool m_hasCustomDelegate;
};
class LogChangeDialog : public QDialog
......@@ -83,6 +88,7 @@ public:
QString commit() const;
int commitIndex() const;
QString resetFlag() const;
LogChangeWidget *widget() const;
private:
LogChangeWidget *m_widget;
......@@ -90,6 +96,33 @@ private:
QComboBox *m_resetTypeComboBox;
};
class LogItemDelegate : public QStyledItemDelegate
{
protected:
LogItemDelegate(LogChangeWidget *widget);
int currentRow() const;
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const = 0;
private:
LogChangeWidget *m_widget;
};
class IconItemDelegate : public LogItemDelegate
{
public:
IconItemDelegate(LogChangeWidget *widget, const QString &icon);
virtual bool hasIcon(int row) const = 0;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
private:
QIcon m_icon;
};
} // namespace Internal
} // namespace Git
......
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