78 lines
2.6 KiB
C#
78 lines
2.6 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using UserControl = System.Windows.Controls.UserControl;
|
|
|
|
namespace Plugin
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ConnectionParameterUserControl.xaml
|
|
/// </summary>
|
|
public partial class EngineConnectionParameterUserControl : UserControl
|
|
{
|
|
public EngineConnectionParameterUserControl()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// ip list box gains focus
|
|
_listBox.Focus();
|
|
}
|
|
|
|
// A delegate type for hooking up change notifications.
|
|
public delegate void ConnectionRequestEventHandler(object sender, EventArgs e);
|
|
public event ConnectionRequestEventHandler ConnectionRequest = null;
|
|
|
|
private EngineConnectionManager ConnectionManager
|
|
{
|
|
get
|
|
{
|
|
if (DataContext == null || DataContext is EngineConnectionManager == false)
|
|
throw new InvalidOperationException("Set Datacontext to your EngineConnectionManager first");
|
|
return (EngineConnectionManager) DataContext;
|
|
}
|
|
}
|
|
|
|
private void OnAddButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var newIPDialog = new NewConnectionSettingWindow(ConnectionManager);
|
|
|
|
Nullable<bool> dialogResult = newIPDialog.ShowDialog();
|
|
if (dialogResult.HasValue && dialogResult.Value)
|
|
{
|
|
string targetIp = newIPDialog.TargetIp;
|
|
string portName = newIPDialog.PortName;
|
|
string target = newIPDialog.Target;
|
|
string name = newIPDialog.SettingName;
|
|
|
|
ConnectionManager.AddConnectionSetting(targetIp, portName, target, name);
|
|
}
|
|
}
|
|
|
|
private void OnRemoveButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (sender is FrameworkElement)
|
|
{
|
|
object dc = (sender as FrameworkElement).DataContext;
|
|
|
|
if (dc is EngineConnectionSettings)
|
|
{
|
|
var connectionSetting = dc as EngineConnectionSettings;
|
|
ConnectionManager.RemoveConnectionSetting(connectionSetting);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnListViewMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (ConnectionRequest != null)
|
|
ConnectionRequest(this, e);
|
|
}
|
|
|
|
private void OnConnectButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (ConnectionRequest != null)
|
|
ConnectionRequest(this, e);
|
|
}
|
|
}
|
|
}
|