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.Content = "All local changes in working copy.";
|
|
|
|
icon.Data = FindResource("Icon.Folder") as Geometry;
|
|
|
|
} else if (changes.Count == 1) {
|
|
|
|
txtPath.Content = changes[0].Path;
|
|
|
|
} else {
|
|
|
|
txtPath.Content = $"Total {changes.Count} changes ...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <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();
|
2020-08-03 01:23:00 -07:00
|
|
|
popup?.Lock();
|
2020-07-03 00:24:31 -07:00
|
|
|
await Task.Run(() => repo.Discard(changes));
|
2020-08-03 01:23:00 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|