diff --git a/src/ClawEngineGUI.Domain/Models/Node.cs b/src/ClawEngineGUI.Domain/Models/Node.cs index 0a6c441824354a6bacc255ba07a73c6e852ea712..87f81cedc510df17f3bc3ed90a090eea7d57891a 100644 --- a/src/ClawEngineGUI.Domain/Models/Node.cs +++ b/src/ClawEngineGUI.Domain/Models/Node.cs @@ -1,26 +1,33 @@ using System.Collections.ObjectModel; +using Avalonia.Media.Imaging; +using Avalonia.Platform; namespace ClawEngineGUI.Domain.Models; public class Node { - public ObservableCollection<Node>? SubNodes { get; } + public ObservableCollection<Node>? SubNodes { get; set; } public string Title { get; set; } - public string Image; + public Node Parent { get; set; } + public Bitmap? Image { get; } public Node(string title, string image) { Title = title; - Image = image; + Parent = this; + SubNodes = new ObservableCollection<Node>(); + Image = new Bitmap(AssetLoader.Open(new Uri("avares://ClawEngineGUI/Assets/file.png"))); } public Node(string title, string image, ObservableCollection<Node> subNodes) { Title = title; SubNodes = subNodes; - Image = image; + Parent = this; + Image = new Bitmap(AssetLoader.Open(new Uri("avares://ClawEngineGUI/Assets/folder.png")));; } + public override string ToString() => $"{Title}"; } diff --git a/src/ClawEngineGUI/Assets/draft.png b/src/ClawEngineGUI/Assets/file.png similarity index 100% rename from src/ClawEngineGUI/Assets/draft.png rename to src/ClawEngineGUI/Assets/file.png diff --git a/src/ClawEngineGUI/Models/Node.cs b/src/ClawEngineGUI/Models/Node.cs index ac8f5d3b252d2474891fb6985ec4e554e0b6bfbd..76706a3146de4b0238bb2d97211443354c73e908 100644 --- a/src/ClawEngineGUI/Models/Node.cs +++ b/src/ClawEngineGUI/Models/Node.cs @@ -4,8 +4,8 @@ using System.Collections.ObjectModel; public class Node { - public ObservableCollection<Node>? SubNodes { get; } - public string Title { get; } + public ObservableCollection<Node>? SubNodes { get; set; } + public string Title { get; set; } public string Image; diff --git a/src/ClawEngineGUI/ViewModels/MainViewModel.cs b/src/ClawEngineGUI/ViewModels/MainViewModel.cs index d5f95b0a6bf42a7024b434f23fce1b9d676f8914..5b69201756f5965a62c8925d6237649c3c4a424e 100644 --- a/src/ClawEngineGUI/ViewModels/MainViewModel.cs +++ b/src/ClawEngineGUI/ViewModels/MainViewModel.cs @@ -1,5 +1,12 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using Avalonia.Controls; +using Avalonia.Input; +using ClawEngineGUI.Domain.Commands.FileSystem.FileCommands; +using ReactiveUI; using CommunityToolkit.Mvvm.ComponentModel; using ClawEngineGUI.ViewModels.Settings; using ClawEngineGUI.Domain.Models; @@ -7,7 +14,7 @@ using ClawEngineGUI.Infrastructure.Repository.Abstractions; namespace ClawEngineGUI.ViewModels; -public partial class MainViewModel : ObservableObject +public partial class MainViewModel : ObservableObject, IReactiveObject { private readonly IInMemoryRepository _inMemoryRepository; @@ -33,6 +40,52 @@ public partial class MainViewModel : ObservableObject _nodes = _inMemoryRepository.GetNodes(); } + private Node _selectedNode; + public Node SelectedNode + { + get => _selectedNode; + set => this.RaiseAndSetIfChanged(ref _selectedNode, value); + } + + public void DeleteItem() + { + if (SelectedNode==null) + { + return; + } + IEnumerable<Node> message = FlattenNodes(_nodes); + var parent = message.Where(x => x.SubNodes.Any(y => y.Title == SelectedNode.Title)).FirstOrDefault(); + parent.SubNodes.Remove(SelectedNode); + } + + public IEnumerable<Node> FlattenNodes(ObservableCollection<Node> nodes) + { + ObservableCollection<Node> flattenNodes = new ObservableCollection<Node>(); + flattenNodes.Add(nodes[0]); + for (int i = 0; i < flattenNodes.Count; i++) + { + if (flattenNodes[i].SubNodes!=null) + { + for (int j = 0; j < flattenNodes[i].SubNodes.Count; j++) + { + flattenNodes.Add(flattenNodes[i].SubNodes[0]); + } + } + } + IEnumerable<Node> result = flattenNodes; + return result; + } + + public int createdFiles = 0; + public void CreateNewFile() + { + createdFiles++; + + Node new_node = new Node($"New File {createdFiles}" , ""); + if (SelectedNode is null) { Nodes[0].SubNodes.Add(new_node); } + else { SelectedNode.SubNodes.Add(new_node); } + } + public void OnNodesUpdated(ObservableCollection<Node> nodes) { _inMemoryRepository.UpdateNodes(nodes); @@ -53,19 +106,6 @@ public partial class MainViewModel : ObservableObject CurrentPage = (ViewModelBase)instance; } - // private static int Length = 9; - // private Type[] Buttons = new Type[] { - // RemoteAccessViewModel, - // ThemeViewModel, - // ExternalInstumentsViewModel, - // InstrumentsViewModel, - // InterfaceViewModel, - // SceneEditorViewModel, - // KeymapViewModel, - // ViewSettingsViewModel, - // ScriptEditorViewModel, - // }; - public ObservableCollection<ListItemTemplate> Items { get; } = new() { new ListItemTemplate(typeof(RemoteAccessViewModel), RemoteAccessViewModel.ButtonName), @@ -78,6 +118,16 @@ public partial class MainViewModel : ObservableObject new ListItemTemplate(typeof(ViewSettingsViewModel), ViewSettingsViewModel.ButtonName), new ListItemTemplate(typeof(ScriptEditorViewModel), ScriptEditorViewModel.ButtonName), }; + + public void RaisePropertyChanging(PropertyChangingEventArgs args) + { + throw new NotImplementedException(); + } + + public void RaisePropertyChanged(PropertyChangedEventArgs args) + { + throw new NotImplementedException(); + } } public class ListItemTemplate diff --git a/src/ClawEngineGUI/Views/Composition/CompositionMainWindow.axaml b/src/ClawEngineGUI/Views/Composition/CompositionMainWindow.axaml index c677fc39b42740ae0532c6511776bc9511bb5b12..0ec9544b040362c6c41c0502802b7dd6b5d4d501 100644 --- a/src/ClawEngineGUI/Views/Composition/CompositionMainWindow.axaml +++ b/src/ClawEngineGUI/Views/Composition/CompositionMainWindow.axaml @@ -71,12 +71,12 @@ </Button> </StackPanel> <Rectangle Grid.Row="3" MinWidth="289" Height="1" Fill="#55585C"></Rectangle> - <TreeView Grid.Row="4" ItemsSource="{Binding Nodes}"> + <TreeView x:Name="Scenes" Grid.Row="4" ItemsSource="{Binding Nodes}"> <TreeView.ItemTemplate> <TreeDataTemplate ItemsSource="{Binding SubNodes}"> <StackPanel Orientation="Horizontal" Height="16"> <Image Height="12" Width="12" HorizontalAlignment="Left" - VerticalAlignment="Center" Margin="0,0,10,0" Source="{Binding Title}"/> + VerticalAlignment="Center" Margin="0,0,10,0" Source="{Binding Image}"/> <TextBox Classes="Data" Text="{Binding Title, Mode=TwoWay}"/> </StackPanel> </TreeDataTemplate> diff --git a/src/ClawEngineGUI/Views/SolutionExplorer/SolutionExplorerMainWindow.axaml b/src/ClawEngineGUI/Views/SolutionExplorer/SolutionExplorerMainWindow.axaml index dfb1dc62079b4511350537469d6a0531b450968f..4f8d0a7672ff7f537288f6d8e0e92386cb0e681b 100644 --- a/src/ClawEngineGUI/Views/SolutionExplorer/SolutionExplorerMainWindow.axaml +++ b/src/ClawEngineGUI/Views/SolutionExplorer/SolutionExplorerMainWindow.axaml @@ -3,18 +3,18 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:ClawEngineGUI.ViewModels" + xmlns:m="clr-namespace:ClawEngineGUI.ViewModels.Composition" + xmlns:model="using:ClawEngineGUI.Models" mc:Ignorable="d" d:DesignWidth="289" d:DesignHeight="362" Width="289" Height="362" MinWidth="289" - x:Class="ClawEngineGUI.Views.SolutionExplorer.SolutionExplorerMainWindow" x:DataType="vm:MainViewModel" + x:Class="ClawEngineGUI.Views.SolutionExplorer.SolutionExplorerMainWindow" Background="{DynamicResource MainContentBackGroundColor}" FontFamily="{DynamicResource MainFontFamily}" Foreground="{DynamicResource MainFontForegroundColor}" BorderBrush="#55585C" BorderThickness="1" CornerRadius="8"> - <Design.DataContext> - <vm:MainViewModel /> - </Design.DataContext> + <UserControl.Styles> <Style Selector="TextBox.search"> <Setter Property="Width" Value="195"/> @@ -54,7 +54,7 @@ </Canvas> <StackPanel Grid.Row="1" Height="16" Width="273" Margin="8" Orientation="Horizontal" Background="#1F1F20"> <Panel Width="40"> - <Button Height="16" Width="16" HorizontalAlignment="Left" Background="#1F1F20"> + <Button Height="16" Width="16" HorizontalAlignment="Left" Background="#1F1F20" Command="{Binding CreateNewFile}"> <Image Height="16" Width="16" Source="/Assets/Создать проект.png"></Image> </Button> <Button Height="16" Width="16" HorizontalAlignment="Right" Background="#1F1F20"> @@ -68,7 +68,7 @@ <Button Height="16" Width="16" HorizontalAlignment="Center" Background="#1F1F20"> <Image Height="16" Width="16" Source="/Assets/Переименовать выбранную папку или пакет.png"></Image> </Button> - <Button Height="16" Width="16" HorizontalAlignment="Right" Background="#1F1F20"> + <Button Height="16" Width="16" HorizontalAlignment="Right" Background="#1F1F20" Command="{Binding DeleteItem}"> <Image Height="16" Width="16" Source="/Assets/Удалить выбранные элементы.png"></Image> </Button> </Panel> @@ -106,12 +106,12 @@ </Button> </StackPanel> <Rectangle Grid.Row="4" MinWidth="289" Height="1" Fill="#55585C"></Rectangle> - <TreeView Grid.Row="5" ItemsSource="{Binding Nodes}"> - <TreeView.ItemTemplate> + <TreeView Grid.Row="5" ItemsSource="{Binding Nodes}" SelectedItem="{Binding SelectedNode}"> + <TreeView.ItemTemplate> <TreeDataTemplate ItemsSource="{Binding SubNodes}"> <StackPanel Orientation="Horizontal" Height="16"> <Image Height="12" Width="12" HorizontalAlignment="Left" - VerticalAlignment="Center" Margin="0,0,10,0" Source="{Binding Title}"/> + VerticalAlignment="Center" Margin="0,0,10,0" Source="{Binding Image}"/> <TextBlock Classes="Data" Text="{Binding Title}"/> </StackPanel> </TreeDataTemplate>