LUAEditorSettingsDialog.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/Script/ScriptAsset.h>
  9. #include <AzFramework/StringFunc/StringFunc.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <AzCore/UserSettings/UserSettingsComponent.h>
  12. #include <QtWidgets/QVBoxLayout>
  13. #include <AzCore/Component/ComponentApplicationBus.h>
  14. #include <AzCore/RTTI/TypeInfo.h>
  15. #include <AzToolsFramework/UI/LegacyFramework/Core/EditorFrameworkAPI.h>
  16. #include "LUAEditorSettingsDialog.hxx"
  17. #include "LUAEditorMainWindow.hxx"
  18. #include "LUAEditorContextMessages.h"
  19. #include "LUAEditorBlockState.h"
  20. #include <Source/LUA/ui_LUAEditorSettingsDialog.h>
  21. namespace
  22. {
  23. }
  24. namespace LUAEditor
  25. {
  26. extern AZ::Uuid ContextID;
  27. LUAEditorSettingsDialog::LUAEditorSettingsDialog(QWidget* parent)
  28. : QDialog(parent)
  29. {
  30. m_gui = azcreate(Ui::LUAEditorSettingsDialog, ());
  31. m_gui->setupUi(this);
  32. AZ::SerializeContext* context = nullptr;
  33. {
  34. AZ::ComponentApplicationBus::BroadcastResult(context, &AZ::ComponentApplicationBus::Events::GetSerializeContext);
  35. AZ_Assert(context, "We should have a valid context!");
  36. }
  37. AZStd::intrusive_ptr<SyntaxStyleSettings> syntaxStyleSettings = AZ::UserSettings::CreateFind<SyntaxStyleSettings>(AZ_CRC("LUA Editor Text Settings", 0xb6e15565), AZ::UserSettings::CT_GLOBAL);
  38. // Store a copy to revert if needed.
  39. m_originalSettings = *syntaxStyleSettings;
  40. m_gui->propertyEditor->Setup(context, nullptr, true, 420);
  41. m_gui->propertyEditor->AddInstance(syntaxStyleSettings.get(), syntaxStyleSettings->RTTI_GetType());
  42. m_gui->propertyEditor->setObjectName("m_gui->propertyEditor");
  43. m_gui->propertyEditor->setMinimumHeight(500);
  44. m_gui->propertyEditor->setMaximumHeight(1000);
  45. m_gui->propertyEditor->SetSavedStateKey(AZ_CRC("LuaIDE_SyntaxStyleSettings"));
  46. setModal(false);
  47. m_gui->propertyEditor->InvalidateAll();
  48. m_gui->propertyEditor->ExpandAll();
  49. m_gui->propertyEditor->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
  50. QVBoxLayout* layout = new QVBoxLayout(this);
  51. layout->setContentsMargins(0, 0, 0, 0);
  52. layout->setSpacing(0);
  53. layout->addWidget(m_gui->propertyEditor);
  54. layout->addWidget(m_gui->cancelButton);
  55. layout->addWidget(m_gui->saveButton);
  56. layout->addWidget(m_gui->saveCloseButton);
  57. setLayout(layout);
  58. }
  59. void LUAEditorSettingsDialog::OnSave()
  60. {
  61. AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequestBus::Events::Save);
  62. LUAEditorMainWindowMessages::Bus::Broadcast(&LUAEditorMainWindowMessages::Bus::Events::Repaint);
  63. }
  64. void LUAEditorSettingsDialog::OnSaveClose()
  65. {
  66. OnSave();
  67. close();
  68. }
  69. void LUAEditorSettingsDialog::OnCancel()
  70. {
  71. AZStd::intrusive_ptr<SyntaxStyleSettings> syntaxStyleSettings = AZ::UserSettings::CreateFind<SyntaxStyleSettings>(AZ_CRC("LUA Editor Text Settings", 0xb6e15565), AZ::UserSettings::CT_GLOBAL);
  72. // Revert the stored copy, no changes will be stored.
  73. *syntaxStyleSettings = m_originalSettings;
  74. LUAEditorMainWindowMessages::Bus::Broadcast(&LUAEditorMainWindowMessages::Bus::Events::Repaint);
  75. close();
  76. }
  77. LUAEditorSettingsDialog::~LUAEditorSettingsDialog()
  78. {
  79. m_gui->propertyEditor->ClearInstances();
  80. azdestroy(m_gui);
  81. }
  82. void LUAEditorSettingsDialog::keyPressEvent(QKeyEvent* event)
  83. {
  84. if (event->key() == Qt::Key_Escape)
  85. {
  86. OnCancel();
  87. return;
  88. }
  89. else
  90. if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
  91. {
  92. OnSaveClose();
  93. return;
  94. }
  95. }
  96. }//namespace LUAEditor
  97. #include <Source/LUA/moc_LUAEditorSettingsDialog.cpp>