Merge pull request #5393 from larsbrubaker/main
Adding ability to see markdown edits live in description object
This commit is contained in:
commit
16ea4efb1e
5 changed files with 42 additions and 12 deletions
|
|
@ -36,4 +36,9 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
public class MultiLineEditAttribute : Attribute
|
public class MultiLineEditAttribute : Attribute
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
|
public class UpdateOnEveryKeystrokeAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -116,6 +116,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
|
|
||||||
[DisplayName("Description - Markdown Text")]
|
[DisplayName("Description - Markdown Text")]
|
||||||
[MultiLineEdit]
|
[MultiLineEdit]
|
||||||
|
[UpdateOnEveryKeystroke]
|
||||||
public string Description { get; set; } = "You can edit this description in the properties panel";
|
public string Description { get; set; } = "You can edit this description in the properties panel";
|
||||||
|
|
||||||
public enum Placements
|
public enum Placements
|
||||||
|
|
@ -352,7 +353,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
|
|
||||||
FixSelectableBasedOnLinks(markdownWidget);
|
FixSelectableBasedOnLinks(markdownWidget);
|
||||||
|
|
||||||
controlLayer.GuiSurface.AddChild(markdownWidget);
|
controlLayer.GuiSurface.AddChild(markdownWidget);
|
||||||
controlLayer.GuiSurface.AfterDraw += GuiSurface_AfterDraw;
|
controlLayer.GuiSurface.AfterDraw += GuiSurface_AfterDraw;
|
||||||
markdownWidget.MouseDown += MarkdownWidget_MouseDown;
|
markdownWidget.MouseDown += MarkdownWidget_MouseDown;
|
||||||
markdownWidget.MouseMove += MarkdownWidget_MouseMove;
|
markdownWidget.MouseMove += MarkdownWidget_MouseMove;
|
||||||
|
|
|
||||||
|
|
@ -1073,7 +1073,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
||||||
if (property.PropertyInfo.GetCustomAttributes(true).OfType<MultiLineEditAttribute>().FirstOrDefault() != null)
|
if (property.PropertyInfo.GetCustomAttributes(true).OfType<MultiLineEditAttribute>().FirstOrDefault() != null)
|
||||||
{
|
{
|
||||||
// create a a multi-line string editor
|
// create a a multi-line string editor
|
||||||
var field = new MultilineStringField(theme);
|
var field = new MultilineStringField(theme, property.PropertyInfo.GetCustomAttributes(true).OfType<UpdateOnEveryKeystrokeAttribute>().FirstOrDefault() != null);
|
||||||
field.Initialize(0);
|
field.Initialize(0);
|
||||||
field.SetValue(stringValue, false);
|
field.SetValue(stringValue, false);
|
||||||
field.ClearUndoHistory();
|
field.ClearUndoHistory();
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,20 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
public class MultilineStringField : UIField
|
public class MultilineStringField : UIField
|
||||||
{
|
{
|
||||||
private ThemedTextEditWidget editWidget;
|
private ThemedTextEditWidget editWidget;
|
||||||
|
|
||||||
|
public bool SetValueOnEveryEdit { get; }
|
||||||
|
|
||||||
private ThemeConfig theme;
|
private ThemeConfig theme;
|
||||||
|
|
||||||
public MultilineStringField(ThemeConfig theme)
|
/// <summary>
|
||||||
|
/// The constructor of a Multiline String Field
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="theme">The theme to use</param>
|
||||||
|
/// <param name="setValueOnEveryEdit">Sets if SetValue gets called with every keystroke or only after EditComplete.</param>
|
||||||
|
public MultilineStringField(ThemeConfig theme, bool setValueOnEveryEdit = false)
|
||||||
{
|
{
|
||||||
this.theme = theme;
|
this.SetValueOnEveryEdit = setValueOnEveryEdit;
|
||||||
|
this.theme = theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize(int tabIndex)
|
public override void Initialize(int tabIndex)
|
||||||
|
|
@ -51,15 +60,30 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||||
Name = this.Name
|
Name = this.Name
|
||||||
};
|
};
|
||||||
editWidget.DrawFromHintedCache();
|
editWidget.DrawFromHintedCache();
|
||||||
editWidget.ActualTextEditWidget.EditComplete += (sender, e) =>
|
if (SetValueOnEveryEdit)
|
||||||
{
|
{
|
||||||
if (sender is TextEditWidget textEditWidget)
|
editWidget.ActualTextEditWidget.TextChanged += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (sender is TextEditWidget textEditWidget)
|
||||||
|
{
|
||||||
|
this.SetValue(
|
||||||
|
textEditWidget.Text.Replace("\n", "\\n"),
|
||||||
|
userInitiated: true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
editWidget.ActualTextEditWidget.EditComplete += (sender, e) =>
|
||||||
{
|
{
|
||||||
this.SetValue(
|
if (sender is TextEditWidget textEditWidget)
|
||||||
textEditWidget.Text.Replace("\n", "\\n"),
|
{
|
||||||
userInitiated: true);
|
this.SetValue(
|
||||||
}
|
textEditWidget.Text.Replace("\n", "\\n"),
|
||||||
};
|
userInitiated: true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
editWidget.ActualTextEditWidget.TextChanged += (s, e) =>
|
editWidget.ActualTextEditWidget.TextChanged += (s, e) =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit fd09e961bc6c5d5c104cc093ef303fd591b960f2
|
Subproject commit 7ae6015eadfeaae062b5e00dfd7a3a4a4c66304d
|
||||||
Loading…
Add table
Add a link
Reference in a new issue