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

Commit 020b93a

Browse files
committed
Added LinkDropDown control.
And use it in PullRequestListView. Only used in one place so far, so it can be compared to the existing implementation.
1 parent 2fefc54 commit 020b93a

File tree

6 files changed

+157
-2
lines changed

6 files changed

+157
-2
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace GitHub.UI
5+
{
6+
/// <summary>
7+
/// A ComboBox that displays as a link with a dropdown.
8+
/// </summary>
9+
public class LinkDropDown : ComboBox
10+
{
11+
/// <summary>
12+
/// Defines the <see cref="LinkText"/> property.
13+
/// </summary>
14+
static readonly DependencyPropertyKey LinkTextPropertyKey =
15+
DependencyProperty.RegisterReadOnly(
16+
"LinkText",
17+
typeof(string),
18+
typeof(LinkDropDown),
19+
new FrameworkPropertyMetadata(string.Empty));
20+
21+
/// <summary>
22+
/// Defines the <see cref="Header"/> property.
23+
/// </summary>
24+
public static readonly DependencyProperty HeaderProperty =
25+
HeaderedItemsControl.HeaderProperty.AddOwner(
26+
typeof(LinkDropDown),
27+
new FrameworkPropertyMetadata(typeof(LinkDropDown), HeaderChanged));
28+
29+
/// <summary>
30+
/// Defines the readonly <see cref="LinkText"/> property.
31+
/// </summary>
32+
public static readonly DependencyProperty LinkTextProperty =
33+
LinkTextPropertyKey.DependencyProperty;
34+
35+
/// <summary>
36+
/// Initializes static members of the <see cref="LinkDropDown"/> class.
37+
/// </summary>
38+
static LinkDropDown()
39+
{
40+
DefaultStyleKeyProperty.OverrideMetadata(
41+
typeof(LinkDropDown),
42+
new FrameworkPropertyMetadata(typeof(LinkDropDown)));
43+
}
44+
45+
/// <summary>
46+
/// Gets or sets a header to use as the link text when no item is selected.
47+
/// </summary>
48+
public object Header
49+
{
50+
get { return GetValue(HeaderProperty); }
51+
set { SetValue(HeaderProperty, value); }
52+
}
53+
54+
/// <summary>
55+
/// Gets the text to display in the link.
56+
/// </summary>
57+
public string LinkText => (string)GetValue(LinkTextProperty);
58+
59+
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
60+
{
61+
UpdateLinkText();
62+
}
63+
64+
private static void HeaderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
65+
{
66+
var source = (LinkDropDown)d;
67+
source.UpdateLinkText();
68+
}
69+
70+
private void UpdateLinkText()
71+
{
72+
SetValue(LinkTextPropertyKey, SelectedItem?.ToString() ?? Header?.ToString());
73+
}
74+
}
75+
}

src/GitHub.UI/GitHub.UI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<Compile Include="Behaviours\AddEmptyItemToList.cs" />
8181
<Compile Include="Behaviours\ClosePopupAction.cs" />
8282
<Compile Include="Behaviours\OpenPopupAction.cs" />
83+
<Compile Include="Controls\ComboBoxes\LinkDropDown.cs" />
8384
<Compile Include="Controls\Octicons\OcticonPaths.Designer.cs">
8485
<AutoGen>True</AutoGen>
8586
<DesignTime>True</DesignTime>

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@
378378
<SubType>Designer</SubType>
379379
<Generator>MSBuild:Compile</Generator>
380380
</Page>
381+
<Page Include="Styles\LinkDropDown.xaml">
382+
<Generator>MSBuild:Compile</Generator>
383+
<SubType>Designer</SubType>
384+
</Page>
381385
<Page Include="Styles\Buttons.xaml">
382386
<SubType>Designer</SubType>
383387
<Generator>MSBuild:Compile</Generator>

src/GitHub.VisualStudio/SharedDictionary.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio;component/Styles/Buttons.xaml" />
1313
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio;component/Styles/GitHubTabControl.xaml" />
1414
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio;component/Styles/TextBlocks.xaml" />
15+
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio;component/Styles/LinkDropDown.xaml" />
1516
</ResourceDictionary.MergedDictionaries>
1617

1718
<Style x:Key="VSStyledButton" BasedOn="{StaticResource VsButtonStyleKey}" TargetType="{x:Type Button}" />
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:cache="clr-namespace:GitHub.VisualStudio.Helpers"
4+
xmlns:ui="clr-namespace:GitHub.UI;assembly=GitHub.UI">
5+
6+
<ResourceDictionary.MergedDictionaries>
7+
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml" />
8+
</ResourceDictionary.MergedDictionaries>
9+
10+
<Style x:Key="FakeHyperlink" TargetType="TextBlock">
11+
<Style.Triggers>
12+
<MultiTrigger>
13+
<MultiTrigger.Conditions>
14+
<Condition Property="IsMouseOver" Value="true" />
15+
<Condition Property="IsEnabled" Value="true" />
16+
</MultiTrigger.Conditions>
17+
<MultiTrigger.Setters>
18+
<Setter Property="TextDecorations" Value="Underline" />
19+
<Setter Property="FrameworkElement.Cursor" Value="Hand" />
20+
</MultiTrigger.Setters>
21+
</MultiTrigger>
22+
</Style.Triggers>
23+
<Setter Property="Cursor" Value="Hand" />
24+
</Style>
25+
26+
<Style x:Key="HyperLinkToggleButton" TargetType="ToggleButton">
27+
<Setter Property="Template">
28+
<Setter.Value>
29+
<ControlTemplate TargetType="ToggleButton">
30+
<TextBlock Style="{StaticResource FakeHyperlink}">
31+
<Run Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" />
32+
<Polygon Margin="2,0,0,1"
33+
Fill="{TemplateBinding Foreground}"
34+
Points="0,0 8,0 4,4 0,0"/>
35+
</TextBlock>
36+
</ControlTemplate>
37+
</Setter.Value>
38+
</Setter>
39+
</Style>
40+
41+
<Style TargetType="{x:Type ui:LinkDropDown}">
42+
<Setter Property="Foreground" Value="#FF0E70C0"/>
43+
<Setter Property="Template">
44+
<Setter.Value>
45+
<ControlTemplate TargetType="ui:LinkDropDown">
46+
<Grid>
47+
<ToggleButton Style="{StaticResource HyperLinkToggleButton}"
48+
Content="{TemplateBinding LinkText}"
49+
Foreground="{TemplateBinding Foreground}"
50+
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
51+
<Popup Name="PART_Popup"
52+
AllowsTransparency="True"
53+
IsOpen="{TemplateBinding IsDropDownOpen}"
54+
Placement="Bottom">
55+
<Border Style="{DynamicResource GitHubComboBoxBorder}">
56+
<DockPanel Style="{DynamicResource GitHubComboBoxDockPanelContainer}"
57+
MinWidth="100">
58+
<ScrollViewer>
59+
<ItemsPresenter/>
60+
</ScrollViewer>
61+
</DockPanel>
62+
</Border>
63+
</Popup>
64+
</Grid>
65+
</ControlTemplate>
66+
</Setter.Value>
67+
</Setter>
68+
</Style>
69+
70+
</ResourceDictionary>

src/GitHub.VisualStudio/UI/Views/PullRequestListView.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@
138138

139139
<Separator Style="{StaticResource VerticalSeparator}" />
140140

141-
<ui:GitHubActionLink x:Name="assigneeSelection"
141+
<ui:LinkDropDown Header="Assignee"
142+
ItemsSource="{Binding Assignees}"
143+
SelectedItem="{Binding SelectedAssignee}"/>
144+
145+
<!--<ui:GitHubActionLink x:Name="assigneeSelection"
142146
Margin="5,0"
143147
VerticalAlignment="Center"
144148
ToolTip="Filter by assignee"
@@ -182,7 +186,7 @@
182186
</ListBox>
183187
</DockPanel>
184188
</Border>
185-
</Popup>
189+
</Popup>-->
186190

187191
<Separator Style="{StaticResource VerticalSeparator}" />
188192

0 commit comments

Comments
 (0)