Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,11 @@ private void Adornment_KeyDown(object sender, KeyEventArgs e)
case Key.Space:
if (Keyboard.Modifiers == ModifierKeys.Control)
{
e.Handled = true;
// If smart rename is available, trigger it.
if (_viewModel.SmartRenameViewModel is not null && _viewModel.SmartRenameViewModel.GetSuggestionsCommand.CanExecute(null))
// If smart rename is available, trigger or toggle it.
if (_viewModel.SmartRenameViewModel is not null)
{
// If smart rename can use automatic behavior, enable it
if (!_viewModel.SmartRenameViewModel.IsUsingDropdown)
{
_viewModel.SmartRenameViewModel.IsSuggestionsPanelCollapsed = !_viewModel.SmartRenameViewModel.IsSuggestionsPanelCollapsed;
}
_viewModel.SmartRenameViewModel.GetSuggestionsCommand.Execute(null);
_viewModel.SmartRenameViewModel.ToggleOrTriggerSuggestions();
e.Handled = true;
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
xmlns:vsui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
xmlns:platformUI="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
mc:Ignorable="d"
Margin="0 0 0 5">
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</UserControl.Resources>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Vertical"
Background="{DynamicResource {x:Static vsui:EnvironmentColors.ComboBoxPopupBackgroundGradientBrushKey}}">
<TextBlock
x:Uid="ErrorTextBlock"
x:Name="ErrorTextBlock"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
xmlns:vsui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
xmlns:sr="clr-namespace:Microsoft.CodeAnalysis.InlineRename.UI.SmartRename"
mc:Ignorable="d"
GotKeyboardFocus="ComboBox_GotKeyboardFocus"
LostKeyboardFocus="ComboBox_LostKeyboardFocus"
Name="SmartRenameInputControl"
Unloaded="ComboBox_Unloaded"
PreviewKeyUp="ComboBox_PreviewKeyUp"
SelectionChanged="ComboBox_SelectionChanged"
Text="{Binding BaseViewModel.IdentifierText, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
ItemsSource="{Binding SuggestedNames}"
StaysOpenOnEdit="True"
IsEditable="True"
Style="{StaticResource {x:Static vsfx:VsResourceKeys.ComboBoxStyleKey}}"
GotKeyboardFocus="ComboBox_GotKeyboardFocus"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling">
<ComboBox.Resources>
Expand Down Expand Up @@ -68,17 +67,17 @@
</Setter>
</Style>

<Style x:Key="GetSuggestionButtonStyle" BasedOn="{StaticResource {x:Static vsfx:VsResourceKeys.ButtonStyleKey}}" TargetType="Button">
<Style x:Key="GetSuggestionsButtonStyle" BasedOn="{StaticResource {x:Static vsfx:VsResourceKeys.ButtonStyleKey}}" TargetType="Button">
<Setter Property="Padding" Value="4,4,1,0"/>
<Setter Property="Margin" Value="3,0,1,1"/>
<Setter Property="Margin" Value="3,1,1,1"/>
<Setter Property="MinHeight" Value="0"/>
<Setter Property="MinWidth" Value="0"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static vsui:CommonControlsColors.ButtonBorderBrushKey}}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Cursor" Value="Arrow"/>
<Setter Property="ForceCursor" Value="True"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsSuggestionsPanelExpanded}" Value="True">
<DataTrigger Binding="{Binding IsAutomaticSuggestionsEnabled}" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static vsui:CommonControlsColors.ButtonDefaultBrushKey}}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static vsui:CommonControlsColors.ButtonBorderPressedBrushKey}}"/>
</DataTrigger>
Expand Down Expand Up @@ -106,41 +105,6 @@
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Popup x:Name="PART_Popup"
x:Uid="PART_Popup"
Visibility="{Binding IsUsingDropdown, Converter={StaticResource BooleanToCollapsedVisibilityConverter}, Mode=OneWay}"
AllowsTransparency="true"
Grid.ColumnSpan="2"
Placement="Bottom"
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
<vsui:SystemDropShadowChrome x:Name="shadow"
x:Uid="shadow"
Color="Transparent"
MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="dropDownBorder"
x:Uid="dropDownBorder"
BorderBrush="{DynamicResource {x:Static vsui:EnvironmentColors.ComboBoxPopupBorderBrushKey}}"
BorderThickness="1">
<ScrollViewer x:Name="DropDownScrollViewer"
x:Uid="DropDownScrollViewer">
<Grid x:Name="grid"
x:Uid="grid"
RenderOptions.ClearTypeHint="Enabled"
RenderOptions.BitmapScalingMode="{x:Static vsui:DpiHelper.BitmapScalingMode}"
Background="{DynamicResource {x:Static vsui:EnvironmentColors.ComboBoxPopupBackgroundGradientBrushKey}}">
<ItemsPresenter x:Name="ItemsPresenter"
x:Uid="ItemsPresenter"
VirtualizingStackPanel.IsVirtualizing="True"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
PreviewMouseUp="ItemsPresenter_PreviewMouseUp">
</ItemsPresenter>
</Grid>
</ScrollViewer>
</Border>
</vsui:SystemDropShadowChrome>
</Popup>
<Border x:Name="border"
x:Uid="border"
Grid.Row="0"
Expand All @@ -159,19 +123,15 @@
Foreground="{TemplateBinding Foreground}"
SelectionBrush="{DynamicResource {x:Static vsui:EnvironmentColors.ComboBoxSelectionBrushKey}}"
IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource Mode=TemplatedParent}}"
Style="{StaticResource ComboBoxEditableTextBox}"
GotFocus="InnerTextBox_GotFocus"
LostFocus="InnerTextBox_LostFocus"
PreviewKeyDown="InnerTextBox_PreviewKeyDown"/>
Style="{StaticResource ComboBoxEditableTextBox}" />
</Border>
<Button x:Name="GetSuggestionsButton"
x:Uid="GetSuggestionsButton"
Grid.Row="0"
Grid.Column="1"
Style="{StaticResource GetSuggestionButtonStyle}"
ToolTip="{Binding GetSuggestionsTooltip}"
Click="GetSuggestionsButtonClick"
Command="{Binding GetSuggestionsCommand}">
x:Uid="GetSuggestionsButton"
Grid.Row="0"
Grid.Column="1"
Style="{StaticResource GetSuggestionsButtonStyle}"
ToolTip="{Binding GetSuggestionsTooltip}"
Click="GetSuggestionsButtonClick">
<Button.Content>
<Canvas Width="16" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center">
<!-- TODO: Replace by KnownMoniker once available. -->
Expand Down Expand Up @@ -214,8 +174,7 @@
x:Uid="ProgressBarHost"
Grid.Row="1"
Grid.Column="0"
BorderThickness="0"
Visibility="{Binding IsUsingDropdown, Converter={StaticResource BooleanToCollapsedVisibilityConverter}, Mode=OneWay}">
BorderThickness="0">
<ProgressBar x:Name="ProgressBar"
x:Uid="ProgressBar"
Height="2"
Expand All @@ -237,36 +196,19 @@
BorderBrush="{DynamicResource {x:Static vsui:EnvironmentColors.ComboBoxPopupBorderBrushKey}}"
BorderThickness="1">
<ScrollViewer x:Name="SuggestionsPanelScrollViewer"
x:Uid="SuggestionsPanelScrollViewer">
x:Uid="SuggestionsPanelScrollViewer"
HorizontalScrollBarVisibility="Hidden"
MouseDoubleClick="SuggestionsPanelScrollViewer_MouseDoubleClick">
<Grid x:Name="SuggestionsPanelGrid"
x:Uid="SuggestionsPanelGrid"
RenderOptions.ClearTypeHint="Enabled"
RenderOptions.BitmapScalingMode="{x:Static vsui:DpiHelper.BitmapScalingMode}"
Background="{DynamicResource {x:Static vsui:EnvironmentColors.ComboBoxPopupBackgroundGradientBrushKey}}">
<StackPanel x:Name="PanelProgressBarHost"
x:Uid="PanelProgressBarHost"
Orientation="Vertical"
Visibility="{Binding IsInProgress, Converter={StaticResource BooleanToHiddenVisibilityConverter}, Mode=OneWay}"
>
<TextBlock x:Name="PanelLabel"
x:Uid="PanelLabel"
Padding="2"
Text="{Binding GeneratingSuggestionsLabel}" />
<ProgressBar x:Name="PanelProgressBar"
x:Uid="PanelProgressBar"
Margin="{TemplateBinding BorderThickness}"
IsIndeterminate="{Binding IsInProgress}"
Height="2"
Template="{DynamicResource {x:Static vsfx:VsResourceKeys.ProgressBarTemplateKey}}"
Foreground="{StaticResource copilotBranding}"
Background="Transparent" />
</StackPanel>
<ItemsPresenter x:Name="AltItemsPresenter"
x:Uid="AltItemsPresenter"
VirtualizingStackPanel.IsVirtualizing="True"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
PreviewMouseUp="ItemsPresenter_PreviewMouseUp">
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" >
</ItemsPresenter>
</Grid>
</ScrollViewer>
Expand All @@ -286,13 +228,6 @@
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource {x:Static vsui:EnvironmentColors.ComboBoxMouseOverBorderBrushKey}}" />
<Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static vsui:EnvironmentColors.ComboBoxMouseOverTextBrushKey}}" />
</Trigger>
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
<Setter Property="Margin" TargetName="shadow" Value="0,0,5,5"/>
<Setter Property="Color" TargetName="shadow" Value="#71000000"/>
</Trigger>
<Trigger Property="HasItems" Value="false">
<Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="true"/>
Expand All @@ -319,6 +254,7 @@
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template" Value="{StaticResource ComboBoxItemTemplate}" />
<Setter Property="Margin" Value="2,0,2,0" />
<Setter Property="Padding" Value="4,1,24,1" /> <!-- Add 20px to the right over the default template to prevent popup from changing size -->
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipping all the xaml. maybe @ryzngard can look at this part.

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ namespace Microsoft.CodeAnalysis.InlineRename.UI.SmartRename;
/// Interaction logic for SmartRenameUserInputComboBox.xaml
/// </summary>
[TemplatePart(Name = InnerTextBox, Type = typeof(TextBox))]
[TemplatePart(Name = DropDownPopup, Type = typeof(Popup))]
internal sealed partial class SmartRenameUserInputComboBox : ComboBox, IRenameUserInput
{
private const string InnerTextBox = "PART_EditableTextBox";
private const string DropDownPopup = "PART_Popup";

private readonly SmartRenameViewModel _smartRenameViewModel;
private readonly RenameFlyoutViewModel _baseViewModel;
private readonly Lazy<TextBox> _innerTextBox;
private Popup? _dropDownPopup;

internal SmartRenameUserInputComboBox(RenameFlyoutViewModel viewModel)
{
Expand All @@ -33,7 +31,7 @@ internal SmartRenameUserInputComboBox(RenameFlyoutViewModel viewModel)

InitializeComponent();
DataContext = viewModel.SmartRenameViewModel;

_baseViewModel = viewModel;
_smartRenameViewModel = viewModel.SmartRenameViewModel;
_innerTextBox = new Lazy<TextBox>(() =>
{
Expand Down Expand Up @@ -95,58 +93,27 @@ void IRenameUserInput.Focus()
this.Focus();
}

public override void OnApplyTemplate()
private void ComboBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
base.OnApplyTemplate();
// Handle the event to avoid stack overflow through passing execution back RenameFlyout.Adornment_GotKeyboardFocus
e.Handled = true;
}

_dropDownPopup = (Popup)GetTemplateChild(DropDownPopup)!;
private void SuggestionsPanelScrollViewer_MouseDoubleClick(object sender, MouseEventArgs e)
{
_baseViewModel.Submit();
}

private void GetSuggestionsButtonClick(object sender, RoutedEventArgs e)
{
if (_smartRenameViewModel.IsUsingResultPanel)
{
_smartRenameViewModel.IsSuggestionsPanelCollapsed = !_smartRenameViewModel.IsSuggestionsPanelCollapsed;
if (_smartRenameViewModel.IsSuggestionsPanelExpanded)
{
_smartRenameViewModel.GetSuggestionsCommand.Execute(null);
}
}
else
{
_smartRenameViewModel.GetSuggestionsCommand.Execute(null);
}
_smartRenameViewModel.ToggleOrTriggerSuggestions();
}

private void ComboBox_Unloaded(object sender, RoutedEventArgs e)
{
_smartRenameViewModel.SuggestedNames.CollectionChanged -= SuggestedNames_CollectionChanged;
}

private void ComboBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
e.Handled = true;
}

private void ComboBox_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
Assumes.NotNull(_dropDownPopup);
_dropDownPopup.IsOpen = false;
}

private void ComboBox_PreviewKeyUp(object sender, KeyEventArgs e)
{
if (!_smartRenameViewModel.IsUsingDropdown)
{
return;
}
if ((e.Key is Key.Up or Key.Down) && Items.Count > 0)
{
Assumes.NotNull(_dropDownPopup);
_dropDownPopup.IsOpen = true;
}
}

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
Expand All @@ -156,44 +123,6 @@ private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs
}
}

private void ItemsPresenter_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
Assumes.NotNull(_dropDownPopup);
_dropDownPopup.IsOpen = false;
}

private void InnerTextBox_GotFocus(object sender, RoutedEventArgs e)
{
e.Handled = true; // Prevent selecting all the text
if (!_smartRenameViewModel.IsUsingDropdown)
{
return;
}
if (Items.Count > 0)
{
Assumes.NotNull(_dropDownPopup);
_dropDownPopup.IsOpen = true;
}
}

private void InnerTextBox_LostFocus(object sender, RoutedEventArgs e)
{
Assumes.NotNull(_dropDownPopup);
_dropDownPopup.IsOpen = false;
}

private void InnerTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
Assumes.NotNull(_dropDownPopup);
if ((e.Key is Key.Escape or Key.Space or Key.Enter)
&& _dropDownPopup.IsOpen) // Handle these keystrokes when dropdown is present
{
_dropDownPopup.IsOpen = false;
SelectAllText();
e.Handled = true;
}
}

private void SuggestedNames_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Focus();
Expand Down
Loading