rewrite into avalonia for linux support

This commit is contained in:
Matěj Kubíček
2026-04-21 18:15:07 +02:00
parent fadca1bd6e
commit 8a57680b0e
33 changed files with 1288 additions and 1213 deletions
+64 -11
View File
@@ -1,6 +1,14 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
namespace NetworkDiagram.Models
{
@@ -18,59 +26,63 @@ namespace NetworkDiagram.Models
public class PlacedDevice : INotifyPropertyChanged
{
private string _name = string.Empty;
public string Name
{
get;
get => _name;
set
{
field = value;
_name = value;
OnPropertyChanged();
}
} = string.Empty;
}
public string TemplateName { get; set; } = string.Empty;
[JsonIgnore]
public string IconPath { get; set; } = string.Empty;
private double _x;
public double X
{
get;
get => _x;
set
{
field = value;
_x = value;
OnPropertyChanged();
OnPropertyChanged(nameof(CenterX));
}
}
private double _y;
public double Y
{
get;
get => _y;
set
{
field = value;
_y = value;
OnPropertyChanged();
OnPropertyChanged(nameof(CenterY));
}
}
private List<string> _ipAddresses = [];
public List<string> IpAddresses
{
get;
get => _ipAddresses;
set
{
field = value;
_ipAddresses = value;
OnPropertyChanged();
}
} = [];
}
public double CenterX => X + 50;
public double CenterY => Y + 40;
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string? name = null)
protected void OnPropertyChanged([CallerMemberName] string? name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
@@ -88,4 +100,45 @@ namespace NetworkDiagram.Models
public List<PlacedDevice> Devices { get; set; } = [];
public List<Connection> Connections { get; set; } = [];
}
public class ImageConverter : IValueConverter
{
public static ImageConverter Instance { get; } = new();
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is string path && !string.IsNullOrEmpty(path))
{
try
{
if (path.StartsWith("avares://"))
return new Bitmap(AssetLoader.Open(new Uri(path)));
if (File.Exists(path))
return new Bitmap(path);
// Try as relative avares
var uri = new Uri($"avares://NetworkDiagram/{path.Replace("\\", "/")}");
return new Bitmap(AssetLoader.Open(uri));
}
catch
{
return null;
}
}
return null;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException();
}
public class DiagramSaveModel {
public List<PlacedDevice> Devices { get; set; } = [];
public List<ConnectionSaveModel> Connections { get; set; } = [];
}
public class ConnectionSaveModel {
public int StartIndex { get; set; }
public int EndIndex { get; set; }
public ConnectionType Type { get; set; }
}
}