Skip to content

Commit f418b72

Browse files
committed
feature: use [$workspace] $repo_name ($repo_path) as main window's title (#818)
1 parent 5425fa6 commit f418b72

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/ViewModels/Launcher.cs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ namespace SourceGit.ViewModels
1111
{
1212
public class Launcher : ObservableObject
1313
{
14+
public string Title
15+
{
16+
get => _title;
17+
private set => SetProperty(ref _title, value);
18+
}
19+
1420
public AvaloniaList<LauncherPage> Pages
1521
{
1622
get;
@@ -31,9 +37,10 @@ public LauncherPage ActivePage
3137
if (SetProperty(ref _activePage, value))
3238
{
3339
PopupHost.Active = value;
40+
UpdateTitle();
3441

3542
if (!_ignoreIndexChange && value is { Data: Repository repo })
36-
ActiveWorkspace.ActiveIdx = ActiveWorkspace.Repositories.IndexOf(repo.FullPath);
43+
_activeWorkspace.ActiveIdx = _activeWorkspace.Repositories.IndexOf(repo.FullPath);
3744
}
3845
}
3946
}
@@ -105,6 +112,9 @@ public Launcher(string startupRepo)
105112
}
106113

107114
_ignoreIndexChange = false;
115+
116+
if (string.IsNullOrEmpty(_title))
117+
UpdateTitle();
108118
}
109119

110120
public void Quit(double width, double height)
@@ -185,6 +195,7 @@ public void CloseTab(LauncherPage page)
185195
last.Node = new RepositoryNode() { Id = Guid.NewGuid().ToString() };
186196
last.Data = Welcome.Instance;
187197
last.Popup = null;
198+
UpdateTitle();
188199

189200
GC.Collect();
190201
}
@@ -193,7 +204,6 @@ public void CloseTab(LauncherPage page)
193204
App.Quit(0);
194205
}
195206

196-
_ignoreIndexChange = false;
197207
return;
198208
}
199209

@@ -308,7 +318,10 @@ public void OpenRepositoryInTab(RepositoryNode node, LauncherPage page)
308318
page.Data = repo;
309319
}
310320

311-
ActivePage = page;
321+
if (page != _activePage)
322+
ActivePage = page;
323+
else
324+
UpdateTitle();
312325

313326
ActiveWorkspace.Repositories.Clear();
314327
foreach (var p in Pages)
@@ -530,8 +543,37 @@ private void CloseRepositoryInTab(LauncherPage page, bool removeFromWorkspace =
530543
page.Data = null;
531544
}
532545

546+
private void UpdateTitle()
547+
{
548+
if (_activeWorkspace == null)
549+
return;
550+
551+
var workspace = _activeWorkspace.Name;
552+
if (_activePage is { Data: Repository repo })
553+
{
554+
var node = _activePage.Node;
555+
var name = node.Name;
556+
var path = node.Id;
557+
558+
if (!OperatingSystem.IsWindows())
559+
{
560+
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
561+
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
562+
if (path.StartsWith(home, StringComparison.Ordinal))
563+
path = "~" + path.Substring(prefixLen);
564+
}
565+
566+
Title = $"[{workspace}] {name} ({path})";
567+
}
568+
else
569+
{
570+
Title = $"[{workspace}] Repositories";
571+
}
572+
}
573+
533574
private Workspace _activeWorkspace = null;
534575
private LauncherPage _activePage = null;
535576
private bool _ignoreIndexChange = false;
577+
private string _title = string.Empty;
536578
}
537579
}

src/Views/Launcher.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
x:DataType="vm:Launcher"
1111
x:Name="ThisControl"
1212
Icon="/App.ico"
13-
Title="SourceGit"
13+
Title="{Binding Title}"
1414
MinWidth="1024" MinHeight="600"
1515
WindowStartupLocation="CenterScreen">
1616
<Grid>

0 commit comments

Comments
 (0)