mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-26 03:06:17 -05:00
Add Del/F2 keyboard shortcuts for macro and var removal/renames
This commit is contained in:
committed by
WarmUpTill
parent
66f9eaf8c2
commit
7b1a256f8a
@@ -74,6 +74,8 @@ AdvSceneSwitcher.variableTab.title="Variables"
|
||||
AdvSceneSwitcher.variableTab.help="Variables can be used in many places throughout the plugin.\n\nClick on the highlighted plus symbol to add a new variable."
|
||||
AdvSceneSwitcher.variableTab.variableAddButton.tooltip="Add new variable"
|
||||
AdvSceneSwitcher.variableTab.variableRemoveButton.tooltip="Remove selected variables"
|
||||
AdvSceneSwitcher.variableTab.removeSingleVariablePopup.text="Are you sure you want to remove \"%1\"?"
|
||||
AdvSceneSwitcher.variableTab.removeMultipleVariablesPopup.text="Are you sure you want to remove %1 variables?"
|
||||
AdvSceneSwitcher.variableTab.name.header="Name"
|
||||
AdvSceneSwitcher.variableTab.value.header="Value"
|
||||
AdvSceneSwitcher.variableTab.saveLoadBehavior.header="Save/Load behavior"
|
||||
@@ -109,9 +111,9 @@ AdvSceneSwitcher.macroTab.onChange="Perform actions only on condition change"
|
||||
AdvSceneSwitcher.macroTab.defaultname="Macro %1"
|
||||
AdvSceneSwitcher.macroTab.defaultGroupName="Group %1"
|
||||
AdvSceneSwitcher.macroTab.exists="Macro name exists already"
|
||||
AdvSceneSwitcher.macroTab.groupDeleteConfirm="Are you sure you want to delete \"%1\" and all its elements?"
|
||||
AdvSceneSwitcher.macroTab.deleteMultipleMacrosConfirmation="Are you sure you want to delete %1 macros?"
|
||||
AdvSceneSwitcher.macroTab.deleteSingleMacroConfirmation="Are you sure you want to delete \"%1\"?"
|
||||
AdvSceneSwitcher.macroTab.removeSingleMacroPopup.text="Are you sure you want to remove \"%1\"?"
|
||||
AdvSceneSwitcher.macroTab.removeMultipleMacrosPopup.text="Are you sure you want to remove %1 macros?"
|
||||
AdvSceneSwitcher.macroTab.removeGroupPopup.text="Are you sure you want to remove \"%1\" group and all its elements?"
|
||||
AdvSceneSwitcher.macroTab.contextMenuAdd="Add"
|
||||
AdvSceneSwitcher.macroTab.copy="Duplicate Macro"
|
||||
AdvSceneSwitcher.macroTab.group="Group Selected Macros"
|
||||
|
||||
@@ -83,9 +83,9 @@ AdvSceneSwitcher.macroTab.onChange="Exécuter des actions uniquement en cas de c
|
||||
AdvSceneSwitcher.macroTab.defaultname="Macro %1"
|
||||
AdvSceneSwitcher.macroTab.defaultGroupName="Groupe %1"
|
||||
AdvSceneSwitcher.macroTab.exists="Le nom de la macro existe déjà"
|
||||
AdvSceneSwitcher.macroTab.groupDeleteConfirm="Êtes-vous sûr de vouloir supprimer \"%1\" et tous ses éléments ?"
|
||||
AdvSceneSwitcher.macroTab.deleteMultipleMacrosConfirmation="Êtes-vous sûr de vouloir supprimer %1 macros ?"
|
||||
AdvSceneSwitcher.macroTab.deleteSingleMacroConfirmation="Êtes-vous sûr de vouloir supprimer \"%1\" ?"
|
||||
AdvSceneSwitcher.macroTab.removeSingleMacroPopup.text="Êtes-vous sûr de vouloir supprimer \"%1\" ?"
|
||||
AdvSceneSwitcher.macroTab.removeMultipleMacrosPopup.text="Êtes-vous sûr de vouloir supprimer %1 macros ?"
|
||||
AdvSceneSwitcher.macroTab.removeGroupPopup.text="Êtes-vous sûr de vouloir supprimer \"%1\" et tous ses éléments ?"
|
||||
AdvSceneSwitcher.macroTab.contextMenuAdd="Ajouter"
|
||||
AdvSceneSwitcher.macroTab.copy="Dupliquer la macro"
|
||||
AdvSceneSwitcher.macroTab.group="Grouper les macros sélectionnées"
|
||||
|
||||
@@ -82,9 +82,9 @@ AdvSceneSwitcher.macroTab.onChange="仅在条件更改时执行操作"
|
||||
AdvSceneSwitcher.macroTab.defaultname="宏 %1"
|
||||
AdvSceneSwitcher.macroTab.defaultGroupName="组 %1"
|
||||
AdvSceneSwitcher.macroTab.exists="宏名称已存在"
|
||||
AdvSceneSwitcher.macroTab.groupDeleteConfirm="您确定要删除 \"%1\"及其所有元素吗?"
|
||||
AdvSceneSwitcher.macroTab.deleteMultipleMacrosConfirmation="您确定要删除 %1 宏吗?"
|
||||
AdvSceneSwitcher.macroTab.deleteSingleMacroConfirmation="你确定你要删除 \"%1\"?"
|
||||
AdvSceneSwitcher.macroTab.deleteSingleMacroPopup.text="你确定你要删除 \"%1\"?"
|
||||
AdvSceneSwitcher.macroTab.removeMultipleMacrosPopup.text="您确定要删除 %1 宏吗?"
|
||||
AdvSceneSwitcher.macroTab.removeGroupPopup.text="您确定要删除 \"%1\"及其所有元素吗?"
|
||||
AdvSceneSwitcher.macroTab.contextMenuAdd="增加"
|
||||
AdvSceneSwitcher.macroTab.copy="创建副本"
|
||||
AdvSceneSwitcher.macroTab.group="对选定的宏进行分组"
|
||||
|
||||
@@ -135,6 +135,23 @@ bool AdvSceneSwitcher::eventFilter(QObject *obj, QEvent *event)
|
||||
}
|
||||
|
||||
SetElseActionsStateToVisible();
|
||||
} else if (eventType == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
auto pressedKey = keyEvent->key();
|
||||
|
||||
if (obj == ui->macros && ui->macros->isVisible()) {
|
||||
if (pressedKey == Qt::Key_F2) {
|
||||
RenameSelectedMacro();
|
||||
} else if (pressedKey == Qt::Key_Delete) {
|
||||
RemoveSelectedMacros();
|
||||
}
|
||||
} else if (obj == ui->variables && ui->variables->isVisible()) {
|
||||
if (pressedKey == Qt::Key_F2) {
|
||||
OpenSettingsForSelectedVariable();
|
||||
} else if (pressedKey == Qt::Key_Delete) {
|
||||
RemoveSelectedVariables();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QDialog::eventFilter(obj, event);
|
||||
|
||||
@@ -81,6 +81,7 @@ public:
|
||||
bool AddNewMacro(std::shared_ptr<Macro> &res, std::string &name,
|
||||
std::string format = "");
|
||||
void RemoveMacro(std::shared_ptr<Macro> &);
|
||||
void RemoveSelectedMacros();
|
||||
void RenameMacro(std::shared_ptr<Macro> &, const QString &name);
|
||||
std::shared_ptr<Macro> GetSelectedMacro();
|
||||
std::vector<std::shared_ptr<Macro>> GetSelectedMacros();
|
||||
@@ -135,7 +136,7 @@ public slots:
|
||||
void ShowMacroElseActionsContextMenu(const QPoint &);
|
||||
void ShowMacroConditionsContextMenu(const QPoint &);
|
||||
void CopyMacro();
|
||||
void RenameCurrentMacro();
|
||||
void RenameSelectedMacro();
|
||||
void ExportMacros();
|
||||
void ImportMacros();
|
||||
void ExpandAllActions();
|
||||
@@ -216,6 +217,9 @@ public slots:
|
||||
void on_variableAdd_clicked();
|
||||
void on_variableRemove_clicked();
|
||||
|
||||
void OpenSettingsForSelectedVariable();
|
||||
void RemoveSelectedVariables();
|
||||
|
||||
/* --- End of variable tab section --- */
|
||||
|
||||
/* --- Begin of legacy tab section --- */
|
||||
|
||||
@@ -94,7 +94,7 @@ void AdvSceneSwitcher::RemoveMacro(std::shared_ptr<Macro> ¯o)
|
||||
auto name = QString::fromStdString(macro->Name());
|
||||
if (macro->IsGroup() && macro->GroupSize() > 0) {
|
||||
QString deleteWarning = obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.groupDeleteConfirm");
|
||||
"AdvSceneSwitcher.macroTab.removeGroupPopup.text");
|
||||
if (!DisplayMessage(deleteWarning.arg(name), true)) {
|
||||
return;
|
||||
}
|
||||
@@ -104,6 +104,40 @@ void AdvSceneSwitcher::RemoveMacro(std::shared_ptr<Macro> ¯o)
|
||||
emit MacroRemoved(name);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::RemoveSelectedMacros()
|
||||
{
|
||||
auto macros = GetSelectedMacros();
|
||||
if (macros.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int macroCount = macros.size();
|
||||
if (macroCount == 1) {
|
||||
QString deleteWarning = obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.removeSingleMacroPopup.text");
|
||||
auto macro = macros.at(0);
|
||||
|
||||
if (!DisplayMessage(deleteWarning.arg(QString::fromStdString(
|
||||
macro->Name())),
|
||||
true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RemoveMacro(macro);
|
||||
return;
|
||||
}
|
||||
|
||||
QString deleteWarning = obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.removeMultipleMacrosPopup.text");
|
||||
if (!DisplayMessage(deleteWarning.arg(macroCount), true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto ¯o : macros) {
|
||||
RemoveMacro(macro);
|
||||
}
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::RenameMacro(std::shared_ptr<Macro> ¯o,
|
||||
const QString &name)
|
||||
{
|
||||
@@ -117,32 +151,7 @@ void AdvSceneSwitcher::RenameMacro(std::shared_ptr<Macro> ¯o,
|
||||
|
||||
void AdvSceneSwitcher::on_macroRemove_clicked()
|
||||
{
|
||||
auto macros = GetSelectedMacros();
|
||||
if (macros.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (macros.size() == 1) {
|
||||
QString deleteWarning = obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.deleteSingleMacroConfirmation");
|
||||
if (!DisplayMessage(deleteWarning.arg(QString::fromStdString(
|
||||
macros.at(0)->Name())),
|
||||
true)) {
|
||||
return;
|
||||
}
|
||||
RemoveMacro(macros.at(0));
|
||||
return;
|
||||
}
|
||||
|
||||
QString deleteWarning = obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.deleteMultipleMacrosConfirmation");
|
||||
if (!DisplayMessage(deleteWarning.arg(macros.size()), true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto ¯o : macros) {
|
||||
RemoveMacro(macro);
|
||||
}
|
||||
RemoveSelectedMacros();
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroUp_clicked()
|
||||
@@ -172,12 +181,13 @@ static bool newMacroNameValid(const std::string &name)
|
||||
return false;
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::RenameCurrentMacro()
|
||||
void AdvSceneSwitcher::RenameSelectedMacro()
|
||||
{
|
||||
auto macro = GetSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string oldName = macro->Name();
|
||||
std::string name;
|
||||
if (!AdvSSNameDialog::AskForName(
|
||||
@@ -186,9 +196,11 @@ void AdvSceneSwitcher::RenameCurrentMacro()
|
||||
QString::fromStdString(oldName))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (name.empty() || name == oldName || !newMacroNameValid(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RenameMacro(macro, QString::fromStdString(name));
|
||||
|
||||
const QSignalBlocker b(ui->macroName);
|
||||
@@ -778,6 +790,7 @@ bool shouldRestoreSplitter(const QList<int> &pos)
|
||||
void AdvSceneSwitcher::SetupMacroTab()
|
||||
{
|
||||
ui->macroElseActions->installEventFilter(this);
|
||||
ui->macros->installEventFilter(this);
|
||||
|
||||
if (GetMacros().size() == 0 && !switcher->disableHints) {
|
||||
addPulse = PulseWidget(ui->macroAdd, QColor(Qt::green));
|
||||
@@ -901,7 +914,7 @@ void AdvSceneSwitcher::ShowMacroContextMenu(const QPoint &pos)
|
||||
|
||||
auto rename = menu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.rename"), this,
|
||||
&AdvSceneSwitcher::RenameCurrentMacro);
|
||||
&AdvSceneSwitcher::RenameSelectedMacro);
|
||||
rename->setEnabled(ui->macros->SingleItemSelected());
|
||||
|
||||
auto remove = menu.addAction(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "ui-helpers.hpp"
|
||||
#include "variable.hpp"
|
||||
|
||||
#include <QTableWidgetItem>
|
||||
@@ -179,31 +180,10 @@ static void renameVariable(QTableWidget *table, const QString &oldName,
|
||||
assert(false);
|
||||
}
|
||||
|
||||
static void openSettingsDialogAtRow(QTableWidget *table, int row)
|
||||
{
|
||||
auto item = table->item(row, 0);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto weakVariable = GetWeakVariableByQString(item->text());
|
||||
auto variable = weakVariable.lock();
|
||||
if (!variable) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto oldName = variable->Name();
|
||||
bool accepted =
|
||||
VariableSettingsDialog::AskForSettings(table, *variable.get());
|
||||
if (accepted && oldName != variable->Name()) {
|
||||
VariableSignalManager::Instance()->Rename(
|
||||
QString::fromStdString(oldName),
|
||||
QString::fromStdString(variable->Name()));
|
||||
}
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::SetupVariableTab()
|
||||
{
|
||||
ui->variables->installEventFilter(this);
|
||||
|
||||
if (GetVariables().empty()) {
|
||||
setVariableTabVisible(ui->tabWidget, false);
|
||||
} else {
|
||||
@@ -258,10 +238,8 @@ void AdvSceneSwitcher::SetupVariableTab()
|
||||
ui->variablesHelp->show();
|
||||
}
|
||||
});
|
||||
QWidget::connect(ui->variables, &QTableWidget::cellDoubleClicked,
|
||||
[this](int row, int _) {
|
||||
openSettingsDialogAtRow(ui->variables, row);
|
||||
});
|
||||
QWidget::connect(ui->variables, &QTableWidget::cellDoubleClicked, this,
|
||||
&AdvSceneSwitcher::OpenSettingsForSelectedVariable);
|
||||
|
||||
auto timer = new QTimer(this);
|
||||
timer->setInterval(1000);
|
||||
@@ -270,6 +248,88 @@ void AdvSceneSwitcher::SetupVariableTab()
|
||||
timer->start();
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::OpenSettingsForSelectedVariable()
|
||||
{
|
||||
auto selectedRows = ui->variables->selectionModel()->selectedRows();
|
||||
if (selectedRows.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto cell = ui->variables->item(selectedRows.last().row(), 0);
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto weakVariable = GetWeakVariableByQString(cell->text());
|
||||
auto variable = weakVariable.lock();
|
||||
if (!variable) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto oldName = variable->Name();
|
||||
bool accepted = VariableSettingsDialog::AskForSettings(ui->variables,
|
||||
*variable.get());
|
||||
if (accepted && oldName != variable->Name()) {
|
||||
VariableSignalManager::Instance()->Rename(
|
||||
QString::fromStdString(oldName),
|
||||
QString::fromStdString(variable->Name()));
|
||||
}
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::RemoveSelectedVariables()
|
||||
{
|
||||
auto selectedRows = ui->variables->selectionModel()->selectedRows();
|
||||
if (selectedRows.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList varNames;
|
||||
for (auto row : selectedRows) {
|
||||
auto cell = ui->variables->item(row.row(), 0);
|
||||
if (!cell) {
|
||||
continue;
|
||||
}
|
||||
|
||||
varNames << cell->text();
|
||||
}
|
||||
|
||||
int varNameCount = varNames.size();
|
||||
if (varNameCount == 1) {
|
||||
QString deleteWarning = obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.removeSingleVariablePopup.text");
|
||||
if (!DisplayMessage(deleteWarning.arg(varNames.at(0)), true)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
QString deleteWarning = obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.removeMultipleVariablesPopup.text");
|
||||
if (!DisplayMessage(deleteWarning.arg(varNameCount), true)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &name : varNames) {
|
||||
VariableSignalManager::Instance()->Remove(name);
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
for (const auto &name : varNames) {
|
||||
auto variable = GetVariableByQString(name);
|
||||
if (!variable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto &variables = GetVariables();
|
||||
variables.erase(
|
||||
std::remove_if(
|
||||
variables.begin(), variables.end(),
|
||||
[variable](const std::shared_ptr<Item> &item) {
|
||||
return item.get() == variable;
|
||||
}),
|
||||
variables.end());
|
||||
}
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_variableAdd_clicked()
|
||||
{
|
||||
auto newVariable = std::make_shared<Variable>();
|
||||
@@ -291,48 +351,7 @@ void AdvSceneSwitcher::on_variableAdd_clicked()
|
||||
|
||||
void AdvSceneSwitcher::on_variableRemove_clicked()
|
||||
{
|
||||
auto selectedItems = ui->variables->selectedItems();
|
||||
QList<int> selectedRows;
|
||||
for (auto item : selectedItems) {
|
||||
int row = item->row();
|
||||
if (!selectedRows.contains(row)) {
|
||||
selectedRows.append(row);
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedRows.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList names;
|
||||
for (int row : selectedRows) {
|
||||
auto item = ui->variables->item(row, 0);
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
names << item->text();
|
||||
}
|
||||
|
||||
for (const auto &name : names) {
|
||||
VariableSignalManager::Instance()->Remove(name);
|
||||
}
|
||||
|
||||
auto lock = LockContext();
|
||||
for (const auto &name : names) {
|
||||
auto variable = GetVariableByQString(name);
|
||||
if (!variable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto &variables = GetVariables();
|
||||
variables.erase(
|
||||
std::remove_if(
|
||||
variables.begin(), variables.end(),
|
||||
[variable](const std::shared_ptr<Item> &item) {
|
||||
return item.get() == variable;
|
||||
}),
|
||||
variables.end());
|
||||
}
|
||||
RemoveSelectedVariables();
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
Reference in New Issue
Block a user