Skip to content

Commit

Permalink
Добавлена возможность импорта XAML
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeAkei committed Nov 13, 2023
1 parent 9af8d32 commit b09bda0
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 46 deletions.
52 changes: 31 additions & 21 deletions DeXAMLize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ public partial class MainWindow
};

public async Task RunDeXAMLIZE(Window window)
{
await OpenXAML(window);
await CorrectXAML();
await LoadXAML();
}

private async Task LoadXAML()
{
// Удаляем элементы из MainCanvas
for (int i = MainCanvas.jChildren.Count - 1; i >= 0; i--)
Expand All @@ -40,6 +33,15 @@ private async Task LoadXAML()
//Радикальная операция
//УЧЁТНЫЙ НОМЕР: 1_KILLALL
Broadcast.KillAll();

await OpenXAML(window);
await CorrectXAML();
await LoadXAML();
}

private async Task LoadXAML()
{



var obj = AvaloniaRuntimeXamlLoader.Load(ExternalXAML, typeof(MainWindow).Assembly) as Canvas;
Expand All @@ -66,17 +68,21 @@ private async Task LoadXAML()
Canvas.SetTop(MainCanvas.Children[i], canv_top[i]);
Canvas.SetLeft(MainCanvas.Children[i], canv_left[i]);
}
MainCanvas.mTreeItem.Items.Clear();

Broadcast.RestoreBehavior();
Broadcast.RestoreTree();
}

public void CorrectLoadedjElement(JControl element)
{
Console.WriteLine();
element.Name ??= element.Type + "_" + (i++);


if (element.Name != "MainCanvas")
{
if (element.Name == "MainCanvas") return;

element.mTreeItem.Header =element.Name;
var parent = ((Control)element).Parent;

element.SetParent((IChildContainer)parent);
Expand All @@ -89,18 +95,8 @@ public void CorrectLoadedjElement(JControl element)
element.Click += jElementClick;
element.PointerPressed += OnjControlPressed;
element.PointerReleased += OnjControlReleased;
}

if (element is IChildContainer)
{
var container = (IChildContainer)element;
foreach (var child in container.jChildren)
{
element.mTreeItem.Items.Add(child.mTreeItem);
}
}

selectedTreeItem = MainCanvas.mTreeItem;



}

Expand Down Expand Up @@ -221,4 +217,18 @@ static string ReplaceMainCanvasTag(string input)

return input;
}

public void CorrectTree(JControl element)
{
if (element is IChildContainer)
{
var container = (IChildContainer)element;
foreach (var child in container.jChildren)
{
element.mTreeItem.Items.Add(child.mTreeItem);
}
}

selectedTreeItem = MainCanvas.mTreeItem;
}
}
2 changes: 2 additions & 0 deletions XAMLGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public static class Broadcast
public static void RestoreBehavior()=> OnBroadcast?.Invoke(2);
//Убить все объекты
public static void KillAll()=> OnBroadcast?.Invoke(3);
//Восстановить дерево объектов
public static void RestoreTree()=> OnBroadcast?.Invoke(4);



Expand Down
4 changes: 4 additions & 0 deletions Xamlade.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<None Remove="Xamlade.png" />
<None Remove="Avalonia.AXAML.LanguageServer.Log20231031.txt" />
<None Remove="bin\**" />
<None Remove="googleca45d2d676594602.html" />
<None Remove="index.html" />
<None Remove="Xamlade2.png~" />
<None Remove="Xamlade2.png" />
</ItemGroup>


Expand Down
Binary file modified bin/Debug/net8.0/Xamlade.dll
Binary file not shown.
Binary file modified bin/Debug/net8.0/Xamlade.pdb
Binary file not shown.
32 changes: 24 additions & 8 deletions bin/Debug/net8.0/XamladeDemo/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,33 @@
Title="TestWindow">
<Canvas Background="#ff1e1e1e" Margin="2,2,2,2" Name="MainCanvas" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Button Name="Button1" Content="Ебач потерялся" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" Canvas.Left="612" Canvas.Top="594" >
<Button Name="Button1" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" Canvas.Left="212" Canvas.Top="511" >
</Button>
<Canvas Background="#fffc6bed" Width="522" Height="503" Name="Canvas0" Canvas.Left="43" Canvas.Top="57" >
<TextBlock Background="Blue" Text="ПРИВЕТ ДУРДОМ!" FontSize="20" Foreground="White" TextAlignment="Center" Width="273" Height="31" HorizontalAlignment="Center" VerticalAlignment="Center" Name="TextBlock2" Canvas.Left="122" Canvas.Top="10" >
</TextBlock>
<Button Name="Button4" Content="Кнопка" Background="#ff009e73" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" Canvas.Left="108" Canvas.Top="128" >
<Canvas Background="#ff5dce68" Width="400" Height="400" Name="Canvas0" Canvas.Left="408" Canvas.Top="32" >
<Button Name="Button2" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" Canvas.Left="227" Canvas.Top="225" >
</Button>
<Button Name="Button5" Content="Кнопка" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" Canvas.Left="342" Canvas.Top="231" >
<Button Name="Button3" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" Canvas.Left="129" Canvas.Top="287" >
</Button>
<CheckBox Content="Галочка" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Background="#ff2ee604" BorderBrush="Transparent" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,0,0,0" MinHeight="32" HorizontalAlignment="Left" VerticalAlignment="Center" Name="CheckBox6" Canvas.Left="55" Canvas.Top="346" >
</CheckBox>
</Canvas>
<StackPanel Background="#ffb9def0" Width="199" Height="410" Name="StackPanel4" Canvas.Left="107" Canvas.Top="41" >
<Button Name="Button5" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" >
</Button>
<Button Name="Button6" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" >
</Button>
<Button Name="Button7" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" >
</Button>
<Button Name="Button8" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" >
</Button>
<Button Name="Button9" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" >
</Button>
<Button Name="Button10" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" >
</Button>
<Button Name="Button11" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" >
</Button>
<Button Name="Button12" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" >
</Button>
<Button Name="Button13" Content="Text" Background="Blue" BorderBrush="Transparent" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" FontSize="20" Foreground="White" Padding="8,5,8,6" HorizontalAlignment="Left" VerticalAlignment="Center" >
</Button>
</StackPanel>
</Canvas>
</Window>
68 changes: 51 additions & 17 deletions jElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,13 @@ public void SetParent(IChildContainer parent)
public bool Focus(NavigationMethod method = NavigationMethod.Unspecified,
KeyModifiers keyModifiers = KeyModifiers.None);

private void HandleBroadcast(int mode)
{
if(mode == 0) XAMLGenerator.XAMLRatingInit(this);
else if (mode == 1) XAMLGenerator.XAMLize(this);
else if (mode == 2) MainWindow._MainWindow.CorrectLoadedjElement(this);
else if (mode == 3) Broadcast.DisposeElement(this);
}
public void Dispose()
{
if(this.Name == "MainCanvas") return;
mTreeItem = null;
FieldInfo privateField =
typeof(StyledElement).GetField("_name", BindingFlags.NonPublic | BindingFlags.Instance);
privateField.SetValue(this, null);
Broadcast.OnBroadcast -= HandleBroadcast;
}


Expand Down Expand Up @@ -219,7 +211,12 @@ private void HandleBroadcast(int mode)
if(mode == 0) XAMLGenerator.XAMLRatingInit(this);
else if (mode == 1) XAMLGenerator.XAMLize(this);
else if (mode == 2) MainWindow._MainWindow.CorrectLoadedjElement(this);
else if (mode == 3) Broadcast.DisposeElement(this);
else if (mode == 3)
{
Broadcast.OnBroadcast -= HandleBroadcast;
Broadcast.DisposeElement(this);
}
else if (mode == 4) MainWindow._MainWindow.CorrectTree(this);
}

}
Expand Down Expand Up @@ -253,7 +250,12 @@ private void HandleBroadcast(int mode)
if(mode == 0) XAMLGenerator.XAMLRatingInit(this);
else if (mode == 1) XAMLGenerator.XAMLize(this);
else if (mode == 2) MainWindow._MainWindow.CorrectLoadedjElement(this);
else if (mode == 3) Broadcast.DisposeElement(this);
else if (mode == 3)
{
Broadcast.OnBroadcast -= HandleBroadcast;
Broadcast.DisposeElement(this);
}
else if (mode == 4) MainWindow._MainWindow.CorrectTree(this);
}
}

Expand Down Expand Up @@ -284,7 +286,12 @@ private void HandleBroadcast(int mode)
if(mode == 0) XAMLGenerator.XAMLRatingInit(this);
else if (mode == 1) XAMLGenerator.XAMLize(this);
else if (mode == 2) MainWindow._MainWindow.CorrectLoadedjElement(this);
else if (mode == 3) Broadcast.DisposeElement(this);
else if (mode == 3)
{
Broadcast.OnBroadcast -= HandleBroadcast;
Broadcast.DisposeElement(this);
}
else if (mode == 4) MainWindow._MainWindow.CorrectTree(this);
}
protected override void OnClick() {}
}
Expand Down Expand Up @@ -318,7 +325,12 @@ private void HandleBroadcast(int mode)
if(mode == 0) XAMLGenerator.XAMLRatingInit(this);
else if (mode == 1) XAMLGenerator.XAMLize(this);
else if (mode == 2) MainWindow._MainWindow.CorrectLoadedjElement(this);
else if (mode == 3) Broadcast.DisposeElement(this);
else if (mode == 3)
{
Broadcast.OnBroadcast -= HandleBroadcast;
Broadcast.DisposeElement(this);
}
else if (mode == 4) MainWindow._MainWindow.CorrectTree(this);
}

protected override void OnClick() {}
Expand Down Expand Up @@ -347,7 +359,12 @@ private void HandleBroadcast(int mode)
if(mode == 0) XAMLGenerator.XAMLRatingInit(this);
else if (mode == 1) XAMLGenerator.XAMLize(this);
else if (mode == 2) MainWindow._MainWindow.CorrectLoadedjElement(this);
else if (mode == 3) Broadcast.DisposeElement(this);
else if (mode == 3)
{
Broadcast.OnBroadcast -= HandleBroadcast;
Broadcast.DisposeElement(this);
}
else if (mode == 4) MainWindow._MainWindow.CorrectTree(this);
}

public bool IsPressed { get; set; }
Expand Down Expand Up @@ -377,6 +394,11 @@ private void HandleBroadcast(int mode)
if (mode == 0) XAMLGenerator.XAMLRatingInit(this);
else if (mode == 1) XAMLGenerator.XAMLize(this);
else if (mode == 2) MainWindow._MainWindow.CorrectLoadedjElement(this);
else if (mode == 3)
{
Broadcast.OnBroadcast -= HandleBroadcast;
Broadcast.DisposeElement(this);
}
}

protected override void OnPointerPressed(PointerPressedEventArgs e) { }
Expand All @@ -402,7 +424,7 @@ public class jCanvas : Canvas, IChildContainer, JControl
public jCanvas()
{
jChildren = new List<JControl>();
Broadcast.OnBroadcast += HandleBroadcastast;
Broadcast.OnBroadcast += HandleBroadcast;
XAMLPiece = new List<string>();
mTreeItem = new mTreeViewItem(this);
}
Expand All @@ -422,12 +444,19 @@ public void RemoveChild(JControl child)
Children.Remove((Control)child);
}
public int XAMLRating { get; set; }
private void HandleBroadcastast(int mode)
private void HandleBroadcast(int mode)
{

if(mode == 0) XAMLGenerator.XAMLRatingInit(this);
else if (mode == 1) XAMLGenerator.XAMLize(this);
else if (mode == 2) MainWindow._MainWindow.CorrectLoadedjElement(this);
else if (mode == 3) Broadcast.DisposeElement(this);
else if (mode == 3)
{
if(Name=="MainCanvas") return;
Broadcast.OnBroadcast -= HandleBroadcast;
Broadcast.DisposeElement(this);
}
else if (mode == 4) MainWindow._MainWindow.CorrectTree(this);
}

}
Expand Down Expand Up @@ -471,6 +500,11 @@ private void HandleBroadcast(int mode)
if(mode == 0) XAMLGenerator.XAMLRatingInit(this);
else if (mode == 1) XAMLGenerator.XAMLize(this);
else if (mode == 2) MainWindow._MainWindow.CorrectLoadedjElement(this);
else if (mode == 3) Broadcast.DisposeElement(this);
else if (mode == 3)
{
Broadcast.OnBroadcast -= HandleBroadcast;
Broadcast.DisposeElement(this);
}
else if (mode == 4) MainWindow._MainWindow.CorrectTree(this);
}
}

0 comments on commit b09bda0

Please sign in to comment.