Skip to content

Commit 62bc04a

Browse files
committed
select first row by default when searching (so can press enter to open), if press up/down key in searchbox move into results
1 parent f068166 commit 62bc04a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
<!-- search box -->
262262
<Grid Background="{DynamicResource TextBoxBackground}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="222" Margin="6,5,0,0" Height="20" >
263263
<TextBlock Margin="3,2" MinWidth="100" Text="Search" Foreground="#7F919191" Visibility="{Binding ElementName=txtSearchBox, Path=Text.IsEmpty, Converter={StaticResource MyBoolToVisibilityConverter}}" Height="24" />
264-
<TextBox MinWidth="100" CaretBrush="#FFE2E2E2" Name="txtSearchBox" Background="Transparent" BorderBrush="{x:Null}" Foreground="#FFC7C7C7" SelectionBrush="#FF003966" BorderThickness="0" Margin="2,2,0,0" UndoLimit="64" TextChanged="OnSearchTextChanged" />
264+
<TextBox MinWidth="100" CaretBrush="#FFE2E2E2" Name="txtSearchBox" Background="Transparent" BorderBrush="{x:Null}" Foreground="#FFC7C7C7" SelectionBrush="#FF003966" BorderThickness="0" Margin="2,2,0,0" UndoLimit="64" TextChanged="OnSearchTextChanged" PreviewKeyDown="TxtSearchBox_PreviewKeyDown" />
265265
<Button Name="btnClearSearch" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" BorderThickness="0" HorizontalAlignment="Right" VerticalAlignment="Top" Height="23" Width="23" Background="Transparent" Padding="0,2" Visibility="Visible" BorderBrush="{x:Null}" Click="OnClearProjectSearchClick">
266266
<TextBlock Text="" FontSize="8" Foreground="{DynamicResource ButtonForeground}" Padding="5,3,4,4" HorizontalAlignment="Center">
267267
<TextBlock.Style>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,19 @@ private void OnSearchPreviewKeyDown(object sender, KeyEventArgs e)
127127
}
128128
}
129129

130+
// main search
130131
void FilterRecentProjects()
131132
{
132133
// https://www.wpftutorial.net/DataViews.html
133134
_filterString = txtSearchBox.Text;
134135
ICollectionView collection = CollectionViewSource.GetDefaultView(projectsSource);
135136
collection.Filter = ProjectFilter;
137+
138+
// set first row selected (good, especially if only one results)
139+
if (gridRecent.Items.Count > 0)
140+
{
141+
gridRecent.SelectedIndex = 0;
142+
}
136143
}
137144

138145
private bool ProjectFilter(object item)
@@ -575,6 +582,26 @@ private void BtnUpdateUnity_Click(object sender, RoutedEventArgs e)
575582
{
576583
// TODO check for newer available version in Updates tab, select that row and jump to tab
577584
}
585+
586+
587+
588+
// if press up/down in search box, move to first item in results
589+
private void TxtSearchBox_PreviewKeyDown(object sender, KeyEventArgs e)
590+
{
591+
switch (e.Key)
592+
{
593+
case Key.Up:
594+
case Key.Down:
595+
//e.Handled = true; // if enabled, we enter to first row initially
596+
gridRecent.Focus();
597+
gridRecent.SelectedIndex = 0;
598+
DataGridRow row = (DataGridRow)gridRecent.ItemContainerGenerator.ContainerFromIndex(0);
599+
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
600+
break;
601+
default:
602+
break;
603+
}
604+
}
578605
} // class
579606
} //namespace
580607

0 commit comments

Comments
 (0)