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

Commit ceca36b

Browse files
author
Steven Kirk
committed
Initial support for collapsing in clone dialog.
Makes groups in the clone dialog collapsible. If there is only a single group, then it will be expanded; as more groups are created, the first group is collapsed and further groups will be added collapsed. Only problem with this is that you can see an initial flash of expanded items when loading with multiple groups, however I felt this was preferable to everything being collapsed until the whole list is loaded...
1 parent e7dc701 commit ceca36b

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

src/GitHub.VisualStudio/UI/Views/Controls/RepositoryCloneControl.xaml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,26 @@
152152
<Setter Property="Template">
153153
<Setter.Value>
154154
<ControlTemplate TargetType="{x:Type GroupItem}">
155-
<StackPanel Orientation="Vertical"
156-
Margin="0">
157-
<Border Background="#F8F8F8"
158-
Style="{StaticResource repositoryBorderStyle}">
155+
<Expander IsExpanded="{Binding Name.IsExpanded}">
156+
<Expander.Header>
157+
<Border Background="#F8F8F8"
158+
Style="{StaticResource repositoryBorderStyle}">
159159
<StackPanel Orientation="Horizontal"
160160
VerticalAlignment="Center"
161161
Margin="0">
162-
<Image x:Name="avatar"
163-
Width="16"
164-
Height="16"
165-
Margin="10,0,6,0"
166-
RenderOptions.BitmapScalingMode="HighQuality"
167-
Source="{Binding Items[0].Owner.Avatar}" />
168-
<TextBlock Text="{Binding Path=Name}"
169-
Style="{StaticResource cloneRepoHeaderStyle}" />
162+
<Image x:Name="avatar"
163+
Width="16"
164+
Height="16"
165+
Margin="10,0,6,0"
166+
RenderOptions.BitmapScalingMode="HighQuality"
167+
Source="{Binding Items[0].Owner.Avatar}" />
168+
<TextBlock Text="{Binding Path=Name.Header}"
169+
Style="{StaticResource cloneRepoHeaderStyle}" />
170170
</StackPanel>
171-
</Border>
171+
</Border>
172+
</Expander.Header>
172173
<ItemsPresenter Margin="0" />
173-
</StackPanel>
174+
</Expander>
174175
</ControlTemplate>
175176
</Setter.Value>
176177
</Setter>

src/GitHub.VisualStudio/UI/Views/Controls/RepositoryCloneControl.xaml.cs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using ReactiveUI;
1818
using System.ComponentModel.Composition;
1919
using GitHub.Services;
20+
using System.Linq;
2021

2122
namespace GitHub.VisualStudio.UI.Views.Controls
2223
{
@@ -30,6 +31,8 @@ public class GenericRepositoryCloneControl : SimpleViewUserControl<IRepositoryCl
3031
[PartCreationPolicy(CreationPolicy.NonShared)]
3132
public partial class RepositoryCloneControl : GenericRepositoryCloneControl
3233
{
34+
private Dictionary<string, RepositoryGroup> groups = new Dictionary<string, RepositoryGroup>();
35+
3336
public RepositoryCloneControl()
3437
{
3538
InitializeComponent();
@@ -60,24 +63,60 @@ public RepositoryCloneControl()
6063
};
6164
}
6265

63-
static ListCollectionView CreateRepositoryListCollectionView(IEnumerable<IRepositoryModel> repositories)
66+
ListCollectionView CreateRepositoryListCollectionView(IEnumerable<IRepositoryModel> repositories)
6467
{
6568
var view = new ListCollectionView((IList)repositories);
6669
Debug.Assert(view.GroupDescriptions != null, "view.GroupDescriptions is null");
67-
view.GroupDescriptions.Add(new RepositoryGroupDescription());
70+
view.GroupDescriptions.Add(new RepositoryGroupDescription(this));
6871
return view;
6972
}
7073

7174
class RepositoryGroupDescription : GroupDescription
7275
{
76+
RepositoryCloneControl owner;
77+
78+
public RepositoryGroupDescription(RepositoryCloneControl owner)
79+
{
80+
this.owner = owner;
81+
}
82+
7383
public override object GroupNameFromItem(object item, int level, System.Globalization.CultureInfo culture)
7484
{
75-
return ((IRepositoryModel)item).Owner.Login;
85+
var name = ((IRepositoryModel)item).Owner.Login;
86+
RepositoryGroup group;
87+
88+
if (!owner.groups.TryGetValue(name, out group))
89+
{
90+
group = new RepositoryGroup(name, owner.groups.Count == 0);
91+
92+
if (owner.groups.Count == 1)
93+
{
94+
owner.groups.Values.First().IsExpanded = false;
95+
}
96+
97+
owner.groups.Add(name, group);
98+
}
99+
100+
return group;
101+
}
102+
}
103+
104+
class RepositoryGroup : ReactiveObject
105+
{
106+
private bool isExpanded;
107+
108+
public RepositoryGroup(string header, bool isExpanded)
109+
{
110+
Header = header;
111+
this.isExpanded = isExpanded;
76112
}
77113

78-
public override bool NamesMatch(object groupName, object itemName)
114+
public string Header { get; }
115+
116+
public bool IsExpanded
79117
{
80-
return string.Equals((string)groupName, (string)itemName);
118+
get { return isExpanded; }
119+
set { this.RaiseAndSetIfChanged(ref isExpanded, value); }
81120
}
82121
}
83122
}

0 commit comments

Comments
 (0)