|
|
@@ -1,4 +1,5 @@
|
|
|
-using System.Collections.Concurrent;
|
|
|
+using System;
|
|
|
+using System.Collections.Concurrent;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Input;
|
|
|
@@ -24,7 +25,7 @@ namespace YSAI.Tool
|
|
|
/// <summary>
|
|
|
/// 数据源
|
|
|
/// </summary>
|
|
|
- public class Source : NotifyObject
|
|
|
+ public class TabSource : NotifyObject
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 图标
|
|
|
@@ -51,17 +52,50 @@ namespace YSAI.Tool
|
|
|
get => GetProperty(() => UserControl);
|
|
|
set => SetProperty(() => UserControl, value);
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 关闭当前选项卡
|
|
|
+ /// </summary>
|
|
|
+ public ICommand CloseTab
|
|
|
+ {
|
|
|
+ get => new CommandX(() =>
|
|
|
+ {
|
|
|
+ OnEventHandler(this);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public event EventHandler<TabSource> OnEvent;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 信息传递
|
|
|
+ /// </summary>
|
|
|
+ protected void OnEventHandler(TabSource e)
|
|
|
+ {
|
|
|
+ OnEvent?.Invoke(null, e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public class MainWindowController : NotifyObject
|
|
|
{
|
|
|
+ public MainWindowController()
|
|
|
+ {
|
|
|
+ //设置初始语言
|
|
|
+ LangsHelper.SetLangs(LangsHelper.GetLangs());
|
|
|
+
|
|
|
+ if (TabControlItemsSource == null)
|
|
|
+ {
|
|
|
+ TabControlItemsSource = new ObservableCollection<TabSource>();
|
|
|
+ }
|
|
|
+ InitControl();
|
|
|
+ }
|
|
|
+
|
|
|
#region 控件
|
|
|
public ICommand AboutUsTool
|
|
|
{
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "AboutUsTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -71,7 +105,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "CanTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -81,7 +115,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "MqttClientTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -91,7 +125,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "MqttServiceTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -101,7 +135,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "MqttWebSocketServiceTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -111,7 +145,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "OpcDaHttpClientTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -121,7 +155,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "OpcUaClientTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -131,7 +165,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "OpcUaServiceTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -141,7 +175,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "SerialPortTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -151,7 +185,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "SocketTcpClientTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -161,7 +195,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "SocketTcpServerTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -171,7 +205,7 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "SocketUdpTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
@@ -181,121 +215,138 @@ namespace YSAI.Tool
|
|
|
get => new CommandX(() =>
|
|
|
{
|
|
|
string name = "SvgTool";
|
|
|
- Source source = Sources[name];
|
|
|
+ TabSource source = TabSources[name];
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
});
|
|
|
}
|
|
|
#endregion 控件
|
|
|
|
|
|
- public MainWindowController()
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化控件
|
|
|
+ /// </summary>
|
|
|
+ public void InitControl()
|
|
|
{
|
|
|
- //设置初始语言
|
|
|
- LangsHelper.SetLangs(LangsHelper.GetLangs());
|
|
|
-
|
|
|
- if (TabControlItemsSource == null)
|
|
|
- {
|
|
|
- TabControlItemsSource = new ObservableCollection<Source>();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ #region 控件提前加载
|
|
|
string name = "CanTool";
|
|
|
UserControl control = new CanTool();
|
|
|
- Source source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ TabSource source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "MqttClientTool";
|
|
|
control = new MqttClientTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "MqttServiceTool";
|
|
|
control = new MqttServiceTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "MqttWebSocketServiceTool";
|
|
|
control = new MqttWebSocketServiceTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "OpcDaHttpClientTool";
|
|
|
control = new OpcDaHttpClientTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "OpcUaClientTool";
|
|
|
control = new OpcUaClientTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "OpcUaServiceTool";
|
|
|
control = new OpcUaServiceTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "SerialPortTool";
|
|
|
control = new SerialPortTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "SocketTcpClientTool";
|
|
|
control = new SocketTcpClientTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "SocketTcpServerTool";
|
|
|
control = new SocketTcpServerTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
name = "SocketUdpTool";
|
|
|
control = new SocketUdpTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
|
|
|
name = "SvgTool";
|
|
|
control = new SvgTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
|
|
|
|
|
|
name = "AboutUsTool";
|
|
|
control = new AboutUsTool();
|
|
|
- source = new Source { Title = name, UserControl = control };
|
|
|
- Sources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
+ source = new TabSource { Title = name, UserControl = control };
|
|
|
+ source.OnEvent += Source_OnEvent;
|
|
|
+ TabSources.AddOrUpdate(name, source, (k, v) => source);
|
|
|
UserControls.AddOrUpdate(name, control, (k, v) => control);
|
|
|
+ #endregion
|
|
|
|
|
|
if (!TabControlItemsSource.Contains(source)) { TabControlItemsSource.Add(source); }
|
|
|
TabControlSelectedItem = source;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 控件集合,提前加载
|
|
|
+ /// 关闭
|
|
|
+ /// </summary>
|
|
|
+ private void Source_OnEvent(object? sender, TabSource e)
|
|
|
+ {
|
|
|
+ TabControlItemsSource.Remove(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 控件集合,提前加载,后期不移除
|
|
|
/// </summary>
|
|
|
private ConcurrentDictionary<string, UserControl> UserControls = new ConcurrentDictionary<string, UserControl>();
|
|
|
/// <summary>
|
|
|
- /// 数据源集合
|
|
|
+ /// 数据源集合,后期不移除
|
|
|
/// </summary>
|
|
|
- private ConcurrentDictionary<string, Source> Sources = new ConcurrentDictionary<string, Source>();
|
|
|
+ private ConcurrentDictionary<string, TabSource> TabSources = new ConcurrentDictionary<string, TabSource>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 选项卡控件项源
|
|
|
/// </summary>
|
|
|
- public ObservableCollection<Source> TabControlItemsSource
|
|
|
+ public ObservableCollection<TabSource> TabControlItemsSource
|
|
|
{
|
|
|
get => GetProperty(() => TabControlItemsSource);
|
|
|
set => SetProperty(() => TabControlItemsSource, value);
|
|
|
@@ -303,10 +354,12 @@ namespace YSAI.Tool
|
|
|
/// <summary>
|
|
|
/// 选中的项
|
|
|
/// </summary>
|
|
|
- public Source TabControlSelectedItem
|
|
|
+ public TabSource TabControlSelectedItem
|
|
|
{
|
|
|
get => GetProperty(() => TabControlSelectedItem);
|
|
|
set => SetProperty(() => TabControlSelectedItem, value);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|