CodeEditor.cs 4.0 KB

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