mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Enable deleting multiple macros at once
This commit is contained in:
parent
46eaada0c4
commit
eddc10c3e2
|
|
@ -82,6 +82,7 @@ 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.copy="Create copy of current macro"
|
||||
AdvSceneSwitcher.macroTab.group="Group selected items"
|
||||
AdvSceneSwitcher.macroTab.ungroup="Ungroup selected groups"
|
||||
|
|
|
|||
|
|
@ -46,7 +46,9 @@ public:
|
|||
|
||||
bool addNewMacro(std::shared_ptr<Macro> &res, std::string &name,
|
||||
std::string format = "");
|
||||
void RemoveMacro(std::shared_ptr<Macro> &);
|
||||
std::shared_ptr<Macro> getSelectedMacro();
|
||||
std::vector<std::shared_ptr<Macro>> getSelectedMacros();
|
||||
void SetEditMacro(Macro &m);
|
||||
void SetMacroEditAreaDisabled(bool);
|
||||
void HighlightAction(int idx, QColor color = QColor(Qt::green));
|
||||
|
|
|
|||
|
|
@ -83,12 +83,12 @@ void AdvSceneSwitcher::on_macroAdd_clicked()
|
|||
emit MacroAdded(QString::fromStdString(name));
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroRemove_clicked()
|
||||
void AdvSceneSwitcher::RemoveMacro(std::shared_ptr<Macro> ¯o)
|
||||
{
|
||||
auto macro = getSelectedMacro();
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto name = QString::fromStdString(macro->Name());
|
||||
if (macro->IsGroup()) {
|
||||
QString deleteWarning = obs_module_text(
|
||||
|
|
@ -106,6 +106,29 @@ void AdvSceneSwitcher::on_macroRemove_clicked()
|
|||
emit MacroRemoved(name);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroRemove_clicked()
|
||||
{
|
||||
auto macros = getSelectedMacros();
|
||||
if (macros.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (macros.size() == 1) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroUp_clicked()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
|
|
@ -314,6 +337,11 @@ std::shared_ptr<Macro> AdvSceneSwitcher::getSelectedMacro()
|
|||
return ui->macros->GetCurrentMacro();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Macro>> AdvSceneSwitcher::getSelectedMacros()
|
||||
{
|
||||
return ui->macros->GetCurrentMacros();
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::MacroSelectionChanged(const QItemSelection &,
|
||||
const QItemSelection &)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -390,6 +390,8 @@ void MacroTreeModel::Remove(std::shared_ptr<Macro> item)
|
|||
if (!item->IsCollapsed()) {
|
||||
uiEndIdx += item->GroupSize();
|
||||
}
|
||||
} else if (item->IsSubitem()) {
|
||||
Macro::PrepareMoveToGroup(nullptr, item);
|
||||
}
|
||||
|
||||
beginRemoveRows(QModelIndex(), uiStartIdx, uiEndIdx);
|
||||
|
|
@ -472,6 +474,21 @@ std::shared_ptr<Macro> MacroTreeModel::GetCurrentMacro() const
|
|||
return _macros[ModelIndexToMacroIndex(idx, _macros)];
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Macro>>
|
||||
MacroTreeModel::GetCurrentMacros(const QModelIndexList &selection) const
|
||||
{
|
||||
std::vector<std::shared_ptr<Macro>> result;
|
||||
result.reserve(selection.size());
|
||||
for (const auto &sel : selection) {
|
||||
try {
|
||||
result.emplace_back(_macros.at(
|
||||
ModelIndexToMacroIndex(sel.row(), _macros)));
|
||||
} catch (const std::out_of_range &) {
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
MacroTreeModel::MacroTreeModel(MacroTree *st_,
|
||||
std::deque<std::shared_ptr<Macro>> ¯os)
|
||||
: QAbstractListModel(st_), _mt(st_), _macros(macros)
|
||||
|
|
@ -708,6 +725,12 @@ std::shared_ptr<Macro> MacroTree::GetCurrentMacro() const
|
|||
return GetModel()->GetCurrentMacro();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Macro>> MacroTree::GetCurrentMacros() const
|
||||
{
|
||||
QModelIndexList indices = selectedIndexes();
|
||||
return GetModel()->GetCurrentMacros(indices);
|
||||
}
|
||||
|
||||
MacroTree::MacroTree(QWidget *parent_) : QListView(parent_)
|
||||
{
|
||||
setStyleSheet(QString(
|
||||
|
|
|
|||
|
|
@ -92,6 +92,8 @@ private:
|
|||
std::shared_ptr<Macro> FindEndOfGroup(const std::shared_ptr<Macro> &m,
|
||||
bool above) const;
|
||||
std::shared_ptr<Macro> GetCurrentMacro() const;
|
||||
std::vector<std::shared_ptr<Macro>>
|
||||
GetCurrentMacros(const QModelIndexList &) const;
|
||||
QString GetNewGroupName();
|
||||
void GroupSelectedItems(QModelIndexList &indices);
|
||||
void UngroupSelectedGroups(QModelIndexList &indices);
|
||||
|
|
@ -121,6 +123,7 @@ public:
|
|||
void Up(std::shared_ptr<Macro> item) const;
|
||||
void Down(std::shared_ptr<Macro> item) const;
|
||||
std::shared_ptr<Macro> GetCurrentMacro() const;
|
||||
std::vector<std::shared_ptr<Macro>> GetCurrentMacros() const;
|
||||
bool GroupsSelected() const;
|
||||
bool GroupedItemsSelected() const;
|
||||
bool SelectionEmpty() const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user