mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 01:13:19 +00:00
Fix wrong source when creating new task or event
This commit is contained in:
parent
893fcc11e3
commit
ab2200ecc1
3 changed files with 18 additions and 1 deletions
|
@ -28,13 +28,13 @@ class Mirai
|
||||||
void deleteSource(int id);
|
void deleteSource(int id);
|
||||||
void unloadAllSources();
|
void unloadAllSources();
|
||||||
void save();
|
void save();
|
||||||
std::optional<std::reference_wrapper<DataProvider>> getSourceByName(const std::string &name);
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Source>> &getSources();
|
std::vector<std::unique_ptr<Source>> &getSources();
|
||||||
const std::vector<std::string> &getTags();
|
const std::vector<std::string> &getTags();
|
||||||
|
|
||||||
// Returns a non owning pointer to the requested resource or nullptr if not found.
|
// Returns a non owning pointer to the requested resource or nullptr if not found.
|
||||||
Source *getSourceById(int id);
|
Source *getSourceById(int id);
|
||||||
|
Source *getSourceByName(const std::string &name);
|
||||||
|
|
||||||
void onSourceAdded(std::function<void(Source *)> f);
|
void onSourceAdded(std::function<void(Source *)> f);
|
||||||
void onSourceEdited(std::function<void(Source *)> f);
|
void onSourceEdited(std::function<void(Source *)> f);
|
||||||
|
|
12
external/mirai-core/src/Mirai.cpp
vendored
12
external/mirai-core/src/Mirai.cpp
vendored
|
@ -149,6 +149,18 @@ Source *Mirai::getSourceById(int id)
|
||||||
return source->get();
|
return source->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Source *Mirai::getSourceByName(const std::string &name)
|
||||||
|
{
|
||||||
|
auto source = std::ranges::find_if(sources_, [&](const std::unique_ptr<Source> &source) {
|
||||||
|
return source->name() == name;
|
||||||
|
});
|
||||||
|
assert(source != sources_.end()); // This should not happen
|
||||||
|
if (source == sources_.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return source->get();
|
||||||
|
}
|
||||||
|
|
||||||
void Mirai::onSourceAdded(std::function<void(Source *)> f)
|
void Mirai::onSourceAdded(std::function<void(Source *)> f)
|
||||||
{
|
{
|
||||||
sourceAdded.registerCallback(f);
|
sourceAdded.registerCallback(f);
|
||||||
|
|
|
@ -93,6 +93,11 @@ std::optional<ui::Date> stringToDate(const std::string &dateStr)
|
||||||
|
|
||||||
void AppWindow::setupCallbacks()
|
void AppWindow::setupCallbacks()
|
||||||
{
|
{
|
||||||
|
models().on_get_source_id_from_name([&](slint::SharedString name) {
|
||||||
|
auto source = miraiInstance_->getSourceByName(std::string(name));
|
||||||
|
assert(source);
|
||||||
|
return source->id;
|
||||||
|
});
|
||||||
miraiInstance_->onSourceAdded([&](mirai::Source *source) {
|
miraiInstance_->onSourceAdded([&](mirai::Source *source) {
|
||||||
refreshModels();
|
refreshModels();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue