3
0

AWSCoreEditorSystemComponent.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Component/Component.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AWSCoreEditorSystemComponent.h>
  12. #include <QMainWindow>
  13. #include <QMenuBar>
  14. #include <QAction>
  15. #include <QList>
  16. #include <QString>
  17. #include <AzToolsFramework/ActionManager/Action/ActionManagerInterface.h>
  18. #include <AzToolsFramework/ActionManager/Menu/MenuManagerInterface.h>
  19. #include <AzToolsFramework/ActionManager/Menu/MenuManagerInternalInterface.h>
  20. #include <AzToolsFramework/Editor/ActionManagerUtils.h>
  21. #include <Editor/Constants/AWSCoreEditorMenuNames.h>
  22. #include <Editor/UI/AWSCoreEditorMenu.h>
  23. #include <QDesktopServices>
  24. #include <QUrl>
  25. namespace AWSCore
  26. {
  27. void AWSCoreEditorSystemComponent::Reflect(AZ::ReflectContext* context)
  28. {
  29. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  30. {
  31. serialize->Class<AWSCoreEditorSystemComponent, AZ::Component>()
  32. ->Version(0)
  33. ;
  34. if (AZ::EditContext* ec = serialize->GetEditContext())
  35. {
  36. ec->Class<AWSCoreEditorSystemComponent>("AWSCoreEditor", "Adds supporting for working with AWS features in the Editor")
  37. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  38. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  39. ;
  40. }
  41. }
  42. }
  43. void AWSCoreEditorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  44. {
  45. provided.push_back(AZ_CRC_CE("AWSCoreEditorService"));
  46. }
  47. void AWSCoreEditorSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  48. {
  49. incompatible.push_back(AZ_CRC_CE("AWSCoreEditorService"));
  50. }
  51. void AWSCoreEditorSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  52. {
  53. AZ_UNUSED(required);
  54. }
  55. void AWSCoreEditorSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  56. {
  57. AZ_UNUSED(dependent);
  58. }
  59. void AWSCoreEditorSystemComponent::Init()
  60. {
  61. }
  62. void AWSCoreEditorSystemComponent::Activate()
  63. {
  64. AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler::BusConnect();
  65. m_actionManagerInterface = AZ::Interface<AzToolsFramework::ActionManagerInterface>::Get();
  66. AZ_Assert(m_actionManagerInterface, "AWSCoreEditorSystemComponent - could not get ActionManagerInterface");
  67. m_menuManagerInterface = AZ::Interface<AzToolsFramework::MenuManagerInterface>::Get();
  68. AZ_Assert(m_menuManagerInterface, "AWSCoreEditorSystemComponent - could not get MenuManagerInterface");
  69. m_menuManagerInternalInterface = AZ::Interface<AzToolsFramework::MenuManagerInternalInterface>::Get();
  70. AZ_Assert(m_menuManagerInterface, "AWSCoreEditorSystemComponent - could not get MenuManagerInternalInterface");
  71. AWSCoreEditorRequestBus::Handler::BusConnect();
  72. }
  73. void AWSCoreEditorSystemComponent::Deactivate()
  74. {
  75. AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler::BusDisconnect();
  76. AWSCoreEditorRequestBus::Handler::BusDisconnect();
  77. m_awsCoreEditorMenu.reset();
  78. }
  79. void AWSCoreEditorSystemComponent::OnMenuBarRegistrationHook()
  80. {
  81. m_awsCoreEditorMenu = AZStd::make_unique<AWSCoreEditorMenu>();
  82. }
  83. void AWSCoreEditorSystemComponent::OnMenuBindingHook()
  84. {
  85. m_awsCoreEditorMenu->UpdateMenuBinding();
  86. }
  87. void AWSCoreEditorSystemComponent::AddExternalLinkAction(const AZStd::string& menuIdentifier, const char* const actionDetails[], int sort)
  88. {
  89. const auto& identifier = actionDetails[IdentIndex];
  90. const auto& text = actionDetails[NameIndex];
  91. const auto& icon = actionDetails[IconIndex];
  92. const auto& url = actionDetails[URLIndex];
  93. AzToolsFramework::ActionProperties actionProperties;
  94. actionProperties.m_name = text;
  95. actionProperties.m_iconPath = icon;
  96. auto outcome = m_actionManagerInterface->RegisterAction(ActionContext, identifier, actionProperties, [url]()
  97. {
  98. QDesktopServices::openUrl(QUrl(url));
  99. });
  100. AZ_Assert(outcome.IsSuccess(), "Failed to register action %s", identifier);
  101. outcome = m_menuManagerInterface->AddActionToMenu(menuIdentifier, identifier, sort);
  102. AZ_Assert(outcome.IsSuccess(), "Failed to add action %s to menu %s", identifier, menuIdentifier.c_str());
  103. }
  104. void AWSCoreEditorSystemComponent::CreateSubMenu(const AZStd::string& parentMenuIdentifier, const char* const menuDetails[], int sort)
  105. {
  106. AzToolsFramework::MenuProperties menuProperties;
  107. menuProperties.m_name = menuDetails[NameIndex];
  108. auto outcome = m_menuManagerInterface->RegisterMenu(menuDetails[IdentIndex], menuProperties);
  109. AZ_Assert(outcome.IsSuccess(), "Failed to register '%s' Menu", menuDetails[IdentIndex]);
  110. QMenu* menu = m_menuManagerInternalInterface->GetMenu(menuDetails[IdentIndex]);
  111. menu->setProperty("noHover", true);
  112. outcome = m_menuManagerInterface->AddSubMenuToMenu(parentMenuIdentifier, menuDetails[IdentIndex], sort);
  113. AZ_Assert(outcome.IsSuccess(), "Failed to add '%s' SubMenu to '%s' Menu", menuDetails[IdentIndex], parentMenuIdentifier.c_str());
  114. }
  115. } // namespace AWSCore