Skip to content

Commit 4cc7f50

Browse files
committedJul 22, 2018
Formatting
1 parent d8f08a9 commit 4cc7f50

File tree

11 files changed

+188
-166
lines changed

11 files changed

+188
-166
lines changed
 

‎GitUI/BranchTreePanel/RepoObjectsTree.cs

+151-132
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public partial class RepoObjectsTree : GitModuleControl
1919
new TranslationString("Filter the revision grid to show this branch only\nTo show all branches, right click the revision grid, select 'view' and then the 'show all branches'");
2020

2121
private readonly List<Tree> _rootNodes = new List<Tree>();
22-
private SearchControl<string> _txtBranchCriterion;
22+
private readonly SearchControl<string> _txtBranchCriterion;
2323
private readonly CancellationTokenSequence _reloadCancellation = new CancellationTokenSequence();
2424
private CancellationToken _currentToken;
2525
private TreeNode _tagTreeRootNode;
@@ -34,9 +34,10 @@ public RepoObjectsTree()
3434
_currentToken = _reloadCancellation.Next();
3535
InitializeComponent();
3636
InitImageList();
37-
InitializeSearchBox();
38-
treeMain.PreviewKeyDown += OnPreviewKeyDown;
37+
_txtBranchCriterion = CreateSearchBox();
38+
branchSearchPanel.Controls.Add(_txtBranchCriterion, 1, 0);
3939

40+
treeMain.PreviewKeyDown += OnPreviewKeyDown;
4041
btnSearch.PreviewKeyDown += OnPreviewKeyDown;
4142
PreviewKeyDown += OnPreviewKeyDown;
4243
InitializeComplete();
@@ -49,6 +50,97 @@ public RepoObjectsTree()
4950
treeMain.NodeMouseDoubleClick += OnNodeDoubleClick;
5051
mnubtnFilterRemoteBranchInRevisionGrid.ToolTipText = _showBranchOnly.Text;
5152
mnubtnFilterLocalBranchInRevisionGrid.ToolTipText = _showBranchOnly.Text;
53+
54+
void InitImageList()
55+
{
56+
const int rowPadding = 1; // added to top and bottom, so doubled -- this value is scaled *after*, so consider 96dpi here
57+
58+
treeMain.ImageList = new ImageList
59+
{
60+
ImageSize = DpiUtil.Scale(new Size(16, 16 + rowPadding + rowPadding)), // Scale ImageSize and images scale automatically
61+
Images =
62+
{
63+
{ nameof(Images.BranchDocument), Pad(Images.BranchDocument) },
64+
{ nameof(Images.Branch), Pad(Images.Branch) },
65+
{ nameof(Images.Remote), Pad(Images.RemoteRepo) },
66+
{ nameof(Images.BitBucket), Pad(Images.BitBucket) },
67+
{ nameof(Images.GitHub), Pad(Images.GitHub) },
68+
{ nameof(Images.BranchLocalRoot), Pad(Images.BranchLocalRoot) },
69+
{ nameof(Images.BranchRemoteRoot), Pad(Images.BranchRemoteRoot) },
70+
{ nameof(Images.BranchRemote), Pad(Images.BranchRemote) },
71+
{ nameof(Images.BranchFolder), Pad(Images.BranchFolder) },
72+
{ nameof(Images.TagHorizontal), Pad(Images.TagHorizontal) },
73+
}
74+
};
75+
treeMain.SelectedImageKey = treeMain.ImageKey;
76+
77+
Image Pad(Image image)
78+
{
79+
var padded = new Bitmap(image.Width, image.Height + rowPadding + rowPadding, PixelFormat.Format32bppArgb);
80+
using (var g = Graphics.FromImage(padded))
81+
{
82+
g.DrawImageUnscaled(image, 0, rowPadding);
83+
return padded;
84+
}
85+
}
86+
}
87+
88+
SearchControl<string> CreateSearchBox()
89+
{
90+
var search = new SearchControl<string>(SearchForBranch, i => { })
91+
{
92+
Anchor = AnchorStyles.Left | AnchorStyles.Right,
93+
Name = "txtBranchCritierion",
94+
TabIndex = 1
95+
};
96+
search.OnTextEntered += () =>
97+
{
98+
OnBranchCriterionChanged(null, null);
99+
OnBtnSearchClicked(null, null);
100+
};
101+
search.TextChanged += OnBranchCriterionChanged;
102+
search.KeyDown += TxtBranchCriterion_KeyDown;
103+
search.PreviewKeyDown += OnPreviewKeyDown;
104+
return search;
105+
106+
IEnumerable<string> SearchForBranch(string arg)
107+
{
108+
return CollectFilterCandidates()
109+
.Where(r => r.IndexOf(arg, StringComparison.OrdinalIgnoreCase) != -1);
110+
}
111+
112+
IEnumerable<string> CollectFilterCandidates()
113+
{
114+
var list = new List<string>();
115+
116+
foreach (TreeNode rootNode in treeMain.Nodes)
117+
{
118+
CollectFromNodes(rootNode.Nodes);
119+
}
120+
121+
return list;
122+
123+
void CollectFromNodes(TreeNodeCollection nodes)
124+
{
125+
foreach (TreeNode node in nodes)
126+
{
127+
if (node.Tag is BaseBranchNode branch)
128+
{
129+
if (branch.Nodes.Count == 0)
130+
{
131+
list.Add(branch.FullPath);
132+
}
133+
}
134+
else
135+
{
136+
list.Add(node.Text);
137+
}
138+
139+
CollectFromNodes(node.Nodes);
140+
}
141+
}
142+
}
143+
}
52144
}
53145

54146
public void SetBranchFilterer(FilterBranchHelper filterBranchHelper)
@@ -149,133 +241,92 @@ private CancellationToken CancelBackgroundTasks()
149241
return _currentToken;
150242
}
151243

152-
private IEnumerable<string> CollectFilterCandidates()
244+
private void DoSearch()
153245
{
154-
var list = new List<string>();
246+
_txtBranchCriterion.CloseDropdown();
155247

156-
foreach (TreeNode rootNode in treeMain.Nodes)
248+
if (_searchCriteriaChanged && _searchResult != null && _searchResult.Any())
157249
{
158-
CollectFromNodes(rootNode.Nodes);
159-
}
250+
_searchCriteriaChanged = false;
251+
foreach (var coloredNode in _searchResult)
252+
{
253+
coloredNode.BackColor = SystemColors.Window;
254+
}
160255

161-
return list;
256+
_searchResult = null;
257+
if (_txtBranchCriterion.Text.IsNullOrWhiteSpace())
258+
{
259+
_txtBranchCriterion.Focus();
260+
return;
261+
}
262+
}
162263

163-
void CollectFromNodes(TreeNodeCollection nodes)
264+
if (_searchResult == null || !_searchResult.Any())
164265
{
165-
foreach (TreeNode node in nodes)
266+
if (_txtBranchCriterion.Text.IsNotNullOrWhitespace())
166267
{
167-
if (node.Tag is BaseBranchNode branch)
168-
{
169-
if (branch.Nodes.Count == 0)
170-
{
171-
list.Add(branch.FullPath);
172-
}
173-
}
174-
else
175-
{
176-
list.Add(node.Text);
177-
}
178-
179-
CollectFromNodes(node.Nodes);
268+
_searchResult = SearchTree(_txtBranchCriterion.Text, treeMain.Nodes.Cast<TreeNode>());
180269
}
181270
}
182-
}
183271

184-
private TreeNode GetNextSearchResult()
185-
{
186-
if (_searchResult == null || !_searchResult.Any())
272+
var node = GetNextSearchResult();
273+
274+
if (node == null)
187275
{
188-
return null;
276+
return;
189277
}
190278

191-
var node = _searchResult.First();
192-
_searchResult.RemoveAt(0);
193-
_searchResult.Add(node);
194-
return node;
195-
}
279+
node.EnsureVisible();
280+
treeMain.SelectedNode = node;
196281

197-
private void InitImageList()
198-
{
199-
const int rowPadding = 1; // added to top and bottom, so doubled -- this value is scaled *after*, so consider 96dpi here
282+
return;
200283

201-
treeMain.ImageList = new ImageList
284+
TreeNode GetNextSearchResult()
202285
{
203-
ImageSize = DpiUtil.Scale(new Size(16, 16 + rowPadding + rowPadding)), // Scale ImageSize and images scale automatically
204-
Images =
205-
{
206-
{ nameof(Images.BranchDocument), Pad(Images.BranchDocument) },
207-
{ nameof(Images.Branch), Pad(Images.Branch) },
208-
{ nameof(Images.Remote), Pad(Images.RemoteRepo) },
209-
{ nameof(Images.BitBucket), Pad(Images.BitBucket) },
210-
{ nameof(Images.GitHub), Pad(Images.GitHub) },
211-
{ nameof(Images.BranchLocalRoot), Pad(Images.BranchLocalRoot) },
212-
{ nameof(Images.BranchRemoteRoot), Pad(Images.BranchRemoteRoot) },
213-
{ nameof(Images.BranchRemote), Pad(Images.BranchRemote) },
214-
{ nameof(Images.BranchFolder), Pad(Images.BranchFolder) },
215-
{ nameof(Images.TagHorizontal), Pad(Images.TagHorizontal) },
216-
}
217-
};
218-
treeMain.SelectedImageKey = treeMain.ImageKey;
286+
var first = _searchResult?.FirstOrDefault();
219287

220-
Image Pad(Image image)
221-
{
222-
var padded = new Bitmap(image.Width, image.Height + rowPadding + rowPadding, PixelFormat.Format32bppArgb);
223-
using (var g = Graphics.FromImage(padded))
288+
if (first == null)
224289
{
225-
g.DrawImageUnscaled(image, 0, rowPadding);
226-
return padded;
290+
return null;
227291
}
292+
293+
_searchResult.RemoveAt(0);
294+
_searchResult.Add(first);
295+
return first;
228296
}
229-
}
230297

231-
private void InitializeSearchBox()
232-
{
233-
_txtBranchCriterion = new SearchControl<string>(SearchForBranch, i => { });
234-
_txtBranchCriterion.OnTextEntered += () =>
298+
List<TreeNode> SearchTree(string text, IEnumerable<TreeNode> nodes)
235299
{
236-
OnBranchCriterionChanged(null, null);
237-
OnBtnSearchClicked(null, null);
238-
};
239-
_txtBranchCriterion.Anchor = AnchorStyles.Left | AnchorStyles.Right;
240-
_txtBranchCriterion.Name = "txtBranchCritierion";
241-
_txtBranchCriterion.TabIndex = 1;
242-
_txtBranchCriterion.TextChanged += OnBranchCriterionChanged;
243-
_txtBranchCriterion.KeyDown += TxtBranchCriterion_KeyDown;
244-
branchSearchPanel.Controls.Add(_txtBranchCriterion, 1, 0);
245-
246-
_txtBranchCriterion.PreviewKeyDown += OnPreviewKeyDown;
247-
}
300+
var queue = new Queue<TreeNode>(nodes);
301+
var ret = new List<TreeNode>();
248302

249-
private IEnumerable<string> SearchForBranch(string arg)
250-
{
251-
return CollectFilterCandidates()
252-
.Where(r => r.IndexOf(arg, StringComparison.OrdinalIgnoreCase) != -1);
253-
}
254-
255-
private static List<TreeNode> SearchTree(string text, TreeNodeCollection nodes)
256-
{
257-
var ret = new List<TreeNode>();
258-
foreach (TreeNode node in nodes)
259-
{
260-
if (node.Tag is BaseBranchNode branch)
303+
while (queue.Count != 0)
261304
{
262-
if (branch.FullPath.IndexOf(text, StringComparison.InvariantCultureIgnoreCase) != -1)
305+
var n = queue.Dequeue();
306+
307+
if (n.Tag is BaseBranchNode branch)
263308
{
264-
AddTreeNodeToSearchResult(ret, node);
309+
if (branch.FullPath.IndexOf(text, StringComparison.InvariantCultureIgnoreCase) != -1)
310+
{
311+
AddTreeNodeToSearchResult(ret, n);
312+
}
265313
}
266-
}
267-
else
268-
{
269-
if (node.Text.IndexOf(text, StringComparison.InvariantCultureIgnoreCase) != -1)
314+
else
315+
{
316+
if (n.Text.IndexOf(text, StringComparison.InvariantCultureIgnoreCase) != -1)
317+
{
318+
AddTreeNodeToSearchResult(ret, n);
319+
}
320+
}
321+
322+
foreach (TreeNode subNode in n.Nodes)
270323
{
271-
AddTreeNodeToSearchResult(ret, node);
324+
queue.Enqueue(subNode);
272325
}
273326
}
274327

275-
ret.AddRange(SearchTree(text, node.Nodes));
328+
return ret;
276329
}
277-
278-
return ret;
279330
}
280331

281332
private void OnPreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
@@ -308,39 +359,7 @@ private void ShowTagsToolStripMenuItem_Click(object sender, EventArgs e)
308359

309360
private void OnBtnSearchClicked(object sender, EventArgs e)
310361
{
311-
_txtBranchCriterion.CloseDropdown();
312-
if (_searchCriteriaChanged && _searchResult != null && _searchResult.Any())
313-
{
314-
_searchCriteriaChanged = false;
315-
foreach (var coloredNode in _searchResult)
316-
{
317-
coloredNode.BackColor = SystemColors.Window;
318-
}
319-
320-
_searchResult = null;
321-
if (_txtBranchCriterion.Text.IsNullOrWhiteSpace())
322-
{
323-
_txtBranchCriterion.Focus();
324-
return;
325-
}
326-
}
327-
328-
if (_searchResult == null || !_searchResult.Any())
329-
{
330-
if (_txtBranchCriterion.Text.IsNotNullOrWhitespace())
331-
{
332-
_searchResult = SearchTree(_txtBranchCriterion.Text, treeMain.Nodes);
333-
}
334-
}
335-
336-
var node = GetNextSearchResult();
337-
if (node == null)
338-
{
339-
return;
340-
}
341-
342-
node.EnsureVisible();
343-
treeMain.SelectedNode = node;
362+
DoSearch();
344363
}
345364

346365
private void OnBranchCriterionChanged(object sender, EventArgs e)

‎GitUI/BuildServerIntegration/BuildServerWatcher.cs

-6
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ public void CancelBuildStatusFetchOperation()
111111
cancellationToken?.Dispose();
112112
}
113113

114-
[CanBeNull]
115114
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "http://stackoverflow.com/questions/1065168/does-disposing-streamreader-close-the-stream")]
116115
public IBuildServerCredentials GetBuildServerCredentials(IBuildServerAdapter buildServerAdapter, bool useStoredCredentialsIfExisting)
117116
{
@@ -209,11 +208,6 @@ public IBuildServerCredentials GetBuildServerCredentials(IBuildServerAdapter bui
209208
}
210209
}
211210

212-
/// <summary>
213-
/// Replace variables for the project string with the current "repo shortname"
214-
/// </summary>
215-
/// <param name="projectNames">build server specific format, compatible with the variable format</param>
216-
/// <returns>projectNames with variables replaced</returns>
217211
public string ReplaceVariables(string projectNames)
218212
{
219213
var (repoProject, repoName) = _repoNameExtractor.Get();

‎GitUI/CommandsDialogs/BuildReportTabPageExtension.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class BuildReportTabPageExtension
1818
private readonly string _caption;
1919

2020
private TabPage _buildReportTabPage;
21-
private WebBrowserCtrl _buildReportWebBrowser;
21+
private WebBrowserControl _buildReportWebBrowser;
2222
private GitRevision _selectedGitRevision;
2323
private string _url;
2424

@@ -28,7 +28,7 @@ public BuildReportTabPageExtension(TabControl tabControl, string caption)
2828
_caption = caption;
2929
}
3030

31-
public void FillBuildReport(GitRevision revision)
31+
public void FillBuildReport([CanBeNull] GitRevision revision)
3232
{
3333
if (_selectedGitRevision != null)
3434
{
@@ -122,7 +122,7 @@ private void CreateBuildReportTabPage(TabControl tabControl)
122122
Text = _caption,
123123
UseVisualStyleBackColor = true
124124
};
125-
_buildReportWebBrowser = new WebBrowserCtrl
125+
_buildReportWebBrowser = new WebBrowserControl
126126
{
127127
Dock = DockStyle.Fill
128128
};

‎GitUI/CommandsDialogs/RepoHosting/ViewPullRequestsForm.Designer.cs

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎GitUI/Editor/Diff/DiffViewerLineNumberCtrl.cs ‎GitUI/Editor/Diff/DiffViewerLineNumberControl.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace GitUI.Editor.Diff
1010
{
11-
internal class DiffViewerLineNumberCtrl : AbstractMargin
11+
internal class DiffViewerLineNumberControl : AbstractMargin
1212
{
1313
private const int TextHorizontalMargin = 4;
1414

@@ -17,7 +17,7 @@ internal class DiffViewerLineNumberCtrl : AbstractMargin
1717
private int _maxValueOfLineNum;
1818
private bool _visible = true;
1919

20-
public DiffViewerLineNumberCtrl(TextArea textArea) : base(textArea)
20+
public DiffViewerLineNumberControl(TextArea textArea) : base(textArea)
2121
{
2222
DiffLines = new Dictionary<int, DiffLineNum>();
2323
}

‎GitUI/Editor/FileViewerInternal.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial class FileViewerInternal : GitExtensionsControl, IFileViewer
2020
public new event EventHandler DoubleClick;
2121

2222
private readonly FindAndReplaceForm _findAndReplaceForm = new FindAndReplaceForm();
23-
private readonly DiffViewerLineNumberCtrl _lineNumbersControl;
23+
private readonly DiffViewerLineNumberControl _lineNumbersControl;
2424
private readonly Func<GitModule> _moduleProvider;
2525

2626
private DiffHighlightService _diffHighlightService = DiffHighlightService.Instance;
@@ -53,7 +53,7 @@ public FileViewerInternal(Func<GitModule> moduleProvider)
5353
HighlightingManager.Manager.DefaultHighlighting.SetColorFor("LineNumbers", new HighlightColor(Color.FromArgb(80, 0, 0, 0), Color.White, false, false));
5454
TextEditor.ActiveTextAreaControl.TextEditorProperties.EnableFolding = false;
5555

56-
_lineNumbersControl = new DiffViewerLineNumberCtrl(TextEditor.ActiveTextAreaControl.TextArea);
56+
_lineNumbersControl = new DiffViewerLineNumberControl(TextEditor.ActiveTextAreaControl.TextArea);
5757

5858
VRulerPosition = AppSettings.DiffVerticalRulerPosition;
5959
}

‎GitUI/GitUI.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
<Compile Include="Editor\Diff\CombinedDiffHighlightService.cs" />
310310
<Compile Include="Editor\Diff\DiffHighlightService.cs" />
311311
<Compile Include="Editor\Diff\DiffLineNumAnalyzer.cs" />
312-
<Compile Include="Editor\Diff\DiffViewerLineNumberCtrl.cs" />
312+
<Compile Include="Editor\Diff\DiffViewerLineNumberControl.cs" />
313313
<Compile Include="Editor\Diff\LinePrefixHelper.cs" />
314314
<Compile Include="Editor\Diff\LineSegmentGetter.cs" />
315315
<Compile Include="Editor\CommitMessageHighlightingStrategy.cs" />
@@ -484,7 +484,7 @@
484484
<Compile Include="UserControls\WaitSpinner.cs">
485485
<SubType>Component</SubType>
486486
</Compile>
487-
<Compile Include="UserControls\WebBrowserCtrl.cs">
487+
<Compile Include="UserControls\WebBrowserControl.cs">
488488
<SubType>Component</SubType>
489489
</Compile>
490490
<Compile Include="UserManual\UserManual.cs" />

‎GitUI/UserControls/WebBrowserCtrl.cs ‎GitUI/UserControls/WebBrowserControl.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace GitUI.UserControls
44
{
5-
internal class WebBrowserCtrl : WebBrowser
5+
internal class WebBrowserControl : WebBrowser
66
{
7-
public WebBrowserCtrl()
7+
public WebBrowserControl()
88
{
99
ScriptErrorsSuppressed = true;
1010
}

‎Plugins/BuildServerIntegration/JenkinsIntegration/JenkinsAdapter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private async Task<ResponseInfo> GetBuildInfoTaskAsync(string projectUrl, bool f
168168
}
169169

170170
// else: The server had no response (overloaded?) or a multi-branch pipeline is not configured
171-
if (timestamp == 0 && jobDescription["lastBuild"] != null && jobDescription["lastBuild"]["timestamp"] != null)
171+
if (timestamp == 0 && jobDescription["lastBuild"]?["timestamp"] != null)
172172
{
173173
timestamp = jobDescription["lastBuild"]["timestamp"].ToObject<long>();
174174
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
using System.Threading.Tasks;
2+
using JetBrains.Annotations;
23

34
namespace GitUIPluginInterfaces.BuildServerIntegration
45
{
56
public interface IBuildServerWatcher
67
{
8+
[CanBeNull]
79
IBuildServerCredentials GetBuildServerCredentials(IBuildServerAdapter buildServerAdapter, bool useStoredCredentialsIfExisting);
810

911
Task LaunchBuildServerInfoFetchOperationAsync();
1012

1113
void CancelBuildStatusFetchOperation();
1214

15+
/// <summary>
16+
/// Replace variables for the project string with the current "repo shortname"
17+
/// </summary>
18+
/// <param name="projectNames">build server specific format, compatible with the variable format</param>
19+
/// <returns>projectNames with variables replaced</returns>
1320
string ReplaceVariables(string projectNames);
1421
}
1522
}

‎UnitTests/CommonTestUtils/GitModuleTestHelper.cs

+16-14
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,23 @@ public GitModuleTestHelper(string repositoryName = "repo1")
2222
Directory.CreateDirectory(path);
2323

2424
var module = new GitModule(path);
25-
module.Init(false, false);
25+
module.Init(bare: false, shared: false);
2626
Module = module;
27+
28+
return;
29+
30+
string GetTemporaryPath()
31+
{
32+
var tempPath = Path.GetTempPath();
33+
34+
// workaround macOS symlinking its temp folder
35+
if (tempPath.StartsWith("/var"))
36+
{
37+
tempPath = "/private" + tempPath;
38+
}
39+
40+
return Path.Combine(tempPath, Path.GetRandomFileName());
41+
}
2742
}
2843

2944
/// <summary>
@@ -117,18 +132,5 @@ private void EnsureCreatedInTempFolder(string path)
117132
throw new ArgumentException("The given module does not belong to this helper.");
118133
}
119134
}
120-
121-
private static string GetTemporaryPath()
122-
{
123-
var tempPath = Path.GetTempPath();
124-
125-
// workaround macOS symlinking its temp folder
126-
if (tempPath.StartsWith("/var"))
127-
{
128-
tempPath = "/private" + tempPath;
129-
}
130-
131-
return Path.Combine(tempPath, Path.GetRandomFileName());
132-
}
133135
}
134136
}

0 commit comments

Comments
 (0)
Please sign in to comment.