private string GetExternalEditorIdentity(ExternalEditorId editorId) { // Manually convert to string to avoid breaking compatibility in case we rename the enum fields. switch (editorId) { case ExternalEditorId.None: return(null); case ExternalEditorId.VisualStudio: return("VisualStudio"); case ExternalEditorId.VsCode: return("VisualStudioCode"); case ExternalEditorId.Rider: return("Rider"); case ExternalEditorId.VisualStudioForMac: return("VisualStudioForMac"); case ExternalEditorId.MonoDevelop: return("MonoDevelop"); default: throw new NotImplementedException(); } }
public EditorPick PickEditor(ExternalEditorId editorId) => new EditorPick(GetExternalEditorIdentity(editorId));
private void LaunchIde(ExternalEditorId editorId, string editorIdentity) { switch (editorId) { case ExternalEditorId.None: case ExternalEditorId.VisualStudio: case ExternalEditorId.VsCode: case ExternalEditorId.Rider: throw new NotSupportedException(); case ExternalEditorId.VisualStudioForMac: goto case ExternalEditorId.MonoDevelop; case ExternalEditorId.MonoDevelop: { MonoDevelop.Instance GetMonoDevelopInstance(string solutionPath) { if (Utils.OS.IsOSX && editorId == ExternalEditorId.VisualStudioForMac) { _vsForMacInstance = (_vsForMacInstance?.IsDisposed ?? true ? null : _vsForMacInstance) ?? new MonoDevelop.Instance(solutionPath, MonoDevelop.EditorId.VisualStudioForMac); return(_vsForMacInstance); } _monoDevelInstance = (_monoDevelInstance?.IsDisposed ?? true ? null : _monoDevelInstance) ?? new MonoDevelop.Instance(solutionPath, MonoDevelop.EditorId.MonoDevelop); return(_monoDevelInstance); } try { var instance = GetMonoDevelopInstance(GodotSharpDirs.ProjectSlnPath); if (instance.IsRunning && !GetRunningOrNewServer().IsAnyConnected(editorIdentity)) { // After launch we wait up to 30 seconds for the IDE to connect to our messaging server. var waitAfterLaunch = TimeSpan.FromSeconds(30); var timeSinceLaunch = DateTime.Now - instance.LaunchTime; if (timeSinceLaunch > waitAfterLaunch) { instance.Dispose(); instance.Execute(); } } else if (!instance.IsRunning) { instance.Execute(); } } catch (FileNotFoundException) { string editorName = editorId == ExternalEditorId.VisualStudioForMac ? "Visual Studio" : "MonoDevelop"; GD.PushError($"Cannot find code editor: {editorName}"); } break; } default: throw new ArgumentOutOfRangeException(); } }