ScriptEditorControl.cs 1.9 KB

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