diff --git a/src/App/EditPage.xaml b/src/App/EditPage.xaml index 40a03c7e..1b9a2a1f 100644 --- a/src/App/EditPage.xaml +++ b/src/App/EditPage.xaml @@ -232,8 +232,14 @@ - - + + + + + + + + diff --git a/src/App/EditPage.xaml.cs b/src/App/EditPage.xaml.cs index 22832785..0a6278cc 100644 --- a/src/App/EditPage.xaml.cs +++ b/src/App/EditPage.xaml.cs @@ -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}"; diff --git a/src/App/SaveLoadEditPage.xaml b/src/App/SaveLoadEditPage.xaml index 4a8edfc2..362c6f72 100644 --- a/src/App/SaveLoadEditPage.xaml +++ b/src/App/SaveLoadEditPage.xaml @@ -106,7 +106,15 @@ - + + + + + + + + + diff --git a/src/App/SaveLoadEditPage.xaml.cs b/src/App/SaveLoadEditPage.xaml.cs index 1bead5de..32dfd24b 100644 --- a/src/App/SaveLoadEditPage.xaml.cs +++ b/src/App/SaveLoadEditPage.xaml.cs @@ -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(); + 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(); + newOrder.AddRange(TaskListCollection.Select(x => x.Guid)); + await Client.ReorderTaskLists(newOrder); + } } /// @@ -458,6 +488,16 @@ namespace Microsoft.FactoryOrchestrator.UWP } } + /// + /// Given a button associated with a tasklist, returns the tasklist 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); + } + /// /// Given a button associated with a tasklist, returns the tasklist GUID. /// @@ -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(); } }