Pārlūkot izejas kodu

Fix #19047 - Fix External scripts editor settings (#19053)

* Fix #19047 - External scripts editor settings

Signed-off-by: LafLaurine <[email protected]>

* Fix #19047 - Improve logic to check prioritized openers

Signed-off-by: LafLaurine <[email protected]>

* Fix #19047 - Changed backslashes to forward ones

Signed-off-by: LafLaurine <[email protected]>

---------

Signed-off-by: LafLaurine <[email protected]>
Laurine Lafontaine 1 mēnesi atpakaļ
vecāks
revīzija
25c0c8dbef

+ 33 - 5
Code/Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.cpp

@@ -1182,18 +1182,46 @@ void AzAssetBrowserRequestHandler::OpenAssetInAssociatedEditor(const AZ::Data::A
         const SourceFileOpenerDetails* firstValidOpener = nullptr;
         int numValidOpeners = 0;
         QMenu menu(mainWindow);
-        for (const SourceFileOpenerDetails& openerDetails : openers)
+        const auto addOpener =
+            [&numValidOpeners, &firstValidOpener, &menu, switchToOpener, mainWindow](const SourceFileOpenerDetails& opener)
         {
-            // bind that function to the current loop element.
-            if (openerDetails.m_opener) // only VALID openers with an actual callback.
+            if (opener.m_opener) // only VALID openers with an actual callback.
             {
                 ++numValidOpeners;
                 if (!firstValidOpener)
                 {
-                    firstValidOpener = &openerDetails;
+                    firstValidOpener = &opener;
                 }
                 // bind a callback such that when the menu item is clicked, it sets that as the opener to use.
-                menu.addAction(openerDetails.m_iconToUse, QObject::tr(openerDetails.m_displayText.c_str()), mainWindow, [switchToOpener, details = &openerDetails] { return switchToOpener(details); });
+                menu.addAction(
+                    opener.m_iconToUse,
+                    QObject::tr(opener.m_displayText.c_str()),
+                    mainWindow,
+                    [switchToOpener, details = &opener]()
+                    {
+                        return switchToOpener(details);
+                    });
+            }
+        };
+
+        // Check if any prioritized opener exists
+        const auto it = std::find_if(
+            openers.begin(),
+            openers.end(),
+            [](const SourceFileOpenerDetails& opener)
+            {
+                return opener.m_opener && opener.m_isPrioritized;
+            });
+
+        if (it != openers.end())
+        {
+            addOpener(*it);
+        }
+        else
+        {
+            for (const SourceFileOpenerDetails& openerDetails : openers)
+            {
+                addOpener(openerDetails);
             }
         }
 

+ 2 - 1
Code/Editor/EditorPreferencesPageFiles.cpp

@@ -69,7 +69,8 @@ void CEditorPreferencesPage_Files::Reflect(AZ::SerializeContext& serialize)
             ->DataElement(AZ::Edit::UIHandlers::LineEdit, &Files::m_saveLocation, "UI Slice Save location", "Specify the default location to save new UI slices");
 
         editContext->Class<ExternalEditors>("External Editors", "External Editors")
-            ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_scripts, "Scripts Editor", "Scripts Text Editor")
+            ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_scripts, "Scripts Editor", "Scripts Text Editor (Default to O3DE internal tool when empty)")
+            ->Attribute(AZ::Edit::Attributes::PlaceholderText, "Default to O3DE internal tool when empty")
             ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_shaders, "Shaders Editor", "Shaders Text Editor")
             ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_BSpaces, "BSpace Editor", "Bspace Text Editor")
             ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_textures, "Texture Editor", "Texture Editor")

+ 12 - 12
Code/Editor/Settings.cpp

@@ -169,12 +169,12 @@ SEditorSettings::SEditorSettings()
     enableSourceControl = false;
 
 #if AZ_TRAIT_OS_PLATFORM_APPLE
-    textEditorForScript = "TextEdit";
+    textEditorForScript = "";
     textEditorForShaders = "TextEdit";
     textEditorForBspaces = "TextEdit";
     textureEditor = "Photoshop";
 #elif defined(AZ_PLATFORM_WINDOWS)
-    textEditorForScript = "notepad++.exe";
+    textEditorForScript = "";
     textEditorForShaders = "notepad++.exe";
     textEditorForBspaces = "notepad++.exe";
     textureEditor = "Photoshop.exe";
@@ -478,11 +478,11 @@ void SEditorSettings::Save(bool isEditorClosing)
     SaveValue("Settings", "ShowScaleWarnings", viewports.bShowScaleWarnings);
     SaveValue("Settings", "ShowRotationWarnings", viewports.bShowRotationWarnings);
 
-    SaveValue("Settings", "TextEditorScript", textEditorForScript);
-    SaveValue("Settings", "TextEditorShaders", textEditorForShaders);
-    SaveValue("Settings", "TextEditorBSpaces", textEditorForBspaces);
-    SaveValue("Settings", "TextureEditor", textureEditor);
-    SaveValue("Settings", "AnimationEditor", animEditor);
+    SaveValue("Settings/Editor", "TextEditorScript", textEditorForScript);
+    SaveValue("Settings/Editor", "TextEditorShaders", textEditorForShaders);
+    SaveValue("Settings/Editor", "TextEditorBSpaces", textEditorForBspaces);
+    SaveValue("Settings/Editor", "TextureEditor", textureEditor);
+    SaveValue("Settings/Editor", "AnimationEditor", animEditor);
 
     SaveEnableSourceControlFlag(true);
 
@@ -654,11 +654,11 @@ void SEditorSettings::Load()
     LoadValue("Settings", "ShowScaleWarnings", viewports.bShowScaleWarnings);
     LoadValue("Settings", "ShowRotationWarnings", viewports.bShowRotationWarnings);
 
-    LoadValue("Settings", "TextEditorScript", textEditorForScript);
-    LoadValue("Settings", "TextEditorShaders", textEditorForShaders);
-    LoadValue("Settings", "TextEditorBSpaces", textEditorForBspaces);
-    LoadValue("Settings", "TextureEditor", textureEditor);
-    LoadValue("Settings", "AnimationEditor", animEditor);
+    LoadValue("Settings/Editor", "TextEditorScript", textEditorForScript);
+    LoadValue("Settings/Editor", "TextEditorShaders", textEditorForShaders);
+    LoadValue("Settings/Editor", "TextEditorBSpaces", textEditorForBspaces);
+    LoadValue("Settings/Editor", "TextureEditor", textureEditor);
+    LoadValue("Settings/Editor", "AnimationEditor", animEditor);
 
     LoadEnableSourceControlFlag();
 

+ 8 - 3
Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/AssetBrowserBus.h

@@ -121,14 +121,19 @@ namespace AzToolsFramework
             //! This is the function to call.  If you fill a nullptr in here, then the default operating system behavior will be suppressed
             //! but no opener will be opened.  This will also cause the 'open' option in context menus to disappear if the only openers
             //! are nullptr ones.
-            SourceFileOpenerFunctionType m_opener; 
+            SourceFileOpenerFunctionType m_opener;
+
+            //! Indicates whether this opener should be prioritized when multiple openers are available
+            //! If set to true, this opener will take precedence over others
+            bool m_isPrioritized = false;
 
             SourceFileOpenerDetails() = default;
-            SourceFileOpenerDetails(const char* identifier, const char* displayText, QIcon icon, SourceFileOpenerFunctionType functionToCall)
+            SourceFileOpenerDetails(const char* identifier, const char* displayText, QIcon icon, SourceFileOpenerFunctionType functionToCall, bool isPrioritized = false)
                 : m_identifier(identifier)
                 , m_displayText(displayText)
                 , m_iconToUse(icon)
-                , m_opener(functionToCall) {}
+                , m_opener(functionToCall)
+                , m_isPrioritized(isPrioritized) {}
         };
 
         typedef AZStd::vector<SourceFileOpenerDetails> SourceFileOpenerList;

+ 22 - 0
Code/Framework/AzToolsFramework/AzToolsFramework/Script/LuaEditorSystemComponent.cpp

@@ -14,7 +14,10 @@
 #include <AzCore/std/string/conversions.h>
 #include <AzFramework/StringFunc/StringFunc.h>
 #include <AzToolsFramework/API/ToolsApplicationAPI.h>
+#include <Editor/EditorSettingsAPIBus.h>
+
 #include <QIcon>
+#include <QProcess>
 
 namespace AzToolsFramework
 {
@@ -132,6 +135,25 @@ namespace AzToolsFramework
         {
             if (AZ::IO::Path(fullSourceFileName).Extension() == LuaExtension)
             {
+                AzToolsFramework::EditorSettingsAPIRequests::SettingOutcome textEditorScriptSettings;
+                AzToolsFramework::EditorSettingsAPIBus::BroadcastResult(
+                    textEditorScriptSettings,
+                    &AzToolsFramework::EditorSettingsAPIBus::Handler::GetValue,
+                    "Settings/Editor|TextEditorScript");
+                AZStd::any textEditorScriptSettingsValue = textEditorScriptSettings.GetValue<AZStd::any>();
+                AZStd::string textEditorScriptSettingsString = AZStd::any_cast<AZStd::string>(textEditorScriptSettingsValue);
+
+                if (!textEditorScriptSettingsString.empty())
+                {
+                    const auto startProcess =
+                        [textEditorScriptSettingsString](const char* fullSourceFileNameInCallback, [[maybe_unused]] const AZ::Uuid&)
+                    {
+                        QProcess::startDetached(textEditorScriptSettingsString.c_str(), { fullSourceFileNameInCallback });
+                    };
+                    constexpr bool isPrioritized = true;
+                    openers.push_back({ "O3DE_LUA_External_Editor", "Open with external editor...", QIcon(), startProcess, isPrioritized });
+                }
+
                 const auto luaScriptOpener = [](const char* fullSourceFileNameInCallback, [[maybe_unused]] const AZ::Uuid&)
                 {
                     AzToolsFramework::EditorRequestBus::Broadcast(