bug fix: ability to move elements up and down a list using keyboard only

This commit is contained in:
ritikaguptams 2021-10-11 09:38:18 -07:00
Родитель 87ae0bb9d7
Коммит 405683a842
4 изменённых файлов: 85 добавлений и 5 удалений

Просмотреть файл

@ -232,8 +232,14 @@
<ColumnDefinition Width="250" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE76F;" Grid.Column="0"/>
<StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" x:Name="moveButtons">
<Button x:Name="Up" Margin="5,0,5,0" Click="MoveUpButton_Click" AutomationProperties.Name="Move up the task list">
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE110;"/>
</Button>
<Button x:Name="Down" Margin="5,0,5,0" Click="MoveDownButton_Click" AutomationProperties.Name="Move down task list" >
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE74B;"/>
</Button>
</StackPanel>
<ContentPresenter Grid.Column="1" />
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" x:Name="buttonGroup">
<Button x:Name="EditListButton" x:Uid="EditListButton" Margin="10,0,5,0" Click="EditButton_Click">

Просмотреть файл

@ -122,6 +122,32 @@ namespace Microsoft.FactoryOrchestrator.UWP
}
}
private void MoveUpButton_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var selectedIndex = TasksCollection.IndexOf(GetTaskFromButton(button));
if (selectedIndex > 0)
{
var itemToMoveUp = TasksCollection[selectedIndex];
TasksCollection.RemoveAt(selectedIndex);
TasksCollection.Insert(selectedIndex - 1, itemToMoveUp);
TaskListView.SelectedIndex = selectedIndex - 1;
}
}
private void MoveDownButton_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var selectedIndex = TasksCollection.IndexOf(GetTaskFromButton(button));
if (selectedIndex + 1 < TasksCollection.Count)
{
var itemToMoveDown = TasksCollection[selectedIndex];
TasksCollection.RemoveAt(selectedIndex);
TasksCollection.Insert(selectedIndex + 1, itemToMoveDown);
TaskListView.SelectedIndex = selectedIndex + 1;
}
}
private void UpdateHeader()
{
TaskListHeader.Text = resourceLoader.GetString("EditingTaskList") + $": {activeList.Name}";

Просмотреть файл

@ -106,7 +106,15 @@
<ColumnDefinition Width="350" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE76F;" Grid.Column="0"/>
<StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" x:Name="moveButtons">
<Button x:Name="Up" Margin="5,0,5,0" Click="MoveUpButton_Click" AutomationProperties.Name="Move up the task list">
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE110;"/>
</Button>
<Button x:Name="Down" Margin="5,0,5,0" Click="MoveDownButton_Click" AutomationProperties.Name="Move down task list">
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE74B;"/>
</Button>
</StackPanel>
<ContentPresenter Grid.Column="1" />
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" x:Name="buttonGroup">
<Button x:Name="EditListButton" Margin="10,0,5,0" x:Uid="EditTaskListButton" Click="EditListButton_Click" AutomationProperties.Name="Edit Task List">

Просмотреть файл

@ -374,7 +374,7 @@ namespace Microsoft.FactoryOrchestrator.UWP
// This is called when the layout is updated to update the accessible name of the edit, delete and save buttons.
private void TaskListsView_LayoutUpdated(object sender, object e)
{
for (int i = 0; i < TaskListCollection.Count; i++)
{
var item = TaskListsView.ContainerFromIndex(i) as FrameworkElement;
@ -417,6 +417,36 @@ namespace Microsoft.FactoryOrchestrator.UWP
ContentDialogResult result = await failedSaveDialog.ShowAsync();
}
}
private async void MoveUpButton_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var selectedIndex = TaskListCollection.IndexOf(GetTaskListFromButton(button));
if (selectedIndex > 0)
{
var itemToMoveUp = TaskListCollection[selectedIndex];
TaskListCollection.RemoveAt(selectedIndex);
TaskListCollection.Insert(selectedIndex - 1, itemToMoveUp);
var newOrder = new List<Guid>();
newOrder.AddRange(TaskListCollection.Select(x => x.Guid));
await Client.ReorderTaskLists(newOrder);
}
}
private async void MoveDownButton_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
var selectedIndex = TaskListCollection.IndexOf(GetTaskListFromButton(button));
if (selectedIndex + 1 < TaskListCollection.Count)
{
var itemToMoveDown = TaskListCollection[selectedIndex];
TaskListCollection.RemoveAt(selectedIndex);
TaskListCollection.Insert(selectedIndex + 1, itemToMoveDown);
var newOrder = new List<Guid>();
newOrder.AddRange(TaskListCollection.Select(x => x.Guid));
await Client.ReorderTaskLists(newOrder);
}
}
/// <summary>
@ -458,6 +488,16 @@ namespace Microsoft.FactoryOrchestrator.UWP
}
}
/// <summary>
/// Given a button associated with a tasklist, returns the tasklist summary.
/// </summary>
private static TaskListSummary GetTaskListFromButton(Button button)
{
var stack = button.Parent as StackPanel;
var grid = stack.Parent as Grid;
return ((TaskListSummary)((ContentPresenter)(grid.Children.Where(x => x.GetType() == typeof(ContentPresenter)).First())).Content);
}
/// <summary>
/// Given a button associated with a tasklist, returns the tasklist GUID.
/// </summary>
@ -501,6 +541,6 @@ namespace Microsoft.FactoryOrchestrator.UWP
private bool _isFileLoad;
private Frame mainPage;
private readonly FactoryOrchestratorUWPClient Client = ((App)Application.Current).Client;
private readonly ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView();
private readonly ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView();
}
}