PluginSettings.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using Unity.CodeEditor;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Packages.Rider.Editor
  5. {
  6. public class PluginSettings
  7. {
  8. public static LoggingLevel SelectedLoggingLevel
  9. {
  10. get => (LoggingLevel) EditorPrefs.GetInt("Rider_SelectedLoggingLevel", 0);
  11. set
  12. {
  13. EditorPrefs.SetInt("Rider_SelectedLoggingLevel", (int) value);
  14. }
  15. }
  16. public static bool LogEventsCollectorEnabled
  17. {
  18. get { return EditorPrefs.GetBool("Rider_LogEventsCollectorEnabled", true); }
  19. private set { EditorPrefs.SetBool("Rider_LogEventsCollectorEnabled", value); }
  20. }
  21. private static GUIStyle ourVersionInfoStyle = new GUIStyle()
  22. {
  23. normal = new GUIStyleState()
  24. {
  25. textColor = new Color(0, 0, 0, .6f),
  26. },
  27. margin = new RectOffset(4, 4, 4, 4),
  28. };
  29. /// <summary>
  30. /// Preferences menu layout
  31. /// </summary>
  32. /// <remarks>
  33. /// Contains all 3 toggles: Enable/Disable; Debug On/Off; Writing Launch File On/Off
  34. /// </remarks>
  35. [SettingsProvider]
  36. private static SettingsProvider RiderPreferencesItem()
  37. {
  38. if (!RiderScriptEditor.IsRiderInstallation(RiderScriptEditor.CurrentEditor))
  39. return null;
  40. if (!RiderScriptEditorData.instance.shouldLoadEditorPlugin)
  41. return null;
  42. var provider = new SettingsProvider("Preferences/Rider", SettingsScope.User)
  43. {
  44. label = "Rider",
  45. keywords = new[] { "Rider" },
  46. guiHandler = (searchContext) =>
  47. {
  48. EditorGUIUtility.labelWidth = 200f;
  49. EditorGUILayout.BeginVertical();
  50. GUILayout.BeginVertical();
  51. LogEventsCollectorEnabled =
  52. EditorGUILayout.Toggle(new GUIContent("Pass Console to Rider:"), LogEventsCollectorEnabled);
  53. GUILayout.EndVertical();
  54. GUILayout.Label("");
  55. if (!string.IsNullOrEmpty(EditorPluginInterop.LogPath))
  56. {
  57. EditorGUILayout.BeginHorizontal();
  58. EditorGUILayout.PrefixLabel("Log file:");
  59. var previous = GUI.enabled;
  60. GUI.enabled = previous && SelectedLoggingLevel != LoggingLevel.OFF;
  61. var button = GUILayout.Button(new GUIContent("Open log"));
  62. if (button)
  63. {
  64. //UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(PluginEntryPoint.LogPath, 0);
  65. // works much faster than the commented code, when Rider is already started
  66. CodeEditor.CurrentEditor.OpenProject(EditorPluginInterop.LogPath, 0, 0);
  67. }
  68. GUI.enabled = previous;
  69. GUILayout.EndHorizontal();
  70. }
  71. var loggingMsg =
  72. @"Sets the amount of Rider Debug output. If you are about to report an issue, please select Verbose logging level and attach Unity console output to the issue.";
  73. SelectedLoggingLevel =
  74. (LoggingLevel) EditorGUILayout.EnumPopup(new GUIContent("Logging Level:", loggingMsg),
  75. SelectedLoggingLevel);
  76. EditorGUILayout.HelpBox(loggingMsg, MessageType.None);
  77. var githubRepo = "https://github.com/JetBrains/resharper-unity";
  78. var caption = $"<color=#0000FF>{githubRepo}</color>";
  79. LinkButton(caption: caption, url: githubRepo);
  80. GUILayout.FlexibleSpace();
  81. GUILayout.BeginHorizontal();
  82. GUILayout.FlexibleSpace();
  83. var assembly = EditorPluginInterop.EditorPluginAssembly;
  84. if (assembly != null)
  85. {
  86. var version = assembly.GetName().Version;
  87. GUILayout.Label("Plugin version: " + version, ourVersionInfoStyle);
  88. }
  89. GUILayout.EndHorizontal();
  90. EditorGUILayout.EndVertical();
  91. }
  92. };
  93. return provider;
  94. }
  95. private static void LinkButton(string caption, string url)
  96. {
  97. var style = GUI.skin.label;
  98. style.richText = true;
  99. var bClicked = GUILayout.Button(caption, style);
  100. var rect = GUILayoutUtility.GetLastRect();
  101. rect.width = style.CalcSize(new GUIContent(caption)).x;
  102. EditorGUIUtility.AddCursorRect(rect, MouseCursor.Link);
  103. if (bClicked)
  104. Application.OpenURL(url);
  105. }
  106. }
  107. }