From 55eef017e76d495075d3dab53f9e240f75aa8d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 20 Jan 2024 21:23:01 +0100 Subject: [PATCH] AssetBrowser: Bad way to open scripts in Visual Studio --- .../src/EditWindows/ContentBrowserWindow.bf | 20 +++--- GlitchyEditor/src/VisualStudioUtility.bf | 65 +++++++++++++++++++ 2 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 GlitchyEditor/src/VisualStudioUtility.bf diff --git a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf index fdb222d..adec8be 100644 --- a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf +++ b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf @@ -206,17 +206,7 @@ namespace GlitchyEditor.EditWindows if (ImGui.MenuItem("Open C# Project...")) { - String solutionPath = scope .(); - Editor.Instance.CurrentProject.PathInProject(solutionPath, scope $"{Editor.Instance.CurrentProject.Name}.sln"); - - ProcessStartInfo psi = scope .(); - psi.SetFileName("devenv"); - psi.SetArguments(solutionPath); - - scope SpawnedProcess().Start(psi); - - /*if (Path.OpenFolder(solutionPath) case .Err) - Log.EngineLogger.Error("Failed to open file.");*/ + VisualStudioUtility.OpenScriptProject(); } } @@ -814,7 +804,13 @@ namespace GlitchyEditor.EditWindows } else { - if (Path.OpenFolder(entry->Path) case .Err) + // Special treatment for scripts, open them in Visual Studio. + if (entry->Path.EndsWith(".cs")) + { + // Obviously windows only + VisualStudioUtility.OpenScript(entry->Path); + } + else if (Path.OpenFolder(entry->Path) case .Err) Log.EngineLogger.Error("Failed to open file."); } } diff --git a/GlitchyEditor/src/VisualStudioUtility.bf b/GlitchyEditor/src/VisualStudioUtility.bf new file mode 100644 index 0000000..5fa33d5 --- /dev/null +++ b/GlitchyEditor/src/VisualStudioUtility.bf @@ -0,0 +1,65 @@ +using System; +using System.Diagnostics; +using GlitchyEngine; +using System.Collections; + +namespace GlitchyEditor; + +class VisualStudioUtility +{ + public static bool IsRunning() + { + List processes = scope .(); + + if (Process.GetProcesses(processes) case .Err) + { + Log.EngineLogger.Error("Failed to get running processes."); + return false; + } + + for (Process process in processes) + { + } + + ClearAndDeleteItems!(processes); + + return false; + } + + public static void OpenScript(StringView fileName) + { + if (IsRunning()) + { + ProcessStartInfo startInfo = scope .(); + startInfo.SetFileName(Application.Instance.Settings.ScriptSettings.VisualStudioPath); + startInfo.SetArguments(scope $"/Edit {fileName}"); + + scope SpawnedProcess().Start(startInfo); + } + else + { + ProcessStartInfo startInfo = scope .(); + startInfo.SetFileName(Application.Instance.Settings.ScriptSettings.VisualStudioPath); + startInfo.SetArguments(scope $"/Edit {fileName}"); + + scope SpawnedProcess().Start(startInfo); + } + } + + public static void OpenScript(StringView fileName, int lineNumber) + { + OpenScript(fileName); + } + + public static void OpenScriptProject() + { + String solutionPath = scope .(); + Editor.Instance.CurrentProject.PathInProject(solutionPath, scope $"{Editor.Instance.CurrentProject.Name}.sln"); + + ProcessStartInfo psi = scope .(); + psi.SetFileName("devenv"); + psi.SetArguments(solutionPath); + + scope SpawnedProcess().Start(psi); + } +}