Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles empty titles for short titles #218

Merged
merged 3 commits into from
Jun 28, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/workspacer.Bar/Widgets/TitleWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TitleWidget : BarWidgetBase
public Color MonitorHasFocusColor { get; set; } = Color.Yellow;
public bool IsShortTitle { get; set; } = false;
public string NoWindowMessage { get; set; } = "No Windows";


public override IBarWidgetPart[] GetParts()
{
Expand All @@ -26,12 +26,13 @@ public override IBarWidgetPart[] GetParts()
{
return Parts(Part(window.Title, color, fontname: FontName));
}
else
else
{
string ShortTitle = window.Title.Split(new char[] { '-', '—', '|' }, StringSplitOptions.RemoveEmptyEntries).Last();
return Parts(Part(ShortTitle, color, fontname: FontName));
var shortTitle = GetShortTitle(window.Title);
return Parts(Part(shortTitle, color, fontname: FontName));
}
} else
}
else
{
return Parts(Part(NoWindowMessage, color, fontname: FontName));
}
Expand Down Expand Up @@ -75,5 +76,15 @@ private void RefreshFocusedMonitor()
{
Context.MarkDirty();
}

private string GetShortTitle(string title)
{
var parts = title.Split(new char[] { '-', '—', '|' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 0)
{
return title;
}
return parts.Last();
}
}
}