Refactor VSCodeManualSetupWindow to inherit from ManualConfigEditorWindow and override methods for improved functionality

main
xsodus 2025-05-12 09:34:04 +07:00
parent d63eb7d4e4
commit 861e6bc62c
2 changed files with 38 additions and 32 deletions

View File

@ -8,13 +8,13 @@ namespace UnityMcpBridge.Editor.Windows
// Editor window to display manual configuration instructions // Editor window to display manual configuration instructions
public class ManualConfigEditorWindow : EditorWindow public class ManualConfigEditorWindow : EditorWindow
{ {
private string configPath; protected string configPath;
private string configJson; protected string configJson;
private Vector2 scrollPos; protected Vector2 scrollPos;
private bool pathCopied = false; protected bool pathCopied = false;
private bool jsonCopied = false; protected bool jsonCopied = false;
private float copyFeedbackTimer = 0; protected float copyFeedbackTimer = 0;
private McpClient mcpClient; protected McpClient mcpClient;
public static void ShowWindow(string configPath, string configJson, McpClient mcpClient) public static void ShowWindow(string configPath, string configJson, McpClient mcpClient)
{ {
@ -26,7 +26,7 @@ namespace UnityMcpBridge.Editor.Windows
window.Show(); window.Show();
} }
private void OnGUI() protected virtual void OnGUI()
{ {
scrollPos = EditorGUILayout.BeginScrollView(scrollPos); scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
@ -245,7 +245,7 @@ namespace UnityMcpBridge.Editor.Windows
EditorGUILayout.EndScrollView(); EditorGUILayout.EndScrollView();
} }
private void Update() protected virtual void Update()
{ {
// Handle the feedback message timer // Handle the feedback message timer
if (copyFeedbackTimer > 0) if (copyFeedbackTimer > 0)

View File

@ -5,25 +5,34 @@ using UnityMcpBridge.Editor.Models;
namespace UnityMcpBridge.Editor.Windows namespace UnityMcpBridge.Editor.Windows
{ {
public class VSCodeManualSetupWindow : EditorWindow public class VSCodeManualSetupWindow : ManualConfigEditorWindow
{ {
private string configPath; // Not defining fields that are inherited from ManualConfigEditorWindow:
private string configJson; // protected string configPath;
private Vector2 scrollPos; // protected string configJson;
private bool pathCopied = false; // protected Vector2 scrollPos;
private bool jsonCopied = false; // protected bool pathCopied;
private float copyFeedbackTimer = 0; // protected bool jsonCopied;
// protected float copyFeedbackTimer;
public static void ShowWindow(string configPath, string configJson) // protected McpClient mcpClient;
public static new void ShowWindow(string configPath, string configJson)
{ {
VSCodeManualSetupWindow window = GetWindow<VSCodeManualSetupWindow>("VSCode GitHub Copilot Setup"); var window = GetWindow<VSCodeManualSetupWindow>("VSCode GitHub Copilot Setup");
window.configPath = configPath; window.configPath = configPath;
window.configJson = configJson; window.configJson = configJson;
window.minSize = new Vector2(550, 500); window.minSize = new Vector2(550, 500);
// Create a McpClient for VSCode
window.mcpClient = new McpClient
{
name = "VSCode GitHub Copilot",
mcpType = McpTypes.VSCode
};
window.Show(); window.Show();
} }
private void OnGUI() protected override void OnGUI()
{ {
scrollPos = EditorGUILayout.BeginScrollView(scrollPos); scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
@ -135,6 +144,12 @@ namespace UnityMcpBridge.Editor.Windows
); );
} }
// Store the path in the base class config path
if (string.IsNullOrEmpty(configPath))
{
configPath = displayPath;
}
// Prevent text overflow by allowing the text field to wrap // Prevent text overflow by allowing the text field to wrap
GUIStyle pathStyle = new(EditorStyles.textField) { wordWrap = true }; GUIStyle pathStyle = new(EditorStyles.textField) { wordWrap = true };
@ -279,19 +294,10 @@ namespace UnityMcpBridge.Editor.Windows
EditorGUILayout.EndScrollView(); EditorGUILayout.EndScrollView();
} }
private void Update() protected override void Update()
{ {
// Handle the feedback message timer // Call the base implementation which handles the copy feedback timer
if (copyFeedbackTimer > 0) base.Update();
{
copyFeedbackTimer -= Time.deltaTime;
if (copyFeedbackTimer <= 0)
{
pathCopied = false;
jsonCopied = false;
Repaint();
}
}
} }
} }
} }