sourcegit/src/UI/Discard.xaml.cs

68 lines
2.1 KiB
C#
Raw Normal View History

2020-07-03 00:24:31 -07:00
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace SourceGit.UI {
/// <summary>
/// Confirm to discard changes dialog.
/// </summary>
public partial class Discard : UserControl {
private Git.Repository repo = null;
private List<Git.Change> changes = null;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="opened"></param>
/// <param name="targets"></param>
public Discard(Git.Repository opened, List<Git.Change> targets) {
repo = opened;
changes = targets;
InitializeComponent();
if (changes == null || changes.Count == 0) {
txtPath.Text = "All local changes in working copy.";
2020-07-03 00:24:31 -07:00
icon.Data = FindResource("Icon.Folder") as Geometry;
} else if (changes.Count == 1) {
txtPath.Text = changes[0].Path;
2020-07-03 00:24:31 -07:00
} else {
txtPath.Text = $"Total {changes.Count} changes ...";
2020-07-03 00:24:31 -07:00
}
}
/// <summary>
/// Show this dialog
/// </summary>
/// <param name="opened"></param>
/// <param name="targets"></param>
public static void Show(Git.Repository opened, List<Git.Change> targets) {
2020-08-06 00:41:25 -07:00
opened.GetPopupManager()?.Show(new Discard(opened, targets));
2020-07-03 00:24:31 -07:00
}
2020-08-06 00:41:25 -07:00
/// <summary>
/// Start to discard changes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2020-07-03 00:24:31 -07:00
private async void Sure(object sender, RoutedEventArgs e) {
2020-08-06 00:41:25 -07:00
var popup = repo.GetPopupManager();
popup?.Lock();
2020-07-03 00:24:31 -07:00
await Task.Run(() => repo.Discard(changes));
popup?.Close(true);
2020-07-03 00:24:31 -07:00
}
2020-08-06 00:41:25 -07:00
/// <summary>
/// Cancel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2020-07-03 00:24:31 -07:00
private void Cancel(object sender, RoutedEventArgs e) {
2020-08-06 00:41:25 -07:00
repo.GetPopupManager()?.Close();
2020-07-03 00:24:31 -07:00
}
}
}