CodeEditor.cs 3.6 KB

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