mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Add "all" option in filter selection
This commit is contained in:
parent
46199efb58
commit
ea5e92017e
|
|
@ -1003,6 +1003,8 @@ AdvSceneSwitcher.sceneItemSelection.type.all.entry="All sources"
|
|||
AdvSceneSwitcher.sceneItemSelection.all="All"
|
||||
AdvSceneSwitcher.sceneItemSelection.any="Any"
|
||||
|
||||
AdvSceneSwitcher.filterSelection.all="All filters"
|
||||
|
||||
AdvSceneSwitcher.status.active="Active"
|
||||
AdvSceneSwitcher.status.inactive="Inactive"
|
||||
AdvSceneSwitcher.running="Plugin running"
|
||||
|
|
|
|||
|
|
@ -21,26 +21,35 @@ const static std::map<MacroActionFilter::Action, std::string> actionTypes = {
|
|||
"AdvSceneSwitcher.action.filter.type.settings"},
|
||||
};
|
||||
|
||||
bool MacroActionFilter::PerformAction()
|
||||
static void performActionHelper(MacroActionFilter::Action action,
|
||||
const OBSWeakSource &filter,
|
||||
const StringVariable &settings)
|
||||
{
|
||||
auto s = obs_weak_source_get_source(_filter.GetFilter(_source));
|
||||
switch (_action) {
|
||||
case Action::ENABLE:
|
||||
obs_source_set_enabled(s, true);
|
||||
OBSSourceAutoRelease source = obs_weak_source_get_source(filter);
|
||||
switch (action) {
|
||||
case MacroActionFilter::Action::ENABLE:
|
||||
obs_source_set_enabled(source, true);
|
||||
break;
|
||||
case Action::DISABLE:
|
||||
obs_source_set_enabled(s, false);
|
||||
case MacroActionFilter::Action::DISABLE:
|
||||
obs_source_set_enabled(source, false);
|
||||
break;
|
||||
case Action::TOGGLE:
|
||||
obs_source_set_enabled(s, !obs_source_enabled(s));
|
||||
case MacroActionFilter::Action::TOGGLE:
|
||||
obs_source_set_enabled(source, !obs_source_enabled(source));
|
||||
break;
|
||||
case Action::SETTINGS:
|
||||
SetSourceSettings(s, _settings);
|
||||
case MacroActionFilter::Action::SETTINGS:
|
||||
SetSourceSettings(source, settings);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
obs_source_release(s);
|
||||
}
|
||||
|
||||
bool MacroActionFilter::PerformAction()
|
||||
{
|
||||
auto filters = _filter.GetFilters(_source);
|
||||
for (const auto &filter : filters) {
|
||||
performActionHelper(_action, filter, _settings);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -214,12 +223,12 @@ void MacroActionFilterEdit::ActionChanged(int value)
|
|||
void MacroActionFilterEdit::GetSettingsClicked()
|
||||
{
|
||||
if (_loading || !_entryData ||
|
||||
!_entryData->_filter.GetFilter(_entryData->_source)) {
|
||||
_entryData->_filter.GetFilters(_entryData->_source).empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_settings->setPlainText(FormatJsonString(GetSourceSettings(
|
||||
_entryData->_filter.GetFilter(_entryData->_source))));
|
||||
_entryData->_filter.GetFilters(_entryData->_source).at(0))));
|
||||
}
|
||||
|
||||
void MacroActionFilterEdit::SettingsChanged()
|
||||
|
|
|
|||
|
|
@ -24,15 +24,14 @@ const static std::map<MacroConditionFilter::Condition, std::string>
|
|||
"AdvSceneSwitcher.condition.filter.type.settingsChanged"},
|
||||
};
|
||||
|
||||
bool MacroConditionFilter::CheckCondition()
|
||||
bool MacroConditionFilter::CheckConditionHelper(const OBSWeakSource &filter)
|
||||
{
|
||||
auto filterWeakSource = _filter.GetFilter(_source);
|
||||
if (!filterWeakSource) {
|
||||
bool ret = false;
|
||||
OBSSourceAutoRelease filterSource = obs_weak_source_get_source(filter);
|
||||
if (!filterSource.Get()) {
|
||||
return false;
|
||||
}
|
||||
auto filterSource = obs_weak_source_get_source(filterWeakSource);
|
||||
|
||||
bool ret = false;
|
||||
switch (_condition) {
|
||||
case Condition::ENABLED:
|
||||
ret = obs_source_enabled(filterSource);
|
||||
|
|
@ -41,10 +40,9 @@ bool MacroConditionFilter::CheckCondition()
|
|||
ret = !obs_source_enabled(filterSource);
|
||||
break;
|
||||
case Condition::SETTINGS_MATCH:
|
||||
ret = CompareSourceSettings(filterWeakSource, _settings,
|
||||
_regex);
|
||||
ret = CompareSourceSettings(filter, _settings, _regex);
|
||||
if (IsReferencedInVars()) {
|
||||
SetVariableValue(GetSourceSettings(filterWeakSource));
|
||||
SetVariableValue(GetSourceSettings(filter));
|
||||
}
|
||||
break;
|
||||
case Condition::SETTINGS_CHANGED: {
|
||||
|
|
@ -57,8 +55,20 @@ bool MacroConditionFilter::CheckCondition()
|
|||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
obs_source_release(filterSource);
|
||||
bool MacroConditionFilter::CheckCondition()
|
||||
{
|
||||
auto filters = _filter.GetFilters(_source);
|
||||
if (filters.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
for (const auto &filter : filters) {
|
||||
ret = ret && CheckConditionHelper(filter);
|
||||
}
|
||||
|
||||
if (GetVariableValue().empty()) {
|
||||
SetVariableValue(ret ? "true" : "false");
|
||||
|
|
@ -211,12 +221,12 @@ void MacroConditionFilterEdit::ConditionChanged(int index)
|
|||
void MacroConditionFilterEdit::GetSettingsClicked()
|
||||
{
|
||||
if (_loading || !_entryData ||
|
||||
!_entryData->_filter.GetFilter(_entryData->_source)) {
|
||||
_entryData->_filter.GetFilters(_entryData->_source).empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString json = FormatJsonString(GetSourceSettings(
|
||||
_entryData->_filter.GetFilter(_entryData->_source)));
|
||||
_entryData->_filter.GetFilters(_entryData->_source).at(0)));
|
||||
if (_entryData->_regex.Enabled()) {
|
||||
json = EscapeForRegex(json);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,8 +38,9 @@ public:
|
|||
RegexConfig _regex;
|
||||
|
||||
private:
|
||||
std::string _currentSettings;
|
||||
bool CheckConditionHelper(const OBSWeakSource &);
|
||||
|
||||
std::string _currentSettings;
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -65,31 +65,56 @@ void FilterSelection::LoadFallback(obs_data_t *obj,
|
|||
_filterName = obs_data_get_string(obj, name);
|
||||
}
|
||||
|
||||
OBSWeakSource FilterSelection::GetFilter(const SourceSelection &source) const
|
||||
static std::vector<OBSWeakSource> getFiltersOfSource(OBSWeakSource source)
|
||||
{
|
||||
if (!source) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto enumFilters = [](obs_source_t *, obs_source_t *filter, void *ptr) {
|
||||
auto filters =
|
||||
reinterpret_cast<std::vector<OBSWeakSource> *>(ptr);
|
||||
OBSWeakSourceAutoRelease weakFilter =
|
||||
obs_source_get_weak_source(filter);
|
||||
filters->emplace_back(weakFilter);
|
||||
};
|
||||
|
||||
std::vector<OBSWeakSource> filters;
|
||||
OBSSourceAutoRelease s = obs_weak_source_get_source(source);
|
||||
obs_source_enum_filters(s, enumFilters, &filters);
|
||||
return filters;
|
||||
}
|
||||
|
||||
std::vector<OBSWeakSource>
|
||||
FilterSelection::GetFilters(const SourceSelection &source) const
|
||||
{
|
||||
switch (_type) {
|
||||
case Type::ALL:
|
||||
return getFiltersOfSource(source.GetSource());
|
||||
case Type::SOURCE:
|
||||
return GetWeakFilterByName(
|
||||
return {GetWeakFilterByName(
|
||||
source.GetSource(),
|
||||
_filter ? GetWeakSourceName(_filter).c_str()
|
||||
: _filterName.c_str());
|
||||
: _filterName.c_str())};
|
||||
case Type::VARIABLE: {
|
||||
auto var = _variable.lock();
|
||||
if (!var) {
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
return GetWeakFilterByName(source.GetSource(),
|
||||
var->Value().c_str());
|
||||
return {GetWeakFilterByName(source.GetSource(),
|
||||
var->Value().c_str())};
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string FilterSelection::ToString(bool resolve) const
|
||||
{
|
||||
switch (_type) {
|
||||
case Type::ALL:
|
||||
return obs_module_text("AdvSceneSwitcher.filterSelection.all");
|
||||
case Type::SOURCE:
|
||||
return _filter ? GetWeakSourceName(_filter) : _filterName;
|
||||
case Type::VARIABLE: {
|
||||
|
|
@ -117,7 +142,9 @@ FilterSelection FilterSelectionWidget::CurrentSelection()
|
|||
return s;
|
||||
}
|
||||
|
||||
if (idx < _variablesEndIdx) {
|
||||
if (idx < _allEndIdx) {
|
||||
s._type = FilterSelection::Type::ALL;
|
||||
} else if (idx < _variablesEndIdx) {
|
||||
s._type = FilterSelection::Type::VARIABLE;
|
||||
s._variable = GetWeakVariableByQString(name);
|
||||
} else if (idx < _filterEndIdx) {
|
||||
|
|
@ -139,6 +166,12 @@ void FilterSelectionWidget::PopulateSelection()
|
|||
{
|
||||
const QSignalBlocker b(this);
|
||||
clear();
|
||||
|
||||
AddSelectionGroup(
|
||||
this,
|
||||
{obs_module_text("AdvSceneSwitcher.filterSelection.all")});
|
||||
_allEndIdx = count();
|
||||
|
||||
if (_addVariables) {
|
||||
const QStringList variables = GetVariablesNameList();
|
||||
AddSelectionGroup(this, variables);
|
||||
|
|
@ -188,6 +221,10 @@ void FilterSelectionWidget::SetFilter(const SourceSelection &source,
|
|||
int idx = -1;
|
||||
|
||||
switch (filter.GetType()) {
|
||||
case FilterSelection::Type::ALL:
|
||||
idx = findText(obs_module_text(
|
||||
"AdvSceneSwitcher.filterSelection.all"));
|
||||
break;
|
||||
case FilterSelection::Type::SOURCE: {
|
||||
if (_filterEndIdx == -1) {
|
||||
idx = -1;
|
||||
|
|
|
|||
|
|
@ -13,15 +13,17 @@ public:
|
|||
enum class Type {
|
||||
SOURCE,
|
||||
VARIABLE,
|
||||
ALL,
|
||||
};
|
||||
|
||||
Type GetType() const { return _type; }
|
||||
OBSWeakSource GetFilter(const SourceSelection &source) const;
|
||||
std::vector<OBSWeakSource>
|
||||
GetFilters(const SourceSelection &source) const;
|
||||
std::string ToString(bool resolve = false) const;
|
||||
|
||||
private:
|
||||
// TODO: Remove in future version
|
||||
// Used for backwards compatability to older settings versions
|
||||
// Used for backwards compatibility to older settings versions
|
||||
void LoadFallback(obs_data_t *obj, const SourceSelection &source,
|
||||
const char *name);
|
||||
|
||||
|
|
@ -65,9 +67,11 @@ private:
|
|||
|
||||
// Order of entries
|
||||
// 1. "select entry" entry
|
||||
// 2. Variables
|
||||
// 3. Regular filters
|
||||
// 2. All filters
|
||||
// 3. Variables
|
||||
// 4. Regular filters
|
||||
const int _selectIdx = 0;
|
||||
int _allEndIdx = -1;
|
||||
int _variablesEndIdx = -1;
|
||||
int _filterEndIdx = -1;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user