CodeEditor.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. None
  17. }
  18. /// <summary>
  19. /// Handles interaction with the external application used for editing scripts.
  20. /// </summary>
  21. public static class CodeEditor
  22. {
  23. /// <summary>
  24. /// Contains resource types that are relevant to the code editor.
  25. /// </summary>
  26. public static readonly ResourceType[] CodeTypes =
  27. {
  28. ResourceType.ScriptCode,
  29. ResourceType.PlainText,
  30. ResourceType.Shader,
  31. ResourceType.ShaderInclude
  32. };
  33. private static bool isSolutionDirty;
  34. /// <summary>
  35. /// Currently active code editor.
  36. /// </summary>
  37. public static CodeEditorType ActiveEditor
  38. {
  39. set { Internal_SetActiveEditor(value); }
  40. get { return Internal_GetActiveEditor(); }
  41. }
  42. /// <summary>
  43. /// Checks if the code editor's solution requires updating.
  44. /// </summary>
  45. internal static bool IsSolutionDirty
  46. {
  47. get { return isSolutionDirty; }
  48. }
  49. /// <summary>
  50. /// Returns a list of all code editors available on this machine.
  51. /// </summary>
  52. public static CodeEditorType[] AvailableEditors
  53. {
  54. get { return Internal_GetAvailableEditors(); }
  55. }
  56. /// <summary>
  57. /// Opens a script file in the currently active code editor.
  58. /// </summary>
  59. /// <param name="path">Path to the script file to open, either absolute or relative to the project resources folder.</param>
  60. /// <param name="line">Line in the file to focus the editor on.</param>
  61. public static void OpenFile(string path, int line)
  62. {
  63. if (IsSolutionDirty)
  64. SyncSolution();
  65. Internal_OpenFile(path, line);
  66. }
  67. /// <summary>
  68. /// Generates a solution file for the active editor, which includes all scripts in the project.
  69. /// </summary>
  70. public static void SyncSolution()
  71. {
  72. Internal_SyncSolution();
  73. isSolutionDirty = false;
  74. }
  75. /// <summary>
  76. /// Notifies the code editor that code file structure has changed and the solution needs to be rebuilt.
  77. /// </summary>
  78. internal static void MarkSolutionDirty()
  79. {
  80. isSolutionDirty = true;
  81. }
  82. [MethodImpl(MethodImplOptions.InternalCall)]
  83. internal static extern void Internal_SetActiveEditor(CodeEditorType type);
  84. [MethodImpl(MethodImplOptions.InternalCall)]
  85. internal static extern CodeEditorType Internal_GetActiveEditor();
  86. [MethodImpl(MethodImplOptions.InternalCall)]
  87. internal static extern CodeEditorType[] Internal_GetAvailableEditors();
  88. [MethodImpl(MethodImplOptions.InternalCall)]
  89. internal static extern void Internal_OpenFile(string path, int line);
  90. [MethodImpl(MethodImplOptions.InternalCall)]
  91. internal static extern void Internal_SyncSolution();
  92. }
  93. }