Skip to content

Commit

Permalink
#473: In Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Sep 18, 2024
1 parent e306fe9 commit 8c41684
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/Myra/Graphics2D/UI/IContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ namespace Myra.Graphics2D
{
public interface IContent
{
Widget Content
{
get; set;
}
Widget Content { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/MyraPad/UI/StudioWidget.Generated.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Generated by MyraPad at 9/18/2024 2:18:15 PM */
/* Generated by MyraPad at 9/18/2024 5:26:28 PM */
using Myra;
using Myra.Graphics2D;
using Myra.Graphics2D.TextureAtlases;
Expand Down Expand Up @@ -153,7 +153,7 @@ private void BuildUI()

var horizontalSeparator1 = new HorizontalSeparator();

_panelExplorer = new Panel();
_panelExplorer = new ScrollViewer();
_panelExplorer.Id = "_panelExplorer";

_projectHolder = new Panel();
Expand Down Expand Up @@ -254,7 +254,7 @@ private void BuildUI()
public MenuItem _menuEditFormatSource;
public MenuItem _menuHelpAbout;
public HorizontalMenu _mainMenu;
public Panel _panelExplorer;
public ScrollViewer _panelExplorer;
public Panel _projectHolder;
public TextBox _textSource;
public VerticalSplitPane _leftSplitPane;
Expand Down
87 changes: 87 additions & 0 deletions src/MyraPad/UI/StudioWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
using System;
using FontStashSharp;
using FontStashSharp.RichText;
using Myra.MML;
using System.Reflection;
using Myra.Attributes;
using System.Collections;

namespace MyraPad.UI
{
Expand Down Expand Up @@ -87,6 +91,7 @@ public partial class StudioWidget
private DateTime? _refreshInitiated;
private readonly Dictionary<string, FontSystem> _fontCache = new Dictionary<string, FontSystem>();
private readonly Dictionary<string, Texture2D> _textureCache = new Dictionary<string, Texture2D>();
private readonly TreeView _treeViewExplorer;

private VerticalMenu _autoCompleteMenu = null;

Expand Down Expand Up @@ -167,6 +172,8 @@ public Project Project
_projectHolder.Widgets.Add(_project.Root);
}

RefreshExplorer();

UpdateMenuFile();
}
}
Expand Down Expand Up @@ -283,6 +290,16 @@ public StudioWidget(State state)

UpdateMenuFile();

_treeViewExplorer = new TreeView
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
};

_treeViewExplorer.SelectionChanged += _treeViewExplorer_SelectionChanged;

_panelExplorer.Content = _treeViewExplorer;

RichTextDefaults.FontResolver = p =>
{
// Parse font name and size
Expand Down Expand Up @@ -1572,5 +1589,75 @@ public void Quit()
{
_queue.Quit();
}

private void BuildExplorerTreeRecursive(ITreeViewNode node, IItemWithId root)
{
if (root == null)
{
return;
}

var id = root.GetType().Name;
if (!string.IsNullOrEmpty(root.Id))
{
id += $" (#{root.Id})";
}

var newNode = node.AddSubNode(new Label
{
Text = id
});

newNode.Tag = root;
newNode.IsExpanded = true;

var props = root.GetType().GetRuntimeProperties();
var contentProperty = (from p in props where p.FindAttribute<ContentAttribute>() != null select p).FirstOrDefault();
if (contentProperty == null)
{
return;
}

var content = contentProperty.GetValue(root);

var asList = content as IList;
if (asList != null)
{
// List
foreach (IItemWithId child in asList)
{
BuildExplorerTreeRecursive(newNode, child);
}

}
else
{
// Simple
BuildExplorerTreeRecursive(newNode, (IItemWithId)content);
}
}

private void RefreshExplorer()
{
_treeViewExplorer.RemoveAllSubNodes();

if (Project == null || Project.Root == null)
{
return;
}

BuildExplorerTreeRecursive(_treeViewExplorer, Project.Root);
}

private void _treeViewExplorer_SelectionChanged(object sender, EventArgs e)
{
if (_treeViewExplorer.SelectedRow == null)
{
return;
}

NewObject = _treeViewExplorer.SelectedRow.Tag;
}

}
}
2 changes: 1 addition & 1 deletion src/MyraPad/UI/studio.xmmp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</HorizontalMenu>
<HorizontalSeparator />
<HorizontalSplitPane Id="_topSplitPane" StackPanel.ProportionType="Fill">
<Panel Id="_panelExplorer" />
<ScrollViewer Id="_panelExplorer" />
<VerticalStackPanel>
<VerticalSplitPane Id="_leftSplitPane" StackPanel.ProportionType="Fill">
<Panel Id="_projectHolder" />
Expand Down

0 comments on commit 8c41684

Please sign in to comment.