From 00d2e88c5806a7a39e7232d3a9240ec54b9c7238 Mon Sep 17 00:00:00 2001 From: Felipe G Date: Wed, 28 Aug 2024 12:02:29 -0700 Subject: [PATCH] Making default titles not be saved in data (#439) Co-authored-by: Felipe da Conceicao Guimaraes --- .../Widgets/GitHubIssuesWidget.cs | 2 +- src/GitHubExtension/Widgets/GitHubPullsWidget.cs | 2 +- .../Widgets/GitHubReleasesWidget.cs | 2 +- .../Widgets/GitHubRepositoryWidget.cs | 16 +++++----------- src/GitHubExtension/Widgets/GitHubUserWidget.cs | 16 +++++++++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs index 7d895e6..355012e 100644 --- a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs @@ -152,7 +152,7 @@ public override void LoadContentData() issuesData.Add("issues", issuesArray); issuesData.Add("selected_repo", repository?.FullName ?? string.Empty); - issuesData.Add("widgetTitle", WidgetTitle); + issuesData.Add("widgetTitle", GetActualTitle()); issuesData.Add("is_loading_data", DataState == WidgetDataState.Unknown); issuesData.Add("issues_icon_data", _issuesIconData); diff --git a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs index fad9d23..54691b8 100644 --- a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs @@ -123,7 +123,7 @@ public override void LoadContentData() pullsData.Add("pulls", pullsArray); pullsData.Add("selected_repo", repository?.FullName ?? string.Empty); - pullsData.Add("widgetTitle", WidgetTitle); + pullsData.Add("widgetTitle", GetActualTitle()); pullsData.Add("is_loading_data", DataState == WidgetDataState.Unknown); pullsData.Add("pulls_icon_data", _pullsIconData); diff --git a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs index 5b3d708..5358c8d 100644 --- a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs @@ -121,7 +121,7 @@ public override void LoadContentData() releasesData.Add("releases", releasesArray); releasesData.Add("selected_repo", repository?.FullName ?? string.Empty); - releasesData.Add("widgetTitle", WidgetTitle); + releasesData.Add("widgetTitle", GetActualTitle()); releasesData.Add("is_loading_data", DataState == WidgetDataState.Unknown); releasesData.Add("releases_icon_data", _releasesIconData); diff --git a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs index 582ac2d..2311b42 100644 --- a/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubRepositoryWidget.cs @@ -143,17 +143,11 @@ private void UpdateTitle(JsonNode? dataObj) } GetTitleFromDataObject(dataObj); - if (string.IsNullOrEmpty(WidgetTitle)) - { - try - { - WidgetTitle = GetRepositoryFromUrl(RepositoryUrl).FullName; - } - catch - { - WidgetTitle = string.Empty; - } - } + } + + protected string GetActualTitle() + { + return string.IsNullOrEmpty(WidgetTitle) ? GetRepositoryFromUrl(RepositoryUrl).FullName : WidgetTitle; } protected override void ResetWidgetInfoFromState() diff --git a/src/GitHubExtension/Widgets/GitHubUserWidget.cs b/src/GitHubExtension/Widgets/GitHubUserWidget.cs index ee8ee1b..b83901c 100644 --- a/src/GitHubExtension/Widgets/GitHubUserWidget.cs +++ b/src/GitHubExtension/Widgets/GitHubUserWidget.cs @@ -57,11 +57,17 @@ public override void OnWidgetContextChanged(WidgetContextChangedArgs contextChan protected void UpdateTitle(JsonNode dataObj) { - GetTitleFromDataObject(dataObj); - if (string.IsNullOrEmpty(WidgetTitle)) + if (dataObj == null) { - WidgetTitle = UserName; + return; } + + GetTitleFromDataObject(dataObj); + } + + protected string GetActualTitle() + { + return string.IsNullOrEmpty(WidgetTitle) ? UserName : WidgetTitle; } protected override void ResetWidgetInfoFromState() @@ -249,7 +255,7 @@ public override void LoadContentData() { "openCount", 0 }, { "items", new JsonArray() }, { "userName", UserName }, - { "widgetTitle", WidgetTitle }, + { "widgetTitle", GetActualTitle() }, { "titleIconUrl", GetTitleIconData() }, { "is_loading_data", true }, }; @@ -302,7 +308,7 @@ public void LoadContentData(IEnumerable items) issuesData.Add("items", issuesArray); issuesData.Add("userName", UserName); issuesData.Add("titleIconUrl", GetTitleIconData()); - issuesData.Add("widgetTitle", WidgetTitle); + issuesData.Add("widgetTitle", GetActualTitle()); LastUpdated = DateTime.Now; ContentData = issuesData.ToJsonString();