2
0

CodeEditor.cs 3.6 KB

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