119 lines
3.8 KiB
C#
119 lines
3.8 KiB
C#
|
|
/*
|
|||
|
|
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 Markdig.Agg;
|
|||
|
|
using MatterHackers.Agg.UI;
|
|||
|
|
using MatterHackers.Localizations;
|
|||
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
|||
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|||
|
|
|
|||
|
|
namespace MatterHackers.MatterControl
|
|||
|
|
{
|
|||
|
|
public class MarkdownEditPage : DialogPage
|
|||
|
|
{
|
|||
|
|
private MHTextEditWidget editWidget;
|
|||
|
|
|
|||
|
|
public MarkdownEditPage(UIField uiField)
|
|||
|
|
{
|
|||
|
|
this.WindowTitle = "MatterControl - " + "Markdown Edit".Localize();
|
|||
|
|
this.HeaderText = "Edit Page".Localize() + ":";
|
|||
|
|
|
|||
|
|
var tabControl = new SimpleTabs(theme, new GuiWidget())
|
|||
|
|
{
|
|||
|
|
HAnchor = HAnchor.Stretch,
|
|||
|
|
VAnchor = VAnchor.Stretch
|
|||
|
|
};
|
|||
|
|
tabControl.TabBar.BackgroundColor = theme.TabBarBackground;
|
|||
|
|
|
|||
|
|
contentRow.AddChild(tabControl);
|
|||
|
|
contentRow.Padding = 0;
|
|||
|
|
|
|||
|
|
editWidget = new MHTextEditWidget("", pixelWidth: 320, multiLine: true, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
|
|||
|
|
{
|
|||
|
|
HAnchor = HAnchor.Stretch,
|
|||
|
|
VAnchor = VAnchor.Fit | VAnchor.Top,
|
|||
|
|
Name = this.Name
|
|||
|
|
};
|
|||
|
|
editWidget.DrawFromHintedCache();
|
|||
|
|
editWidget.ActualTextEditWidget.TextChanged += (s, e) =>
|
|||
|
|
{
|
|||
|
|
UiThread.RunOnIdle(() =>
|
|||
|
|
{
|
|||
|
|
editWidget.ActualTextEditWidget.Height = Math.Min(editWidget.ActualTextEditWidget.Printer.LocalBounds.Height, 1500);
|
|||
|
|
});
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
var editTab = new ToolTab("Edit".Localize(), tabControl, editWidget, theme, hasClose: false)
|
|||
|
|
{
|
|||
|
|
Name = "Edit Tab"
|
|||
|
|
};
|
|||
|
|
tabControl.AddTab(editTab);
|
|||
|
|
|
|||
|
|
var markdownWidget = new MarkdownWidget(theme, true)
|
|||
|
|
{
|
|||
|
|
HAnchor = HAnchor.Stretch,
|
|||
|
|
VAnchor = VAnchor.Stretch,
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
var previewTab = new ToolTab("Preview".Localize(), tabControl, markdownWidget, theme, hasClose: false)
|
|||
|
|
{
|
|||
|
|
Name = "Preview Tab"
|
|||
|
|
};
|
|||
|
|
tabControl.AddTab(previewTab);
|
|||
|
|
|
|||
|
|
tabControl.ActiveTabChanged += (s, e) =>
|
|||
|
|
{
|
|||
|
|
if (tabControl.SelectedTabIndex == 1)
|
|||
|
|
{
|
|||
|
|
markdownWidget.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 Markdown
|
|||
|
|
{
|
|||
|
|
get => editWidget.Text;
|
|||
|
|
set => editWidget.Text = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|