Skip to content

Commit

Permalink
优化 插件和情景项目在管理界面现在不可选中
Browse files Browse the repository at this point in the history
新增 情景编辑右键节点/连接可以直接删除
修复 清理节点无效
  • Loading branch information
MakesYT committed Oct 23, 2023
1 parent b10cf11 commit b84384a
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 245 deletions.
1 change: 0 additions & 1 deletion Core/SDKs/Tools/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public static class Math
// 评估一个复杂数学表达式,返回一个decimal类型的值
public static decimal Evaluate(string expression)
{
//log.Debug($"计算{expression}");
// 去掉空格
expression = expression.Replace(" ", "");
// 处理括号
Expand Down
159 changes: 103 additions & 56 deletions Core/ViewModel/TaskEditor/TaskEditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,63 @@ namespace Core.ViewModel.TaskEditor;

public partial class TaskEditorViewModel : ObservableRecipient
{
private static readonly ILog Log = LogManager.GetLogger(nameof(TaskEditorViewModel));

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(SaveCustomScenarioCommand))]
[NotifyCanExecuteChangedFor(nameof(SaveAndQuitCustomScenarioCommand))]
public bool _isModified = false;

[ObservableProperty] private BindingList<BindingList<object>> _nodeMethods = new();

[ObservableProperty] private CustomScenario _scenario = new CustomScenario() { IsActive = true };


private Window _window;

public TaskEditorViewModel()
{
Scenario.PropertyChanged += (e, s) =>
{
if (s.PropertyName == "Name")
{
Scenario.nodes[0].Title = Scenario.Name;
}
IsModified = true;
};
PendingConnection = new PendingConnectionViewModel(this);
GetAllMethods();
var nodify2 = new PointItem()
{
Title = "任务1"
};
nodify2.Output = new ObservableCollection<ConnectorItem>
{
new()
{
IsOut = true,
Source = nodify2,
Type = typeof(NodeConnectorClass),
TypeName = BaseNodeMethodsGen.GetI18N(typeof(NodeConnectorClass).FullName),
Title = "开始"
}
};
Scenario.nodes.Add(nodify2);
//nodeMethods.Add("new PointItem(){Title = \"Test\"}");
}

public object ContentPresenter
{
get;
set;
}

private static readonly ILog Log = LogManager.GetLogger(nameof(TaskEditorViewModel));

public PendingConnectionViewModel PendingConnection
{
get;
}

[ObservableProperty] private BindingList<BindingList<object>> _nodeMethods = new();


[RelayCommand]
private void AddNodes(PointItem pointItem)
Expand Down Expand Up @@ -102,10 +144,52 @@ private void AddNodes(PointItem pointItem)
Scenario.nodes.Add(item);
}

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(SaveCustomScenarioCommand))]
[NotifyCanExecuteChangedFor(nameof(SaveAndQuitCustomScenarioCommand))]
public bool _isModified = false;
[RelayCommand]
private void DelNode(PointItem pointItem)
{
IsModified = true;
if (Scenario.nodes.IndexOf(pointItem) == 0)
{
return;
}

var connectionItems = Scenario.connections
.Where((e) => e.Source.Source == pointItem || e.Target.Source == pointItem).ToList();
foreach (var connectionItem in connectionItems)
{
Scenario.connections.Remove(connectionItem);
if (Scenario.connections.All(e => e.Source != connectionItem.Source))
{
connectionItem.Source.IsConnected = false;
}

if (Scenario.connections.All(e => e.Target != connectionItem.Target))
{
connectionItem.Target.IsConnected = false;
}
}

Scenario.nodes.Remove(pointItem);
}

[RelayCommand]
private void DelConnection(ConnectionItem connection)
{
IsModified = true;
Scenario.connections.Remove(connection);
if (Scenario.connections.All(e => e.Source != connection.Source))
{
connection.Source.IsConnected = false;
}

if (Scenario.connections.All(e => e.Target != connection.Target))
{
connection.Target.IsConnected = false;
}

IsModified = true;
ToFirstVerify();
}


[RelayCommand(CanExecute = nameof(IsModified))]
Expand Down Expand Up @@ -155,7 +239,7 @@ private void CleanUnusedNode()

if (!toRemove)
{
return;
continue;
}

foreach (var connectorItem in Scenario.nodes[i].Output)
Expand Down Expand Up @@ -199,8 +283,6 @@ private void DisconnectConnector(ConnectorItem connector)
ToFirstVerify();
}

[ObservableProperty] private CustomScenario _scenario = new CustomScenario() { IsActive = true };

private void GetAllMethods()
{
BaseNodeMethodsGen.GenBaseNodeMethods(NodeMethods);
Expand All @@ -217,38 +299,6 @@ private void GetAllMethods()
}
}

public TaskEditorViewModel()
{
Scenario.PropertyChanged += (e, s) =>
{
if (s.PropertyName == "Name")
{
Scenario.nodes[0].Title = Scenario.Name;
}
IsModified = true;
};
PendingConnection = new PendingConnectionViewModel(this);
GetAllMethods();
var nodify2 = new PointItem()
{
Title = "任务1"
};
nodify2.Output = new ObservableCollection<ConnectorItem>
{
new()
{
IsOut = true,
Source = nodify2,
Type = typeof(NodeConnectorClass),
TypeName = BaseNodeMethodsGen.GetI18N(typeof(NodeConnectorClass).FullName),
Title = "开始"
}
};
Scenario.nodes.Add(nodify2);
//nodeMethods.Add("new PointItem(){Title = \"Test\"}");
}

public void Load(CustomScenario customScenario)
{
Scenario = customScenario;
Expand All @@ -267,9 +317,6 @@ public void Load(CustomScenario customScenario)
};
}


private Window _window;

[RelayCommand]
private void Load(object window)
{
Expand Down Expand Up @@ -381,6 +428,13 @@ private void AddKey(string key)

public partial class PointItem : ObservableRecipient
{
[ObservableProperty] private Point _location;

[ObservableProperty] private string _title;
[ObservableProperty] private ObservableCollection<ConnectorItem> input = new();
[ObservableProperty] private ObservableCollection<ConnectorItem> output = new();
[ObservableProperty] private s节点状态 status = s节点状态.未验证;

public string? Plugin
{
get;
Expand All @@ -398,13 +452,6 @@ public string MerthodName
get;
set;
}

[ObservableProperty] private Point _location;

[ObservableProperty] private string _title;
[ObservableProperty] private s节点状态 status = s节点状态.未验证;
[ObservableProperty] private ObservableCollection<ConnectorItem> input = new();
[ObservableProperty] private ObservableCollection<ConnectorItem> output = new();
}

public enum s节点状态
Expand All @@ -418,12 +465,14 @@ public enum s节点状态
public partial class ConnectorItem : ObservableRecipient
{
[ObservableProperty] private Point _anchor;
[ObservableProperty] private object? _inputObject; //数据

[ObservableProperty] private bool _isConnected;
[ObservableProperty] private bool _isNotUsed = false;
[ObservableProperty] private bool _isOut;
[ObservableProperty] private bool _isSelf = false;
[ObservableProperty] private object? _inputObject; //数据

private Type? _realType;


public int AutoUnboxIndex
Expand Down Expand Up @@ -454,8 +503,6 @@ public Type Type
set;
}

private Type? _realType;

/// <summary>
///
/// </summary>
Expand Down
29 changes: 13 additions & 16 deletions uToolkitopia/Services/SearchItemTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class SearchItemTool : ISearchItemTool
{
private static readonly ILog Log = LogManager.GetLogger(nameof(SearchItemTool));

public void OpenSearchItem(SearchViewItem item)
public void OpenSearchItem(SearchViewItem searchViewItem)
{
WeakReferenceMessenger.Default.Send("a", "SearchWindowClose");
Log.Debug("打开指定内容" + item.OnlyKey);
switch (item.OnlyKey)
Log.Debug("打开指定内容" + searchViewItem.OnlyKey);
switch (searchViewItem.OnlyKey)
{
case "ClipboardImageData":
{
Expand All @@ -39,31 +39,31 @@ public void OpenSearchItem(SearchViewItem item)
case "Math": break;
default:
{
switch (item.FileType)
switch (searchViewItem.FileType)
{
case FileType.UWP应用:
Shell32.ShellExecute(IntPtr.Zero, "open", "explorer.exe",
$"shell:AppsFolder\\{item.OnlyKey}", "",
$"shell:AppsFolder\\{searchViewItem.OnlyKey}", "",
ShowWindowCommand.SW_NORMAL);
break;
case FileType.自定义情景:
CustomScenarioManger.CustomScenarios
.FirstOrDefault((e) => $"CustomScenario:{e.UUID}" == item.OnlyKey)?.Run();
.FirstOrDefault((e) => $"CustomScenario:{e.UUID}" == searchViewItem.OnlyKey)?.Run();
break;
case FileType.便签:
((ILabelWindowService)ServiceManager.Services.GetService(typeof(ILabelWindowService))!)
.Show(item.OnlyKey);
.Show(searchViewItem.OnlyKey);
break;
case FileType.自定义:
item.Action?.Invoke(item);
searchViewItem.Action?.Invoke(searchViewItem);
break;
default:
Shell32.ShellExecute(IntPtr.Zero, "open", item.OnlyKey, "", "",
Shell32.ShellExecute(IntPtr.Zero, "open", searchViewItem.OnlyKey, "", "",
ShowWindowCommand.SW_NORMAL);
break;
}

switch (item.FileType)
switch (searchViewItem.FileType)
{
case FileType.文件夹:
case FileType.应用程序:
Expand All @@ -75,22 +75,19 @@ public void OpenSearchItem(SearchViewItem item)
case FileType.文件:
case FileType.自定义情景:
{
if (ConfigManger.Config.lastOpens.ContainsKey(item.OnlyKey))
if (ConfigManger.Config.lastOpens.ContainsKey(searchViewItem.OnlyKey))
{
ConfigManger.Config.lastOpens[item.OnlyKey]++;
ConfigManger.Config.lastOpens[searchViewItem.OnlyKey]++;
}
else
{
ConfigManger.Config.lastOpens.Add(item.OnlyKey, 1);
ConfigManger.Config.lastOpens.Add(searchViewItem.OnlyKey, 1);
}

break;
}
}


//if (ConfigManger.config.lastOpens.Count > ConfigManger.config.maxHistory) ConfigManger.config.lastOpens.RemoveAt(ConfigManger.config.lastOpens.Count-1);

ConfigManger.Save();
return;
}
Expand Down
17 changes: 16 additions & 1 deletion uToolkitopia/View/Pages/Plugin/CustomScenariosManagerPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,22 @@
ItemsSource="{Binding Source= {x:Static config:CustomScenarioManger.CustomScenarios},NotifyOnSourceUpdated=True,NotifyOnTargetUpdated=True,Mode=OneWay}"
Margin="0,10,0,0">


<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter
Margin="0,5,0,0"
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="IsTabStop" Value="False" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<ui:Button HorizontalAlignment="Stretch" x:Name="Button"
Expand Down
17 changes: 16 additions & 1 deletion uToolkitopia/View/Pages/Plugin/PluginManagerPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@
MaxHeight="385" HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Items,UpdateSourceTrigger=PropertyChanged}"
Margin="0,10,0,0">

<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter
Margin="0,5,0,0"
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="IsTabStop" Value="False" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<ui:Button HorizontalAlignment="Stretch" x:Name="Button"
Expand Down
Loading

0 comments on commit b84384a

Please sign in to comment.