Fix notification queue and add gem action (#4985) (#5024)

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>
This commit is contained in:
Alex Peterson
2021-10-27 13:55:32 -07:00
committed by GitHub
parent d23df465dd
commit 59c898fc48
6 changed files with 95 additions and 45 deletions
@@ -63,6 +63,12 @@ namespace AzToolsFramework
ToastId ToastNotificationsView::ShowToastNotification(const AzQtComponents::ToastConfiguration& toastConfiguration)
{
// reject duplicate messages
if (m_rejectDuplicates && DuplicateNotificationInQueue(toastConfiguration))
{
return ToastId();
}
ToastId toastId = CreateToastNotification(toastConfiguration);
m_queuedNotifications.emplace_back(toastId);
@@ -70,10 +76,28 @@ namespace AzToolsFramework
{
DisplayQueuedNotification();
}
else if (m_queuedNotifications.size() >= m_maxQueuedNotifications)
{
// hiding the active toast will cause the next toast to be displayed
HideToastNotification(m_activeNotification);
}
return toastId;
}
bool ToastNotificationsView::DuplicateNotificationInQueue(const AzQtComponents::ToastConfiguration& toastConfiguration)
{
for (auto iter : m_notifications)
{
if (iter.second && iter.second->IsDuplicate(toastConfiguration))
{
return true;
}
}
return false;
}
ToastId ToastNotificationsView::ShowToastAtCursor(const AzQtComponents::ToastConfiguration& toastConfiguration)
{
ToastId toastId = CreateToastNotification(toastConfiguration);
@@ -187,4 +211,14 @@ namespace AzToolsFramework
{
m_anchorPoint = anchorPoint;
}
void ToastNotificationsView::SetMaxQueuedNotifications(AZ::u32 maxQueuedNotifications)
{
m_maxQueuedNotifications = maxQueuedNotifications;
}
void ToastNotificationsView::SetRejectDuplicates(bool rejectDuplicates)
{
m_rejectDuplicates = rejectDuplicates;
}
}
@@ -52,10 +52,13 @@ namespace AzToolsFramework
void SetOffset(const QPoint& offset);
void SetAnchorPoint(const QPointF& anchorPoint);
void SetMaxQueuedNotifications(AZ::u32 maxQueuedNotifications);
void SetRejectDuplicates(bool rejectDuplicates);
private:
ToastId CreateToastNotification(const AzQtComponents::ToastConfiguration& toastConfiguration);
void DisplayQueuedNotification();
bool DuplicateNotificationInQueue(const AzQtComponents::ToastConfiguration& toastConfiguration);
QPoint GetGlobalPoint();
ToastId m_activeNotification;
@@ -64,5 +67,7 @@ namespace AzToolsFramework
QPoint m_offset = QPoint(10, 10);
QPointF m_anchorPoint = QPointF(1, 0);
AZ::u32 m_maxQueuedNotifications = 5;
bool m_rejectDuplicates = true;
};
} // AzToolsFramework