ScriptEditorControl.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Media;
  8. using InABox.Core;
  9. namespace InABox.DynamicGrid
  10. {
  11. public class ScriptEditorControl : DynamicEditorControl<string>
  12. {
  13. private Button Editor;
  14. private string script = "";
  15. public ScriptEditorControl()
  16. {
  17. SyntaxLanguage = SyntaxLanguage.CSharp;
  18. }
  19. public SyntaxLanguage SyntaxLanguage { get; set; }
  20. public event OnEditorClicked OnEditorClicked;
  21. protected override FrameworkElement CreateEditor()
  22. {
  23. Editor = new Button
  24. {
  25. Content = "Edit..",
  26. HorizontalAlignment = HorizontalAlignment.Left,
  27. VerticalAlignment = VerticalAlignment.Stretch,
  28. VerticalContentAlignment = VerticalAlignment.Center,
  29. Width = 50
  30. };
  31. Editor.Click += Editor_Click;
  32. return Editor;
  33. }
  34. private void Editor_Click(object sender, RoutedEventArgs e)
  35. {
  36. if (EditorDefinition.GetType() == typeof(ScriptEditor))
  37. {
  38. CheckTemplateEditor();
  39. }
  40. else
  41. ShowEditor();
  42. }
  43. private void CheckTemplateEditor()
  44. {
  45. var edt = EditorDefinition as ScriptEditor;
  46. if (edt.Type == ScriptEditorType.TemplateEditor)
  47. edt.InvokeEvent();
  48. else
  49. ShowEditor();
  50. }
  51. private void ShowEditor()
  52. {
  53. var editor = new ScriptEditorWindow(script, SyntaxLanguage);
  54. if (editor.ShowDialog() == true)
  55. {
  56. script = editor.Script;
  57. CheckChanged();
  58. }
  59. }
  60. public override int DesiredHeight()
  61. {
  62. return 25;
  63. }
  64. public override int DesiredWidth()
  65. {
  66. return 100;
  67. }
  68. protected override string RetrieveValue()
  69. {
  70. return script;
  71. }
  72. protected override void UpdateValue(string value)
  73. {
  74. script = value;
  75. }
  76. public override void SetFocus()
  77. {
  78. Editor.Focus();
  79. }
  80. public override void SetColor(Color color)
  81. {
  82. //Editor.Background = new SolidColorBrush(color);
  83. }
  84. }
  85. }