AzAssetBrowserMultiWindow.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <AzAssetBrowser/AzAssetBrowserMultiWindow.h>
  9. #include "QtViewPaneManager.h"
  10. using namespace AzToolsFramework::AssetBrowser;
  11. static constexpr int MaxWindowAmount = 10;
  12. AzAssetBrowserWindow* AzAssetBrowserMultiWindow::OpenNewAssetBrowserWindow()
  13. {
  14. int id = 1;
  15. while (id < MaxWindowAmount)
  16. {
  17. QString candidateName = QString("%1 (%2)").arg(LyViewPane::AssetBrowser).arg(id);
  18. if (id == 1)
  19. {
  20. // Special case, no trailing id.
  21. candidateName = QString("%1").arg(LyViewPane::AssetBrowser);
  22. }
  23. QtViewPane* pane = QtViewPaneManager::instance()->GetPane(candidateName);
  24. if (pane && !pane->IsVisible())
  25. {
  26. // The pane has been registered but is not in use: use that one.
  27. return qobject_cast<AzAssetBrowserWindow*>(QtViewPaneManager::instance()->OpenPane(candidateName)->Widget());
  28. }
  29. else if (!pane)
  30. {
  31. // All currently registered panes are visible. Register another one and use that.
  32. AzToolsFramework::ViewPaneOptions options;
  33. options.preferedDockingArea = Qt::BottomDockWidgetArea;
  34. options.showInMenu = false;
  35. AzToolsFramework::RegisterViewPane<AzAssetBrowserWindow>(qPrintable(candidateName), LyViewPane::CategoryTools, options);
  36. return qobject_cast<AzAssetBrowserWindow*>(QtViewPaneManager::instance()->OpenPane(candidateName)->Widget());
  37. }
  38. id++;
  39. }
  40. return nullptr;
  41. }
  42. bool AzAssetBrowserMultiWindow::IsAnyAssetBrowserWindowOpen()
  43. {
  44. int id = 1;
  45. while (id < MaxWindowAmount)
  46. {
  47. QString candidateName = QString("%1 (%2)").arg(LyViewPane::AssetBrowser).arg(id);
  48. if (id == 1)
  49. {
  50. // Special case, no trailing id.
  51. candidateName = QString("%1").arg(LyViewPane::AssetBrowser);
  52. }
  53. QtViewPane* pane = QtViewPaneManager::instance()->GetPane(candidateName);
  54. if (pane && pane->IsVisible())
  55. {
  56. return true;
  57. }
  58. }
  59. return false;
  60. }