diff --git a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp index 661c722df1..119f7ea3dc 100644 --- a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp +++ b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp @@ -5,8 +5,10 @@ #include "DolphinQt/Config/ARCodeWidget.h" #include +#include #include #include +#include #include #include @@ -49,6 +51,8 @@ void ARCodeWidget::CreateWidgets() m_code_edit = new QPushButton(tr("&Edit Code...")); m_code_remove = new QPushButton(tr("&Remove Code")); + m_code_list->setContextMenuPolicy(Qt::CustomContextMenu); + auto* button_layout = new QHBoxLayout; button_layout->addWidget(m_code_add); @@ -68,10 +72,13 @@ void ARCodeWidget::ConnectWidgets() { connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this, &ARCodeWidget::OpenGeneralSettings); + connect(m_code_list, &QListWidget::itemChanged, this, &ARCodeWidget::OnItemChanged); connect(m_code_list, &QListWidget::itemSelectionChanged, this, &ARCodeWidget::OnSelectionChanged); connect(m_code_list->model(), &QAbstractItemModel::rowsMoved, this, &ARCodeWidget::OnListReordered); + connect(m_code_list, &QListWidget::customContextMenuRequested, this, + &ARCodeWidget::OnContextMenuRequested); connect(m_code_add, &QPushButton::pressed, this, &ARCodeWidget::OnCodeAddPressed); connect(m_code_edit, &QPushButton::pressed, this, &ARCodeWidget::OnCodeEditPressed); @@ -89,6 +96,21 @@ void ARCodeWidget::OnItemChanged(QListWidgetItem* item) SaveCodes(); } +void ARCodeWidget::OnContextMenuRequested() +{ + QMenu menu; + + menu.addAction(tr("Sort Alphabetically"), this, &ARCodeWidget::SortAlphabetically); + + menu.exec(QCursor::pos()); +} + +void ARCodeWidget::SortAlphabetically() +{ + m_code_list->sortItems(); + OnListReordered(); +} + void ARCodeWidget::OnListReordered() { // Reorder codes based on the indices of table item diff --git a/Source/Core/DolphinQt/Config/ARCodeWidget.h b/Source/Core/DolphinQt/Config/ARCodeWidget.h index 9e84d59bd3..37077d1dd8 100644 --- a/Source/Core/DolphinQt/Config/ARCodeWidget.h +++ b/Source/Core/DolphinQt/Config/ARCodeWidget.h @@ -37,11 +37,13 @@ signals: private: void OnSelectionChanged(); void OnItemChanged(QListWidgetItem* item); + void OnContextMenuRequested(); void CreateWidgets(); void ConnectWidgets(); void UpdateList(); void SaveCodes(); + void SortAlphabetically(); void OnCodeAddPressed(); void OnCodeEditPressed();