Skip to content

Commit

Permalink
connect disconnect functions
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 12, 2023
1 parent 1b9560e commit d95514e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
36 changes: 35 additions & 1 deletion src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@

<Border Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Background="{DynamicResource ThemeBackgroundBrush}">
<StackPanel Orientation="Vertical" VerticalAlignment="Center" Spacing="15">
<Button Classes="BorderButton" Height="40" Width="40" CornerRadius="5">
<Button Command="{Binding ConnectCommand}" Classes="BorderButton" Height="40" Width="40" CornerRadius="5">
<Image Source="{DynamicResource VSImageLib2019.Plugged_16x}" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button>
<Button Classes="BorderButton" Height="40" Width="40" CornerRadius="5">
<Button Command="{Binding DisconnectCommand}" Classes="BorderButton" Height="40" Width="40" CornerRadius="5">
<Image Source="{DynamicResource VSImageLib2019.Unplugged_16x}" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button>
</StackPanel>
Expand All @@ -90,6 +90,7 @@
<DataTemplate>
<DockPanel>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Connection}" />
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
Expand Down

0 comments on commit d95514e

Please sign in to comment.