Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit f7d2b95

Browse files
committed
Merge pull request #290 from github/fixes/149-remember-section-expanded
Remember section expanded state.
2 parents ba5f661 + 1f4b3fb commit f7d2b95

File tree

8 files changed

+98
-8
lines changed

8 files changed

+98
-8
lines changed

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
<DesignTime>True</DesignTime>
131131
<DependentUpon>IPackageSettings.tt</DependentUpon>
132132
</Compile>
133+
<Compile Include="Settings\GitHubConnectSectionState.cs" />
134+
<Compile Include="Settings\UIState.cs" />
133135
<Compile Include="ViewModels\IServiceProviderAware.cs" />
134136
<Compile Include="UI\IView.cs" />
135137
<Compile Include="UI\Octicon.cs" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using GitHub.Settings;
3+
4+
namespace GitHub.Settings
5+
{
6+
/// <summary>
7+
/// Stores persistent UI state for a <see cref="GitHubConnectSection"/> in
8+
/// <see cref="IPackageSettings"/>.
9+
/// </summary>
10+
public class GitHubConnectSectionState
11+
{
12+
/// <summary>
13+
/// Gets or sets the name of the connection section.
14+
/// </summary>
15+
public string SectionName { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets a value indicating whether the section should be expanded.
19+
/// </summary>
20+
public bool IsExpanded { get; set; } = true;
21+
}
22+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using GitHub.Settings;
4+
using System.Linq;
5+
using GitHub.VisualStudio.TeamExplorer.Connect;
6+
7+
namespace GitHub.Settings
8+
{
9+
/// <summary>
10+
/// Stores persistent UI state in <see cref="IPackageSettings"/>.
11+
/// </summary>
12+
public class UIState
13+
{
14+
/// <summary>
15+
/// Gets or sets the UI state for the <see cref="IGitHubConnectSection"/>s in Team Explorer.
16+
/// </summary>
17+
public List<GitHubConnectSectionState> GitHubConnectSections { get; set; }
18+
= new List<GitHubConnectSectionState>();
19+
20+
/// <summary>
21+
/// Gets or creates the UI state for a named <see cref="IGitHubConnectSection"/>.
22+
/// </summary>
23+
/// <param name="sectionName">The name of the section.</param>
24+
/// <returns>A <see cref="GitHubConnectSectionState"/> object.</returns>
25+
public GitHubConnectSectionState GetOrCreateConnectSection(string sectionName)
26+
{
27+
var result = GitHubConnectSections.FirstOrDefault(x => x.SectionName == sectionName);
28+
29+
if (result == null)
30+
{
31+
result = new GitHubConnectSectionState { SectionName = sectionName };
32+
GitHubConnectSections.Add(result);
33+
}
34+
35+
return result;
36+
}
37+
}
38+
}

src/GitHub.Exports/Settings/generated/IPackageSettings.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ foreach (var j in json["settings"].Children()) {
2727
<#
2828
}
2929
#>
30+
UIState UIState { get; }
3031
}
3132
}

src/GitHub.TeamFoundation.14/Connect/GitHubConnectSection.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using ReactiveUI;
2121
using System.Threading.Tasks;
2222
using GitHub.VisualStudio.UI;
23+
using GitHub.Settings;
2324

2425
namespace GitHub.VisualStudio.TeamExplorer.Connect
2526
{
@@ -28,6 +29,9 @@ public class GitHubConnectSection : TeamExplorerSectionBase, IGitHubConnectSecti
2829
readonly int sectionIndex;
2930
bool isCloning;
3031
bool isCreating;
32+
IPackageSettings packageSettings;
33+
GitHubConnectSectionState settings;
34+
3135
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
3236
SectionStateTracker sectionTracker;
3337

@@ -84,17 +88,21 @@ public ISimpleRepositoryModel SelectedRepository
8488

8589
internal ITeamExplorerServiceHolder Holder => holder;
8690

87-
public GitHubConnectSection(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder, IConnectionManager manager, int index)
91+
public GitHubConnectSection(ISimpleApiClientFactory apiFactory,
92+
ITeamExplorerServiceHolder holder,
93+
IConnectionManager manager,
94+
IPackageSettings packageSettings,
95+
int index)
8896
: base(apiFactory, holder, manager)
8997
{
9098
Title = "GitHub";
9199
IsEnabled = true;
92100
IsVisible = false;
93-
IsExpanded = true;
94101
LoggedIn = false;
95-
96102
sectionIndex = index;
97103

104+
this.packageSettings = packageSettings;
105+
98106
connectionManager.Connections.CollectionChanged += RefreshConnections;
99107
PropertyChanged += OnPropertyChange;
100108
UpdateConnection();
@@ -126,6 +134,7 @@ protected void Refresh(IConnection connection)
126134
if (Repositories != null)
127135
Repositories.CollectionChanged -= UpdateRepositoryList;
128136
Repositories = null;
137+
settings = null;
129138

130139
if (sectionIndex == 0 && ServiceProvider != null)
131140
{
@@ -152,6 +161,9 @@ protected void Refresh(IConnection connection)
152161
LoggedIn = true;
153162
if (ServiceProvider != null)
154163
RefreshRepositories().Forget();
164+
165+
settings = packageSettings.UIState.GetOrCreateConnectSection(Title);
166+
IsExpanded = settings.IsExpanded;
155167
}
156168
}
157169
}
@@ -184,6 +196,8 @@ void OnPropertyChange(object sender, PropertyChangedEventArgs e)
184196
{
185197
if (e.PropertyName == "IsVisible" && IsVisible && View == null)
186198
View = new GitHubConnectContent { DataContext = this };
199+
else if (e.PropertyName == "IsExpanded" && settings != null)
200+
settings.IsExpanded = IsExpanded;
187201
}
188202

189203
async void UpdateRepositoryList(object sender, NotifyCollectionChangedEventArgs e)
@@ -359,6 +373,7 @@ protected override void Dispose(bool disposing)
359373
if (Repositories != null)
360374
Repositories.CollectionChanged -= UpdateRepositoryList;
361375
disposed = true;
376+
packageSettings.Save();
362377
}
363378
}
364379
base.Dispose(disposing);

src/GitHub.TeamFoundation.14/Connect/GitHubConnectSection0.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using GitHub.Api;
22
using GitHub.Models;
33
using GitHub.Services;
4+
using GitHub.Settings;
45
using Microsoft.TeamFoundation.Controls;
56
using System.ComponentModel.Composition;
67

@@ -13,8 +14,11 @@ public class GitHubConnectSection0 : GitHubConnectSection
1314
public const string GitHubConnectSection0Id = "519B47D3-F2A9-4E19-8491-8C9FA25ABE90";
1415

1516
[ImportingConstructor]
16-
public GitHubConnectSection0(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder, IConnectionManager manager)
17-
: base(apiFactory, holder, manager, 0)
17+
public GitHubConnectSection0(ISimpleApiClientFactory apiFactory,
18+
ITeamExplorerServiceHolder holder,
19+
IConnectionManager manager,
20+
IPackageSettings settings)
21+
: base(apiFactory, holder, manager, settings, 0)
1822
{
1923
}
2024
}

src/GitHub.TeamFoundation.14/Connect/GitHubConnectSection1.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using GitHub.Api;
22
using GitHub.Models;
33
using GitHub.Services;
4+
using GitHub.Settings;
45
using Microsoft.TeamFoundation.Controls;
56
using System.ComponentModel.Composition;
67

@@ -13,8 +14,11 @@ public class GitHubConnectSection1 : GitHubConnectSection
1314
public const string GitHubConnectSection1Id = "519B47D3-F2A9-4E19-8491-8C9FA25ABE91";
1415

1516
[ImportingConstructor]
16-
public GitHubConnectSection1(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder, IConnectionManager manager)
17-
: base(apiFactory, holder, manager, 1)
17+
public GitHubConnectSection1(ISimpleApiClientFactory apiFactory,
18+
ITeamExplorerServiceHolder holder,
19+
IConnectionManager manager,
20+
IPackageSettings settings)
21+
: base(apiFactory, holder, manager, settings, 1)
1822
{
1923
}
2024
}

src/GitHub.VisualStudio/Settings/PackageSettings.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace GitHub.VisualStudio.Settings
1010
{
1111
[Export(typeof(IPackageSettings))]
12-
[PartCreationPolicy(CreationPolicy.NonShared)]
12+
[PartCreationPolicy(CreationPolicy.Shared)]
1313
public partial class PackageSettings : IPackageSettings
1414
{
1515
readonly SettingsStore settingsStore;
@@ -20,11 +20,15 @@ public PackageSettings([Import(typeof(SVsServiceProvider))] IServiceProvider ser
2020
var sm = new ShellSettingsManager(serviceProvider);
2121
settingsStore = new SettingsStore(sm.GetWritableSettingsStore(SettingsScope.UserSettings), Info.ApplicationInfo.ApplicationSafeName);
2222
LoadSettings();
23+
UIState = SimpleJson.DeserializeObject<UIState>((string)settingsStore.Read("UIState", "{}"));
2324
}
2425

26+
public UIState UIState { get; }
27+
2528
public void Save()
2629
{
2730
SaveSettings();
31+
settingsStore.Write("UIState", SimpleJson.SerializeObject(UIState));
2832
}
2933
}
3034
}

0 commit comments

Comments
 (0)