forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitModuleForm.cs
100 lines (86 loc) · 3.52 KB
/
GitModuleForm.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
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
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
using GitCommands;
using GitUI.Infrastructure.Telemetry;
using GitUI.Script;
namespace GitUI
{
// NOTE do not make this class abstract as it breaks the WinForms designer in VS
/// <summary>Base <see cref="Form"/> that provides access to <see cref="GitModule"/> and <see cref="GitUICommands"/>.</summary>
public class GitModuleForm : GitExtensionsForm, IGitUICommandsSource
{
/// <inheritdoc />
public event EventHandler<GitUICommandsChangedEventArgs>? UICommandsChanged;
/// <summary>
/// Indicates that the process is run by unit tests runner.
/// </summary>
internal static bool IsUnitTestActive { get; set; }
public virtual RevisionGridControl? RevisionGridControl { get => null; }
private GitUICommands? _uiCommands;
/// <inheritdoc />
[Browsable(false)]
public GitUICommands UICommands
{
get
{
// If this exception is seen, it's because the parameterless constructor was called.
// That constructor is only for use by the VS designer, and translation unit tests.
// Using it at run time is an error.
return _uiCommands
?? throw new InvalidOperationException(
$"{nameof(UICommands)} is null. {GetType().FullName} was constructed incorrectly.");
}
protected set
{
var oldCommands = _uiCommands;
_uiCommands = value ?? throw new ArgumentNullException(nameof(value));
OnUICommandsChanged(new GitUICommandsChangedEventArgs(oldCommands));
}
}
/// <summary>Gets a <see cref="GitModule"/> reference.</summary>
[Browsable(false)]
public GitModule Module => UICommands.Module;
[Obsolete("For VS designer and translation test only. Do not remove.")]
protected GitModuleForm()
{
if (!IsDesignMode && !IsUnitTestActive)
{
throw new InvalidOperationException(
"This constructor is only to be called by the Visual Studio designer, and the translation unit tests.");
}
}
protected GitModuleForm(GitUICommands? commands, bool enablePositionRestore)
: base(enablePositionRestore)
{
if (commands is null && _uiCommands is null)
{
// In some cases we may want to initialise a form without a module,
// e.g. a process dialog that executes a git command which is completely self contained.
}
else
{
UICommands = commands;
}
DiagnosticsClient.TrackPageView(GetType().FullName);
}
protected GitModuleForm([NotNull] GitUICommands commands)
: this(commands, enablePositionRestore: true)
{
}
protected override CommandStatus ExecuteCommand(int command)
{
CommandStatus result = ScriptRunner.ExecuteScriptCommand(this, Module, command, UICommands, RevisionGridControl);
if (!result.Executed)
{
result = base.ExecuteCommand(command);
}
return result;
}
protected virtual void OnUICommandsChanged(GitUICommandsChangedEventArgs e)
{
UICommandsChanged?.Invoke(this, e);
}
}
}