LUAEditorSettingsDialog.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #include <QPushButton>
  22. namespace
  23. {
  24. }
  25. namespace LUAEditor
  26. {
  27. extern AZ::Uuid ContextID;
  28. LUAEditorSettingsDialog::LUAEditorSettingsDialog(QWidget* parent)
  29. : QDialog(parent)
  30. {
  31. m_gui = azcreate(Ui::LUAEditorSettingsDialog, ());
  32. m_gui->setupUi(this);
  33. AZ::SerializeContext* context = nullptr;
  34. {
  35. AZ::ComponentApplicationBus::BroadcastResult(context, &AZ::ComponentApplicationBus::Events::GetSerializeContext);
  36. AZ_Assert(context, "We should have a valid context!");
  37. }
  38. AZStd::intrusive_ptr<SyntaxStyleSettings> syntaxStyleSettings = AZ::UserSettings::CreateFind<SyntaxStyleSettings>(AZ_CRC_CE("LUA Editor Text Settings"), AZ::UserSettings::CT_GLOBAL);
  39. // Store a copy to revert if needed.
  40. m_originalSettings = *syntaxStyleSettings;
  41. m_gui->propertyEditor->Setup(context, nullptr, true, 420);
  42. m_gui->propertyEditor->AddInstance(syntaxStyleSettings.get(), syntaxStyleSettings->RTTI_GetType());
  43. m_gui->propertyEditor->setObjectName("m_gui->propertyEditor");
  44. m_gui->propertyEditor->setMinimumHeight(500);
  45. m_gui->propertyEditor->setMaximumHeight(1000);
  46. m_gui->propertyEditor->SetSavedStateKey(AZ_CRC_CE("LuaIDE_SyntaxStyleSettings"));
  47. setModal(false);
  48. m_gui->propertyEditor->InvalidateAll();
  49. m_gui->propertyEditor->ExpandAll();
  50. m_gui->propertyEditor->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
  51. auto* layout = new QVBoxLayout(this);
  52. layout->addWidget(m_gui->propertyEditor);
  53. auto* hlayout = new QHBoxLayout(this);
  54. hlayout->addWidget(m_gui->applyButton);
  55. hlayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed));
  56. hlayout->addWidget(m_gui->saveButton);
  57. hlayout->addWidget(m_gui->saveCloseButton);
  58. hlayout->addWidget(m_gui->cancelButton);
  59. layout->addLayout(hlayout);
  60. QObject::connect(m_gui->saveButton, &QPushButton::clicked, this, &LUAEditorSettingsDialog::OnSave);
  61. QObject::connect(m_gui->saveCloseButton, &QPushButton::clicked, this, &LUAEditorSettingsDialog::OnSaveClose);
  62. QObject::connect(m_gui->cancelButton, &QPushButton::clicked, this, &LUAEditorSettingsDialog::OnCancel);
  63. QObject::connect(m_gui->applyButton, &QPushButton::clicked, this, &LUAEditorSettingsDialog::OnApply);
  64. setLayout(layout);
  65. }
  66. void LUAEditorSettingsDialog::OnSave()
  67. {
  68. AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequestBus::Events::Save);
  69. LUAEditorMainWindowMessages::Bus::Broadcast(&LUAEditorMainWindowMessages::Bus::Events::Repaint);
  70. }
  71. void LUAEditorSettingsDialog::OnSaveClose()
  72. {
  73. OnSave();
  74. close();
  75. }
  76. void LUAEditorSettingsDialog::OnCancel()
  77. {
  78. AZStd::intrusive_ptr<SyntaxStyleSettings> syntaxStyleSettings = AZ::UserSettings::CreateFind<SyntaxStyleSettings>(AZ_CRC_CE("LUA Editor Text Settings"), AZ::UserSettings::CT_GLOBAL);
  79. // Revert the stored copy, no changes will be stored.
  80. *syntaxStyleSettings = m_originalSettings;
  81. LUAEditorMainWindowMessages::Bus::Broadcast(&LUAEditorMainWindowMessages::Bus::Events::Repaint);
  82. close();
  83. }
  84. void LUAEditorSettingsDialog::OnApply()
  85. {
  86. LUAEditorMainWindowMessages::Bus::Broadcast(&LUAEditorMainWindowMessages::Bus::Events::Repaint);
  87. }
  88. LUAEditorSettingsDialog::~LUAEditorSettingsDialog()
  89. {
  90. m_gui->propertyEditor->ClearInstances();
  91. azdestroy(m_gui);
  92. }
  93. void LUAEditorSettingsDialog::keyPressEvent(QKeyEvent* event)
  94. {
  95. if (event->key() == Qt::Key_Escape)
  96. {
  97. OnCancel();
  98. }
  99. else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
  100. {
  101. OnSaveClose();
  102. }
  103. }
  104. }//namespace LUAEditor
  105. #include <Source/LUA/moc_LUAEditorSettingsDialog.cpp>