This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
SnippetSearchControl.xaml
310 lines (260 loc) · 14.3 KB
/
SnippetSearchControl.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<UserControl x:Class="Extension.SearchWindow.View.SnippetSearchControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
xmlns:local="clr-namespace:Extension.SearchWindow.View"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
x:Name="CodeSnippetSearch">
<UserControl.Resources>
<ResourceDictionary>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<!--Overwrite default button styling-->
<!--see https://stackoverflow.com/questions/28346852/background-does-not-change-of-button-c-sharp-wpf -->
<ControlTemplate x:Key="PreviewButton" TargetType="ButtonBase">
<Border BorderThickness="{TemplateBinding Border.BorderThickness}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
Name="border"
SnapsToDevicePixels="True">
<ContentPresenter RecognizesAccessKey="True"
Content="{TemplateBinding ContentControl.Content}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
Name="contentPresenter"
Margin="{TemplateBinding Control.Padding}"
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
Focusable="False" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsDefaulted" Value="True">
<Setter Property="Border.BorderBrush" TargetName="border">
<Setter.Value>
<DynamicResource ResourceKey="{x:Static SystemColors.HighlightBrushKey}" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="UIElement.IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static vsshell:VsBrushes.FileTabDocumentBorderHighlightKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static vsshell:VsBrushes.FileTabSelectedTextKey}}" />
<Setter Property="Border.BorderBrush" Value="{DynamicResource {x:Static vsshell:VsBrushes.AccentPaleKey}}" />
<Setter Property="Content" Value="Insert"/>
</Trigger>
<Trigger Property="ButtonBase.IsPressed" Value="True">
<Setter Property="Panel.Background" TargetName="border">
<Setter.Value>
<SolidColorBrush>#FFC4E5F6</SolidColorBrush>
</Setter.Value>
</Setter>
<Setter Property="Border.BorderBrush" TargetName="border">
<Setter.Value>
<SolidColorBrush>#FF2C628B</SolidColorBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="True">
<Setter Property="Panel.Background" TargetName="border">
<Setter.Value>
<SolidColorBrush>#FFBCDDEE</SolidColorBrush>
</Setter.Value>
</Setter>
<Setter Property="Border.BorderBrush" TargetName="border">
<Setter.Value>
<SolidColorBrush>#FF245A83</SolidColorBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="UIElement.IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource {x:Static vsshell:VsBrushes.AccentPaleKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!--Customizable Button stylings-->
<Style TargetType="Button">
<Setter Property="Foreground" Value="{DynamicResource {x:Static vsshell:VsBrushes.ButtonTextKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static vsshell:VsBrushes.ButtonFaceKey}}"/>
<Setter Property="Width" Value="90"/>
<Setter Property="Content" Value="Preview"/>
</Style>
<!--Customizable Label stylings-->
<Style TargetType="Label">
<Setter Property="Foreground" Value="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"/>
</Style>
<!--Customizable RadioButton stylings-->
<Style TargetType="RadioButton">
<Setter Property="Foreground" Value="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"/>
</Style>
<!--Customizable CheckBox stylings-->
<Style TargetType="CheckBox">
<Setter Property="Foreground" Value="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"/>
</Style>
<!--Customizable TextBox stylings-->
<Style TargetType="TextBox">
<Setter Property="Foreground" Value="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static vsshell:VsBrushes.SearchBoxBackgroundKey}}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static vsshell:VsBrushes.SearchBoxBorderKey}}"/>
<Setter Property="Height" Value="25"/>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<UserControl.DataContext>
<local:SnippetSearchViewModel/>
</UserControl.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--Title-->
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="10" HorizontalAlignment="Left" Text="Code Snippet Search"/>
<Grid Grid.Column="1" HorizontalAlignment="Right">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" HorizontalAlignment="Right">
<TextBlock Margin="10" Text="Logged as" />
<TextBlock Margin="0 10 10 0">
<Hyperlink NavigateUri="https://app.codiga.io/account/profile">
<i:Interaction.Triggers>
<i:EventTrigger EventName="RequestNavigate">
<i:EventTrigger.Actions>
<i:InvokeCommandAction Command="{Binding OpenProfileCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger.Actions>
</i:EventTrigger>
</i:Interaction.Triggers>
<Run Text="{Binding UserName, Mode=OneWay}"></Run>
</Hyperlink>
</TextBlock>
<DockPanel.Style>
<Style TargetType="{x:Type DockPanel}">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding UserName}" Value="">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DockPanel.Style>
</DockPanel>
<TextBlock Grid.Row="1" HorizontalAlignment="Right" Margin="0 0 10 0" Text="{Binding CurrentLanguage, Mode=OneWay}"/>
</Grid>
</Grid>
<!--Search box-->
<Grid Grid.Row="1" Margin="5">
<TextBox x:Name="txtSearch" VerticalContentAlignment="Center" IsEnabled="{Binding ValidEditor}" Text="{Binding Term, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding GetSnippetsCommand}"></KeyBinding>
</TextBox.InputBindings>
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyUp">
<i:EventTrigger.Actions>
<i:InvokeCommandAction Command="{Binding KeyUpCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger.Actions>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
<TextBlock IsHitTestVisible="False" Text="{Binding Watermark, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,0" Foreground="{DynamicResource {x:Static vsshell:VsBrushes.GrayTextKey}}">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Text, ElementName=txtSearch}" Value="">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<imaging:CrispImage x:Name="imgCheck" Margin="0 0 5 0" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.Search}" HorizontalAlignment="Right"/>
</Grid>
<!--Search parameters-->
<Grid Grid.Row="2" Margin="10 0 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<RadioButton Grid.Column="0" Grid.Row="0" GroupName="Filter" IsEnabled="{Binding ValidEditor}" IsChecked="{Binding AllSnippets, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">All snippets</RadioButton>
<RadioButton Grid.Column="0" Grid.Row="1" GroupName="Filter" IsEnabled="{Binding ValidEditor}" IsChecked="{Binding OnlyPrivate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">Private Snippets Only</RadioButton>
<RadioButton Grid.Column="1" Grid.Row="0" GroupName="Filter" IsEnabled="{Binding ValidEditor}" IsChecked="{Binding OnlyPublic, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">Public Snippets Only</RadioButton>
<CheckBox Grid.Column="1" Grid.Row="1" IsEnabled="{Binding ValidEditor}" IsChecked="{Binding OnlyFavorite, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">Favorite Snippets Only</CheckBox>
</Grid>
<!--Snippet scroll area-->
<ScrollViewer Grid.Row="3" HorizontalScrollBarVisibility="Disabled" Width="Auto" Height="Auto" VerticalScrollBarVisibility="Auto">
<ItemsControl Grid.Column="0" ItemsSource="{Binding Snippets}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<!--Snippet view-->
<Grid Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowFrameKey}}" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!--Title bar-->
<Grid Grid.Row="0" Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0">
<TextBlock Padding="10" Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}" FontSize="18" HorizontalAlignment="Left" Text="{Binding CodeSnippet.Header.Title}" TextTrimming="WordEllipsis"/>
<imaging:CrispImage Visibility="{Binding CodeSnippet.Header.IsPrivate, Converter={StaticResource BooleanToVisibilityConverter}}" HorizontalAlignment="Left" ToolTip="Private Snippet" x:Name="imgPrivate" Margin="0 0 5 0" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.Lock}"/>
<imaging:CrispImage Visibility="{Binding CodeSnippet.Header.IsPublic, Converter={StaticResource BooleanToVisibilityConverter}}" HorizontalAlignment="Left" ToolTip="Public Snippet" x:Name="imgPublic" Margin="0 0 5 0" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.Unlock}"/>
<imaging:CrispImage Visibility="{Binding CodeSnippet.Header.IsSubscribed, Converter={StaticResource BooleanToVisibilityConverter}}" HorizontalAlignment="Left" ToolTip="Favorite Snippet" x:Name="imgSubscribed" Margin="0 0 5 0" Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.Favorite}"/>
</DockPanel>
<Button Grid.Column="1" Margin="10" HorizontalAlignment="Right" Template="{DynamicResource PreviewButton}" Command="{Binding Path=DataContext.InsertSnippetCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" CommandParameter="{Binding }">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:EventTrigger.Actions>
<i:InvokeCommandAction Command="{Binding Path=DataContext.ShowPreviewCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" CommandParameter="{Binding}"/>
</i:EventTrigger.Actions>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:EventTrigger.Actions>
<i:InvokeCommandAction Command="{Binding Path=DataContext.HidePreviewCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" CommandParameter="{Binding}"/>
</i:EventTrigger.Actions>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
<!--Snippet meta data-->
<StackPanel Margin="5" Grid.Row="1" Orientation="Horizontal">
<Label VerticalAlignment="Center">Owner:</Label>
<TextBlock VerticalAlignment="Center" Text="{Binding CodeSnippet.Header.Author}"></TextBlock>
</StackPanel>
<!--Code-->
<TextBox Margin="30 0 0 0" Height="Auto" Grid.Row="2" BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Auto" IsReadOnly="true" Padding="10" Foreground="{DynamicResource {x:Static vsshell:VsBrushes.VizSurfaceGreenMediumKey}}" Background="{DynamicResource {x:Static vsshell:VsBrushes.BackgroundKey}}" FontFamily="Cascadia Code" Text="{Binding PreviewCode, Mode=OneWay}"></TextBox>
<!--Description-->
<TextBlock Padding="10" Grid.Row="3" TextWrapping="Wrap" Width="Auto" Text="{Binding CodeSnippet.Header.Description}"></TextBlock>
<!--Footer-->
<TextBlock Grid.Row="4"></TextBlock>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</UserControl>