-
Notifications
You must be signed in to change notification settings - Fork 9
/
SettingsView.xaml.cs
65 lines (57 loc) · 1.95 KB
/
SettingsView.xaml.cs
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
using Flow.Launcher.Plugin;
using Flow.Plugin.VSCodeWorkspaces.WorkspacesHelper;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace Flow.Plugin.VSCodeWorkspaces
{
/// <summary>
/// Interaction logic for SettingsView.xaml
/// </summary>
public partial class SettingsView : UserControl
{
private readonly PluginInitContext _context;
private readonly Settings _settings;
public SettingsView(PluginInitContext context, Settings settings)
{
_context = context;
DataContext = _settings = settings;
InitializeComponent();
}
public void Save(object sender = null, RoutedEventArgs e = null) => _context.API.SaveSettingJsonStorage<Settings>();
private void ButtonDelete_Click(object sender, RoutedEventArgs e)
{
foreach (var ws in listView.SelectedItems.Cast<string>().ToArray())
{
_settings.CustomWorkspaces.Remove(ws);
}
Save();
}
private void ButtonAdd_Click(object sender, RoutedEventArgs e)
{
try
{
var uri = addUri.Text;
// System.Uri fails to parse vscode-remote://XXX+YYY URIs, skip them
var type = ParseVSCodeUri.GetTypeWorkspace(uri).TypeWorkspace;
if (!type.HasValue || type.Value == TypeWorkspace.Local)
{
// Converts file paths to proper URI
uri = new Uri(uri).AbsoluteUri;
}
addUri.Clear();
if (_settings.CustomWorkspaces.Contains(uri))
{
return;
}
_settings.CustomWorkspaces.Add(uri);
Save();
}
catch (Exception ex)
{
_context.API.ShowMsgError("Error", ex.Message);
}
}
}
}