AssetBundlerTabWidget.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <source/models/AssetBundlerAbstractFileTableModel.h>
  11. #include <source/models/AssetBundlerFileTableFilterModel.h>
  12. #include <source/utils/GUIApplicationManager.h>
  13. #include <AzCore/Outcome/Outcome.h>
  14. #include <AzCore/std/containers/vector.h>
  15. #include <AzCore/std/string/string.h>
  16. #include <AzQtComponents/Components/Widgets/TableView.h>
  17. #include <QLabel>
  18. #include <QWidget>
  19. #include <QItemSelection>
  20. #endif
  21. namespace AssetBundler
  22. {
  23. // Keys for the corresponding scan path lists in the asset bundling settings file
  24. extern const QString AssetBundlingFileTypes[];
  25. extern const int MarginSize;
  26. class AssetBundlerTabWidget
  27. : public QWidget
  28. {
  29. Q_OBJECT
  30. public:
  31. explicit AssetBundlerTabWidget(QWidget* parent, GUIApplicationManager* guiApplicationManager);
  32. virtual ~AssetBundlerTabWidget();
  33. void Activate();
  34. virtual QString GetTabTitle() = 0;
  35. virtual QString GetFileTypeDisplayName() = 0;
  36. virtual AssetBundlingFileType GetFileType() = 0;
  37. virtual bool HasUnsavedChanges() = 0;
  38. //! Reload all the files on display.
  39. virtual void Reload() = 0;
  40. //! Saves the selected file to disk.
  41. //! @return true on successful save, or throws an error message and returns false on a failed save.
  42. virtual bool SaveCurrentSelection() = 0;
  43. //! Saves all modified files to disk.
  44. //! @return true on successful save, or throws an error message and returns false on a failed save.
  45. virtual bool SaveAll() = 0;
  46. //! Set watched folders and files for the model
  47. virtual void SetModelDataSource() = 0;
  48. virtual AzQtComponents::TableView* GetFileTableView() = 0;
  49. virtual QModelIndex GetSelectedFileTableIndex() = 0;
  50. virtual AssetBundlerAbstractFileTableModel* GetFileTableModel() = 0;
  51. virtual void SetActiveProjectLabel(const QString& labelText) = 0;
  52. virtual void ApplyConfig() = 0;
  53. virtual void FileSelectionChanged(
  54. const QItemSelection& /*selected*/ = QItemSelection(),
  55. const QItemSelection& /*deselected*/ = QItemSelection()) = 0;
  56. static void InitAssetBundlerSettings(const char* currentProjectFolderPath);
  57. void AddScanPathToAssetBundlerSettings(AssetBundlingFileType fileType, AZStd::string filePath);
  58. GUIApplicationManager* GetGUIApplicationManager() { return m_guiApplicationManager; }
  59. protected:
  60. void OnFileTableContextMenuRequested(const QPoint& pos);
  61. //! Asks the user to confirm they wish to permanently delete the selected file, then removes it from disk and memory.
  62. void OnDeleteSelectedFileRequested();
  63. bool ConfirmFileDeleteDialog(const QString& absoluteFilePath);
  64. void ReadScanPathsFromAssetBundlerSettings(AssetBundlingFileType fileType);
  65. void RemoveScanPathFromAssetBundlerSettings(AssetBundlingFileType fileType, const QString& filePath);
  66. GUIApplicationManager* m_guiApplicationManager = nullptr;
  67. QScopedPointer<AssetBundler::AssetBundlerFileTableFilterModel> m_fileTableFilterModel;
  68. QSet<QString> m_watchedFolders;
  69. QSet<QString> m_watchedFiles;
  70. AZStd::unordered_map<AZStd::string, AZStd::string> m_filePathToGemNameMap;
  71. private slots:
  72. void OnUpdateTab(const AZStd::string& path);
  73. void OnUpdateFiles(AssetBundlingFileType fileType, const AZStd::vector<AZStd::string>& absoluteFilePaths);
  74. private:
  75. void SetupContextMenu();
  76. void AddScanPathToAssetBundlerSettings(AssetBundlingFileType fileType, const QString& filePath);
  77. void ReadAssetBundlerSettings(const AZStd::string& filePath, AssetBundlingFileType fileType);
  78. static AZStd::string GetAssetBundlerUserSettingsFile(const char* currentProjectFolderPath);
  79. static AZStd::string GetAssetBundlerCommonSettingsFile(const char* currentProjectFolderPath);
  80. static void CreateEmptyAssetBundlerSettings(const AZStd::string& filePath);
  81. };
  82. } // namespace AssetBundler