Skip to content

Commit 02b4ebd

Browse files
authored
Merge pull request #346 from garstenauer/port-styles-to-controlthemes
Port styles to control themes
2 parents d965651 + 02c1a4c commit 02b4ebd

File tree

14 files changed

+433
-614
lines changed

14 files changed

+433
-614
lines changed

src/AvaloniaEdit.Demo/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public int SelectedIndex
328328
}
329329

330330
public int Count => _items.Count;
331-
public string CurrentIndexText => null;
331+
public string CurrentIndexText => $"{SelectedIndex + 1} of {Count}";
332332
public object CurrentHeader => _items[SelectedIndex].header;
333333
public object CurrentContent => _items[SelectedIndex].content;
334334

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,35 @@
1-
<Styles xmlns="https://github.com/avaloniaui"
2-
xmlns:cc="clr-namespace:AvaloniaEdit.CodeCompletion;assembly=AvaloniaEdit"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:cc="clr-namespace:AvaloniaEdit.CodeCompletion">
44

5-
<Style Selector="cc|CompletionList">
6-
<Setter Property="Template">
7-
<ControlTemplate>
8-
<cc:CompletionListBox Name="PART_ListBox">
9-
<cc:CompletionListBox.ItemTemplate>
10-
<DataTemplate x:DataType="cc:ICompletionData">
11-
<StackPanel Orientation="Horizontal" Margin="0">
12-
<Image Source="{Binding Image}"
13-
Width="16"
14-
Height="16"
15-
Margin="0,0,2,0" />
16-
<ContentPresenter Content="{Binding Content}" />
17-
</StackPanel>
18-
</DataTemplate>
19-
</cc:CompletionListBox.ItemTemplate>
20-
</cc:CompletionListBox>
21-
</ControlTemplate>
22-
</Setter>
23-
</Style>
24-
25-
<Style Selector="cc|CompletionList > ListBox">
26-
<Setter Property="Padding" Value="0" />
27-
</Style>
28-
29-
<Style Selector="cc|CompletionList > ListBox > ListBoxItem">
5+
<ControlTheme x:Key="{x:Type cc:CompletionListBox}" TargetType="cc:CompletionListBox"
6+
BasedOn="{StaticResource {x:Type ListBox}}">
7+
<Setter Property="Padding" Value="0" />
8+
<Setter Property="ItemContainerTheme">
9+
<ControlTheme TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
3010
<Setter Property="Padding" Value="4,2" />
31-
</Style>
11+
</ControlTheme>
12+
</Setter>
13+
</ControlTheme>
3214

33-
<Style Selector="ContentControl.ToolTip">
34-
<Setter Property="BorderThickness"
35-
Value="{DynamicResource CompletionToolTipBorderThickness}" />
36-
<Setter Property="BorderBrush"
37-
Value="{DynamicResource CompletionToolTipBorderBrush}" />
38-
<Setter Property="Background"
39-
Value="{DynamicResource CompletionToolTipBackground}" />
40-
<Setter Property="Foreground"
41-
Value="{DynamicResource CompletionToolTipForeground}" />
42-
<Setter Property="Padding"
43-
Value="4,2" />
44-
</Style>
15+
<ControlTheme x:Key="{x:Type cc:CompletionList}" TargetType="cc:CompletionList">
16+
<Setter Property="Template">
17+
<ControlTemplate>
18+
<cc:CompletionListBox Name="PART_ListBox">
19+
<cc:CompletionListBox.ItemTemplate>
20+
<DataTemplate x:DataType="cc:ICompletionData">
21+
<StackPanel Orientation="Horizontal" Margin="0">
22+
<Image Source="{Binding Image}"
23+
Width="16"
24+
Height="16"
25+
Margin="0,0,2,0" />
26+
<ContentPresenter Content="{Binding Content}" />
27+
</StackPanel>
28+
</DataTemplate>
29+
</cc:CompletionListBox.ItemTemplate>
30+
</cc:CompletionListBox>
31+
</ControlTemplate>
32+
</Setter>
33+
</ControlTheme>
4534

46-
</Styles>
35+
</ResourceDictionary>

src/AvaloniaEdit/CodeCompletion/CompletionListBox.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public class CompletionListBox : ListBox
3030
{
3131
internal ScrollViewer ScrollViewer;
3232

33-
protected override Type StyleKeyOverride => typeof(ListBox);
34-
3533
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
3634
{
3735
base.OnApplyTemplate(e);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Styles xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
3+
4+
<!-- Style used for tooltip next to completion list box. -->
5+
<Style Selector="ContentControl.ToolTip">
6+
<Setter Property="BorderThickness" Value="{DynamicResource CompletionToolTipBorderThickness}" />
7+
<Setter Property="BorderBrush" Value="{DynamicResource CompletionToolTipBorderBrush}" />
8+
<Setter Property="Background" Value="{DynamicResource CompletionToolTipBackground}" />
9+
<Setter Property="Foreground" Value="{DynamicResource CompletionToolTipForeground}" />
10+
<Setter Property="Padding" Value="4,2" />
11+
</Style>
12+
13+
</Styles>

src/AvaloniaEdit/CodeCompletion/CompletionWindowBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ public CompletionWindowBase(TextArea textArea) : base()
9595

9696
AttachEvents();
9797

98-
Initailize();
98+
Initialize();
9999
}
100100

101101
protected virtual void OnClosed()
102102
{
103103
DetachEvents();
104104
}
105105

106-
private void Initailize()
106+
private void Initialize()
107107
{
108108
if (_document != null && StartOffset != TextArea.Caret.Offset)
109109
{
Lines changed: 65 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,68 @@
1-
<Styles xmlns="https://github.com/avaloniaui"
2-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:cc="clr-namespace:AvaloniaEdit.CodeCompletion;assembly=AvaloniaEdit">
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:cc="clr-namespace:AvaloniaEdit.CodeCompletion">
4+
<ControlTheme x:Key="{x:Type cc:OverloadViewer}" TargetType="cc:OverloadViewer">
5+
<Setter Property="BorderThickness" Value="1" />
6+
<Setter Property="BorderBrush" Value="Black" />
7+
<Setter Property="Background" Value="#eeeeee" />
8+
<Setter Property="Padding" Value="2" />
9+
<Setter Property="Template">
10+
<ControlTemplate>
11+
<Border BorderThickness="{TemplateBinding BorderThickness}"
12+
BorderBrush="{TemplateBinding BorderBrush}"
13+
Background="{TemplateBinding Background}"
14+
Padding="{TemplateBinding Padding}">
15+
<Grid ColumnDefinitions="Auto,*"
16+
RowDefinitions="Auto,*">
417

5-
<Style Selector="cc|OverloadViewer">
6-
<Setter Property="BorderThickness"
7-
Value="1" />
8-
<Setter Property="BorderBrush"
9-
Value="Black" />
10-
<Setter Property="Background"
11-
Value="#eeeeee" />
12-
<Setter Property="Padding"
13-
Value="2" />
14-
<Setter Property="Template">
15-
<ControlTemplate>
16-
<Border BorderThickness="{TemplateBinding BorderThickness}"
17-
BorderBrush="{TemplateBinding BorderBrush}"
18-
Background="{TemplateBinding Background}"
19-
Padding="{TemplateBinding Padding}">
20-
<Grid ColumnDefinitions="Auto,*"
21-
RowDefinitions="Auto,*">
18+
<StackPanel Grid.Row="0"
19+
Grid.Column="0"
20+
Margin="0,0,4,0"
21+
Orientation="Horizontal"
22+
IsVisible="{Binding Provider.Count, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static cc:CollapseIfSingleOverloadConverter.Instance}}">
23+
<Button Name="PART_UP">
24+
<Path Stroke="Black"
25+
Fill="Black"
26+
Data="M 0,0.866 L 1,0.866 L 0.5,0 Z"
27+
Stretch="UniformToFill" />
28+
</Button>
29+
<TextBlock Margin="2,0,2,0"
30+
Text="{Binding Provider.CurrentIndexText, RelativeSource={RelativeSource TemplatedParent}}" />
31+
<Button Name="PART_DOWN">
32+
<Path Stroke="Black"
33+
Fill="Black"
34+
Data="M 0,0 L 1,0 L 0.5,0.866 Z"
35+
Stretch="UniformToFill" />
36+
</Button>
37+
</StackPanel>
38+
<ContentPresenter Grid.Row="0"
39+
Grid.Column="1"
40+
Content="{Binding Provider.CurrentHeader, RelativeSource={RelativeSource TemplatedParent}}" />
41+
<ContentPresenter Grid.Row="1"
42+
Grid.Column="0"
43+
Grid.ColumnSpan="2"
44+
Content="{Binding Provider.CurrentContent, RelativeSource={RelativeSource TemplatedParent}}" />
45+
</Grid>
46+
</Border>
47+
</ControlTemplate>
48+
</Setter>
2249

23-
<StackPanel Grid.Row="0"
24-
Grid.Column="0"
25-
Margin="0,0,4,0"
26-
Orientation="Horizontal"
27-
IsVisible="{Binding Provider.Count, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static cc:CollapseIfSingleOverloadConverter.Instance}}">
28-
<Button Name="PART_UP">
29-
<Path Stroke="Black"
30-
Fill="Black"
31-
Data="M 0,0.866 L 1,0.866 L 0.5,0 Z"
32-
Stretch="UniformToFill" />
33-
</Button>
34-
<TextBlock Margin="2,0,2,0"
35-
Text="{Binding Provider.CurrentIndexText, RelativeSource={RelativeSource TemplatedParent}}" />
36-
<Button Name="PART_DOWN">
37-
<Path Stroke="Black"
38-
Fill="Black"
39-
Data="M 0,0 L 1,0 L 0.5,0.866 Z"
40-
Stretch="UniformToFill" />
41-
</Button>
42-
</StackPanel>
43-
<ContentPresenter Grid.Row="0"
44-
Grid.Column="1"
45-
Content="{Binding Provider.CurrentHeader, RelativeSource={RelativeSource TemplatedParent}}" />
46-
<ContentPresenter Grid.Row="1"
47-
Grid.Column="0"
48-
Grid.ColumnSpan="2"
49-
Content="{Binding Provider.CurrentContent, RelativeSource={RelativeSource TemplatedParent}}" />
50-
</Grid>
51-
</Border>
52-
</ControlTemplate>
53-
</Setter>
50+
<Style Selector="^/template/ Button">
51+
<Setter Property="Background" Value="LightGray" />
52+
<Setter Property="Padding" Value="2,2,2,2" />
53+
<Setter Property="Width" Value="9" />
54+
<Setter Property="Height" Value="9" />
55+
<Setter Property="Template">
56+
<ControlTemplate>
57+
<Border Name="bd"
58+
Background="{TemplateBinding Background}"
59+
CornerRadius="2">
60+
<ContentPresenter Margin="{TemplateBinding Padding}"
61+
Content="{TemplateBinding Content}" />
62+
</Border>
63+
</ControlTemplate>
64+
</Setter>
5465
</Style>
55-
56-
<Style Selector="cc|OverloadViewer /template/ Button">
57-
<Setter Property="Background"
58-
Value="LightGray" />
59-
<Setter Property="Padding"
60-
Value="2,2,2,2" />
61-
<Setter Property="Width"
62-
Value="9" />
63-
<Setter Property="Height"
64-
Value="9" />
65-
<Setter Property="Template">
66-
<ControlTemplate>
67-
<Border Name="bd"
68-
Background="{TemplateBinding Background}"
69-
CornerRadius="2">
70-
<ContentPresenter Margin="{TemplateBinding Padding}"
71-
Content="{TemplateBinding Content}" />
72-
</Border>
73-
</ControlTemplate>
74-
</Setter>
75-
</Style>
76-
</Styles>
66+
67+
</ControlTheme>
68+
</ResourceDictionary>

src/AvaloniaEdit/CodeCompletion/OverloadViewer.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,24 @@ public void ChangeIndex(int relativeIndexChange)
104104
}
105105
}
106106

107-
internal sealed class CollapseIfSingleOverloadConverter : IValueConverter
107+
/// <summary>
108+
/// Converter to be used in the <see cref="OverloadViewer"/> control theme. Used to set the
109+
/// visibility of the part showing the number of overloads.
110+
/// </summary>
111+
public sealed class CollapseIfSingleOverloadConverter : IValueConverter
108112
{
109-
public static CollapseIfSingleOverloadConverter Instance { get; } = new CollapseIfSingleOverloadConverter();
113+
public static CollapseIfSingleOverloadConverter Instance { get; } = new();
110114

111115
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
112116
{
113-
return (int)value >= 2;
117+
// Show the up/down arrows and the "i of n" text if there are 2 or more method overloads.
118+
if (value is int count)
119+
return count >= 2;
120+
121+
return AvaloniaProperty.UnsetValue;
114122
}
115123

116-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
124+
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
117125
{
118126
throw new NotImplementedException();
119127
}
Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
<Styles xmlns="https://github.com/avaloniaui"
2-
xmlns:Editing="clr-namespace:AvaloniaEdit.Editing;assembly=AvaloniaEdit">
3-
4-
<Style Selector="Editing|TextArea">
5-
<Setter Property="SelectionBrush"
6-
Value="#660000ff" />
7-
<!--<Setter Property="SelectionBorder">
8-
<Pen Brush="#0000ff"
9-
Thickness="1" />
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:editing="clr-namespace:AvaloniaEdit.Editing">
4+
<ControlTheme x:Key="{x:Type editing:TextArea}" TargetType="editing:TextArea">
5+
<Setter Property="SelectionBrush" Value="#660000ff" />
6+
<!--<Setter Property="SelectionBorder">
7+
<Pen Brush="#0000ff" Thickness="1" />
108
</Setter>-->
11-
<!--<Setter Property="SelectionForeground"
12-
Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />-->
13-
<Setter Property="Template">
14-
<ControlTemplate>
15-
<DockPanel Focusable="False" Background="{TemplateBinding Background}">
16-
<ItemsControl DockPanel.Dock="Left"
17-
Focusable="False"
18-
ItemsSource="{TemplateBinding LeftMargins}">
19-
<ItemsControl.ItemsPanel>
20-
<ItemsPanelTemplate>
21-
<StackPanel Orientation="Horizontal" />
22-
</ItemsPanelTemplate>
23-
</ItemsControl.ItemsPanel>
24-
</ItemsControl>
25-
<ContentPresenter Name="PART_CP" Cursor="IBeam"
26-
Focusable="False" Background="{TemplateBinding Background}" />
27-
</DockPanel>
28-
</ControlTemplate>
29-
</Setter>
30-
</Style>
31-
</Styles>
9+
<!--<Setter Property="SelectionForeground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />-->
10+
<Setter Property="Template">
11+
<ControlTemplate>
12+
<DockPanel Focusable="False" Background="{TemplateBinding Background}">
13+
<ItemsControl DockPanel.Dock="Left"
14+
Focusable="False"
15+
ItemsSource="{TemplateBinding LeftMargins}">
16+
<ItemsControl.ItemsPanel>
17+
<ItemsPanelTemplate>
18+
<StackPanel Orientation="Horizontal" />
19+
</ItemsPanelTemplate>
20+
</ItemsControl.ItemsPanel>
21+
</ItemsControl>
22+
<ContentPresenter Name="PART_CP" Cursor="IBeam"
23+
Focusable="False" Background="{TemplateBinding Background}" />
24+
</DockPanel>
25+
</ControlTemplate>
26+
</Setter>
27+
</ControlTheme>
28+
</ResourceDictionary>

0 commit comments

Comments
 (0)