using System.Collections.Generic; using System.Windows; using System.Windows.Controls; namespace SourceGit.UI { /// /// Stashes viewer. /// public partial class Stashes : UserControl { private Git.Repository repo = null; private string selectedStash = null; /// /// File tree node. /// public class Node { public string FilePath { get; set; } = ""; public string OriginalPath { get; set; } = ""; public string Name { get; set; } = ""; public bool IsFile { get; set; } = false; public bool IsNodeExpanded { get; set; } = true; public Git.Change.Status Status { get; set; } = Git.Change.Status.None; public List Children { get; set; } = new List(); } /// /// Constructor. /// public Stashes() { InitializeComponent(); } /// /// Cleanup /// /// /// private void Cleanup(object sender, RoutedEventArgs e) { stashList.ItemsSource = null; changeList.ItemsSource = null; diff.Reset(); } /// /// Set data. /// /// /// public void SetData(Git.Repository opened, List stashes) { repo = opened; selectedStash = null; stashList.ItemsSource = stashes; changeList.ItemsSource = null; diff.Reset(); } /// /// Stash list selection changed event. /// /// /// private void StashSelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count != 1) return; var stash = e.AddedItems[0] as Git.Stash; if (stash == null) return; selectedStash = stash.SHA; diff.Reset(); changeList.ItemsSource = stash.GetChanges(repo); } /// /// File selection changed in TreeView. /// /// /// private void FileSelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count != 1) return; var change = e.AddedItems[0] as Git.Change; if (change == null) return; diff.Diff(repo, $"{selectedStash}^ {selectedStash}", change.Path, change.OriginalPath); } /// /// Stash context menu. /// /// /// private void StashContextMenuOpening(object sender, ContextMenuEventArgs ev) { var stash = (sender as ListViewItem).DataContext as Git.Stash; if (stash == null) return; var apply = new MenuItem(); apply.Header = "Apply"; apply.Click += (o, e) => stash.Apply(repo); var pop = new MenuItem(); pop.Header = "Pop"; pop.Click += (o, e) => stash.Pop(repo); var delete = new MenuItem(); delete.Header = "Drop"; delete.Click += (o, e) => stash.Drop(repo); var menu = new ContextMenu(); menu.Items.Add(apply); menu.Items.Add(pop); menu.Items.Add(delete); menu.IsOpen = true; ev.Handled = true; } } }