Commit 25c8a36d authored by Jonathan Verner's avatar Jonathan Verner Committed by Milian Wolff
Browse files

Update the stash manager to show more information about stashes.

- use the newly defined method in the previous commit to get information
  about stashes
- show the stack position, branch & parent commit description for each
  stash item
- show the date-time of each stash as a tooltip
- make the stash dialog resizable (now that it shows more information,
  which not always fits)
- fix tooltip for the drop button
- separate the close button from the others (instead of the drop button)
- make the stash list extend to the bottom of the dialog
parent d8c30800
Pipeline #236637 passed with stage
in 36 minutes and 32 seconds
......@@ -29,9 +29,8 @@ StashManagerDialog::StashManagerDialog(const QDir& stashed, GitPlugin* plugin, Q
{
setWindowTitle(i18nc("@title:window", "Stash Manager"));
m_mainWidget = new QWidget(this);
m_ui = new Ui::StashManager;
m_ui->setupUi(m_mainWidget);
m_ui->setupUi(this);
auto* m = new StashModel(stashed, plugin, this);
m_ui->stashView->setModel(m);
......@@ -45,7 +44,7 @@ StashManagerDialog::StashManagerDialog(const QDir& stashed, GitPlugin* plugin, Q
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &StashManagerDialog::reject);
m_mainWidget->setEnabled(false); //we won't enable it until we have the model with data and selection
setEnabled(false); //we won't enable it until we have the model with data and selection
}
StashManagerDialog::~StashManagerDialog()
......@@ -57,14 +56,14 @@ void StashManagerDialog::stashesFound()
{
QModelIndex firstIdx=m_ui->stashView->model()->index(0, 0);
m_ui->stashView->setCurrentIndex(firstIdx);
m_mainWidget->setEnabled(true);
setEnabled(true);
}
QString StashManagerDialog::selection() const
{
QModelIndex idx = m_ui->stashView->currentIndex();
Q_ASSERT(idx.isValid());
return idx.data().toString();
return idx.data(StashModel::RefRole).toString();
}
void StashManagerDialog::runStash(const QStringList& arguments)
......@@ -72,7 +71,7 @@ void StashManagerDialog::runStash(const QStringList& arguments)
VcsJob* job = m_plugin->gitStash(m_dir, arguments, OutputJob::Verbose);
connect(job, &VcsJob::result, this, &StashManagerDialog::accept);
m_mainWidget->setEnabled(false);
setEnabled(false);
ICore::self()->runController()->registerJob(job);
}
......@@ -136,26 +135,29 @@ void StashManagerDialog::branchClicked()
StashModel::StashModel(const QDir& dir, GitPlugin* git, QObject* parent)
: QStandardItemModel(parent)
{
VcsJob* job=git->gitStash(dir, QStringList(QStringLiteral("list")), OutputJob::Silent);
auto job = git->stashList(dir, OutputJob::Silent);
connect(job, &VcsJob::finished, this, &StashModel::stashListReady);
ICore::self()->runController()->registerJob(job);
}
void StashModel::stashListReady(KJob* _job)
{
auto* job = qobject_cast<DVcsJob*>(_job);
const QList<QByteArray> output = job->rawOutput().split('\n');
for (const QByteArray& line : output) {
const QList<QByteArray> fields = line.split(':');
QList<QStandardItem*> elements;
elements.reserve(fields.size());
for (const QByteArray& field : fields) {
elements += new QStandardItem(QString::fromUtf8(field.trimmed()));
}
appendRow(elements);
}
auto* job = qobject_cast<VcsJob*>(_job);
for(const auto& s_item: job->fetchResults().value<QList<GitPlugin::StashItem>>()) {
const QString itemValue = i18nc("%1: stack depth, %2: branch, %3: parent description", "%1. %2: %3",
QString::number(s_item.stackDepth), s_item.branch, s_item.parentDescription);
auto* item = new QStandardItem(itemValue);
item->setData(s_item.shortRef, StashModel::RefRole);
item->setData(s_item.parentSHA, StashModel::CommitHashRole);
item->setData(s_item.parentDescription, StashModel::CommitDescRole);
item->setData(s_item.branch, StashModel::BranchRole);
item->setData(s_item.message, StashModel::MessageRole);
item->setData(s_item.creationTime, StashModel::DateRole);
item->setData(
i18n("%1 created on %2", s_item.branch, s_item.creationTime.toString()),
Qt::ToolTipRole
);
appendRow(item);
};
}
......@@ -36,7 +36,6 @@ class StashManagerDialog : public QDialog
void runStash(const QStringList& arguments);
Ui::StashManager* m_ui;
QWidget* m_mainWidget;
GitPlugin* m_plugin;
QDir m_dir;
};
......@@ -45,6 +44,14 @@ class StashModel : public QStandardItemModel
{
Q_OBJECT
public:
enum ItemRoles {
RefRole = Qt::UserRole+1, /**< the stash item ref*/
MessageRole, /**< the message associated with the stash item (possibly empty)**/
CommitHashRole, /**< a short hash of the commit on which the stash was made */
CommitDescRole, /**< a brief description of the commit on which the stash was made (possibly empty) */
BranchRole, /**< the name of the branch on which the stash was made (possibly empty)*/
DateRole, /**< the date when the stash was created */
};
explicit StashModel(const QDir& dir, GitPlugin* git, QObject* parent = nullptr);
private Q_SLOTS:
......
......@@ -6,21 +6,28 @@
<rect>
<x>0</x>
<y>0</y>
<width>354</width>
<height>244</height>
<width>558</width>
<height>445</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QPushButton" name="apply">
<item row="5" column="1">
<widget class="QPushButton" name="drop">
<property name="toolTip">
<string comment="@info:tooltip">Apply stash's patch</string>
<string comment="@info:tooltip">Remove the selected stash</string>
</property>
<property name="text">
<string comment="@action:button">Apply</string>
<string comment="@action:button">Drop</string>
</property>
<property name="icon">
<iconset theme="dialog-ok-apply"/>
<iconset theme="edit-delete">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
......@@ -33,24 +40,60 @@
<string comment="@action:button">Pop</string>
</property>
<property name="icon">
<iconset theme="vcs-stash-pop"/>
<iconset theme="vcs-stash-pop">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="branch">
<item row="0" column="1">
<widget class="QPushButton" name="show">
<property name="toolTip">
<string comment="@info:tooltip">Create a new branch and apply the stash there, then drop the stash</string>
<string comment="@info:tooltip">Show the content of the stash</string>
</property>
<property name="text">
<string comment="@action:button">Branch</string>
<string comment="@action:button">Show</string>
</property>
<property name="icon">
<iconset theme="document-preview">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="8">
<widget class="QListView" name="stashView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="apply">
<property name="toolTip">
<string comment="@info:tooltip">Apply stash's patch</string>
</property>
<property name="text">
<string comment="@action:button">Apply</string>
</property>
<property name="icon">
<iconset theme="vcs-branch"/>
<iconset theme="dialog-ok-apply">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="6" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -63,43 +106,17 @@
</property>
</spacer>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="drop">
<property name="toolTip">
<string comment="@info:tooltip">Remove the selected branch</string>
</property>
<property name="text">
<string comment="@action:button">Drop</string>
</property>
<property name="icon">
<iconset theme="edit-delete"/>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="show">
<item row="3" column="1">
<widget class="QPushButton" name="branch">
<property name="toolTip">
<string comment="@info:tooltip">Show the content of the stash</string>
<string comment="@info:tooltip">Create a new branch and apply the stash there, then drop the stash</string>
</property>
<property name="text">
<string comment="@action:button">Show</string>
<string comment="@action:button">Branch</string>
</property>
<property name="icon">
<iconset theme="document-preview"/>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="5">
<widget class="QListView" name="stashView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
<iconset theme="vcs-branch">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
......
Supports Markdown
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