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
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class UpdateOnEveryKeystrokeAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -116,6 +116,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
[DisplayName("Description - Markdown Text")]
|
||||
[MultiLineEdit]
|
||||
[UpdateOnEveryKeystroke]
|
||||
public string Description { get; set; } = "You can edit this description in the properties panel";
|
||||
|
||||
public enum Placements
|
||||
|
|
|
|||
|
|
@ -1073,7 +1073,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
if (property.PropertyInfo.GetCustomAttributes(true).OfType<MultiLineEditAttribute>().FirstOrDefault() != null)
|
||||
{
|
||||
// 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.SetValue(stringValue, false);
|
||||
field.ClearUndoHistory();
|
||||
|
|
|
|||
|
|
@ -35,10 +35,19 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
public class MultilineStringField : UIField
|
||||
{
|
||||
private ThemedTextEditWidget editWidget;
|
||||
|
||||
public bool SetValueOnEveryEdit { get; }
|
||||
|
||||
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.SetValueOnEveryEdit = setValueOnEveryEdit;
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +60,20 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
Name = this.Name
|
||||
};
|
||||
editWidget.DrawFromHintedCache();
|
||||
if (SetValueOnEveryEdit)
|
||||
{
|
||||
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) =>
|
||||
{
|
||||
if (sender is TextEditWidget textEditWidget)
|
||||
|
|
@ -60,6 +83,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
userInitiated: true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
editWidget.ActualTextEditWidget.TextChanged += (s, e) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit fd09e961bc6c5d5c104cc093ef303fd591b960f2
|
||||
Subproject commit 7ae6015eadfeaae062b5e00dfd7a3a4a4c66304d
|
||||
Loading…
Add table
Add a link
Reference in a new issue