123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using UnityEngine;
- using UnityEditor;
- using System;
- namespace UnityVersionControl
- {
- // Enhanced Input Dialog Window
- public class InputDialogWindow : EditorWindow
- {
- private string inputText = "";
- private string dialogTitle = "";
- private string dialogMessage = "";
- private System.Action<string> onConfirm;
- private System.Action onCancel;
- private bool focusSet = false;
- public static void Show(string title, string message, System.Action<string> onConfirm, System.Action onCancel = null)
- {
- var window = GetWindow<InputDialogWindow>(true, title, true);
- window.dialogTitle = title;
- window.dialogMessage = message;
- window.onConfirm = onConfirm;
- window.onCancel = onCancel;
- window.inputText = "";
- window.focusSet = false;
-
- // Center the window
- window.position = new Rect(
- (Screen.currentResolution.width - 400) / 2,
- (Screen.currentResolution.height - 150) / 2,
- 400, 150
- );
-
- window.ShowModal();
- }
- private void OnGUI()
- {
- GUILayout.Space(10);
-
- EditorGUILayout.LabelField(dialogMessage, EditorStyles.wordWrappedLabel);
-
- GUILayout.Space(10);
-
- GUI.SetNextControlName("InputField");
- inputText = EditorGUILayout.TextField(inputText);
-
- // Auto-focus the input field
- if (!focusSet)
- {
- EditorGUI.FocusTextInControl("InputField");
- focusSet = true;
- }
-
- // Handle Enter key
- if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
- {
- ConfirmInput();
- return;
- }
-
- // Handle Escape key
- if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
- {
- CancelInput();
- return;
- }
-
- GUILayout.Space(10);
-
- EditorGUILayout.BeginHorizontal();
-
- GUILayout.FlexibleSpace();
-
- GUI.enabled = !string.IsNullOrEmpty(inputText.Trim());
- if (GUILayout.Button("OK", GUILayout.Width(80)))
- {
- ConfirmInput();
- }
- GUI.enabled = true;
-
- if (GUILayout.Button("Cancel", GUILayout.Width(80)))
- {
- CancelInput();
- }
-
- EditorGUILayout.EndHorizontal();
- }
- private void ConfirmInput()
- {
- if (!string.IsNullOrEmpty(inputText.Trim()))
- {
- onConfirm?.Invoke(inputText.Trim());
- Close();
- }
- }
- private void CancelInput()
- {
- onCancel?.Invoke();
- Close();
- }
- }
- // Note: EditorInputDialog is now defined in VersionControlWindow.cs to avoid conflicts
- }
|