forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageBoxes.cs
154 lines (115 loc) · 8.67 KB
/
MessageBoxes.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Windows.Forms;
using GitCommands;
using GitCommands.Config;
using GitUIPluginInterfaces;
using ResourceManager;
namespace GitUI
{
public class MessageBoxes : Translate
{
private readonly TranslationString _cannotFindRevisionFilter = new(@"Revision ""{0}"" is not visible in the revision grid. Remove the revision filter.");
private readonly TranslationString _cannotFindRevisionCaption = new("Cannot find revision");
private readonly TranslationString _noRevisionFoundError = new("No revision found.");
private readonly TranslationString _archiveRevisionCaption = new("Archive revision");
private readonly TranslationString _failedToRunShell = new("Failed to run shell");
private readonly TranslationString _notValidGitDirectory = new("The current directory is not a valid git repository.");
private readonly TranslationString _unresolvedMergeConflictsCaption = new("Merge conflicts");
private readonly TranslationString _unresolvedMergeConflicts = new("There are unresolved merge conflicts, solve conflicts now?");
private readonly TranslationString _middleOfRebaseCaption = new("Rebase");
private readonly TranslationString _middleOfRebase = new("You are in the middle of a rebase, continue rebase?");
private readonly TranslationString _middleOfPatchApplyCaption = new("Patch apply");
private readonly TranslationString _middleOfPatchApply = new("You are in the middle of a patch apply, continue patch apply?");
private const string _putty = "PuTTY";
private readonly TranslationString _pageantNotFound = new("Cannot load SSH key. PuTTY is not configured properly.");
private readonly TranslationString _serverHostkeyNotCachedText =
new("The server's host key is not cached in the registry.\n\nDo you want to trust this host key and then try again?");
private readonly TranslationString _updateSubmodules = new("Update submodules");
private readonly TranslationString _theRepositorySubmodules = new("Update submodules on checkout?");
private readonly TranslationString _updateSubmodulesToo = new("Since this repository has submodules, it's necessary to update them on every checkout.\r\n\r\nThis will just checkout on the submodule the commit determined by the superproject.");
private readonly TranslationString _rememberChoice = new("Remember choice");
private readonly TranslationString _reason = new("Reason");
private readonly TranslationString _selectOnlyOneOrTwoRevisions = new("Select only one or two revisions. Abort.");
private readonly TranslationString _shellNotFoundCaption = new("Shell not found");
private readonly TranslationString _shellNotFound = new("The selected shell is not installed, or is not on your path.");
private readonly TranslationString _resetChangesCaption = new("Reset changes");
private readonly TranslationString _submoduleDirectoryDoesNotExist = new(@"The directory ""{0}"" does not exist for submodule ""{1}"".");
private readonly TranslationString _directoryDoesNotExist = new(@"The directory ""{0}"" does not exist.");
private readonly TranslationString _cannotOpenSubmoduleCaption = new("Cannot open submodule");
private readonly TranslationString _cannotOpenGitExtensionsCaption = new("Cannot open Git Extensions");
// internal for FormTranslate
internal MessageBoxes()
{
Translator.Translate(this, AppSettings.CurrentTranslation);
}
private static MessageBoxes? instance;
private static MessageBoxes Instance => instance ??= new();
public static void RevisionFilteredInGrid(IWin32Window? owner, ObjectId objectId)
=> ShowError(owner, string.Format(Instance._cannotFindRevisionFilter.Text, objectId.ToShortString()), Instance._cannotFindRevisionCaption.Text);
public static void CannotFindGitRevision(IWin32Window? owner)
=> ShowError(owner, Instance._noRevisionFoundError.Text, Instance._cannotFindRevisionCaption.Text);
public static void FailedToRunShell(IWin32Window? owner, string shell, Exception ex)
=> ShowError(owner, $"{Instance._failedToRunShell.Text} {shell.Quote()}.{Environment.NewLine}"
+ $"{Instance._reason.Text}: {ex.Message}");
public static void NotValidGitDirectory(IWin32Window? owner)
=> ShowError(owner, Instance._notValidGitDirectory.Text);
public static void ShowGitConfigurationExceptionMessage(IWin32Window? owner, GitConfigurationException exception)
=> Show(owner,
string.Format(ResourceManager.TranslatedStrings.GeneralGitConfigExceptionMessage,
exception.ConfigPath, Environment.NewLine, (exception.InnerException ?? exception).Message),
ResourceManager.TranslatedStrings.GeneralGitConfigExceptionCaption,
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
public static bool MiddleOfRebase(IWin32Window? owner)
=> Confirm(owner, Instance._middleOfRebase.Text, Instance._middleOfRebaseCaption.Text);
public static bool MiddleOfPatchApply(IWin32Window? owner)
=> Confirm(owner, Instance._middleOfPatchApply.Text, Instance._middleOfPatchApplyCaption.Text);
public static void PAgentNotFound(IWin32Window? owner)
=> ShowError(owner, Instance._pageantNotFound.Text, _putty);
public static void SelectOnlyOneOrTwoRevisions(IWin32Window? owner)
=> ShowError(owner, Instance._selectOnlyOneOrTwoRevisions.Text, Instance._archiveRevisionCaption.Text);
public static void SubmoduleDirectoryDoesNotExist(IWin32Window? owner, string directory, string submoduleName)
=> ShowError(owner, string.Format(Instance._submoduleDirectoryDoesNotExist.Text, directory, submoduleName), Instance._cannotOpenSubmoduleCaption.Text);
public static void SubmoduleDirectoryDoesNotExist(IWin32Window? owner, string directory)
=> ShowError(owner, string.Format(Instance._directoryDoesNotExist.Text, directory), Instance._cannotOpenSubmoduleCaption.Text);
public static void GitExtensionsDirectoryDoesNotExist(IWin32Window? owner, string directory)
=> ShowError(owner, string.Format(Instance._directoryDoesNotExist.Text, directory), Instance._cannotOpenGitExtensionsCaption.Text);
public static bool CacheHostkey(IWin32Window? owner)
=> Confirm(owner, Instance._serverHostkeyNotCachedText.Text, "SSH");
public static bool ConfirmResetSelectedFiles(IWin32Window? owner, string text)
=> Confirm(owner, text, Instance._resetChangesCaption.Text);
public static bool ConfirmResolveMergeConflicts(IWin32Window? owner)
=> Confirm(owner, Instance._unresolvedMergeConflicts.Text, Instance._unresolvedMergeConflictsCaption.Text);
public static bool ConfirmUpdateSubmodules(IWin32Window? owner)
{
TaskDialogPage page = new()
{
Text = Instance._updateSubmodulesToo.Text,
Heading = Instance._theRepositorySubmodules.Text,
Caption = Instance._updateSubmodules.Text,
Icon = TaskDialogIcon.Information,
Buttons = { TaskDialogButton.Yes, TaskDialogButton.No },
Verification = new TaskDialogVerificationCheckBox
{
Text = Instance._rememberChoice.Text
},
SizeToContent = true
};
bool result = TaskDialog.ShowDialog(owner?.Handle ?? IntPtr.Zero, page) == TaskDialogButton.Yes;
if (page.Verification.Checked)
{
AppSettings.DontConfirmUpdateSubmodulesOnCheckout = result;
AppSettings.UpdateSubmodulesOnCheckout = result;
}
return result;
}
public static void ShellNotFound(IWin32Window? owner)
=> ShowError(owner, Instance._shellNotFound.Text, Instance._shellNotFoundCaption.Text);
public static void ShowError(IWin32Window? owner, string text, string? caption = null)
=> Show(owner, text, caption ?? TranslatedStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
private static bool Confirm(IWin32Window? owner, string text, string caption)
=> Show(owner, text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
private static DialogResult Show(IWin32Window? owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
=> MessageBox.Show(owner, text, caption, buttons, icon);
}
}