forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepositoryCommandPalette.cs
More file actions
124 lines (108 loc) · 3.45 KB
/
Copy pathRepositoryCommandPalette.cs
File metadata and controls
124 lines (108 loc) · 3.45 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
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
namespace SourceGit.ViewModels
{
public class RepositoryCommandPaletteCmd
{
public string Key { get; set; }
public Action Action { get; set; }
public string Label => $"{App.Text(Key)}...";
public RepositoryCommandPaletteCmd(string key, Action action)
{
Key = key;
Action = action;
}
}
public class RepositoryCommandPalette : ICommandPalette
{
public List<RepositoryCommandPaletteCmd> VisibleCmds
{
get => _visibleCmds;
private set => SetProperty(ref _visibleCmds, value);
}
public RepositoryCommandPaletteCmd SelectedCmd
{
get => _selectedCmd;
set => SetProperty(ref _selectedCmd, value);
}
public string Filter
{
get => _filter;
set
{
if (SetProperty(ref _filter, value))
UpdateVisible();
}
}
public RepositoryCommandPalette(Launcher launcher, Repository repo)
{
_launcher = launcher;
_repo = repo;
_cmds.Add(new("FileHistory", () =>
{
var sub = new FileHistoryCommandPalette(_launcher, _repo.FullPath);
_launcher.OpenCommandPalette(sub);
}));
_cmds.Add(new("Blame", () =>
{
var sub = new BlameCommandPalette(_launcher, _repo.FullPath);
_launcher.OpenCommandPalette(sub);
}));
_cmds.Add(new("Merge", () =>
{
var sub = new MergeCommandPalette(_launcher, _repo);
_launcher.OpenCommandPalette(sub);
}));
_cmds.Add(new("BranchCompare", () =>
{
var sub = new BranchCompareCommandPalette(_launcher, _repo);
_launcher.OpenCommandPalette(sub);
}));
_visibleCmds = _cmds;
}
public override void Cleanup()
{
_launcher = null;
_repo = null;
_cmds.Clear();
_visibleCmds.Clear();
_selectedCmd = null;
_filter = null;
}
public void ClearFilter()
{
Filter = string.Empty;
}
public void Exec()
{
if (_selectedCmd != null)
_selectedCmd.Action?.Invoke();
else
_launcher?.CancelCommandPalette();
}
private void UpdateVisible()
{
if (string.IsNullOrEmpty(_filter))
{
VisibleCmds = _cmds;
}
else
{
var visible = new List<RepositoryCommandPaletteCmd>();
foreach (var cmd in VisibleCmds)
{
if (cmd.Key.Contains(_filter, StringComparison.OrdinalIgnoreCase) ||
cmd.Label.Contains(_filter, StringComparison.OrdinalIgnoreCase))
visible.Add(cmd);
}
VisibleCmds = visible;
}
}
private Launcher _launcher = null;
private Repository _repo = null;
private List<RepositoryCommandPaletteCmd> _cmds = [];
private List<RepositoryCommandPaletteCmd> _visibleCmds = [];
private RepositoryCommandPaletteCmd _selectedCmd = null;
private string _filter;
}
}