104 lines
2.6 KiB
C#
104 lines
2.6 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using TBF.Rig.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
|
|
string classNamePrefix;
|
|
|
|
int selectedIndex = -1;
|
|
|
|
/// Constructor
|
|
public SelectComponentClassDlg(string prefix = null)
|
|
{
|
|
InitializeComponent();
|
|
|
|
classNamePrefix = (prefix != null) ? prefix : string.Empty;
|
|
foreach (var componentFactory in Rig.TbfComponents.Factories)
|
|
{
|
|
if (componentFactory.ClassName.StartsWith(classNamePrefix))
|
|
{
|
|
availCmpntsLstBox.Items.Add(componentFactory);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Load components from Rig.SupportedComponents
|
|
private void SelectComponentClassDlg_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
if (selectedIndex >= 0 && selectedIndex < Rig.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)
|
|
{
|
|
if (availCmpntsLstBox.SelectedItem is IComponentFactory)
|
|
{
|
|
SlctdCmpntFactory = availCmpntsLstBox.SelectedItem as IComponentFactory;
|
|
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 < Rig.TbfComponents.Factories.Count)
|
|
{
|
|
selectedIndex = index;
|
|
SlctdCmpntFactory = Rig.TbfComponents.Factories[index];
|
|
|
|
OpenFileDialog dlg = new OpenFileDialog();
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
SelectedScriptName = dlg.FileName;
|
|
}
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|