/// /// Copyright (c) 2013-2015 Sensus Slovensko a.s. /// using System; using System.Windows.Forms; using TBF.BenchControl.Generic; using TBF.Resources; namespace TBF.UI.Bench.Components { public partial class SelectComponentClassDlg : Form { /// This is the main result of this dialog public IComponentFactory SlctdCmpntFactory = null; public string SelectedScriptName = null; /// Filled with a script file name after a right-click int selectedIndex = -1; /// Constructor public SelectComponentClassDlg() { InitializeComponent(); foreach (var componentFactory in BenchControl.TbfComponents.Factories) { availCmpntsLstBox.Items.Add(componentFactory.ClassName); } } /// Load components from BenchControl.SupportedComponents private void SelectComponentClassDlg_Load(object sender, EventArgs e) { Localize(); if (selectedIndex >= 0 && selectedIndex < BenchControl.TbfComponents.Factories.Count) { availCmpntsLstBox.SelectedIndex = selectedIndex; } } void Localize() { Text = Strings.Select_Component; availableComponentsLabel.Text = Strings.Available_Components_; okButton.Text = Strings.OkBtnText; cancelButton.Text = Strings.CancelBtnText; } /// Double click - Add the clicked component private void availCmpntsLstBox_DoubleClick(object sender, EventArgs e) { okButton_Click(sender, e); } /// OK - Add the selected component private void okButton_Click(object sender, EventArgs e) { int ix = availCmpntsLstBox.SelectedIndex; if (ix >= 0 && ix < BenchControl.TbfComponents.Factories.Count) { selectedIndex = ix; SlctdCmpntFactory = BenchControl.TbfComponents.Factories[ix]; DialogResult = DialogResult.OK; Close(); return; } } /// Cancel - Do nothing private void cancelButton_Click(object sender, EventArgs e) { SlctdCmpntFactory = null; DialogResult = DialogResult.Cancel; Close(); return; } private void availCmpntsLstBox_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { int index = availCmpntsLstBox.IndexFromPoint(e.Location); if (index >= 0 && index < BenchControl.TbfComponents.Factories.Count) { selectedIndex = index; SlctdCmpntFactory = BenchControl.TbfComponents.Factories[index]; OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) { SelectedScriptName = dlg.FileName; } DialogResult = DialogResult.OK; Close(); return; } } } } }