|
@@ -6,122 +6,121 @@ using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
using InABox.Core;
|
|
|
|
|
|
-namespace InABox.DynamicGrid
|
|
|
+namespace InABox.DynamicGrid;
|
|
|
+
|
|
|
+public class CodeEditorControl : DynamicEditorControl<string, BaseCodeEditor>
|
|
|
{
|
|
|
- public class CodeEditorControl : DynamicEditorControl<string, BaseCodeEditor>
|
|
|
+
|
|
|
+ static CodeEditorControl()
|
|
|
{
|
|
|
-
|
|
|
- static CodeEditorControl()
|
|
|
- {
|
|
|
- //DynamicEditorControlFactory.Register<CodeEditorControl, BaseCodeEditor, CodeEditor>();
|
|
|
- //DynamicEditorControlFactory.Register<CodeEditorControl, BaseCodeEditor, UniqueCodeEditor>();
|
|
|
- }
|
|
|
-
|
|
|
- private TextBox Editor;
|
|
|
+ //DynamicEditorControlFactory.Register<CodeEditorControl, BaseCodeEditor, CodeEditor>();
|
|
|
+ //DynamicEditorControlFactory.Register<CodeEditorControl, BaseCodeEditor, UniqueCodeEditor>();
|
|
|
+ }
|
|
|
+
|
|
|
+ private TextBox Editor;
|
|
|
|
|
|
- public override void Configure()
|
|
|
- {
|
|
|
- }
|
|
|
+ public override void Configure()
|
|
|
+ {
|
|
|
+ }
|
|
|
|
|
|
- protected override FrameworkElement CreateEditor()
|
|
|
+ protected override FrameworkElement CreateEditor()
|
|
|
+ {
|
|
|
+ var dock = new DockPanel
|
|
|
{
|
|
|
- var dock = new DockPanel
|
|
|
- {
|
|
|
- HorizontalAlignment = HorizontalAlignment.Stretch,
|
|
|
- VerticalAlignment = VerticalAlignment.Stretch
|
|
|
- };
|
|
|
-
|
|
|
- var buttons = CreateButtons(out var DisableEditor);
|
|
|
- foreach (var button in buttons)
|
|
|
- {
|
|
|
- button.SetValue(DockPanel.DockProperty, Dock.Right);
|
|
|
- dock.Children.Add(button);
|
|
|
- dock.Width += button.Width + 5;
|
|
|
- }
|
|
|
-
|
|
|
- Editor = new TextBox
|
|
|
- {
|
|
|
- CharacterCasing = CharacterCasing.Upper,
|
|
|
- VerticalContentAlignment = VerticalAlignment.Center
|
|
|
- };
|
|
|
- Editor.SetValue(DockPanel.DockProperty, Dock.Left);
|
|
|
- if (DisableEditor)
|
|
|
- {
|
|
|
- Editor.Background = new SolidColorBrush(Colors.Silver);
|
|
|
- Editor.IsEnabled = false;
|
|
|
- }
|
|
|
-
|
|
|
- Editor.TextChanged += (o, e) => { CheckChanged(); };
|
|
|
-
|
|
|
- Editor.PreviewTextInput += Editor_PreviewTextInput;
|
|
|
- DataObject.AddPastingHandler(Editor, Editor_TextPaste);
|
|
|
-
|
|
|
- dock.Children.Add(Editor);
|
|
|
-
|
|
|
- return dock;
|
|
|
- }
|
|
|
+ HorizontalAlignment = HorizontalAlignment.Stretch,
|
|
|
+ VerticalAlignment = VerticalAlignment.Stretch
|
|
|
+ };
|
|
|
|
|
|
- private void Editor_TextPaste(object sender, DataObjectPastingEventArgs e)
|
|
|
+ var buttons = CreateButtons(out var DisableEditor);
|
|
|
+ foreach (var button in buttons)
|
|
|
{
|
|
|
- if (e.DataObject.GetDataPresent(typeof(string)))
|
|
|
- {
|
|
|
- var allowable = (EditorDefinition as BaseCodeEditor)?.ValidChars;
|
|
|
- var text = (string)e.DataObject.GetData(typeof(string));
|
|
|
- if (!IsTextAllowed(text, allowable))
|
|
|
- e.CancelCommand();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- e.CancelCommand();
|
|
|
- }
|
|
|
+ button.SetValue(DockPanel.DockProperty, Dock.Right);
|
|
|
+ dock.Children.Add(button);
|
|
|
+ dock.Width += button.Width + 5;
|
|
|
}
|
|
|
|
|
|
- private bool IsTextAllowed(string text, string allowable)
|
|
|
+ Editor = new TextBox
|
|
|
+ {
|
|
|
+ CharacterCasing = CharacterCasing.Upper,
|
|
|
+ VerticalContentAlignment = VerticalAlignment.Center
|
|
|
+ };
|
|
|
+ Editor.SetValue(DockPanel.DockProperty, Dock.Left);
|
|
|
+ if (DisableEditor)
|
|
|
{
|
|
|
- if (string.IsNullOrWhiteSpace(allowable))
|
|
|
- return true;
|
|
|
- return Array.TrueForAll(text.ToCharArray(), delegate(char c) { return allowable.Contains(c); });
|
|
|
+ Editor.Background = new SolidColorBrush(Colors.Silver);
|
|
|
+ Editor.IsEnabled = false;
|
|
|
}
|
|
|
|
|
|
- private void Editor_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
|
+ Editor.TextChanged += (o, e) => { CheckChanged(); };
|
|
|
+
|
|
|
+ Editor.PreviewTextInput += Editor_PreviewTextInput;
|
|
|
+ DataObject.AddPastingHandler(Editor, Editor_TextPaste);
|
|
|
+
|
|
|
+ dock.Children.Add(Editor);
|
|
|
+
|
|
|
+ return dock;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Editor_TextPaste(object sender, DataObjectPastingEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.DataObject.GetDataPresent(typeof(string)))
|
|
|
{
|
|
|
var allowable = (EditorDefinition as BaseCodeEditor)?.ValidChars;
|
|
|
- e.Handled = !IsTextAllowed(e.Text, allowable);
|
|
|
+ var text = (string)e.DataObject.GetData(typeof(string));
|
|
|
+ if (!IsTextAllowed(text, allowable))
|
|
|
+ e.CancelCommand();
|
|
|
}
|
|
|
-
|
|
|
- public override int DesiredHeight()
|
|
|
+ else
|
|
|
{
|
|
|
- return 25;
|
|
|
+ e.CancelCommand();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- public override int DesiredWidth()
|
|
|
- {
|
|
|
- var result = 150;
|
|
|
- var btnEditor = EditorDefinition as IButtonEditor;
|
|
|
- if (btnEditor?.Buttons != null)
|
|
|
- foreach (var button in ((IButtonEditor)EditorDefinition).Buttons)
|
|
|
- result += button.Width + 5;
|
|
|
- return result;
|
|
|
- }
|
|
|
+ private bool IsTextAllowed(string text, string allowable)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(allowable))
|
|
|
+ return true;
|
|
|
+ return Array.TrueForAll(text.ToCharArray(), delegate(char c) { return allowable.Contains(c); });
|
|
|
+ }
|
|
|
|
|
|
- protected override string RetrieveValue()
|
|
|
- {
|
|
|
- return Editor.Text;
|
|
|
- }
|
|
|
+ private void Editor_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
|
+ {
|
|
|
+ var allowable = (EditorDefinition as BaseCodeEditor)?.ValidChars;
|
|
|
+ e.Handled = !IsTextAllowed(e.Text, allowable);
|
|
|
+ }
|
|
|
|
|
|
- protected override void UpdateValue(string value)
|
|
|
- {
|
|
|
- Editor.Text = value;
|
|
|
- }
|
|
|
+ public override int DesiredHeight()
|
|
|
+ {
|
|
|
+ return 25;
|
|
|
+ }
|
|
|
|
|
|
- public override void SetFocus()
|
|
|
- {
|
|
|
- Editor.Focus();
|
|
|
- }
|
|
|
+ public override int DesiredWidth()
|
|
|
+ {
|
|
|
+ var result = 150;
|
|
|
+ var btnEditor = EditorDefinition as IButtonEditor;
|
|
|
+ if (btnEditor?.Buttons != null)
|
|
|
+ foreach (var button in ((IButtonEditor)EditorDefinition).Buttons)
|
|
|
+ result += button.Width + 5;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- public override void SetColor(Color color)
|
|
|
- {
|
|
|
- Editor.Background = new SolidColorBrush(color);
|
|
|
- }
|
|
|
+ protected override string RetrieveValue()
|
|
|
+ {
|
|
|
+ return Editor.Text;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void UpdateValue(string value)
|
|
|
+ {
|
|
|
+ Editor.Text = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SetFocus()
|
|
|
+ {
|
|
|
+ Editor.Focus();
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SetColor(Color color)
|
|
|
+ {
|
|
|
+ Editor.Background = new SolidColorBrush(color);
|
|
|
}
|
|
|
}
|