mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
refactored IgnoredController
This commit is contained in:
parent
89389608e9
commit
8ae9abb250
7 changed files with 33 additions and 43 deletions
|
@ -434,6 +434,7 @@ HEADERS += \
|
||||||
src/util/LayoutCreator.hpp \
|
src/util/LayoutCreator.hpp \
|
||||||
src/util/LayoutHelper.hpp \
|
src/util/LayoutHelper.hpp \
|
||||||
src/util/Overloaded.hpp \
|
src/util/Overloaded.hpp \
|
||||||
|
src/util/PersistSignalVector.hpp \
|
||||||
src/util/PostToThread.hpp \
|
src/util/PostToThread.hpp \
|
||||||
src/util/QObjectRef.hpp \
|
src/util/QObjectRef.hpp \
|
||||||
src/util/QStringHash.hpp \
|
src/util/QStringHash.hpp \
|
||||||
|
|
|
@ -1,26 +1,10 @@
|
||||||
#include "HighlightController.hpp"
|
#include "HighlightController.hpp"
|
||||||
|
|
||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
#include "common/ChatterinoSetting.hpp"
|
#include "util/PersistSignalVector.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
inline void persist(SignalVector<T> &vec, const std::string &name)
|
|
||||||
{
|
|
||||||
auto setting = std::make_unique<ChatterinoSetting<std::vector<T>>>(name);
|
|
||||||
|
|
||||||
for (auto &&item : setting->getValue())
|
|
||||||
vec.append(item);
|
|
||||||
|
|
||||||
vec.delayedItemsChanged.connect([setting = setting.get(), vec = &vec] {
|
|
||||||
setting->setValue(vec->raw());
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: Delete when appropriate.
|
|
||||||
setting.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HighlightController::initialize(Settings &settings, Paths &paths)
|
void HighlightController::initialize(Settings &settings, Paths &paths)
|
||||||
{
|
{
|
||||||
assert(!this->initialized_);
|
assert(!this->initialized_);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
#include "controllers/ignores/IgnoreModel.hpp"
|
#include "controllers/ignores/IgnoreModel.hpp"
|
||||||
|
#include "util/PersistSignalVector.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
@ -12,22 +13,7 @@ void IgnoreController::initialize(Settings &, Paths &)
|
||||||
assert(!this->initialized_);
|
assert(!this->initialized_);
|
||||||
this->initialized_ = true;
|
this->initialized_ = true;
|
||||||
|
|
||||||
for (const IgnorePhrase &phrase : this->ignoresSetting_.getValue())
|
persist(this->phrases, "/ignore/phrases");
|
||||||
{
|
|
||||||
this->phrases.append(phrase);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->phrases.delayedItemsChanged.connect([this] { //
|
|
||||||
this->ignoresSetting_.setValue(this->phrases.raw());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
IgnoreModel *IgnoreController::createModel(QObject *parent)
|
|
||||||
{
|
|
||||||
IgnoreModel *model = new IgnoreModel(parent);
|
|
||||||
model->initialize(&this->phrases);
|
|
||||||
|
|
||||||
return model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -21,13 +21,8 @@ public:
|
||||||
|
|
||||||
SignalVector<IgnorePhrase> phrases;
|
SignalVector<IgnorePhrase> phrases;
|
||||||
|
|
||||||
IgnoreModel *createModel(QObject *parent);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
|
|
||||||
ChatterinoSetting<std::vector<IgnorePhrase>> ignoresSetting_ = {
|
|
||||||
"/ignore/phrases"};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -7,10 +7,9 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class IgnoreController;
|
|
||||||
|
|
||||||
class IgnoreModel : public SignalVectorModel<IgnorePhrase>
|
class IgnoreModel : public SignalVectorModel<IgnorePhrase>
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
explicit IgnoreModel(QObject *parent);
|
explicit IgnoreModel(QObject *parent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -21,8 +20,6 @@ protected:
|
||||||
// turns a row in the model into a vector item
|
// turns a row in the model into a vector item
|
||||||
virtual void getRowFromItem(const IgnorePhrase &item,
|
virtual void getRowFromItem(const IgnorePhrase &item,
|
||||||
std::vector<QStandardItem *> &row) override;
|
std::vector<QStandardItem *> &row) override;
|
||||||
|
|
||||||
friend class IgnoreController;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
25
src/util/PersistSignalVector.hpp
Normal file
25
src/util/PersistSignalVector.hpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include "common/ChatterinoSetting.hpp"
|
||||||
|
#include "common/SignalVector.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void persist(SignalVector<T> &vec, const std::string &name)
|
||||||
|
{
|
||||||
|
auto setting = std::make_unique<ChatterinoSetting<std::vector<T>>>(name);
|
||||||
|
|
||||||
|
for (auto &&item : setting->getValue())
|
||||||
|
vec.append(item);
|
||||||
|
|
||||||
|
vec.delayedItemsChanged.connect([setting = setting.get(), vec = &vec] {
|
||||||
|
setting->setValue(vec->raw());
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Delete when appropriate.
|
||||||
|
setting.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
|
@ -44,7 +44,9 @@ void addPhrasesTab(LayoutCreator<QVBoxLayout> layout)
|
||||||
layout.emplace<QLabel>("Ignore messages based certain patterns.");
|
layout.emplace<QLabel>("Ignore messages based certain patterns.");
|
||||||
EditableModelView *view =
|
EditableModelView *view =
|
||||||
layout
|
layout
|
||||||
.emplace<EditableModelView>(getApp()->ignores->createModel(nullptr))
|
.emplace<EditableModelView>(
|
||||||
|
(new IgnoreModel(nullptr))
|
||||||
|
->initialized(&getApp()->ignores->phrases))
|
||||||
.getElement();
|
.getElement();
|
||||||
view->setTitles(
|
view->setTitles(
|
||||||
{"Pattern", "Regex", "Case Sensitive", "Block", "Replacement"});
|
{"Pattern", "Regex", "Case Sensitive", "Block", "Replacement"});
|
||||||
|
|
Loading…
Reference in a new issue