using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
namespace MusicMetaTagger.UI
{
///
/// GUI object for selecting an IMusicLibraryinterface
///
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof (IDesigner))]
public partial class LibrarySelector : UserControl
{
public event PropertyChangedEventHandler LibraryNameChanged;
///
/// Text assocatied with the imageList array objects
///
private static readonly string[] LibraryNames = new[] {"iTunes", "Windows Media Player"};
///
/// Gets the currently selected library.
///
/// The selected library.
public IMusicLibraryInterface SelectedLibrary { get; private set; }
///
/// Initializes a new instance of the class.
///
public LibrarySelector()
{
InitializeComponent();
}
///
/// Handles the SelectionChangeCommitted event of the libraryTypeComboBox control.
///
/// The source of the event.
/// The instance containing the event data.
private void libraryTypeComboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
if (libraryTypeComboBox.SelectedIndex == 0)
{
SelectedLibrary = new ItunesLibraryInterface();
pictureBox.Image = imageList.Images[0];
}
else if (libraryTypeComboBox.SelectedIndex == 1)
{
SelectedLibrary = new MediaPlayerLibraryInterface();
pictureBox.Image = imageList.Images[1];
}
if (LibraryNameChanged != null)
LibraryNameChanged.Invoke(this, new PropertyChangedEventArgs("SelectedLibrary"));
}
///
/// Handles the Click event of the LibrarySelector control.
///
/// The source of the event.
/// The instance containing the event data.
private void LibrarySelector_Click(object sender, EventArgs e)
{
libraryTypeComboBox.DroppedDown = !libraryTypeComboBox.DroppedDown;
}
///
/// Handles the Click event of the pictureBox control.
///
/// The source of the event.
/// The instance containing the event data.
private void pictureBox_Click(object sender, EventArgs e)
{
libraryTypeComboBox.DroppedDown = !libraryTypeComboBox.DroppedDown;
}
///
/// Handles the Load event of the LibrarySelector control.
///
/// The source of the event.
/// The instance containing the event data.
private void LibrarySelector_Load(object sender, EventArgs e)
{
libraryTypeComboBox.Items.AddRange(LibraryNames);
libraryTypeComboBox.SelectedIndex = 0;
libraryTypeComboBox_SelectionChangeCommitted(this, e);
}
///
/// Handles the KeyDown event of the libraryTypeComboBox control.
///
/// The source of the event.
/// The instance containing the event data.
private void libraryTypeComboBox_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
}
}
}