mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-23 10:39:46 -05:00
Add macro list context menu options for add, rename, remove
This commit is contained in:
parent
4345db0d2e
commit
7f28b22599
|
|
@ -83,9 +83,12 @@ 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.copy="Create copy of current macro"
|
||||
AdvSceneSwitcher.macroTab.group="Group selected items"
|
||||
AdvSceneSwitcher.macroTab.ungroup="Ungroup selected groups"
|
||||
AdvSceneSwitcher.macroTab.contextMenuAdd="Add"
|
||||
AdvSceneSwitcher.macroTab.copy="Duplicate Macro"
|
||||
AdvSceneSwitcher.macroTab.group="Group Selected Macros"
|
||||
AdvSceneSwitcher.macroTab.ungroup="Ungroup Selected Groups"
|
||||
AdvSceneSwitcher.macroTab.rename="Rename"
|
||||
AdvSceneSwitcher.macroTab.remove="Remove"
|
||||
AdvSceneSwitcher.macroTab.expandAll="Expand all"
|
||||
AdvSceneSwitcher.macroTab.collapseAll="Collapse all"
|
||||
AdvSceneSwitcher.macroTab.maximize="Maximize"
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ public:
|
|||
bool addNewMacro(std::shared_ptr<Macro> &res, std::string &name,
|
||||
std::string format = "");
|
||||
void RemoveMacro(std::shared_ptr<Macro> &);
|
||||
void RenameMacro(std::shared_ptr<Macro> &, const QString &name);
|
||||
std::shared_ptr<Macro> getSelectedMacro();
|
||||
std::vector<std::shared_ptr<Macro>> getSelectedMacros();
|
||||
void SetEditMacro(Macro &m);
|
||||
|
|
@ -147,6 +148,7 @@ public slots:
|
|||
void ShowMacroActionsContextMenu(const QPoint &);
|
||||
void ShowMacroConditionsContextMenu(const QPoint &);
|
||||
void CopyMacro();
|
||||
void RenameCurrentMacro();
|
||||
void ExpandAllActions();
|
||||
void ExpandAllConditions();
|
||||
void CollapseAllActions();
|
||||
|
|
|
|||
|
|
@ -106,6 +106,17 @@ void AdvSceneSwitcher::RemoveMacro(std::shared_ptr<Macro> ¯o)
|
|||
emit MacroRemoved(name);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::RenameMacro(std::shared_ptr<Macro> ¯o,
|
||||
const QString &name)
|
||||
{
|
||||
auto oldName = QString::fromStdString(macro->Name());
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
macro->SetName(name.toStdString());
|
||||
}
|
||||
emit MacroRenamed(oldName, name);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroRemove_clicked()
|
||||
{
|
||||
auto macros = getSelectedMacros();
|
||||
|
|
@ -149,10 +160,37 @@ void AdvSceneSwitcher::on_macroDown_clicked()
|
|||
ui->macros->Down(macro);
|
||||
}
|
||||
|
||||
static bool newMacroNameValid(const std::string &name)
|
||||
{
|
||||
if (!macroNameExists(name)) {
|
||||
return true;
|
||||
}
|
||||
DisplayMessage(obs_module_text("AdvSceneSwitcher.macroTab.exists"));
|
||||
return false;
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::RenameCurrentMacro()
|
||||
{
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
std::string oldName = macro->Name();
|
||||
std::string name;
|
||||
if (!AdvSSNameDialog::AskForName(
|
||||
this, obs_module_text("AdvSceneSwitcher.windowTitle"),
|
||||
obs_module_text("AdvSceneSwitcher.item.newName"), name,
|
||||
QString::fromStdString(oldName))) {
|
||||
return;
|
||||
}
|
||||
if (name.empty() || name == oldName || !newMacroNameValid(name)) {
|
||||
return;
|
||||
}
|
||||
RenameMacro(macro, QString::fromStdString(name));
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroName_editingFinished()
|
||||
{
|
||||
bool nameValid = true;
|
||||
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
|
|
@ -161,33 +199,12 @@ void AdvSceneSwitcher::on_macroName_editingFinished()
|
|||
QString newName = ui->macroName->text();
|
||||
QString oldName = QString::fromStdString(macro->Name());
|
||||
|
||||
if (newName.isEmpty() || newName == oldName) {
|
||||
nameValid = false;
|
||||
}
|
||||
|
||||
if (nameValid && macroNameExists(newName.toUtf8().constData())) {
|
||||
DisplayMessage(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.exists"));
|
||||
nameValid = false;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
if (nameValid) {
|
||||
macro->SetName(newName.toUtf8().constData());
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
macro->SetName(newName.toStdString());
|
||||
} else {
|
||||
ui->macroName->setText(oldName);
|
||||
}
|
||||
}
|
||||
|
||||
if (nameValid) {
|
||||
emit MacroRenamed(oldName, newName);
|
||||
if (newName.isEmpty() || newName == oldName ||
|
||||
!newMacroNameValid(newName.toStdString())) {
|
||||
ui->macroName->setText(oldName);
|
||||
return;
|
||||
}
|
||||
RenameMacro(macro, newName);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_runMacro_clicked()
|
||||
|
|
@ -495,15 +512,20 @@ void AdvSceneSwitcher::ShowMacroContextMenu(const QPoint &pos)
|
|||
{
|
||||
QPoint globalPos = ui->macros->mapToGlobal(pos);
|
||||
QMenu menu;
|
||||
|
||||
auto add = menu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.contextMenuAdd"),
|
||||
this, &AdvSceneSwitcher::on_macroAdd_clicked);
|
||||
|
||||
auto copy = menu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.copy"), this,
|
||||
&AdvSceneSwitcher::CopyMacro);
|
||||
copy->setDisabled(ui->macros->GroupsSelected());
|
||||
copy->setEnabled(ui->macros->SingleItemSelected());
|
||||
menu.addSeparator();
|
||||
|
||||
auto group = menu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.group"), ui->macros,
|
||||
&MacroTree::GroupSelectedItems);
|
||||
// Nested groups are not supported
|
||||
group->setDisabled(ui->macros->GroupedItemsSelected() ||
|
||||
ui->macros->GroupsSelected() ||
|
||||
ui->macros->SelectionEmpty());
|
||||
|
|
@ -512,6 +534,17 @@ void AdvSceneSwitcher::ShowMacroContextMenu(const QPoint &pos)
|
|||
obs_module_text("AdvSceneSwitcher.macroTab.ungroup"),
|
||||
ui->macros, &MacroTree::UngroupSelectedGroups);
|
||||
ungroup->setEnabled(ui->macros->GroupsSelected());
|
||||
menu.addSeparator();
|
||||
|
||||
auto rename = menu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.rename"), this,
|
||||
&AdvSceneSwitcher::RenameCurrentMacro);
|
||||
rename->setEnabled(ui->macros->SingleItemSelected());
|
||||
|
||||
auto remove = menu.addAction(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.remove"), this,
|
||||
&AdvSceneSwitcher::on_macroRemove_clicked);
|
||||
remove->setDisabled(ui->macros->SelectionEmpty());
|
||||
|
||||
menu.exec(globalPos);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1057,14 +1057,12 @@ void MacroTree::dropEvent(QDropEvent *event)
|
|||
|
||||
bool MacroTree::GroupsSelected() const
|
||||
{
|
||||
MacroTreeModel *mtm = GetModel();
|
||||
QModelIndexList selectedIndices = selectedIndexes();
|
||||
|
||||
if (SelectionEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto &idx : selectedIndices) {
|
||||
MacroTreeModel *mtm = GetModel();
|
||||
for (auto &idx : selectedIndexes()) {
|
||||
std::shared_ptr<Macro> item =
|
||||
mtm->_macros[ModelIndexToMacroIndex(idx.row(),
|
||||
mtm->_macros)];
|
||||
|
|
@ -1077,14 +1075,12 @@ bool MacroTree::GroupsSelected() const
|
|||
|
||||
bool MacroTree::GroupedItemsSelected() const
|
||||
{
|
||||
MacroTreeModel *mtm = GetModel();
|
||||
QModelIndexList selectedIndices = selectedIndexes();
|
||||
|
||||
if (SelectionEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto &idx : selectedIndices) {
|
||||
auto *mtm = GetModel();
|
||||
for (auto &idx : selectedIndexes()) {
|
||||
std::shared_ptr<Macro> item =
|
||||
mtm->_macros[ModelIndexToMacroIndex(idx.row(),
|
||||
mtm->_macros)];
|
||||
|
|
@ -1096,6 +1092,11 @@ bool MacroTree::GroupedItemsSelected() const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool MacroTree::SingleItemSelected() const
|
||||
{
|
||||
return selectedIndexes().size() == 1;
|
||||
}
|
||||
|
||||
bool MacroTree::SelectionEmpty() const
|
||||
{
|
||||
return selectedIndexes().empty();
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ public:
|
|||
std::vector<std::shared_ptr<Macro>> GetCurrentMacros() const;
|
||||
bool GroupsSelected() const;
|
||||
bool GroupedItemsSelected() const;
|
||||
bool SingleItemSelected() const;
|
||||
bool SelectionEmpty() const;
|
||||
|
||||
public slots:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user