CheckOutDialog.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 "CheckOutDialog.h"
  10. // Qt
  11. #include <QStyle>
  12. // AzToolsFramework
  13. #include <AzToolsFramework/SourceControl/SourceControlAPI.h> // for AzToolsFramework::SourceControlConnectionRequestBus
  14. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  15. #include "ui_CheckOutDialog.h"
  16. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  17. // CCheckOutDialog dialog
  18. int CCheckOutDialog::m_lastResult = CCheckOutDialog::CANCEL;
  19. CCheckOutDialog::CCheckOutDialog(const QString& file, QWidget* pParent)
  20. : QDialog(pParent)
  21. , m_ui(new Ui::CheckOutDialog)
  22. {
  23. m_ui->setupUi(this);
  24. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  25. m_file = file;
  26. m_ui->icon->setPixmap(style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(m_ui->icon->width()));
  27. OnInitDialog();
  28. connect(m_ui->buttonCancel, &QPushButton::clicked, this, &CCheckOutDialog::OnBnClickedCancel);
  29. connect(m_ui->buttonCheckout, &QPushButton::clicked, this, &CCheckOutDialog::OnBnClickedCheckout);
  30. connect(m_ui->buttonOverwrite, &QPushButton::clicked, this, &CCheckOutDialog::OnBnClickedOverwrite);
  31. }
  32. CCheckOutDialog::~CCheckOutDialog()
  33. {
  34. }
  35. //////////////////////////////////////////////////////////////////////////
  36. void CCheckOutDialog::OnBnClickedCancel()
  37. {
  38. // Cancel operation
  39. HandleResult(CANCEL);
  40. }
  41. //////////////////////////////////////////////////////////////////////////
  42. // CCheckOutDialog message handlers
  43. void CCheckOutDialog::OnBnClickedCheckout()
  44. {
  45. // Check out this file.
  46. HandleResult(CHECKOUT);
  47. }
  48. //////////////////////////////////////////////////////////////////////////
  49. void CCheckOutDialog::OnBnClickedOverwrite()
  50. {
  51. // Overwrite this file.
  52. HandleResult(OVERWRITE);
  53. }
  54. //////////////////////////////////////////////////////////////////////////
  55. void CCheckOutDialog::HandleResult(int result)
  56. {
  57. m_lastResult = result;
  58. InstanceIsForAll() = m_ui->chkForAll->isChecked();
  59. done(result);
  60. }
  61. //////////////////////////////////////////////////////////////////////////
  62. void CCheckOutDialog::OnInitDialog()
  63. {
  64. setWindowTitle(tr("Source Control"));
  65. using namespace AzToolsFramework;
  66. SourceControlState state = SourceControlState::Disabled;
  67. SourceControlConnectionRequestBus::BroadcastResult(state, &SourceControlConnectionRequestBus::Events::GetSourceControlState);
  68. bool sccAvailable = state == SourceControlState::Active ? true : false;
  69. QString text(tr("%1\n\nis read-only, and needs to be writable to continue.").arg(m_file));
  70. if (!sccAvailable)
  71. {
  72. text.append("\nEnable and connect to source control for more options.");
  73. }
  74. m_ui->m_text->setText(text);
  75. m_ui->chkForAll->setEnabled(InstanceEnableForAll());
  76. m_ui->chkForAll->setChecked(InstanceIsForAll());
  77. m_ui->buttonCheckout->setEnabled(sccAvailable);
  78. adjustSize();
  79. }
  80. //static ////////////////////////////////////////////////////////////////
  81. bool& CCheckOutDialog::InstanceEnableForAll()
  82. {
  83. static bool isEnableForAll = false;
  84. return isEnableForAll;
  85. }
  86. //static ////////////////////////////////////////////////////////////////
  87. bool& CCheckOutDialog::InstanceIsForAll()
  88. {
  89. static bool isForAll = false;
  90. return isForAll;
  91. }
  92. //static ////////////////////////////////////////////////////////////////
  93. bool CCheckOutDialog::EnableForAll(bool isEnable)
  94. {
  95. bool bPrevEnable = InstanceEnableForAll();
  96. InstanceEnableForAll() = isEnable;
  97. if (!bPrevEnable || !isEnable)
  98. {
  99. InstanceIsForAll() = false;
  100. m_lastResult = CANCEL;
  101. }
  102. return bPrevEnable;
  103. }
  104. #include <moc_CheckOutDialog.cpp>