Skip to content

Commit ead66d2

Browse files
committed
Tweak priority button visibility, search and browse layout.
1 parent 9bc9d80 commit ead66d2

File tree

7 files changed

+114
-40
lines changed

7 files changed

+114
-40
lines changed

Rubberduck.Core/AddRemoveReferences/ReferenceModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public ReferenceModel(IReference reference, int priority) : this()
8383

8484
public ReferenceModel(ITypeLib reference) : this()
8585
{
86-
var documentation = new ComDocumentation(reference, -1);
86+
var documentation = new ComDocumentation(reference, ComDocumentation.LibraryIndex);
8787
Name = documentation.Name;
8888
Description = documentation.DocString;
8989

@@ -111,6 +111,7 @@ public ReferenceModel(string path, bool broken = false) : this()
111111
{
112112
// Yeah, that's probably busted.
113113
IsBroken = true;
114+
return;
114115
}
115116

116117
IsBroken = broken;

Rubberduck.Core/Settings/ReferenceConfigProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ReferenceSettings CreateDefaults()
2828
RecentReferencesTracked = 20
2929
};
3030

31-
var version = Assembly.GetEntryAssembly().GetName().Version;
31+
var version = Assembly.GetExecutingAssembly().GetName().Version;
3232
defaults.PinReference(new ReferenceInfo(new Guid(RubberduckGuid.RubberduckTypeLibGuid), string.Empty, string.Empty, version.Major, version.Minor));
3333
defaults.PinReference(new ReferenceInfo(new Guid(RubberduckGuid.RubberduckApiTypeLibGuid), string.Empty, string.Empty, version.Major, version.Minor));
3434

Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public AddRemoveReferencesViewModel(IAddRemoveReferencesModel model, IReferenceR
9292

9393
_clean = new List<(int?, ReferenceInfo)>(_project.Select(reference => (reference.Priority, reference.ToReferenceInfo())));
9494

95+
BuiltInReferenceCount = _project.Count(reference => reference.IsBuiltIn);
96+
9597
AddCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteAddCommand);
9698
RemoveCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRemoveCommand);
9799
BrowseCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteBrowseCommand);
@@ -109,6 +111,8 @@ public AddRemoveReferencesViewModel(IAddRemoveReferencesModel model, IReferenceR
109111

110112
public bool ProjectsVisible => HostHasProjects;
111113

114+
public int BuiltInReferenceCount { get; }
115+
112116
public ICommand AddCommand { get; }
113117

114118
public ICommand RemoveCommand { get; }

Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesWindow.xaml

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<BitmapImage x:Key="RemoveIcon" UriSource="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/arrow-180.png" />
2424

2525
<local:ReferenceStatusImageSourceConverter x:Key="StatusToIcon" />
26+
<local:PriorityButtonVisibilityConverter x:Key="PriorityButtonVisibility" />
2627
<converters:RemainingWidthConverter x:Key="RemainingWidth" />
2728

2829
<Style x:Key="DialogButtonStyle" TargetType="Button">
@@ -135,7 +136,6 @@
135136
<Border BorderThickness="1" BorderBrush="{x:Static SystemColors.ControlLightBrush}" Margin="5">
136137
<Grid>
137138
<Grid.RowDefinitions>
138-
<RowDefinition Height="Auto" />
139139
<RowDefinition Height="Auto" />
140140
<RowDefinition Height="*" />
141141
<RowDefinition Height="Auto" />
@@ -174,42 +174,51 @@
174174
</TabItem.Header>
175175
</TabItem>
176176
</TabControl>
177-
<Border Grid.Row="1"
178-
Background="{x:Static SystemColors.ControlBrush}"
179-
BorderBrush="{x:Static SystemColors.ActiveBorderBrush}"
180-
BorderThickness="1"
181-
Margin="10,10,10,0"
182-
Padding="2">
183-
<Grid>
184-
<Grid.ColumnDefinitions>
185-
<ColumnDefinition Width="*" />
186-
<ColumnDefinition Width="20" />
187-
<ColumnDefinition Width="20" />
188-
</Grid.ColumnDefinitions>
189-
<TextBox Grid.Column="0">
190-
<TextBox.Style>
191-
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource PlaceHolder}">
192-
<Setter Property="Height" Value="20"></Setter>
193-
<Setter Property="Tag" Value="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=References_SearchPlaceholder}" />
194-
<Setter Property="Text" Value="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
195-
</Style>
196-
</TextBox.Style>
197-
</TextBox>
198-
<Border Grid.Column="1" Margin="2">
199-
<Image Source="{StaticResource SearchIcon}" />
200-
</Border>
201-
<Button Grid.Column="2" Command="{Binding BrowseCommand}">
202-
<Image Margin="2,0" Source="{StaticResource BrowseIcon}" />
203-
</Button>
204-
</Grid>
205-
</Border>
206-
<Grid Grid.Row="2" Margin="10,10,10,5">
177+
<Button Grid.Row="0" Height="24" Background="{x:Static SystemColors.ControlBrush}" Margin="0,0,10,0"
178+
BorderBrush="{x:Static SystemColors.ActiveBorderBrush}" Width="100" HorizontalAlignment="Right"
179+
Command="{Binding BrowseCommand}">
180+
<StackPanel Orientation="Horizontal">
181+
<Image Margin="0,0,5,0" Height="16" Source="{StaticResource BrowseIcon}" />
182+
<TextBlock Background="Transparent" Text="Browse..."></TextBlock>
183+
</StackPanel>
184+
</Button>
185+
<Grid Grid.Row="1" Margin="10,10,10,5">
207186
<Grid.ColumnDefinitions>
208187
<ColumnDefinition Width="*" />
209188
<ColumnDefinition Width="50" />
210189
<ColumnDefinition Width="*" />
211190
</Grid.ColumnDefinitions>
212-
<Border Grid.Column="0">
191+
<Grid.RowDefinitions>
192+
<RowDefinition Height="Auto" />
193+
<RowDefinition Height="*" />
194+
</Grid.RowDefinitions>
195+
<Border Grid.Row="0" Grid.Column="0"
196+
Background="{x:Static SystemColors.ControlBrush}"
197+
BorderBrush="{x:Static SystemColors.ActiveBorderBrush}"
198+
BorderThickness="1"
199+
Margin="0,5"
200+
Padding="2">
201+
<Grid>
202+
<Grid.ColumnDefinitions>
203+
<ColumnDefinition Width="*" />
204+
<ColumnDefinition Width="20" />
205+
</Grid.ColumnDefinitions>
206+
<TextBox Grid.Column="0">
207+
<TextBox.Style>
208+
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource PlaceHolder}">
209+
<Setter Property="Height" Value="20" />
210+
<Setter Property="Width" Value="Auto" />
211+
<Setter Property="Tag" Value="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=References_SearchPlaceholder}" />
212+
<Setter Property="Text" Value="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
213+
</Style>
214+
</TextBox.Style>
215+
</TextBox>
216+
<Border Grid.Column="1" Margin="2" Width="16" Height="16">
217+
<Image Source="{StaticResource SearchIcon}" />
218+
</Border>
219+
</Grid>
220+
</Border>
221+
<Border Grid.Row="1" Grid.Column="0">
213222
<ListView Name="LibrarySelect" SelectedItem="{Binding SelectedLibrary, Mode=TwoWay}" ItemsSource="{Binding AvailableReferences}" HorizontalContentAlignment="Stretch">
214223
<ListView.ItemContainerStyle>
215224
<Style TargetType="ListViewItem">
@@ -243,15 +252,15 @@
243252
</ListView.ItemTemplate>
244253
</ListView>
245254
</Border>
246-
<StackPanel Grid.Column="1" VerticalAlignment="Center">
255+
<StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Center">
247256
<Button Command="{Binding AddCommand}" Width="40" Height="20" Padding="0" Margin="0,1">
248257
<Image Margin="5,0" Source="{StaticResource AddIcon}" />
249258
</Button>
250259
<Button Command="{Binding RemoveCommand}" Width="40" Height="20" Padding="0" Margin="0,1">
251260
<Image Margin="5,0" Source="{StaticResource RemoveIcon}" />
252261
</Button>
253262
</StackPanel>
254-
<Border Grid.Column="2">
263+
<Border Grid.Row="1" Grid.Column="2">
255264
<ListView Name="ProjectSelect" SelectedItem="{Binding SelectedReference, Mode=TwoWay}" ItemsSource="{Binding ProjectReferences}" HorizontalContentAlignment="Stretch">
256265
<ListView.ItemContainerStyle>
257266
<Style TargetType="ListViewItem">
@@ -290,7 +299,17 @@
290299
<Style TargetType="{x:Type Button}">
291300
<Setter Property="Visibility" Value="Collapsed"/>
292301
<Style.Triggers>
293-
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
302+
<DataTrigger Value="True">
303+
<DataTrigger.Binding>
304+
<MultiBinding Converter="{StaticResource PriorityButtonVisibility}" ConverterParameter="Up">
305+
<MultiBinding.Bindings>
306+
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}" Path="IsSelected" />
307+
<Binding ElementName="ProjectSelect" Path="Items.Count"/>
308+
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}" Path="DataContext"/>
309+
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:AddRemoveReferencesWindow}}" Path="DataContext.BuiltInReferenceCount"/>
310+
</MultiBinding.Bindings>
311+
</MultiBinding>
312+
</DataTrigger.Binding>
294313
<Setter Property="Visibility" Value="Visible"/>
295314
</DataTrigger>
296315
</Style.Triggers>
@@ -306,7 +325,17 @@
306325
<Style TargetType="{x:Type Button}">
307326
<Setter Property="Visibility" Value="Collapsed"/>
308327
<Style.Triggers>
309-
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
328+
<DataTrigger Value="True">
329+
<DataTrigger.Binding>
330+
<MultiBinding Converter="{StaticResource PriorityButtonVisibility}" ConverterParameter="Down">
331+
<MultiBinding.Bindings>
332+
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}" Path="IsSelected" />
333+
<Binding ElementName="ProjectSelect" Path="Items.Count"/>
334+
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}" Path="DataContext"/>
335+
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:AddRemoveReferencesWindow}}" Path="DataContext.BuiltInReferenceCount"/>
336+
</MultiBinding.Bindings>
337+
</MultiBinding>
338+
</DataTrigger.Binding>
310339
<Setter Property="Visibility" Value="Visible"/>
311340
</DataTrigger>
312341
</Style.Triggers>
@@ -320,7 +349,7 @@
320349
</ListView>
321350
</Border>
322351
</Grid>
323-
<Border Style="{StaticResource BorderStyle}" Grid.Row="3" Margin="10,0,10,0">
352+
<Border Style="{StaticResource BorderStyle}" Grid.Row="2" Margin="10,0,10,0">
324353
<Border Style="{StaticResource BorderStyle}">
325354
<Grid>
326355
<Grid.RowDefinitions>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using Rubberduck.AddRemoveReferences;
5+
6+
namespace Rubberduck.UI.AddRemoveReferences
7+
{
8+
internal class PriorityButtonVisibilityConverter : IMultiValueConverter
9+
{
10+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
if (values is null ||
13+
values.Length != 4 ||
14+
!(bool)values[0] || //IsSelected
15+
!(values[2] is ReferenceModel reference) || //DataContext
16+
reference.IsBuiltIn ||
17+
!(parameter is string direction))
18+
{
19+
return false;
20+
}
21+
22+
var position = reference.Priority; //ProjectSelect.SelectedIndex
23+
var items = (int)values[1]; //ProjectSelect.Items.Count
24+
var builtIn = (int)values[3]; //AddRemoveReferencesWindow.DataContext.BuiltInReferenceCount
25+
26+
if (direction.Equals("Up"))
27+
{
28+
return position > builtIn + 1;
29+
}
30+
31+
return position != items;
32+
}
33+
34+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
35+
{
36+
throw new InvalidOperationException();
37+
}
38+
}
39+
}

Rubberduck.Parsing/ComReflection/ComDocumentation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Rubberduck.Parsing.ComReflection
77
public class ComDocumentation
88
{
99
public const int LibraryIndex = -1;
10+
1011
[DataMember(IsRequired = true)]
1112
public string Name { get; private set; }
1213

Rubberduck.Parsing/ComReflection/ComField.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private void GetFieldType(TYPEDESC desc, ITypeInfo info)
118118
_enumGuid = attribs.guid;
119119
}
120120
IsReferenceType = ReferenceTypeKinds.Contains(attribs.typekind);
121-
_valueType = new ComDocumentation(refTypeInfo, -1).Name;
121+
_valueType = new ComDocumentation(refTypeInfo, ComDocumentation.LibraryIndex).Name;
122122
}
123123
}
124124
catch (COMException) { }

0 commit comments

Comments
 (0)