CodeEditor.cs 3.7 KB

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