EditorPreferencesPageFiles.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 "EditorDefs.h"
  9. #include "EditorPreferencesPageFiles.h"
  10. #include <AzCore/Serialization/EditContext.h>
  11. // AzToolsFramework
  12. #include <AzToolsFramework/Slice/SliceUtilities.h>
  13. // Editor
  14. #include "Settings.h"
  15. #include "EditorViewportSettings.h"
  16. void CEditorPreferencesPage_Files::Reflect(AZ::SerializeContext& serialize)
  17. {
  18. serialize.Class<Files>()
  19. ->Version(3)
  20. ->Field("AutoNumberSlices", &Files::m_autoNumberSlices)
  21. ->Field("BackupOnSave", &Files::m_backupOnSave)
  22. ->Field("BackupOnSaveMaxCount", &Files::m_backupOnSaveMaxCount)
  23. ->Field("TempDirectory", &Files::m_standardTempDirectory)
  24. ->Field("SliceSaveLocation", &Files::m_saveLocation);
  25. serialize.Class<ExternalEditors>()
  26. ->Version(1)
  27. ->Field("Scripts", &ExternalEditors::m_scripts)
  28. ->Field("Shaders", &ExternalEditors::m_shaders)
  29. ->Field("BSpaces", &ExternalEditors::m_BSpaces)
  30. ->Field("Textures", &ExternalEditors::m_textures)
  31. ->Field("Animations", &ExternalEditors::m_animations);
  32. serialize.Class<AutoBackup>()
  33. ->Version(1)
  34. ->Field("Enabled", &AutoBackup::m_enabled)
  35. ->Field("Interval", &AutoBackup::m_timeInterval)
  36. ->Field("MaxCount", &AutoBackup::m_maxCount)
  37. ->Field("RemindTime", &AutoBackup::m_remindTime);
  38. serialize.Class<AssetBrowserSettings>()
  39. ->Version(1)
  40. ->Field("MaxEntriesShownCount", &AssetBrowserSettings::m_maxNumberOfItemsShownInSearch);
  41. serialize.Class<CEditorPreferencesPage_Files>()
  42. ->Version(1)
  43. ->Field("Files", &CEditorPreferencesPage_Files::m_files)
  44. ->Field("Editors", &CEditorPreferencesPage_Files::m_editors)
  45. ->Field("AutoBackup", &CEditorPreferencesPage_Files::m_autoBackup)
  46. ->Field("AssetBrowserSettings", &CEditorPreferencesPage_Files::m_assetBrowserSettings);
  47. AZ::EditContext* editContext = serialize.GetEditContext();
  48. if (editContext)
  49. {
  50. editContext->Class<Files>("Files", "File Preferences")
  51. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Files::m_autoNumberSlices, "Append numeric value to slices", "Should the name of the slice file be automatically numbered. e.g SliceName_001.slice vs. SliceName.slice")
  52. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Files::m_backupOnSave, "Backup on Save", "Backup on Save")
  53. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &Files::m_backupOnSaveMaxCount, "Maximum Save Backups", "Maximum Save Backups")
  54. ->Attribute(AZ::Edit::Attributes::Min, 1)
  55. ->Attribute(AZ::Edit::Attributes::Max, 100)
  56. ->DataElement(AZ::Edit::UIHandlers::LineEdit, &Files::m_standardTempDirectory, "Standard Temporary Directory", "Standard Temporary Directory")
  57. ->DataElement(AZ::Edit::UIHandlers::LineEdit, &Files::m_saveLocation, "UI Slice Save location", "Specify the default location to save new UI slices");
  58. editContext->Class<ExternalEditors>("External Editors", "External Editors")
  59. ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_scripts, "Scripts Editor", "Scripts Text Editor")
  60. ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_shaders, "Shaders Editor", "Shaders Text Editor")
  61. ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_BSpaces, "BSpace Editor", "Bspace Text Editor")
  62. ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_textures, "Texture Editor", "Texture Editor")
  63. ->DataElement(AZ::Edit::UIHandlers::ExeSelectBrowseEdit, &ExternalEditors::m_animations, "Animation Editor", "Animation Editor");
  64. editContext->Class<AutoBackup>("Auto Backup", "Auto Backup")
  65. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &AutoBackup::m_enabled, "Enable", "Enable Auto Backup")
  66. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &AutoBackup::m_timeInterval, "Time Interval", "Auto Backup Interval (Minutes)")
  67. ->Attribute(AZ::Edit::Attributes::Min, 2)
  68. ->Attribute(AZ::Edit::Attributes::Max, 10000)
  69. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &AutoBackup::m_maxCount, "Maximum Backups", "Maximum Auto Backups")
  70. ->Attribute(AZ::Edit::Attributes::Min, 1)
  71. ->Attribute(AZ::Edit::Attributes::Max, 100)
  72. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &AutoBackup::m_remindTime, "Remind Time", "Auto Remind Every (Minutes)");
  73. editContext->Class<AssetBrowserSettings>("Asset Browser Settings", "Asset Browser Settings")
  74. ->DataElement(
  75. AZ::Edit::UIHandlers::SpinBox, &AssetBrowserSettings::m_maxNumberOfItemsShownInSearch, "Maximum number of displayed items",
  76. "Maximum number of items to display in the Search View.")
  77. ->Attribute(AZ::Edit::Attributes::Min, 50)
  78. ->Attribute(AZ::Edit::Attributes::Max, 5000);
  79. editContext->Class<CEditorPreferencesPage_Files>("File Preferences", "Class for handling File Preferences")
  80. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  81. ->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC_CE("PropertyVisibility_ShowChildrenOnly"))
  82. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_Files::m_files, "Files", "File Preferences")
  83. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_Files::m_editors, "External Editors", "External Editors")
  84. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_Files::m_autoBackup, "Auto Backup", "Auto Backup")
  85. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_Files::m_assetBrowserSettings, "Asset Browser Settings","Asset Browser Settings");
  86. }
  87. }
  88. CEditorPreferencesPage_Files::CEditorPreferencesPage_Files()
  89. {
  90. InitializeSettings();
  91. m_icon = QIcon(":/res/Files.svg");
  92. }
  93. QIcon& CEditorPreferencesPage_Files::GetIcon()
  94. {
  95. return m_icon;
  96. }
  97. void CEditorPreferencesPage_Files::OnApply()
  98. {
  99. using namespace AzToolsFramework::SliceUtilities;
  100. auto sliceSettings = AZ::UserSettings::CreateFind<SliceUserSettings>(AZ_CRC_CE("SliceUserSettings"), AZ::UserSettings::CT_LOCAL);
  101. sliceSettings->m_autoNumber = m_files.m_autoNumberSlices;
  102. sliceSettings->m_saveLocation = m_files.m_saveLocation;
  103. gSettings.bBackupOnSave = m_files.m_backupOnSave;
  104. gSettings.backupOnSaveMaxCount = m_files.m_backupOnSaveMaxCount;
  105. gSettings.strStandardTempDirectory = m_files.m_standardTempDirectory.c_str();
  106. gSettings.textEditorForScript = m_editors.m_scripts.c_str();
  107. gSettings.textEditorForShaders = m_editors.m_shaders.c_str();
  108. gSettings.textEditorForBspaces = m_editors.m_BSpaces.c_str();
  109. gSettings.textureEditor = m_editors.m_textures.c_str();
  110. gSettings.animEditor = m_editors.m_animations.c_str();
  111. gSettings.autoBackupEnabled = m_autoBackup.m_enabled;
  112. gSettings.autoBackupTime = m_autoBackup.m_timeInterval;
  113. gSettings.autoBackupMaxCount = m_autoBackup.m_maxCount;
  114. gSettings.autoRemindTime = m_autoBackup.m_remindTime;
  115. SandboxEditor::SetMaxItemsShownInAssetBrowserSearch(m_assetBrowserSettings.m_maxNumberOfItemsShownInSearch);
  116. }
  117. void CEditorPreferencesPage_Files::InitializeSettings()
  118. {
  119. using namespace AzToolsFramework::SliceUtilities;
  120. auto sliceSettings = AZ::UserSettings::CreateFind<SliceUserSettings>(AZ_CRC_CE("SliceUserSettings"), AZ::UserSettings::CT_LOCAL);
  121. m_files.m_autoNumberSlices = sliceSettings->m_autoNumber;
  122. m_files.m_saveLocation = sliceSettings->m_saveLocation;
  123. m_files.m_backupOnSave = gSettings.bBackupOnSave;
  124. m_files.m_backupOnSaveMaxCount = gSettings.backupOnSaveMaxCount;
  125. m_files.m_standardTempDirectory = gSettings.strStandardTempDirectory.toUtf8().data();
  126. m_editors.m_scripts = gSettings.textEditorForScript.toUtf8().data();
  127. m_editors.m_shaders = gSettings.textEditorForShaders.toUtf8().data();
  128. m_editors.m_BSpaces = gSettings.textEditorForBspaces.toUtf8().data();
  129. m_editors.m_textures = gSettings.textureEditor.toUtf8().data();
  130. m_editors.m_animations = gSettings.animEditor.toUtf8().data();
  131. m_autoBackup.m_enabled = gSettings.autoBackupEnabled;
  132. m_autoBackup.m_timeInterval = gSettings.autoBackupTime;
  133. m_autoBackup.m_maxCount = gSettings.autoBackupMaxCount;
  134. m_autoBackup.m_remindTime = gSettings.autoRemindTime;
  135. m_assetBrowserSettings.m_maxNumberOfItemsShownInSearch = SandboxEditor::MaxItemsShownInAssetBrowserSearch();
  136. }