diff --git a/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs b/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs index d3629aad..b6ce4189 100644 --- a/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs +++ b/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs @@ -4,7 +4,9 @@ using System.Text.Json.Serialization; using Avalonia.Platform; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using DynamicData; +using DynamicData.Binding; namespace OneWare.UniversalFpgaProjectSystem.Models; @@ -40,9 +42,41 @@ public NodeModel? SelectedNode public string Name { get; private set; } = "Unknown"; - protected FpgaModelBase() + public RelayCommand ConnectCommand { get; } + + public RelayCommand DisconnectCommand { get; } + + public FpgaModelBase() { + ConnectCommand = new RelayCommand(Connect, () => SelectedNode is not null && SelectedPin is not null); + + DisconnectCommand = new RelayCommand(Disconnect, () => SelectedPin is {Connection: not null}); + + this.WhenValueChanged(x => x.SelectedNode).Subscribe(x => + { + ConnectCommand.NotifyCanExecuteChanged(); + DisconnectCommand.NotifyCanExecuteChanged(); + }); + this.WhenValueChanged(x => x.SelectedPin).Subscribe(x => + { + ConnectCommand.NotifyCanExecuteChanged(); + DisconnectCommand.NotifyCanExecuteChanged(); + }); + } + + private void Connect() + { + SelectedPin!.Connection = SelectedNode; + ConnectCommand.NotifyCanExecuteChanged(); + DisconnectCommand.NotifyCanExecuteChanged(); + } + + private void Disconnect() + { + SelectedPin!.Connection = null; + ConnectCommand.NotifyCanExecuteChanged(); + DisconnectCommand.NotifyCanExecuteChanged(); } protected void LoadFromJson(string path) diff --git a/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaPinModel.cs b/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaPinModel.cs index 2802df57..f3822daf 100644 --- a/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaPinModel.cs +++ b/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaPinModel.cs @@ -36,7 +36,8 @@ public NodeModel? Connection public FpgaPinModel(string name, string description, FpgaModelBase parent) { Name = name; - Description = description; + _description = description; + _toolTipText = "Click to connect " + Name; Parent = parent; } } \ No newline at end of file diff --git a/src/OneWare.UniversalFpgaProjectSystem/Views/UniversalFpgaProjectCompileView.axaml b/src/OneWare.UniversalFpgaProjectSystem/Views/UniversalFpgaProjectCompileView.axaml index 8d8155e8..7e7396f7 100644 --- a/src/OneWare.UniversalFpgaProjectSystem/Views/UniversalFpgaProjectCompileView.axaml +++ b/src/OneWare.UniversalFpgaProjectSystem/Views/UniversalFpgaProjectCompileView.axaml @@ -66,10 +66,10 @@ - - @@ -90,6 +90,7 @@ +