CodeEditor.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// Contains all supported external code editors
  8. /// </summary>
  9. public enum CodeEditorType // Note: Must match C++ CodeEditorType enum
  10. {
  11. VS2008,
  12. VS2010,
  13. VS2012,
  14. VS2013,
  15. VS2015
  16. }
  17. /// <summary>
  18. /// Handles interaction with the external application used for editing scripts.
  19. /// </summary>
  20. public static class CodeEditor
  21. {
  22. /// <summary>
  23. /// Contains resource types that are relevant to the code editor.
  24. /// </summary>
  25. public static readonly ResourceType[] CodeTypes =
  26. {
  27. ResourceType.ScriptCode,
  28. ResourceType.PlainText,
  29. ResourceType.Shader,
  30. ResourceType.ShaderInclude
  31. };
  32. private static bool isSolutionDirty;
  33. /// <summary>
  34. /// Currently active code editor.
  35. /// </summary>
  36. public static CodeEditorType ActiveEditor
  37. {
  38. set { Internal_SetActiveEditor(value); }
  39. }
  40. /// <summary>
  41. /// Checks if the code editor's solution requires updating.
  42. /// </summary>
  43. internal static bool IsSolutionDirty
  44. {
  45. get { return isSolutionDirty; }
  46. }
  47. /// <summary>
  48. /// Returns a list of all code editors available on this machine.
  49. /// </summary>
  50. public static CodeEditorType[] AvailableEditors
  51. {
  52. get { return Internal_GetAvailableEditors(); }
  53. }
  54. /// <summary>
  55. /// Opens a script file in the currently active code editor.
  56. /// </summary>
  57. /// <param name="path">Path to the script file to open, either absolute or relative to the project resources folder.</param>
  58. /// <param name="line">Line in the file to focus the editor on.</param>
  59. public static void OpenFile(string path, UInt32 line)
  60. {
  61. if (IsSolutionDirty)
  62. SyncSolution();
  63. Internal_OpenFile(path, line);
  64. }
  65. /// <summary>
  66. /// Generates a solution file for the active editor, which includes all scripts in the project.
  67. /// </summary>
  68. public static void SyncSolution()
  69. {
  70. Internal_SyncSolution();
  71. isSolutionDirty = false;
  72. }
  73. /// <summary>
  74. /// Notifies the code editor that code file structure has changed and the solution needs to be rebuilt.
  75. /// </summary>
  76. internal static void MarkSolutionDirty()
  77. {
  78. isSolutionDirty = true;
  79. }
  80. [MethodImpl(MethodImplOptions.InternalCall)]
  81. internal static extern void Internal_SetActiveEditor(CodeEditorType type);
  82. [MethodImpl(MethodImplOptions.InternalCall)]
  83. internal static extern CodeEditorType[] Internal_GetAvailableEditors();
  84. [MethodImpl(MethodImplOptions.InternalCall)]
  85. internal static extern void Internal_OpenFile(string path, UInt32 line);
  86. [MethodImpl(MethodImplOptions.InternalCall)]
  87. internal static extern void Internal_SyncSolution();
  88. }
  89. }