From c2fdb8cfd20957bc4f6a9078b647574e24f72257 Mon Sep 17 00:00:00 2001 From: Kevin Zander Date: Mon, 25 Mar 2024 18:22:37 -0500 Subject: [PATCH] Move confirmation to remove mixer channels outside `MixerView::deleteChannel` #7154) Moves the confirmation to remove mixer channels outside of `MixerView::deleteChannel` and into `MixerChannelView::removeChannel`. This is so that the confirmation only applies when the user uses the context menu to remove a channel, which is important since no confirmation should apply when, for example, the mixer view is cleared with calls to `MixerView::clear`. --- include/MixerChannelView.h | 1 + include/MixerView.h | 1 - src/gui/MixerChannelView.cpp | 39 ++++++++++++++++++++++++++++ src/gui/MixerView.cpp | 49 ------------------------------------ 4 files changed, 40 insertions(+), 50 deletions(-) diff --git a/include/MixerChannelView.h b/include/MixerChannelView.h index 1710623d7..cbaf0ccc6 100644 --- a/include/MixerChannelView.h +++ b/include/MixerChannelView.h @@ -104,6 +104,7 @@ namespace lmms::gui void moveChannelRight(); private: + bool confirmRemoval(int index); QString elideName(const QString& name); MixerChannel* mixerChannel() const; auto isMasterChannel() const -> bool { return m_channelIndex == 0; } diff --git a/include/MixerView.h b/include/MixerView.h index 81287bc54..89315f93a 100644 --- a/include/MixerView.h +++ b/include/MixerView.h @@ -78,7 +78,6 @@ public: // notify the view that a mixer channel was deleted void deleteChannel(int index); - bool confirmRemoval(int index); // delete all unused channels void deleteUnusedChannels(); diff --git a/src/gui/MixerChannelView.cpp b/src/gui/MixerChannelView.cpp index e7d4fc5b3..bd518093b 100644 --- a/src/gui/MixerChannelView.cpp +++ b/src/gui/MixerChannelView.cpp @@ -29,6 +29,7 @@ #include "MixerChannelView.h" #include "MixerView.h" #include "Song.h" +#include "ConfigManager.h" #include "gui_templates.h" #include "lmms_math.h" @@ -38,6 +39,8 @@ #include #include #include +#include +#include #include @@ -412,8 +415,44 @@ namespace lmms::gui update(); } + bool MixerChannelView::confirmRemoval(int index) + { + // if config variable is set to false, there is no need for user confirmation + bool needConfirm = ConfigManager::inst()->value("ui", "mixerchanneldeletionwarning", "1").toInt(); + if (!needConfirm) { return true; } + + // is the channel is not in use, there is no need for user confirmation + if (!getGUI()->mixerView()->getMixer()->isChannelInUse(index)) { return true; } + + QString messageRemoveTrack = tr("This Mixer Channel is being used.\n" + "Are you sure you want to remove this channel?\n\n" + "Warning: This operation can not be undone."); + + QString messageTitleRemoveTrack = tr("Confirm removal"); + QString askAgainText = tr("Don't ask again"); + auto askAgainCheckBox = new QCheckBox(askAgainText, nullptr); + connect(askAgainCheckBox, &QCheckBox::stateChanged, [](int state) { + // Invert button state, if it's checked we *shouldn't* ask again + ConfigManager::inst()->setValue("ui", "mixerchanneldeletionwarning", state ? "0" : "1"); + }); + + QMessageBox mb(this); + mb.setText(messageRemoveTrack); + mb.setWindowTitle(messageTitleRemoveTrack); + mb.setIcon(QMessageBox::Warning); + mb.addButton(QMessageBox::Cancel); + mb.addButton(QMessageBox::Ok); + mb.setCheckBox(askAgainCheckBox); + mb.setDefaultButton(QMessageBox::Cancel); + + int answer = mb.exec(); + + return answer == QMessageBox::Ok; + } + void MixerChannelView::removeChannel() { + if (!confirmRemoval(m_channelIndex)) { return; } auto mix = getGUI()->mixerView(); mix->deleteChannel(m_channelIndex); } diff --git a/src/gui/MixerView.cpp b/src/gui/MixerView.cpp index 8b2ecdc56..e97b5414f 100644 --- a/src/gui/MixerView.cpp +++ b/src/gui/MixerView.cpp @@ -23,9 +23,7 @@ */ -#include #include -#include #include #include #include @@ -377,12 +375,6 @@ void MixerView::deleteChannel(int index) // can't delete master if (index == 0) return; - // if there is no user confirmation, do nothing - if (!confirmRemoval(index)) - { - return; - } - // Disconnect from the solo/mute models of the channel we are about to delete disconnectFromSoloAndMute(index); @@ -421,47 +413,6 @@ void MixerView::deleteChannel(int index) updateMaxChannelSelector(); } -bool MixerView::confirmRemoval(int index) -{ - // if config variable is set to false, there is no need for user confirmation - bool needConfirm = ConfigManager::inst()->value("ui", "mixerchanneldeletionwarning", "1").toInt(); - if (!needConfirm) { return true; } - - Mixer* mix = getMixer(); - - if (!mix->isChannelInUse(index)) - { - // is the channel is not in use, there is no need for user confirmation - return true; - } - - QString messageRemoveTrack = tr("This Mixer Channel is being used.\n" - "Are you sure you want to remove this channel?\n\n" - "Warning: This operation can not be undone."); - - QString messageTitleRemoveTrack = tr("Confirm removal"); - QString askAgainText = tr("Don't ask again"); - auto askAgainCheckBox = new QCheckBox(askAgainText, nullptr); - connect(askAgainCheckBox, &QCheckBox::stateChanged, [](int state) { - // Invert button state, if it's checked we *shouldn't* ask again - ConfigManager::inst()->setValue("ui", "mixerchanneldeletionwarning", state ? "0" : "1"); - }); - - QMessageBox mb(this); - mb.setText(messageRemoveTrack); - mb.setWindowTitle(messageTitleRemoveTrack); - mb.setIcon(QMessageBox::Warning); - mb.addButton(QMessageBox::Cancel); - mb.addButton(QMessageBox::Ok); - mb.setCheckBox(askAgainCheckBox); - mb.setDefaultButton(QMessageBox::Cancel); - - int answer = mb.exec(); - - return answer == QMessageBox::Ok; -} - - void MixerView::deleteUnusedChannels() { Mixer* mix = getMixer();