File size: 1,471 Bytes
e3ea2f2 07bbbbf e3ea2f2 07bbbbf e3ea2f2 07bbbbf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
using mdict.Services;
namespace mdict.Views
{
public partial class LibraryView : UserControl
{
public LibraryView()
{
InitializeComponent();
DictionariesList.ItemsSource = LibraryManager.Instance.LoadedDictionaries;
}
private void AddDictionary_Click(object sender, RoutedEventArgs e)
{
var openFileDialog = new OpenFileDialog
{
Filter = "MDict Files (*.mdx)|*.mdx|All Files (*.*)|*.*",
Multiselect = true
};
if (openFileDialog.ShowDialog() == true)
{
foreach (var filename in openFileDialog.FileNames)
{
try
{
LibraryManager.Instance.AddDictionary(filename);
}
catch (System.Exception ex)
{
MessageBox.Show($"Failed to load {filename}:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
private void RemoveDictionary_Click(object sender, RoutedEventArgs e)
{
if (sender is Button button && button.Tag is DictionaryItem item)
{
LibraryManager.Instance.RemoveDictionary(item);
}
}
}
}
|