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`.
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QFont>
|
||||
#include <QMessageBox>
|
||||
#include <QCheckBox>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QStyle>
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user