forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppTitleGenerator.cs
55 lines (48 loc) · 1.94 KB
/
AppTitleGenerator.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
using GitCommands.UserRepositoryHistory;
namespace GitCommands
{
/// <summary>
/// Provides the ability to generate application title.
/// </summary>
public interface IAppTitleGenerator
{
/// <summary>
/// Generates main window title according to given repository.
/// </summary>
/// <param name="workingDir">Path to repository.</param>
/// <param name="isValidWorkingDir">Indicates whether the given path contains a valid repository.</param>
/// <param name="branchName">Current branch name.</param>
string Generate(string workingDir = null, bool isValidWorkingDir = false, string branchName = null);
}
/// <summary>
/// Generates application title.
/// </summary>
public sealed class AppTitleGenerator : IAppTitleGenerator
{
private readonly IRepositoryDescriptionProvider _description;
public AppTitleGenerator(IRepositoryDescriptionProvider description)
{
_description = description;
}
/// <summary>
/// Generates main window title according to given repository.
/// </summary>
/// <param name="workingDir">Path to repository.</param>
/// <param name="isValidWorkingDir">Indicates whether the given path contains a valid repository.</param>
/// <param name="branchName">Current branch name.</param>
public string Generate(string workingDir = null, bool isValidWorkingDir = false, string branchName = null)
{
if (string.IsNullOrWhiteSpace(workingDir) || !isValidWorkingDir)
{
return "Git Extensions";
}
branchName = branchName?.Trim('(', ')') ?? "no branch";
var description = _description.Get(workingDir);
#if DEBUG
return $"{description} ({branchName}) - Git Extensions [DEBUG]";
#else
return $"{description} ({branchName}) - Git Extensions";
#endif
}
}
}