Menu

[38707f]: / FormUnstash.cs  Maximize  Restore  History

Download this file

115 lines (104 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Windows.Forms;
namespace GitForce
{
/// <summary>
/// Form implementing the git unstash command
/// </summary>
public partial class FormUnstash : Form
{
/// <summary>
/// Currently selected stash string (stash id part only)
/// </summary>
private string stash;
public FormUnstash()
{
InitializeComponent();
ClassWinGeometry.Restore(this);
PopulateStashList();
}
/// <summary>
/// Form is closing.
/// </summary>
private void FormUnstashFormClosing(object sender, FormClosingEventArgs e)
{
ClassWinGeometry.Save(this);
}
/// <summary>
/// Populate list with existing stashes
/// </summary>
private void PopulateStashList()
{
listStashes.Items.Clear();
ExecResult result = App.Repos.Current.Run("stash list");
if (result.Success())
{
string[] response = result.stdout.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (var stash in response)
listStashes.Items.Add(stash);
}
// Disable buttons (in the case the stash list was empty)
// but re-enable them once we have a stash to select (select the top one by default)
btApply.Enabled = btRemove.Enabled = btShow.Enabled = false;
if (listStashes.Items.Count > 0)
{
string s = listStashes.Items[0].ToString();
stash = s.Substring(0, s.IndexOf(':'));
listStashes.SelectedIndex = 0;
btApply.Enabled = btRemove.Enabled = btShow.Enabled = true;
}
}
/// <summary>
/// User clicked on one of the selected stash entries.
/// Set the proper control enables.
/// </summary>
private void ListStashesSelectedIndexChanged(object sender, EventArgs e)
{
string s = listStashes.SelectedItem.ToString();
stash = s.Substring(0, s.IndexOf(':'));
}
/// <summary>
/// Apply the selected stash
/// </summary>
private void BtUnstashClick(object sender, EventArgs e)
{
string cmd = String.Format("stash {0} {1}",
checkKeepStash.Checked ? "apply" : "pop",
stash);
App.Repos.Current.RunCmd(cmd);
}
/// <summary>
/// Remove selected stash from the list of stashes
/// </summary>
private void BtRemoveClick(object sender, EventArgs e)
{
string cmd = "stash drop " + stash;
App.Repos.Current.RunCmd(cmd);
PopulateStashList();
}
/// <summary>
/// Show more information on the selected stash
/// </summary>
private void BtShowClick(object sender, EventArgs e)
{
FormShowChangelist formShowChangelist = new FormShowChangelist();
DialogResult result;
do
{
formShowChangelist.LoadChangelist(stash);
// Walk the list of stashes up and down
result = formShowChangelist.ShowDialog();
if (result == DialogResult.No)
{
if (listStashes.SelectedIndex < listStashes.Items.Count - 1)
listStashes.SelectedIndex++;
}
if (result == DialogResult.Yes)
{
if (listStashes.SelectedIndex > 0)
listStashes.SelectedIndex--;
}
} while (result != DialogResult.Cancel);
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.