/// Copyright (c) 2021 Iiro Iivanainen, Harri Linna, Jere Pakkanen, Riikka Vilavaara
///
/// Permission is hereby granted, free of charge, to any person obtaining
/// a copy of this software and associated documentation files (the
/// "Software"), to deal in the Software without restriction, including
/// without limitation the rights to use, copy, modify, merge, publish,
/// distribute, sublicense, and/or sell copies of the Software, and to
/// permit persons to whom the Software is furnished to do so, subject to
/// the following conditions:
///
/// The above copyright notice and this permission notice shall be included
/// in all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
/// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
/// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
/// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
/// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
/// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
/// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
///
using System.Windows;
using System.Windows.Controls;
using CoreLibrary;
namespace GroundhogApp.Dialogs
{
///
/// Interaction logic for MetaDataDialog.xaml
///
public partial class MetaDataDialog : Window
{
private readonly Metas metas;
public Metas metasEditable;
public MetaDataDialog(Metas metas)
{
InitializeComponent();
this.metas = metas;
metasEditable = Metas.Clone(metas);
DataGrid.ItemsSource = metasEditable.MetaList;
}
///
/// Removes a row from editable metadata.
///
///
///
private void RemoveRow(object sender, RoutedEventArgs e)
{
if (metasEditable.MetaList.Count == 0) return; // Nothing to delete
var i = DataGrid.SelectedIndex;
// if preview row is selected
if (i >= metasEditable.MetaList.Count) return;
// If nothing is selected
if (i < 0)
{
metasEditable.MetaList.RemoveAt(metasEditable.MetaList.Count - 1);
DataGrid.Items.Refresh();
}
Meta selectedItem = (Meta)DataGrid.SelectedItem;
if (selectedItem != null)
{
// TODO: Not working, need to have reference to the collection to be removed
metasEditable.MetaList.Remove(selectedItem);
DataGrid.Items.Refresh();
}
}
///
/// Resets the changes to the last save action or when the dialog was opened.
///
///
///
private void ResetChanges(object sender, RoutedEventArgs e)
{
metasEditable = Metas.Clone(metas);
DataGrid.ItemsSource = metasEditable.MetaList;
}
///
/// Closes the dialog for saving changes to metadata.
///
///
///
private void SaveChanges(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
///
/// Creates a new row for metadata.
///
///
///
private void CreateRow(object sender, RoutedEventArgs e)
{
metasEditable.MetaList.Add(new Meta("", ""));
DataGrid.Items.Refresh();
}
}
}