Editor wip
This commit is contained in:
parent
acbd5a5380
commit
117826aa68
6 changed files with 263 additions and 4 deletions
|
|
@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Platform;
|
||||
|
|
@ -68,7 +69,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
private void Rebuild()
|
||||
protected virtual void Rebuild()
|
||||
{
|
||||
this.Content.CloseAllChildren();
|
||||
|
||||
|
|
|
|||
179
SlicerConfiguration/UIFields/SurfacedEditorPage.cs
Normal file
179
SlicerConfiguration/UIFields/SurfacedEditorPage.cs
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
Copyright (c) 2018, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.DesignTools;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class SurfacedEditorPage : DialogPage
|
||||
{
|
||||
private MHTextEditWidget editWidget;
|
||||
|
||||
public SurfacedEditorPage(UIField uiField, IObject3D selectedItem)
|
||||
{
|
||||
this.WindowTitle = "MatterControl - " + "Editor Selector".Localize();
|
||||
this.HeaderText = "Surfaced Editor".Localize();
|
||||
|
||||
var tabControl = new SimpleTabs(theme, new GuiWidget())
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Stretch,
|
||||
};
|
||||
tabControl.TabBar.BackgroundColor = theme.TabBarBackground;
|
||||
tabControl.TabBar.Padding = 0;
|
||||
|
||||
contentRow.AddChild(tabControl);
|
||||
contentRow.Padding = 0;
|
||||
|
||||
var editContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Stretch,
|
||||
Padding = theme.DefaultContainerPadding,
|
||||
BackgroundColor = theme.ActiveTabColor
|
||||
};
|
||||
|
||||
editWidget = new MHTextEditWidget("", multiLine: true)
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
Name = this.Name
|
||||
};
|
||||
editWidget.DrawFromHintedCache();
|
||||
//editWidget.ActualTextEditWidget.VAnchor = VAnchor.Stretch;
|
||||
|
||||
editContainer.AddChild(editWidget);
|
||||
|
||||
// add the tree view
|
||||
var treeView = new TreeView(theme)
|
||||
{
|
||||
Margin = new BorderDouble(left: 18),
|
||||
};
|
||||
treeView.AfterSelect += (s, e) =>
|
||||
{
|
||||
if (treeView.SelectedNode.Tag is IObject3D contextNode)
|
||||
{
|
||||
Console.WriteLine(contextNode.Name);
|
||||
}
|
||||
};
|
||||
treeView.ScrollArea.ChildAdded += (s, e) =>
|
||||
{
|
||||
if (e is GuiWidgetEventArgs childEventArgs
|
||||
&& childEventArgs.Child is TreeNode treeNode)
|
||||
{
|
||||
treeNode.AlwaysExpandable = true;
|
||||
}
|
||||
};
|
||||
|
||||
treeView.Click += (s, e) =>
|
||||
{
|
||||
if (treeView.IsDoubleClick(e))
|
||||
{
|
||||
Console.WriteLine();
|
||||
}
|
||||
};
|
||||
|
||||
treeView.ScrollArea.CloseAllChildren();
|
||||
|
||||
var rootNode = Object3DTreeBuilder.BuildTree(selectedItem, theme);
|
||||
treeView.AddChild(rootNode);
|
||||
rootNode.TreeView = treeView;
|
||||
|
||||
editContainer.AddChild(treeView);
|
||||
|
||||
var createButton = new TextButton("Create from selection", theme);
|
||||
createButton.VAnchor = VAnchor.Absolute;
|
||||
createButton.HAnchor = HAnchor.Left;
|
||||
createButton.BackgroundColor = theme.MinimalShade;
|
||||
createButton.Click += (s, e) =>
|
||||
{
|
||||
if (treeView.SelectedNode.Tag is IObject3D contextNode)
|
||||
{
|
||||
editWidget.Text = "$." + string.Join(".", contextNode.AncestorsAndSelf().TakeWhile(o => !(o is ComponentObject3D)).Select(o => $"Children<{o.GetType().Name.ToString()}>").Reverse().ToArray());
|
||||
}
|
||||
};
|
||||
|
||||
editContainer.AddChild(createButton);
|
||||
|
||||
var dummyWidget = new GuiWidget()
|
||||
{
|
||||
BackgroundColor = Color.Red
|
||||
};
|
||||
|
||||
var editTab = new ToolTab("Edit".Localize(), tabControl, editContainer, theme, hasClose: false)
|
||||
{
|
||||
Name = "Edit Tab"
|
||||
};
|
||||
tabControl.AddTab(editTab);
|
||||
|
||||
var previewTab = new ToolTab("Preview".Localize(), tabControl, dummyWidget, theme, hasClose: false)
|
||||
{
|
||||
Name = "Preview Tab"
|
||||
};
|
||||
tabControl.AddTab(previewTab);
|
||||
|
||||
tabControl.ActiveTabChanged += (s, e) =>
|
||||
{
|
||||
if (tabControl.SelectedTabIndex == 1)
|
||||
{
|
||||
// dummyWidget.Markdown = editWidget.Text;
|
||||
}
|
||||
};
|
||||
|
||||
tabControl.SelectedTabIndex = 0;
|
||||
|
||||
var saveButton = theme.CreateDialogButton("Save".Localize());
|
||||
saveButton.Click += (s, e) =>
|
||||
{
|
||||
uiField.SetValue(
|
||||
editWidget.Text.Replace("\n", "\\n"),
|
||||
userInitiated: true);
|
||||
|
||||
this.DialogWindow.CloseOnIdle();
|
||||
};
|
||||
this.AddPageAction(saveButton);
|
||||
}
|
||||
|
||||
public string EditorString
|
||||
{
|
||||
get => editWidget.Text;
|
||||
set
|
||||
{
|
||||
editWidget.Text = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
75
SlicerConfiguration/UIFields/SurfacedEditorsField.cs
Normal file
75
SlicerConfiguration/UIFields/SurfacedEditorsField.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Copyright (c) 2018, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
public class SurfacedEditorsField : ListStringField
|
||||
{
|
||||
private IObject3D selectedItem;
|
||||
|
||||
public SurfacedEditorsField(ThemeConfig theme, IObject3D selectedItem)
|
||||
: base(theme)
|
||||
{
|
||||
this.selectedItem = selectedItem;
|
||||
}
|
||||
|
||||
protected override void Rebuild()
|
||||
{
|
||||
base.Rebuild();
|
||||
|
||||
foreach(var inlineEdit in this.Content.Children<InlineListItemEdit>())
|
||||
{
|
||||
inlineEdit.EditOverride += InlineEdit_EditOverride;
|
||||
}
|
||||
}
|
||||
|
||||
private void InlineEdit_EditOverride(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is InlineStringEdit inlineEdit)
|
||||
{
|
||||
var uifield = new TextField();
|
||||
uifield.Initialize(0);
|
||||
uifield.ValueChanged += (s, e2) =>
|
||||
{
|
||||
inlineEdit.Text = uifield.Value;
|
||||
};
|
||||
|
||||
DialogWindow.Show(new SurfacedEditorPage(uifield, selectedItem)
|
||||
{
|
||||
EditorString = inlineEdit.Text,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue