Kaynağa Gözat

C#: Always show "Create C# solution" option

Prevents ending up with an empty C# menu.
The option to create the C# solution no longer disappears, to avoid confusing users.
If an user tries to use it when a C# solution already exists they are warned that it will override their sln and csproj files.
Raul Santos 2 yıl önce
ebeveyn
işleme
a1a2fc2255

+ 25 - 5
modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs

@@ -35,6 +35,7 @@ namespace GodotTools
         private PopupMenu _menuPopup;
 
         private AcceptDialog _errorDialog;
+        private ConfirmationDialog _confirmCreateSlnDialog;
 
         private Button _bottomPanelBtn;
         private Button _toolBarBuildButton;
@@ -99,7 +100,7 @@ namespace GodotTools
                     pr.Step("Done".TTR());
 
                     // Here, after all calls to progress_task_step
-                    CallDeferred(nameof(_RemoveCreateSlnMenuOption));
+                    CallDeferred(nameof(_ShowDotnetFeatures));
                 }
                 else
                 {
@@ -110,9 +111,8 @@ namespace GodotTools
             }
         }
 
-        private void _RemoveCreateSlnMenuOption()
+        private void _ShowDotnetFeatures()
         {
-            _menuPopup.RemoveItem(_menuPopup.GetItemIndex((int)MenuOptions.CreateSln));
             _bottomPanelBtn.Show();
             _toolBarBuildButton.Show();
         }
@@ -122,8 +122,17 @@ namespace GodotTools
             switch ((MenuOptions)id)
             {
                 case MenuOptions.CreateSln:
-                    CreateProjectSolution();
+                {
+                    if (File.Exists(GodotSharpDirs.ProjectSlnPath) || File.Exists(GodotSharpDirs.ProjectCsProjPath))
+                    {
+                        ShowConfirmCreateSlnDialog();
+                    }
+                    else
+                    {
+                        CreateProjectSolution();
+                    }
                     break;
+                }
                 case MenuOptions.SetupGodotNugetFallbackFolder:
                 {
                     try
@@ -169,6 +178,13 @@ namespace GodotTools
             _errorDialog.PopupCentered();
         }
 
+        public void ShowConfirmCreateSlnDialog()
+        {
+            _confirmCreateSlnDialog.Title = "C# solution already exists. This will override the existing C# project file, any manual changes will be lost.".TTR();
+            _confirmCreateSlnDialog.DialogText = "Create C# solution".TTR();
+            _confirmCreateSlnDialog.PopupCentered();
+        }
+
         private static string _vsCodePath = string.Empty;
 
         private static readonly string[] VsCodeNames =
@@ -420,6 +436,10 @@ namespace GodotTools
             _errorDialog = new AcceptDialog();
             editorBaseControl.AddChild(_errorDialog);
 
+            _confirmCreateSlnDialog = new ConfirmationDialog();
+            _confirmCreateSlnDialog.Confirmed += () => CreateProjectSolution();
+            editorBaseControl.AddChild(_confirmCreateSlnDialog);
+
             MSBuildPanel = new MSBuildPanel();
             MSBuildPanel.Ready += () =>
                 MSBuildPanel.BuildOutputView.BuildStateChanged += BuildStateChanged;
@@ -453,8 +473,8 @@ namespace GodotTools
             {
                 _bottomPanelBtn.Hide();
                 _toolBarBuildButton.Hide();
-                _menuPopup.AddItem("Create C# solution".TTR(), (int)MenuOptions.CreateSln);
             }
+            _menuPopup.AddItem("Create C# solution".TTR(), (int)MenuOptions.CreateSln);
 
             _menuPopup.IdPressed += _MenuOptionPressed;