This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathDialogService.cs
More file actions
112 lines (99 loc) · 3.76 KB
/
Copy pathDialogService.cs
File metadata and controls
112 lines (99 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using GitHub.Api;
using GitHub.Exports;
using GitHub.Extensions;
using GitHub.Factories;
using GitHub.Models;
using GitHub.ViewModels.Dialog;
using GitHub.ViewModels.Dialog.Clone;
namespace GitHub.Services
{
[Export(typeof(IDialogService))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class DialogService : IDialogService
{
readonly IViewViewModelFactory factory;
readonly IShowDialogService showDialog;
readonly IGitHubContextService gitHubContextService;
[ImportingConstructor]
public DialogService(
IViewViewModelFactory factory,
IShowDialogService showDialog,
IGitHubContextService gitHubContextService)
{
Guard.ArgumentNotNull(factory, nameof(factory));
Guard.ArgumentNotNull(showDialog, nameof(showDialog));
Guard.ArgumentNotNull(showDialog, nameof(gitHubContextService));
this.factory = factory;
this.showDialog = showDialog;
this.gitHubContextService = gitHubContextService;
}
public async Task<CloneDialogResult> ShowCloneDialog(IConnection connection, string url = null)
{
if (string.IsNullOrEmpty(url))
{
var clipboardContext = gitHubContextService.FindContextFromClipboard();
switch (clipboardContext?.LinkType)
{
case LinkType.Blob:
case LinkType.Repository:
url = clipboardContext?.Url;
break;
}
}
var viewModel = factory.CreateViewModel<IRepositoryCloneViewModel>();
if (url != null)
{
viewModel.Url = url;
}
if (connection != null)
{
return (CloneDialogResult)await showDialog.Show(
viewModel,
connection,
ApiClientConfiguration.RequestedScopes)
.ConfigureAwait(false);
}
else
{
return (CloneDialogResult)await showDialog.ShowWithFirstConnection(viewModel)
.ConfigureAwait(false);
}
}
public async Task ShowCreateGist(IConnection connection)
{
var viewModel = factory.CreateViewModel<IGistCreationViewModel>();
if (connection != null)
{
await viewModel.InitializeAsync(connection);
await showDialog.Show(viewModel);
}
else
{
await showDialog.ShowWithFirstConnection(viewModel);
}
}
public async Task ShowCreateRepositoryDialog(IConnection connection)
{
Guard.ArgumentNotNull(connection, nameof(connection));
var viewModel = factory.CreateViewModel<IRepositoryCreationViewModel>();
await viewModel.InitializeAsync(connection);
await showDialog.Show(viewModel);
}
public async Task<IConnection> ShowLoginDialog()
{
var viewModel = factory.CreateViewModel<ILoginViewModel>();
return (IConnection)await showDialog.Show(viewModel);
}
public async Task ShowForkDialog(LocalRepositoryModel repository, IConnection connection)
{
Guard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotNull(connection, nameof(connection));
var viewModel = factory.CreateViewModel<IForkRepositoryViewModel>();
await viewModel.InitializeAsync(repository, connection);
await showDialog.Show(viewModel);
}
}
}