refactor(PopupManager): rewrite popup

This commit is contained in:
leo 2020-08-06 15:41:25 +08:00
parent 28e3a1bb27
commit 7558bbd4f2
34 changed files with 183 additions and 221 deletions

View file

@ -28,40 +28,13 @@ namespace SourceGit {
} }
} }
/// <summary>
/// Error handler.
/// </summary>
public static Action<string> OnError {
get;
set;
}
/// <summary> /// <summary>
/// Raise error message. /// Raise error message.
/// </summary> /// </summary>
/// <param name="message"></param> /// <param name="message"></param>
public static void RaiseError(string message) { public static void RaiseError(string msg) {
OnError?.Invoke(message);
}
/// <summary>
/// Get popup manager by repository
/// </summary>
/// <param name="repo"></param>
/// <returns></returns>
public static UI.PopupManager GetPopupManager(Git.Repository repo) {
var main = Current.MainWindow as UI.Launcher; var main = Current.MainWindow as UI.Launcher;
if (main == null) return null; main.Dispatcher.Invoke(() => main.Errors.Add(msg));
if (repo == null) return (main.Tabs[0].Page as UI.Manager).popupManager;
for (int i = 1; i < main.Tabs.Count; i++) {
var opened = main.Tabs[i];
if (opened.Repo.Path == repo.Path) {
return (opened.Page as UI.Dashboard).popupManager;
}
}
return null;
} }
/// <summary> /// <summary>

View file

@ -34,8 +34,7 @@ namespace SourceGit.UI {
/// </summary> /// </summary>
/// <param name="repo"></param> /// <param name="repo"></param>
public static void Show(Git.Repository repo) { public static void Show(Git.Repository repo) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new AddSubmodule(repo));
popup?.Show(new AddSubmodule(repo));
} }
#region EVENTS #region EVENTS
@ -58,7 +57,7 @@ namespace SourceGit.UI {
if (Validation.GetHasError(txtPath)) return; if (Validation.GetHasError(txtPath)) return;
var recursive = chkRecursive.IsChecked == true; var recursive = chkRecursive.IsChecked == true;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => repo.AddSubmodule(RepoURL, LocalPath, recursive, msg => { await Task.Run(() => repo.AddSubmodule(RepoURL, LocalPath, recursive, msg => {
@ -68,7 +67,7 @@ namespace SourceGit.UI {
} }
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
#endregion #endregion
} }

View file

@ -52,8 +52,7 @@ namespace SourceGit.UI {
/// </summary> /// </summary>
/// <param name="opened"></param> /// <param name="opened"></param>
public static void Show(Git.Repository opened) { public static void Show(Git.Repository opened) {
var popup = App.GetPopupManager(opened); opened.GetPopupManager()?.Show(new Apply(opened));
popup?.Show(new Apply(opened));
} }
/// <summary> /// <summary>
@ -83,7 +82,7 @@ namespace SourceGit.UI {
txtPatchFile.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtPatchFile.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtPatchFile)) return; if (Validation.GetHasError(txtPatchFile)) return;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
var mode = combWhitespaceOptions.SelectedItem as WhitespaceOption; var mode = combWhitespaceOptions.SelectedItem as WhitespaceOption;
@ -99,7 +98,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -29,8 +29,7 @@ namespace SourceGit.UI {
/// <param name="repo"></param> /// <param name="repo"></param>
/// <param name="commit"></param> /// <param name="commit"></param>
public static void Show(Git.Repository repo, Git.Commit commit) { public static void Show(Git.Repository repo, Git.Commit commit) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new CherryPick(repo, commit));
popup?.Show(new CherryPick(repo, commit));
} }
/// <summary> /// <summary>
@ -40,9 +39,7 @@ namespace SourceGit.UI {
/// <param name="e"></param> /// <param name="e"></param>
private void Start(object sender, RoutedEventArgs e) { private void Start(object sender, RoutedEventArgs e) {
repo.CherryPick(commitSHA, chkCommitChanges.IsChecked != true); repo.CherryPick(commitSHA, chkCommitChanges.IsChecked != true);
repo.GetPopupManager()?.Close();
var popup = App.GetPopupManager(repo);
popup?.Close();
} }
/// <summary> /// <summary>
@ -51,8 +48,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Close();
popup?.Close();
} }
} }
} }

View file

@ -9,6 +9,7 @@ namespace SourceGit.UI {
/// Clone dialog. /// Clone dialog.
/// </summary> /// </summary>
public partial class Clone : UserControl { public partial class Clone : UserControl {
private PopupManager popup = null;
/// <summary> /// <summary>
/// Remote repository /// Remote repository
@ -33,19 +34,12 @@ namespace SourceGit.UI {
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
public Clone() { public Clone(PopupManager mgr) {
ParentFolder = App.Preference.GitDefaultCloneDir; ParentFolder = App.Preference.GitDefaultCloneDir;
popup = mgr;
InitializeComponent(); InitializeComponent();
} }
/// <summary>
/// Show clone dialog.
/// </summary>
public static void Show() {
var popup = App.GetPopupManager(null);
popup?.Show(new Clone());
}
/// <summary> /// <summary>
/// Select parent folder. /// Select parent folder.
/// </summary> /// </summary>
@ -92,7 +86,6 @@ namespace SourceGit.UI {
rName = RemoteName; rName = RemoteName;
} }
var popup = App.GetPopupManager(null);
popup.Lock(); popup.Lock();
var repo = await Task.Run(() => { var repo = await Task.Run(() => {
@ -113,7 +106,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(null).Close(); popup.Close();
} }
} }
} }

View file

@ -43,8 +43,7 @@ namespace SourceGit.UI {
/// </summary> /// </summary>
/// <param name="repo"></param> /// <param name="repo"></param>
public static void Show(Git.Repository repo) { public static void Show(Git.Repository repo) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new Configure(repo));
popup?.Show(new Configure(repo));
} }
#region EVENTS #region EVENTS
@ -64,7 +63,7 @@ namespace SourceGit.UI {
} }
private void Close(object sender, RoutedEventArgs e) { private void Close(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
#endregion #endregion
} }

View file

@ -58,9 +58,7 @@ namespace SourceGit.UI {
dialog.basedOnDesc.Content = branch.Name; dialog.basedOnDesc.Content = branch.Name;
if (!branch.IsLocal) dialog.txtName.Text = branch.Name.Substring(branch.Remote.Length + 1); if (!branch.IsLocal) dialog.txtName.Text = branch.Name.Substring(branch.Remote.Length + 1);
repo.GetPopupManager()?.Show(dialog);
var popup = App.GetPopupManager(repo);
popup?.Show(dialog);
} }
/// <summary> /// <summary>
@ -74,8 +72,7 @@ namespace SourceGit.UI {
dialog.basedOnType.Data = dialog.FindResource("Icon.Tag") as Geometry; dialog.basedOnType.Data = dialog.FindResource("Icon.Tag") as Geometry;
dialog.basedOnDesc.Content = tag.Name; dialog.basedOnDesc.Content = tag.Name;
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(dialog);
popup?.Show(dialog);
} }
/// <summary> /// <summary>
@ -89,8 +86,7 @@ namespace SourceGit.UI {
dialog.basedOnType.Data = dialog.FindResource("Icon.Commit") as Geometry; dialog.basedOnType.Data = dialog.FindResource("Icon.Commit") as Geometry;
dialog.basedOnDesc.Content = $"{commit.ShortSHA} {commit.Subject}"; dialog.basedOnDesc.Content = $"{commit.ShortSHA} {commit.Subject}";
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(dialog);
popup?.Show(dialog);
} }
/// <summary> /// <summary>
@ -102,7 +98,7 @@ namespace SourceGit.UI {
txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtName)) return; if (Validation.GetHasError(txtName)) return;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
bool checkout = chkCheckout.IsChecked == true; bool checkout = chkCheckout.IsChecked == true;
@ -135,7 +131,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -52,8 +52,7 @@ namespace SourceGit.UI {
dialog.basedOnType.Data = dialog.FindResource("Icon.Branch") as Geometry; dialog.basedOnType.Data = dialog.FindResource("Icon.Branch") as Geometry;
dialog.basedOnDesc.Content = branch.Name; dialog.basedOnDesc.Content = branch.Name;
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(dialog);
popup?.Show(dialog);
} }
/// <summary> /// <summary>
@ -67,8 +66,7 @@ namespace SourceGit.UI {
dialog.basedOnType.Data = dialog.FindResource("Icon.Commit") as Geometry; dialog.basedOnType.Data = dialog.FindResource("Icon.Commit") as Geometry;
dialog.basedOnDesc.Content = $"{commit.ShortSHA} {commit.Subject}"; dialog.basedOnDesc.Content = $"{commit.ShortSHA} {commit.Subject}";
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(dialog);
popup?.Show(dialog);
} }
/// <summary> /// <summary>
@ -82,8 +80,7 @@ namespace SourceGit.UI {
Git.Tag.Add(repo, TagName, based, tagMessage.Text); Git.Tag.Add(repo, TagName, based, tagMessage.Text);
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Close();
popup?.Close();
} }
/// <summary> /// <summary>
@ -92,7 +89,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -959,7 +959,7 @@ namespace SourceGit.UI {
sub.Name = Path.GetFileName(path); sub.Name = Path.GetFileName(path);
sub.Parent = repo; sub.Parent = repo;
if (!(App.Current.MainWindow as Launcher).GotoRepo(sub)) sub.Open(); if (!sub.BringUpTab()) sub.Open();
} }
#endregion #endregion

View file

@ -28,8 +28,7 @@ namespace SourceGit.UI {
/// <param name="opened"></param> /// <param name="opened"></param>
/// <param name="branch"></param> /// <param name="branch"></param>
public static void Show(Git.Repository opened, Git.Branch branch) { public static void Show(Git.Repository opened, Git.Branch branch) {
var popup = App.GetPopupManager(opened); opened.GetPopupManager()?.Show(new DeleteBranch(opened, branch));
popup?.Show(new DeleteBranch(opened, branch));
} }
/// <summary> /// <summary>
@ -38,7 +37,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) { private async void Sure(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => branch.Delete(repo)); await Task.Run(() => branch.Delete(repo));
popup?.Close(true); popup?.Close(true);
@ -50,7 +49,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -29,8 +29,7 @@ namespace SourceGit.UI {
/// <param name="opened"></param> /// <param name="opened"></param>
/// <param name="remote"></param> /// <param name="remote"></param>
public static void Show(Git.Repository opened, string remote) { public static void Show(Git.Repository opened, string remote) {
var popup = App.GetPopupManager(opened); opened.GetPopupManager()?.Show(new DeleteRemote(opened, remote));
popup?.Show(new DeleteRemote(opened, remote));
} }
/// <summary> /// <summary>
@ -39,7 +38,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) { private async void Sure(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => Git.Remote.Delete(repo, remote)); await Task.Run(() => Git.Remote.Delete(repo, remote));
popup?.Close(true); popup?.Close(true);
@ -51,7 +50,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -30,8 +30,7 @@ namespace SourceGit.UI {
/// <param name="repo"></param> /// <param name="repo"></param>
/// <param name="tag"></param> /// <param name="tag"></param>
public static void Show(Git.Repository repo, Git.Tag tag) { public static void Show(Git.Repository repo, Git.Tag tag) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new DeleteTag(repo, tag));
popup?.Show(new DeleteTag(repo, tag));
} }
/// <summary> /// <summary>
@ -40,7 +39,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private async void Start(object sender, RoutedEventArgs e) { private async void Start(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
var push = chkWithRemote.IsChecked == true; var push = chkWithRemote.IsChecked == true;
@ -55,7 +54,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -40,19 +40,28 @@ namespace SourceGit.UI {
/// <param name="opened"></param> /// <param name="opened"></param>
/// <param name="targets"></param> /// <param name="targets"></param>
public static void Show(Git.Repository opened, List<Git.Change> targets) { public static void Show(Git.Repository opened, List<Git.Change> targets) {
var popup = App.GetPopupManager(opened); opened.GetPopupManager()?.Show(new Discard(opened, targets));
popup?.Show(new Discard(opened, targets));
} }
/// <summary>
/// Start to discard changes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) { private async void Sure(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => repo.Discard(changes)); await Task.Run(() => repo.Discard(changes));
popup?.Close(true); popup?.Close(true);
} }
/// <summary>
/// Cancel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -40,8 +40,7 @@ namespace SourceGit.UI {
/// <param name="repo"></param> /// <param name="repo"></param>
/// <param name="preferRemote"></param> /// <param name="preferRemote"></param>
public static void Show(Git.Repository repo, string preferRemote = null) { public static void Show(Git.Repository repo, string preferRemote = null) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new Fetch(repo, preferRemote));
popup?.Show(new Fetch(repo, preferRemote));
} }
/// <summary> /// <summary>
@ -52,7 +51,7 @@ namespace SourceGit.UI {
private async void Start(object sender, RoutedEventArgs e) { private async void Start(object sender, RoutedEventArgs e) {
bool prune = chkPrune.IsChecked == true; bool prune = chkPrune.IsChecked == true;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
if (chkFetchAll.IsChecked == true) { if (chkFetchAll.IsChecked == true) {
@ -71,7 +70,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View file

@ -36,8 +36,7 @@ namespace SourceGit.UI {
txtBranchType.Content = "Hotfix :"; txtBranchType.Content = "Hotfix :";
break; break;
default: default:
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Close();
popup?.Close();
return; return;
} }
@ -50,8 +49,7 @@ namespace SourceGit.UI {
/// <param name="repo"></param> /// <param name="repo"></param>
/// <param name="branch"></param> /// <param name="branch"></param>
public static void Show(Git.Repository repo, Git.Branch branch) { public static void Show(Git.Repository repo, Git.Branch branch) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new GitFlowFinishBranch(repo, branch));
popup?.Show(new GitFlowFinishBranch(repo, branch));
} }
/// <summary> /// <summary>
@ -60,7 +58,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) { private async void Sure(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => repo.FinishGitFlowBranch(branch)); await Task.Run(() => repo.FinishGitFlowBranch(branch));
popup?.Close(true); popup?.Close(true);
@ -72,7 +70,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -26,8 +26,7 @@ namespace SourceGit.UI {
/// </summary> /// </summary>
/// <param name="repo"></param> /// <param name="repo"></param>
public static void Show(Git.Repository repo) { public static void Show(Git.Repository repo) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new GitFlowSetup(repo));
popup?.Show(new GitFlowSetup(repo));
} }
/// <summary> /// <summary>
@ -36,7 +35,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) { private async void Sure(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
var master = txtMaster.Text; var master = txtMaster.Text;
@ -56,7 +55,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
/// <summary> /// <summary>

View file

@ -51,8 +51,7 @@ namespace SourceGit.UI {
nameValidator.Prefix = hotfixPrefix; nameValidator.Prefix = hotfixPrefix;
break; break;
default: default:
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Close();
popup?.Close();
return; return;
} }
} }
@ -63,8 +62,7 @@ namespace SourceGit.UI {
/// <param name="repo"></param> /// <param name="repo"></param>
/// <param name="type"></param> /// <param name="type"></param>
public static void Show(Git.Repository repo, Git.Branch.Type type) { public static void Show(Git.Repository repo, Git.Branch.Type type) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new GitFlowStartBranch(repo, type));
popup?.Show(new GitFlowStartBranch(repo, type));
} }
/// <summary> /// <summary>
@ -76,7 +74,7 @@ namespace SourceGit.UI {
txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtName)) return; if (Validation.GetHasError(txtName)) return;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => repo.StartGitFlowBranch(type, SubName)); await Task.Run(() => repo.StartGitFlowBranch(type, SubName));
popup?.Close(true); popup?.Close(true);
@ -88,7 +86,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -8,34 +8,27 @@ namespace SourceGit.UI {
/// `git init` confirm panel. /// `git init` confirm panel.
/// </summary> /// </summary>
public partial class Init : UserControl { public partial class Init : UserControl {
private PopupManager popup = null;
private string workingDir = null; private string workingDir = null;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
/// <param name="mgr"></param>
/// <param name="path"></param> /// <param name="path"></param>
public Init(string path) { public Init(PopupManager mgr, string path) {
popup = mgr;
workingDir = path; workingDir = path;
InitializeComponent(); InitializeComponent();
txtPath.Content = path; txtPath.Content = path;
} }
/// <summary>
/// Show this dialog.
/// </summary>
/// <param name="path"></param>
public static void Show(string path) {
var popup = App.GetPopupManager(null);
popup.Show(new Init(path));
}
/// <summary> /// <summary>
/// Do `git init` /// Do `git init`
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) { private async void Sure(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(null);
popup.Lock(); popup.Lock();
await Task.Run(() => { await Task.Run(() => {
@ -59,7 +52,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(null).Close(); popup.Close();
} }
} }
} }

View file

@ -255,7 +255,7 @@
HorizontalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
Panel.ZIndex="100"> Panel.ZIndex="100">
<ItemsControl Margin="4" Width="300" Height="Auto" ItemsSource="{Binding Alerts, ElementName=me}"> <ItemsControl Margin="4" Width="300" Height="Auto" ItemsSource="{Binding Errors, ElementName=me}">
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid x:Name="item" Height="Auto" Width="300" Margin="0,8,0,0"> <Grid x:Name="item" Height="Auto" Width="300" Margin="0,8,0,0">
@ -272,12 +272,12 @@
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding Title}" FontWeight="DemiBold"/> <Label Grid.Row="0" Content="ERROR" FontWeight="DemiBold"/>
<TextBlock Grid.Row="1" Margin="6,8" Text="{Binding Message}" Foreground="{StaticResource Brush.FG}" TextWrapping="Wrap"/> <TextBlock Grid.Row="1" Margin="6,8" Text="{Binding}" Foreground="{StaticResource Brush.FG}" TextWrapping="Wrap"/>
<Button <Button
Grid.Row="2" Grid.Row="2"
Margin="4,0" Margin="4,0"
Click="RemoveAlert" Click="RemoveError"
Content="CLOSE" Content="CLOSE"
Style="{StaticResource Style.Button.AccentBordered}" Style="{StaticResource Style.Button.AccentBordered}"
BorderBrush="{StaticResource Brush.FG}" BorderBrush="{StaticResource Brush.FG}"

View file

@ -21,18 +21,10 @@ namespace SourceGit.UI {
public object Page { get; set; } public object Page { get; set; }
} }
/// <summary>
/// Alert data.
/// </summary>
public class Alert {
public string Title { get; set; }
public string Message { get; set; }
}
/// <summary> /// <summary>
/// Alerts. /// Alerts.
/// </summary> /// </summary>
public ObservableCollection<Alert> Alerts { get; set; } = new ObservableCollection<Alert>(); public ObservableCollection<string> Errors { get; set; } = new ObservableCollection<string>();
/// <summary> /// <summary>
/// Opened tabs. /// Opened tabs.
@ -43,19 +35,17 @@ namespace SourceGit.UI {
/// Constructor /// Constructor
/// </summary> /// </summary>
public Launcher() { public Launcher() {
App.OnError = msg => {
ShowAlert(new Alert() { Title = "ERROR", Message = msg });
};
Git.Repository.OnOpen = repo => { Git.Repository.OnOpen = repo => {
Dispatcher.Invoke(() => { Dispatcher.Invoke(() => {
var page = new Dashboard(repo);
var tab = new Tab() { var tab = new Tab() {
Title = repo.Parent == null ? repo.Name : $"{repo.Parent.Name} : {repo.Name}", Title = repo.Parent == null ? repo.Name : $"{repo.Parent.Name} : {repo.Name}",
Tooltip = repo.Path, Tooltip = repo.Path,
Repo = repo, Repo = repo,
Page = new Dashboard(repo), Page = page,
}; };
repo.SetPopupManager(page.popupManager);
Tabs.Add(tab); Tabs.Add(tab);
openedTabs.SelectedItem = tab; openedTabs.SelectedItem = tab;
}); });
@ -71,23 +61,6 @@ namespace SourceGit.UI {
openedTabs.SelectedItem = Tabs[0]; openedTabs.SelectedItem = Tabs[0];
} }
/// <summary>
/// Goto opened repository.
/// </summary>
/// <param name="repo"></param>
/// <returns></returns>
public bool GotoRepo(Git.Repository repo) {
for (int i = 1; i < Tabs.Count; i++) {
var opened = Tabs[i];
if (opened.Repo.Path == repo.Path) {
openedTabs.SelectedItem = opened;
return true;
}
}
return false;
}
#region LAYOUT_CONTENT #region LAYOUT_CONTENT
/// <summary> /// <summary>
/// Close repository tab. /// Close repository tab.
@ -98,12 +71,11 @@ namespace SourceGit.UI {
var tab = (sender as Button).DataContext as Tab; var tab = (sender as Button).DataContext as Tab;
if (tab == null || tab.Repo == null) return; if (tab == null || tab.Repo == null) return;
var popup = (tab.Page as Dashboard).popupManager;
if (popup.IsLocked()) popup.Close(true);
Tabs.Remove(tab); Tabs.Remove(tab);
tab.Page = null; tab.Page = null;
tab.Repo.RemovePopup();
tab.Repo.Close(); tab.Repo.Close();
tab.Repo = null;
} }
/// <summary> /// <summary>
@ -128,22 +100,14 @@ namespace SourceGit.UI {
about.ShowDialog(); about.ShowDialog();
} }
/// <summary>
/// Show alert.
/// </summary>
/// <param name="alert"></param>
private void ShowAlert(Alert alert) {
Dispatcher.Invoke(() => Alerts.Add(alert));
}
/// <summary> /// <summary>
/// Remove an alert. /// Remove an alert.
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void RemoveAlert(object sender, RoutedEventArgs e) { private void RemoveError(object sender, RoutedEventArgs e) {
var alert = (sender as Button).DataContext as Alert; var alert = (sender as Button).DataContext as string;
Alerts.Remove(alert); Errors.Remove(alert);
} }
#endregion #endregion
@ -222,4 +186,29 @@ namespace SourceGit.UI {
} }
#endregion #endregion
} }
/// <summary>
/// Extension methods for repository.
/// </summary>
public static class RepositoryTabBindings {
/// <summary>
/// Bring up tab of repository if it was opened before.
/// </summary>
/// <param name="repo"></param>
/// <returns></returns>
public static bool BringUpTab(this Git.Repository repo) {
var main = App.Current.MainWindow as Launcher;
for (int i = 1; i < main.Tabs.Count; i++) {
var opened = main.Tabs[i];
if (opened.Repo.Path == repo.Path) {
main.openedTabs.SelectedItem = opened;
return true;
}
}
return false;
}
}
} }

View file

@ -61,7 +61,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void CloneRepo(object sender, RoutedEventArgs e) { private void CloneRepo(object sender, RoutedEventArgs e) {
if (MakeSureReady()) Clone.Show(); if (MakeSureReady()) popupManager.Show(new Clone(popupManager));
} }
#endregion #endregion
@ -350,7 +350,7 @@ namespace SourceGit.UI {
private void ShowBrief(Git.Repository repo) { private void ShowBrief(Git.Repository repo) {
if (repo == null || !Git.Repository.IsValid(repo.Path)) { if (repo == null || !Git.Repository.IsValid(repo.Path)) {
if (Directory.Exists(repo.Path)) { if (Directory.Exists(repo.Path)) {
Init.Show(repo.Path); popupManager.Show(new Init(popupManager, repo.Path));
} else { } else {
App.RaiseError("Path is NOT valid git repository or has been removed."); App.RaiseError("Path is NOT valid git repository or has been removed.");
App.Preference.RemoveRepository(repo.Path); App.Preference.RemoveRepository(repo.Path);
@ -426,7 +426,7 @@ namespace SourceGit.UI {
if (!Git.Repository.IsValid(path)) { if (!Git.Repository.IsValid(path)) {
if (Directory.Exists(path)) { if (Directory.Exists(path)) {
Init.Show(path); popupManager.Show(new Init(popupManager, path));
return; return;
} }
@ -435,7 +435,7 @@ namespace SourceGit.UI {
} }
var repo = App.Preference.AddRepository(path, ""); var repo = App.Preference.AddRepository(path, "");
if (!(App.Current.MainWindow as Launcher).GotoRepo(repo)) repo.Open(); if (!repo.BringUpTab()) repo.Open();
} }
/// <summary> /// <summary>

View file

@ -53,8 +53,7 @@ namespace SourceGit.UI {
/// <param name="source"></param> /// <param name="source"></param>
/// <param name="dest"></param> /// <param name="dest"></param>
public static void Show(Git.Repository opened, string source, string dest) { public static void Show(Git.Repository opened, string source, string dest) {
var popup = App.GetPopupManager(opened); opened.GetPopupManager()?.Show(new Merge(opened, source, dest));
popup?.Show(new Merge(opened, source, dest));
} }
/// <summary> /// <summary>
@ -65,7 +64,7 @@ namespace SourceGit.UI {
/// <param name="dest"></param> /// <param name="dest"></param>
public static void StartDirectly(Git.Repository opened, string source, string dest) { public static void StartDirectly(Git.Repository opened, string source, string dest) {
var merge = new Merge(opened, source, dest); var merge = new Merge(opened, source, dest);
var popup = App.GetPopupManager(opened); var popup = opened.GetPopupManager();
popup?.Show(merge); popup?.Show(merge);
popup?.Lock(); popup?.Lock();
@ -83,7 +82,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private async void Start(object sender, RoutedEventArgs e) { private async void Start(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
var branch = sourceBranch.Content as string; var branch = sourceBranch.Content as string;
@ -99,7 +98,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
@ -111,4 +112,42 @@ namespace SourceGit.UI {
Close(); Close();
} }
} }
/// <summary>
/// Extension methods for Git.Repository
/// </summary>
public static class RepositoryPopupBindings {
private static Dictionary<string, PopupManager> popups = new Dictionary<string, PopupManager>();
/// <summary>
/// Set popup manager for given repo.
/// </summary>
/// <param name="repo"></param>
/// <param name="popup"></param>
public static void SetPopupManager(this Git.Repository repo, PopupManager popup) {
if (popups.ContainsKey(repo.Path)) popups[repo.Path] = popup;
else popups.Add(repo.Path, popup);
}
/// <summary>
/// Remove popup manager by given repo.
/// </summary>
/// <param name="repo"></param>
public static void RemovePopup(this Git.Repository repo) {
if (popups.ContainsKey(repo.Path)) {
popups[repo.Path].Unlock();
popups.Remove(repo.Path);
}
}
/// <summary>
///
/// </summary>
/// <param name="repo"></param>
/// <returns></returns>
public static PopupManager GetPopupManager(this Git.Repository repo) {
if (popups.ContainsKey(repo.Path)) return popups[repo.Path];
return null;
}
}
} }

View file

@ -30,8 +30,7 @@ namespace SourceGit.UI {
/// <param name="opened">Opened repository</param> /// <param name="opened">Opened repository</param>
/// <param name="preferRemoteBranch">Prefered remote branch</param> /// <param name="preferRemoteBranch">Prefered remote branch</param>
public static void Show(Git.Repository opened, string preferRemoteBranch = null) { public static void Show(Git.Repository opened, string preferRemoteBranch = null) {
var popup = App.GetPopupManager(opened); opened.GetPopupManager()?.Show(new Pull(opened, preferRemoteBranch));
popup?.Show(new Pull(opened, preferRemoteBranch));
} }
/// <summary> /// <summary>
@ -77,7 +76,7 @@ namespace SourceGit.UI {
if (remote == null || branch == null) return; if (remote == null || branch == null) return;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => repo.Pull(remote, branch.Substring(branch.IndexOf('/')+1), msg => popup?.UpdateStatus(msg), rebase, autoStash)); await Task.Run(() => repo.Pull(remote, branch.Substring(branch.IndexOf('/')+1), msg => popup?.UpdateStatus(msg), rebase, autoStash));
popup?.Close(true); popup?.Close(true);
@ -89,7 +88,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
/// <summary> /// <summary>

View file

@ -29,8 +29,7 @@ namespace SourceGit.UI {
/// <param name="repo"></param> /// <param name="repo"></param>
/// <param name="prefer"></param> /// <param name="prefer"></param>
public static void Show(Git.Repository repo, Git.Branch prefer = null) { public static void Show(Git.Repository repo, Git.Branch prefer = null) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new Push(repo, prefer));
popup?.Show(new Push(repo, prefer));
} }
/// <summary> /// <summary>
@ -45,7 +44,7 @@ namespace SourceGit.UI {
} }
var push = new Push(repo, current); var push = new Push(repo, current);
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Show(push); popup?.Show(push);
popup?.Lock(); popup?.Lock();
@ -98,7 +97,7 @@ namespace SourceGit.UI {
remoteBranch = remoteBranch.Substring(0, remoteBranch.Length - 6); remoteBranch = remoteBranch.Substring(0, remoteBranch.Length - 6);
} }
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => repo.Push(remote, localBranch.Name, remoteBranch, msg => popup?.UpdateStatus(msg), tags, track, force)); await Task.Run(() => repo.Push(remote, localBranch.Name, remoteBranch, msg => popup?.UpdateStatus(msg), tags, track, force));
popup?.Close(true); popup?.Close(true);
@ -110,7 +109,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
/// <summary> /// <summary>

View file

@ -32,8 +32,7 @@ namespace SourceGit.UI {
/// <param name="repo"></param> /// <param name="repo"></param>
/// <param name="tag"></param> /// <param name="tag"></param>
public static void Show(Git.Repository repo, Git.Tag tag) { public static void Show(Git.Repository repo, Git.Tag tag) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new PushTag(repo, tag));
popup?.Show(new PushTag(repo, tag));
} }
/// <summary> /// <summary>
@ -45,7 +44,7 @@ namespace SourceGit.UI {
var remote = combRemotes.SelectedItem as Git.Remote; var remote = combRemotes.SelectedItem as Git.Remote;
if (remote == null) return; if (remote == null) return;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => Git.Tag.Push(repo, tag.Name, remote.Name)); await Task.Run(() => Git.Tag.Push(repo, tag.Name, remote.Name));
popup?.Close(true); popup?.Close(true);
@ -57,8 +56,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Close();
popup?.Close();
} }
} }
} }

View file

@ -38,8 +38,7 @@ namespace SourceGit.UI {
dialog.type.Data = dialog.FindResource("Icon.Branch") as Geometry; dialog.type.Data = dialog.FindResource("Icon.Branch") as Geometry;
dialog.desc.Content = branch.Name; dialog.desc.Content = branch.Name;
var popup = App.GetPopupManager(opened); opened.GetPopupManager()?.Show(dialog);
popup?.Show(dialog);
} }
/// <summary> /// <summary>
@ -57,8 +56,7 @@ namespace SourceGit.UI {
dialog.type.Data = dialog.FindResource("Icon.Commit") as Geometry; dialog.type.Data = dialog.FindResource("Icon.Commit") as Geometry;
dialog.desc.Content = $"{commit.ShortSHA} {commit.Subject}"; dialog.desc.Content = $"{commit.ShortSHA} {commit.Subject}";
var popup = App.GetPopupManager(opened); opened.GetPopupManager()?.Show(dialog);
popup?.Show(dialog);
} }
/// <summary> /// <summary>
@ -67,7 +65,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private async void Start(object sender, RoutedEventArgs e) { private async void Start(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
var autoStash = chkAutoStash.IsChecked == true; var autoStash = chkAutoStash.IsChecked == true;
@ -77,7 +75,7 @@ namespace SourceGit.UI {
} }
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -44,7 +44,7 @@ namespace SourceGit.UI {
/// <param name="opened"></param> /// <param name="opened"></param>
/// <param name="editing"></param> /// <param name="editing"></param>
public static void Show(Git.Repository opened, Git.Remote editing = null) { public static void Show(Git.Repository opened, Git.Remote editing = null) {
App.GetPopupManager(opened)?.Show(new Remote(opened, editing)); opened.GetPopupManager()?.Show(new Remote(opened, editing));
} }
/// <summary> /// <summary>
@ -59,7 +59,7 @@ namespace SourceGit.UI {
txtUrl.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtUrl.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtUrl)) return; if (Validation.GetHasError(txtUrl)) return;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => { await Task.Run(() => {
@ -79,7 +79,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -38,7 +38,7 @@ namespace SourceGit.UI {
/// <param name="opened"></param> /// <param name="opened"></param>
/// <param name="branch"></param> /// <param name="branch"></param>
public static void Show(Git.Repository opened, Git.Branch branch) { public static void Show(Git.Repository opened, Git.Branch branch) {
App.GetPopupManager(opened)?.Show(new RenameBranch(opened, branch)); opened.GetPopupManager()?.Show(new RenameBranch(opened, branch));
} }
/// <summary> /// <summary>
@ -50,7 +50,7 @@ namespace SourceGit.UI {
txtNewName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); txtNewName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtNewName)) return; if (Validation.GetHasError(txtNewName)) return;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => branch.Rename(repo, NewName)); await Task.Run(() => branch.Rename(repo, NewName));
popup?.Close(true); popup?.Close(true);
@ -62,7 +62,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -59,7 +59,7 @@ namespace SourceGit.UI {
var current = repo.CurrentBranch(); var current = repo.CurrentBranch();
if (current == null) return; if (current == null) return;
App.GetPopupManager(repo)?.Show(new Reset(repo, current, commit)); repo.GetPopupManager()?.Show(new Reset(repo, current, commit));
} }
/// <summary> /// <summary>
@ -71,7 +71,7 @@ namespace SourceGit.UI {
var mode = combMode.SelectedItem as Mode; var mode = combMode.SelectedItem as Mode;
if (mode == null) return; if (mode == null) return;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => repo.Reset(revision, mode.Arg)); await Task.Run(() => repo.Reset(revision, mode.Arg));
popup?.Close(true); popup?.Close(true);
@ -83,7 +83,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -30,8 +30,7 @@ namespace SourceGit.UI {
/// <param name="repo"></param> /// <param name="repo"></param>
/// <param name="commit"></param> /// <param name="commit"></param>
public static void Show(Git.Repository repo, Git.Commit commit) { public static void Show(Git.Repository repo, Git.Commit commit) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new Revert(repo, commit));
popup?.Show(new Revert(repo, commit));
} }
/// <summary> /// <summary>
@ -41,7 +40,7 @@ namespace SourceGit.UI {
/// <param name="e"></param> /// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) { private async void Sure(object sender, RoutedEventArgs e) {
bool autoCommit = chkCommit.IsChecked == true; bool autoCommit = chkCommit.IsChecked == true;
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Lock(); popup?.Lock();
await Task.Run(() => repo.Revert(sha, autoCommit)); await Task.Run(() => repo.Revert(sha, autoCommit));
popup?.Close(true); popup?.Close(true);
@ -53,8 +52,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Close();
popup?.Close();
} }
} }
} }

View file

@ -28,8 +28,7 @@ namespace SourceGit.UI {
/// <param name="repo">Opened repository</param> /// <param name="repo">Opened repository</param>
/// <param name="files">Special files to stash</param> /// <param name="files">Special files to stash</param>
public static void Show(Git.Repository repo, List<string> files) { public static void Show(Git.Repository repo, List<string> files) {
var popup = App.GetPopupManager(repo); repo.GetPopupManager()?.Show(new Stash(repo, files));
popup?.Show(new Stash(repo, files));
} }
/// <summary> /// <summary>
@ -42,7 +41,7 @@ namespace SourceGit.UI {
string message = txtName.Text; string message = txtName.Text;
Git.Stash.Push(repo, includeUntracked, message, files); Git.Stash.Push(repo, includeUntracked, message, files);
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
/// <summary> /// <summary>
@ -51,7 +50,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) { private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close(); repo.GetPopupManager()?.Close();
} }
} }
} }

View file

@ -23,7 +23,7 @@ namespace SourceGit.UI {
/// <param name="job"></param> /// <param name="job"></param>
public static void Show(Git.Repository repo, Action job) { public static void Show(Git.Repository repo, Action job) {
var dialog = new Waiting(); var dialog = new Waiting();
var popup = App.GetPopupManager(repo); var popup = repo.GetPopupManager();
popup?.Show(dialog); popup?.Show(dialog);
popup?.Lock(); popup?.Lock();