PlainTextInspector.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections.Generic;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. /// <summary>
  6. /// Renders an inspector for the <see cref="PlainText"/> resource.
  7. /// </summary>
  8. [CustomInspector(typeof(PlainText))]
  9. internal class PlainTextInspector : Inspector
  10. {
  11. private const int MAX_SHOWN_CHARACTERS = 3000;
  12. private GUILabel textLabel = new GUILabel("", EditorStyles.MultiLineLabel, GUIOption.FixedHeight(500));
  13. private GUITexture textBg = new GUITexture(null, EditorStyles.ScrollAreaBg);
  14. private string shownText = "";
  15. /// <inheritdoc/>
  16. protected internal override void Initialize()
  17. {
  18. PlainText plainText = InspectedObject as PlainText;
  19. if (plainText == null)
  20. return;
  21. GUIPanel textPanel = Layout.AddPanel();
  22. GUILayout textLayoutY = textPanel.AddLayoutY();
  23. textLayoutY.AddSpace(5);
  24. GUILayout textLayoutX = textLayoutY.AddLayoutX();
  25. textLayoutX.AddSpace(5);
  26. textLayoutX.AddElement(textLabel);
  27. textLayoutX.AddSpace(5);
  28. textLayoutY.AddSpace(5);
  29. GUIPanel textBgPanel = textPanel.AddPanel(1);
  30. textBgPanel.AddElement(textBg);
  31. }
  32. /// <inheritdoc/>
  33. protected internal override InspectableState Refresh()
  34. {
  35. PlainText plainText = InspectedObject as PlainText;
  36. if (plainText == null)
  37. return InspectableState.NotModified;
  38. string newText = plainText.Text;
  39. string newShownText = plainText.Text.Substring(0, MathEx.Min(newText.Length, MAX_SHOWN_CHARACTERS));
  40. if (newShownText != shownText)
  41. {
  42. textLabel.SetContent(newShownText);
  43. shownText = newShownText;
  44. }
  45. return InspectableState.NotModified;
  46. }
  47. }
  48. }