-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathViewModelLocator.cs
More file actions
53 lines (44 loc) · 1.79 KB
/
ViewModelLocator.cs
File metadata and controls
53 lines (44 loc) · 1.79 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
using Neptuo.Productivity.SnippetManager.Models;
using Neptuo.Productivity.SnippetManager.Variables;
using Neptuo.Productivity.SnippetManager.ViewModels;
using Neptuo.Productivity.SnippetManager.ViewModels.Commands;
namespace Neptuo.Productivity.SnippetManager.Views.DesignData;
internal class ViewModelLocator
{
private static readonly SnippetExpansionPipeline emptyPipeline = new SnippetExpansionPipeline(
new TokenSnippetVariableScanner(),
new ConfigurationVariableValueResolver(null),
new TokenSnippetTextExpander()
);
private static MainViewModel? mainViewModel;
public static MainViewModel MainViewModel
{
get
{
if (mainViewModel == null)
{
var tree = LoadSnippets();
mainViewModel = new MainViewModel(
tree,
new ApplySnippetCommand(InteropService.Instance, emptyPipeline),
new CopySnippetCommand(InteropService.Instance, emptyPipeline)
);
mainViewModel.Snippets.AddRange(tree.GetRoots());
mainViewModel.Search("");
mainViewModel.IsInitializing = false;
}
return mainViewModel;
}
}
private static ISnippetTree LoadSnippets()
{
SnippetProviderContext ctx = new SnippetProviderContext();
void Add(string title, string text, string? description = null)
=> ctx.Add(new SnippetModel(title, text, description, SnippetPriority.High));
Add("C# class", "using System;", "public class Class...");
Add("Maps", "https://maps.google.com");
Add("GitHub - dotnet - runtime", "https://github.com/dotnet/runtime");
Add("Money", "https://app.money.neptuo.com");
return ctx;
}
}