Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ target_sources(
lib/macro/macro-ref.hpp
lib/macro/macro-run-button.cpp
lib/macro/macro-run-button.hpp
lib/macro/macro-search.cpp
lib/macro/macro-search.hpp
lib/macro/macro-segment-copy-paste.cpp
lib/macro/macro-segment-copy-paste.hpp
lib/macro/macro-segment-list.cpp
Expand Down
1 change: 1 addition & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ AdvSceneSwitcher.macroTab.tooltip.elseActionUpButton="Move selected action up in
AdvSceneSwitcher.macroTab.tooltip.elseActionDownButton="Move selected action down in the else section"
AdvSceneSwitcher.macroTab.tooltip.elseActionBottomButton="Move selected action to the bottom in the else section"
AdvSceneSwitcher.macroTab.tooltip.openMacroSettingsButton="Open macro settings"
AdvSceneSwitcher.macroTab.search.placeholder="Search ..."

AdvSceneSwitcher.macroDock.pause="Pause"
AdvSceneSwitcher.macroDock.unpause="Unpause"
Expand Down
68 changes: 66 additions & 2 deletions forms/advanced-scene-switcher.ui
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@
</widget>
</item>
<item>
<widget class="advss::SceneSelectionWidget" name="noMatchSwitchScene">
</widget>
<widget class="advss::SceneSelectionWidget" name="noMatchSwitchScene" native="true"/>
</item>
</layout>
</item>
Expand Down Expand Up @@ -721,6 +720,71 @@
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="macroSearch">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="macroSearchWrapperWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>239</width>
<height>68</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_30">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="macroSearchText"/>
</item>
<item>
<widget class="QPushButton" name="macroSearchClear">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="macroSearchType"/>
</item>
<item>
<widget class="advss::RegexConfigWidget" name="macroSearchRegex" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="advss::MacroTree" name="macros">
<property name="showDropIndicator" stdset="0">
Expand Down
52 changes: 52 additions & 0 deletions lib/macro/macro-search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "macro-search.hpp"
#include "plugin-state-helpers.hpp"

#include <obs.hpp>

namespace advss {

static bool setup();
static bool setupDone = setup();

static void save(obs_data_t *data)
{
GetMacroSearchSettings().Save(data, "macroSearchSettings");
}

static void load(obs_data_t *data)
{
GetMacroSearchSettings().Load(data, "macroSearchSettings");
}

static bool setup()
{
AddSaveStep(save);
AddLoadStep(load);
return true;
}

void MacroSearchSettings::Save(obs_data_t *data, const char *name)
{
OBSDataAutoRelease settings = obs_data_create();
obs_data_set_int(settings, "searchType", static_cast<int>(searchType));
obs_data_set_string(settings, "searchString", searchString.c_str());
regex.Save(settings);
obs_data_set_obj(data, name, settings);
}

void MacroSearchSettings::Load(obs_data_t *data, const char *name)
{
OBSDataAutoRelease settings = obs_data_get_obj(data, name);
searchType = static_cast<SearchType>(
obs_data_get_int(settings, "searchType"));
searchString = obs_data_get_string(settings, "searchString");
regex.Load(settings);
}

MacroSearchSettings &GetMacroSearchSettings()
{
static MacroSearchSettings settings;
return settings;
}

} // namespace advss
29 changes: 29 additions & 0 deletions lib/macro/macro-search.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include "regex-config.hpp"

#include <string>

namespace advss {

struct MacroSearchSettings {
void Save(obs_data_t *data, const char *name);
void Load(obs_data_t *data, const char *name);

enum SearchType {
ALL = -1,
NAME,
ALL_SEGMENTS,
CONDITIONS,
ACTIONS,
ELSE_ACTIONS,
LABEL
};

SearchType searchType = SearchType::ALL;
std::string searchString;
RegexConfig regex;
};

MacroSearchSettings &GetMacroSearchSettings();

} // namespace advss
89 changes: 86 additions & 3 deletions lib/macro/macro-tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "macro-condition-edit.hpp"
#include "macro-export-import-dialog.hpp"
#include "macro-settings.hpp"
#include "macro-search.hpp"
#include "macro-signals.hpp"
#include "macro-tree.hpp"
#include "macro.hpp"
Expand Down Expand Up @@ -638,16 +639,17 @@ void AdvSceneSwitcher::SetupMacroTab()
{
ui->macros->installEventFilter(this);

if (GetTopLevelMacros().size() == 0 && !switcher->disableHints) {
auto &macros = GetTopLevelMacros();

if (macros.size() == 0 && !switcher->disableHints) {
addPulse = HighlightWidget(ui->macroAdd, QColor(Qt::green));
}

auto macroControls = setupToolBar({{ui->macroAdd, ui->macroRemove},
{ui->macroUp, ui->macroDown}});
ui->macroControlLayout->addWidget(macroControls);

ui->macros->Reset(GetTopLevelMacros(),
GetGlobalMacroSettings()._highlightExecuted);
ui->macros->Reset(macros, GetGlobalMacroSettings()._highlightExecuted);
connect(ui->macros, SIGNAL(MacroSelectionChanged()), this,
SLOT(MacroSelectionChanged()));
ui->runMacro->SetMacroTree(ui->macros);
Expand Down Expand Up @@ -676,6 +678,87 @@ void AdvSceneSwitcher::SetupMacroTab()
switcher->macroListMacroEditSplitterPosition);
}
}

static const int showSearchThreshold = 10;
const bool showSearch = macros.size() >= showSearchThreshold;
ui->macroSearch->setVisible(showSearch);

ui->macroSearchWrapperWidget->setAttribute(
Qt::WA_TranslucentBackground);
ui->macroSearchWrapperWidget->setAttribute(Qt::WA_NoSystemBackground);
ui->macroSearch->viewport()->setAttribute(Qt::WA_TranslucentBackground);

ui->macroSearchClear->setMaximumWidth(22);
SetButtonIcon(ui->macroSearchClear, GetThemeTypeName() == "Light"
? "theme:Light/close.svg"
: "theme:Dark/close.svg");
ui->macroSearchClear->setToolTip(
obs_module_text("AdvSceneSwitcher.variableTab.clear"));
ui->macroSearchClear->setDisabled(
GetMacroSearchSettings().searchString.empty());

connect(ui->macroSearchClear, &QPushButton::clicked, this, [this]() {
ui->macroSearchText->setText("");
ui->macroSearchClear->setDisabled(true);
});

//connect(Table(), &QTableWidget::itemChanged, this,
// [ this]() { Filter(); });

ui->macroSearchText->setPlaceholderText(obs_module_text(
("AdvSceneSwitcher.macroTab.search.placeholder")));

const auto ph = ui->macroSearchText->placeholderText();
const QFontMetrics fm(ui->macroSearchText->font());
const int width = fm.horizontalAdvance(ph);
// Add a little padding so the text isn't cramped
ui->macroSearchText->setMinimumWidth(width + 10);

ui->macroSearchText->setText(
QString::fromStdString(GetMacroSearchSettings().searchString));
connect(ui->macroSearchText, &QLineEdit::textChanged, this,
[this](const QString &text) {
GetMacroSearchSettings().searchString =
text.toStdString();
ui->macroSearchClear->setDisabled(text.isEmpty());
//Filter();
});

ui->macroSearchType->addItem(
obs_module_text("AdvSceneSwitcher.variableTab.search.all"),
MacroSearchSettings::SearchType::ALL);
ui->macroSearchType->addItem(
obs_module_text("AdvSceneSwitcher.variableTab.search.name"),
MacroSearchSettings::SearchType::ALL_SEGMENTS);
ui->macroSearchType->addItem(
obs_module_text("AdvSceneSwitcher.variableTab.search.value"),
MacroSearchSettings::SearchType::CONDITIONS);
ui->macroSearchType->addItem(
obs_module_text("AdvSceneSwitcher.variableTab.search.value"),
MacroSearchSettings::SearchType::ACTIONS);
ui->macroSearchType->addItem(
obs_module_text("AdvSceneSwitcher.variableTab.search.value"),
MacroSearchSettings::SearchType::ELSE_ACTIONS);
ui->macroSearchType->addItem(
obs_module_text("AdvSceneSwitcher.variableTab.search.value"),
MacroSearchSettings::SearchType::LABEL);
ui->macroSearchType->setCurrentIndex(ui->macroSearchType->findData(
GetMacroSearchSettings().searchType));

connect(ui->macroSearchType, &QComboBox::currentIndexChanged, this,
[this]() {
GetMacroSearchSettings().searchType =
static_cast<MacroSearchSettings::SearchType>(
ui->macroSearchType->currentData()
.toInt());
});

ui->macroSearchRegex->SetRegexConfig(GetMacroSearchSettings().regex);
connect(ui->macroSearchRegex, &RegexConfigWidget::RegexConfigChanged,
this, [this](const RegexConfig &regex) {
GetMacroSearchSettings().regex = regex;
//Filter();
});
}

void AdvSceneSwitcher::ShowMacroContextMenu(const QPoint &pos)
Expand Down
Loading