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>
/// Raise error message.
/// </summary>
/// <param name="message"></param>
public static void RaiseError(string message) {
OnError?.Invoke(message);
}
/// <summary>
/// Get popup manager by repository
/// </summary>
/// <param name="repo"></param>
/// <returns></returns>
public static UI.PopupManager GetPopupManager(Git.Repository repo) {
public static void RaiseError(string msg) {
var main = Current.MainWindow as UI.Launcher;
if (main == null) return null;
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;
main.Dispatcher.Invoke(() => main.Errors.Add(msg));
}
/// <summary>

View file

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

View file

@ -52,8 +52,7 @@ namespace SourceGit.UI {
/// </summary>
/// <param name="opened"></param>
public static void Show(Git.Repository opened) {
var popup = App.GetPopupManager(opened);
popup?.Show(new Apply(opened));
opened.GetPopupManager()?.Show(new Apply(opened));
}
/// <summary>
@ -83,7 +82,7 @@ namespace SourceGit.UI {
txtPatchFile.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtPatchFile)) return;
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
var mode = combWhitespaceOptions.SelectedItem as WhitespaceOption;
@ -99,7 +98,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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="commit"></param>
public static void Show(Git.Repository repo, Git.Commit commit) {
var popup = App.GetPopupManager(repo);
popup?.Show(new CherryPick(repo, commit));
repo.GetPopupManager()?.Show(new CherryPick(repo, commit));
}
/// <summary>
@ -40,9 +39,7 @@ namespace SourceGit.UI {
/// <param name="e"></param>
private void Start(object sender, RoutedEventArgs e) {
repo.CherryPick(commitSHA, chkCommitChanges.IsChecked != true);
var popup = App.GetPopupManager(repo);
popup?.Close();
repo.GetPopupManager()?.Close();
}
/// <summary>
@ -51,8 +48,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo);
popup?.Close();
repo.GetPopupManager()?.Close();
}
}
}

View file

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

View file

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

View file

@ -58,9 +58,7 @@ namespace SourceGit.UI {
dialog.basedOnDesc.Content = branch.Name;
if (!branch.IsLocal) dialog.txtName.Text = branch.Name.Substring(branch.Remote.Length + 1);
var popup = App.GetPopupManager(repo);
popup?.Show(dialog);
repo.GetPopupManager()?.Show(dialog);
}
/// <summary>
@ -74,8 +72,7 @@ namespace SourceGit.UI {
dialog.basedOnType.Data = dialog.FindResource("Icon.Tag") as Geometry;
dialog.basedOnDesc.Content = tag.Name;
var popup = App.GetPopupManager(repo);
popup?.Show(dialog);
repo.GetPopupManager()?.Show(dialog);
}
/// <summary>
@ -89,8 +86,7 @@ namespace SourceGit.UI {
dialog.basedOnType.Data = dialog.FindResource("Icon.Commit") as Geometry;
dialog.basedOnDesc.Content = $"{commit.ShortSHA} {commit.Subject}";
var popup = App.GetPopupManager(repo);
popup?.Show(dialog);
repo.GetPopupManager()?.Show(dialog);
}
/// <summary>
@ -102,7 +98,7 @@ namespace SourceGit.UI {
txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtName)) return;
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
bool checkout = chkCheckout.IsChecked == true;
@ -135,7 +131,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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.basedOnDesc.Content = branch.Name;
var popup = App.GetPopupManager(repo);
popup?.Show(dialog);
repo.GetPopupManager()?.Show(dialog);
}
/// <summary>
@ -67,8 +66,7 @@ namespace SourceGit.UI {
dialog.basedOnType.Data = dialog.FindResource("Icon.Commit") as Geometry;
dialog.basedOnDesc.Content = $"{commit.ShortSHA} {commit.Subject}";
var popup = App.GetPopupManager(repo);
popup?.Show(dialog);
repo.GetPopupManager()?.Show(dialog);
}
/// <summary>
@ -82,8 +80,7 @@ namespace SourceGit.UI {
Git.Tag.Add(repo, TagName, based, tagMessage.Text);
var popup = App.GetPopupManager(repo);
popup?.Close();
repo.GetPopupManager()?.Close();
}
/// <summary>
@ -92,7 +89,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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.Parent = repo;
if (!(App.Current.MainWindow as Launcher).GotoRepo(sub)) sub.Open();
if (!sub.BringUpTab()) sub.Open();
}
#endregion

View file

@ -28,8 +28,7 @@ namespace SourceGit.UI {
/// <param name="opened"></param>
/// <param name="branch"></param>
public static void Show(Git.Repository opened, Git.Branch branch) {
var popup = App.GetPopupManager(opened);
popup?.Show(new DeleteBranch(opened, branch));
opened.GetPopupManager()?.Show(new DeleteBranch(opened, branch));
}
/// <summary>
@ -38,7 +37,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
await Task.Run(() => branch.Delete(repo));
popup?.Close(true);
@ -50,7 +49,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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="remote"></param>
public static void Show(Git.Repository opened, string remote) {
var popup = App.GetPopupManager(opened);
popup?.Show(new DeleteRemote(opened, remote));
opened.GetPopupManager()?.Show(new DeleteRemote(opened, remote));
}
/// <summary>
@ -39,7 +38,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
await Task.Run(() => Git.Remote.Delete(repo, remote));
popup?.Close(true);
@ -51,7 +50,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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="tag"></param>
public static void Show(Git.Repository repo, Git.Tag tag) {
var popup = App.GetPopupManager(repo);
popup?.Show(new DeleteTag(repo, tag));
repo.GetPopupManager()?.Show(new DeleteTag(repo, tag));
}
/// <summary>
@ -40,7 +39,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private async void Start(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
var push = chkWithRemote.IsChecked == true;
@ -55,7 +54,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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="targets"></param>
public static void Show(Git.Repository opened, List<Git.Change> targets) {
var popup = App.GetPopupManager(opened);
popup?.Show(new Discard(opened, targets));
opened.GetPopupManager()?.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) {
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
await Task.Run(() => repo.Discard(changes));
popup?.Close(true);
}
/// <summary>
/// Cancel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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="preferRemote"></param>
public static void Show(Git.Repository repo, string preferRemote = null) {
var popup = App.GetPopupManager(repo);
popup?.Show(new Fetch(repo, preferRemote));
repo.GetPopupManager()?.Show(new Fetch(repo, preferRemote));
}
/// <summary>
@ -52,7 +51,7 @@ namespace SourceGit.UI {
private async void Start(object sender, RoutedEventArgs e) {
bool prune = chkPrune.IsChecked == true;
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
if (chkFetchAll.IsChecked == true) {
@ -71,7 +70,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close();
repo.GetPopupManager()?.Close();
}
}
}

View file

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

View file

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

View file

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

View file

@ -51,8 +51,7 @@ namespace SourceGit.UI {
nameValidator.Prefix = hotfixPrefix;
break;
default:
var popup = App.GetPopupManager(repo);
popup?.Close();
repo.GetPopupManager()?.Close();
return;
}
}
@ -63,8 +62,7 @@ namespace SourceGit.UI {
/// <param name="repo"></param>
/// <param name="type"></param>
public static void Show(Git.Repository repo, Git.Branch.Type type) {
var popup = App.GetPopupManager(repo);
popup?.Show(new GitFlowStartBranch(repo, type));
repo.GetPopupManager()?.Show(new GitFlowStartBranch(repo, type));
}
/// <summary>
@ -76,7 +74,7 @@ namespace SourceGit.UI {
txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtName)) return;
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
await Task.Run(() => repo.StartGitFlowBranch(type, SubName));
popup?.Close(true);
@ -88,7 +86,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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.
/// </summary>
public partial class Init : UserControl {
private PopupManager popup = null;
private string workingDir = null;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="mgr"></param>
/// <param name="path"></param>
public Init(string path) {
public Init(PopupManager mgr, string path) {
popup = mgr;
workingDir = path;
InitializeComponent();
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>
/// Do `git init`
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(null);
popup.Lock();
await Task.Run(() => {
@ -59,7 +52,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(null).Close();
popup.Close();
}
}
}

View file

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

View file

@ -21,18 +21,10 @@ namespace SourceGit.UI {
public object Page { get; set; }
}
/// <summary>
/// Alert data.
/// </summary>
public class Alert {
public string Title { get; set; }
public string Message { get; set; }
}
/// <summary>
/// Alerts.
/// </summary>
public ObservableCollection<Alert> Alerts { get; set; } = new ObservableCollection<Alert>();
public ObservableCollection<string> Errors { get; set; } = new ObservableCollection<string>();
/// <summary>
/// Opened tabs.
@ -43,19 +35,17 @@ namespace SourceGit.UI {
/// Constructor
/// </summary>
public Launcher() {
App.OnError = msg => {
ShowAlert(new Alert() { Title = "ERROR", Message = msg });
};
Git.Repository.OnOpen = repo => {
Dispatcher.Invoke(() => {
var page = new Dashboard(repo);
var tab = new Tab() {
Title = repo.Parent == null ? repo.Name : $"{repo.Parent.Name} : {repo.Name}",
Tooltip = repo.Path,
Repo = repo,
Page = new Dashboard(repo),
Page = page,
};
repo.SetPopupManager(page.popupManager);
Tabs.Add(tab);
openedTabs.SelectedItem = tab;
});
@ -71,23 +61,6 @@ namespace SourceGit.UI {
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
/// <summary>
/// Close repository tab.
@ -98,12 +71,11 @@ namespace SourceGit.UI {
var tab = (sender as Button).DataContext as Tab;
if (tab == null || tab.Repo == null) return;
var popup = (tab.Page as Dashboard).popupManager;
if (popup.IsLocked()) popup.Close(true);
Tabs.Remove(tab);
tab.Page = null;
tab.Repo.RemovePopup();
tab.Repo.Close();
tab.Repo = null;
}
/// <summary>
@ -128,22 +100,14 @@ namespace SourceGit.UI {
about.ShowDialog();
}
/// <summary>
/// Show alert.
/// </summary>
/// <param name="alert"></param>
private void ShowAlert(Alert alert) {
Dispatcher.Invoke(() => Alerts.Add(alert));
}
/// <summary>
/// Remove an alert.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RemoveAlert(object sender, RoutedEventArgs e) {
var alert = (sender as Button).DataContext as Alert;
Alerts.Remove(alert);
private void RemoveError(object sender, RoutedEventArgs e) {
var alert = (sender as Button).DataContext as string;
Errors.Remove(alert);
}
#endregion
@ -222,4 +186,29 @@ namespace SourceGit.UI {
}
#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="e"></param>
private void CloneRepo(object sender, RoutedEventArgs e) {
if (MakeSureReady()) Clone.Show();
if (MakeSureReady()) popupManager.Show(new Clone(popupManager));
}
#endregion
@ -350,7 +350,7 @@ namespace SourceGit.UI {
private void ShowBrief(Git.Repository repo) {
if (repo == null || !Git.Repository.IsValid(repo.Path)) {
if (Directory.Exists(repo.Path)) {
Init.Show(repo.Path);
popupManager.Show(new Init(popupManager, repo.Path));
} else {
App.RaiseError("Path is NOT valid git repository or has been removed.");
App.Preference.RemoveRepository(repo.Path);
@ -426,7 +426,7 @@ namespace SourceGit.UI {
if (!Git.Repository.IsValid(path)) {
if (Directory.Exists(path)) {
Init.Show(path);
popupManager.Show(new Init(popupManager, path));
return;
}
@ -435,7 +435,7 @@ namespace SourceGit.UI {
}
var repo = App.Preference.AddRepository(path, "");
if (!(App.Current.MainWindow as Launcher).GotoRepo(repo)) repo.Open();
if (!repo.BringUpTab()) repo.Open();
}
/// <summary>

View file

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

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@ -111,4 +112,42 @@ namespace SourceGit.UI {
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="preferRemoteBranch">Prefered remote branch</param>
public static void Show(Git.Repository opened, string preferRemoteBranch = null) {
var popup = App.GetPopupManager(opened);
popup?.Show(new Pull(opened, preferRemoteBranch));
opened.GetPopupManager()?.Show(new Pull(opened, preferRemoteBranch));
}
/// <summary>
@ -77,7 +76,7 @@ namespace SourceGit.UI {
if (remote == null || branch == null) return;
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
await Task.Run(() => repo.Pull(remote, branch.Substring(branch.IndexOf('/')+1), msg => popup?.UpdateStatus(msg), rebase, autoStash));
popup?.Close(true);
@ -89,7 +88,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) {
App.GetPopupManager(repo)?.Close();
repo.GetPopupManager()?.Close();
}
/// <summary>

View file

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

View file

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

View file

@ -38,8 +38,7 @@ namespace SourceGit.UI {
dialog.type.Data = dialog.FindResource("Icon.Branch") as Geometry;
dialog.desc.Content = branch.Name;
var popup = App.GetPopupManager(opened);
popup?.Show(dialog);
opened.GetPopupManager()?.Show(dialog);
}
/// <summary>
@ -57,8 +56,7 @@ namespace SourceGit.UI {
dialog.type.Data = dialog.FindResource("Icon.Commit") as Geometry;
dialog.desc.Content = $"{commit.ShortSHA} {commit.Subject}";
var popup = App.GetPopupManager(opened);
popup?.Show(dialog);
opened.GetPopupManager()?.Show(dialog);
}
/// <summary>
@ -67,7 +65,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private async void Start(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
var autoStash = chkAutoStash.IsChecked == true;
@ -77,7 +75,7 @@ namespace SourceGit.UI {
}
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="editing"></param>
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>
@ -59,7 +59,7 @@ namespace SourceGit.UI {
txtUrl.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtUrl)) return;
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
await Task.Run(() => {
@ -79,7 +79,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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="branch"></param>
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>
@ -50,7 +50,7 @@ namespace SourceGit.UI {
txtNewName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtNewName)) return;
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
await Task.Run(() => branch.Rename(repo, NewName));
popup?.Close(true);
@ -62,7 +62,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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();
if (current == null) return;
App.GetPopupManager(repo)?.Show(new Reset(repo, current, commit));
repo.GetPopupManager()?.Show(new Reset(repo, current, commit));
}
/// <summary>
@ -71,7 +71,7 @@ namespace SourceGit.UI {
var mode = combMode.SelectedItem as Mode;
if (mode == null) return;
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
await Task.Run(() => repo.Reset(revision, mode.Arg));
popup?.Close(true);
@ -83,7 +83,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
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="commit"></param>
public static void Show(Git.Repository repo, Git.Commit commit) {
var popup = App.GetPopupManager(repo);
popup?.Show(new Revert(repo, commit));
repo.GetPopupManager()?.Show(new Revert(repo, commit));
}
/// <summary>
@ -41,7 +40,7 @@ namespace SourceGit.UI {
/// <param name="e"></param>
private async void Sure(object sender, RoutedEventArgs e) {
bool autoCommit = chkCommit.IsChecked == true;
var popup = App.GetPopupManager(repo);
var popup = repo.GetPopupManager();
popup?.Lock();
await Task.Run(() => repo.Revert(sha, autoCommit));
popup?.Close(true);
@ -53,8 +52,7 @@ namespace SourceGit.UI {
/// <param name="sender"></param>
/// <param name="e"></param>
private void Cancel(object sender, RoutedEventArgs e) {
var popup = App.GetPopupManager(repo);
popup?.Close();
repo.GetPopupManager()?.Close();
}
}
}

View file

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