PlainTextInspector.cs 2.2 KB

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