mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-11 03:21:29 +00:00
core: introduce register_dive() function
There was a weird asymmetry, where the undo-commands would register the fulltext index of the dive, but the core would unregister the fulltext index in the "unregister_dive()" function. To make this more logical, create a "register_dive()" function in core that does registers the fulltext index. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
aa60e5d21d
commit
b9df26066e
3 changed files with 21 additions and 12 deletions
|
@ -72,18 +72,7 @@ dive *DiveListBase::addDive(DiveToAdd &d)
|
||||||
d.site->add_dive(d.dive.get());
|
d.site->add_dive(d.dive.get());
|
||||||
diveSiteCountChanged(d.site);
|
diveSiteCountChanged(d.site);
|
||||||
}
|
}
|
||||||
dive *res = d.dive.release(); // Give up ownership of dive
|
return register_dive(std::move(d.dive)); // Transfer ownership to core and update fulltext index
|
||||||
|
|
||||||
// When we add dives, we start in hidden-by-filter status. Once all
|
|
||||||
// dives have been added, their status will be updated.
|
|
||||||
res->hidden_by_filter = true;
|
|
||||||
|
|
||||||
int idx = dive_table_get_insertion_index(divelog.dives.get(), res);
|
|
||||||
fulltext_register(res); // Register the dive's fulltext cache
|
|
||||||
add_to_dive_table(divelog.dives.get(), idx, res); // Return ownership to backend
|
|
||||||
invalidate_dive_cache(res); // Ensure that dive is written in git_save()
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some signals are sent in batches per trip. To avoid writing the same loop
|
// Some signals are sent in batches per trip. To avoid writing the same loop
|
||||||
|
|
|
@ -745,6 +745,24 @@ struct dive *unregister_dive(int idx)
|
||||||
return dive;
|
return dive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add a dive to the global dive table.
|
||||||
|
* Index it in the fulltext cache and make sure that it is written
|
||||||
|
* in git_save().
|
||||||
|
*/
|
||||||
|
struct dive *register_dive(std::unique_ptr<dive> d)
|
||||||
|
{
|
||||||
|
// When we add dives, we start in hidden-by-filter status. Once all
|
||||||
|
// dives have been added, their status will be updated.
|
||||||
|
d->hidden_by_filter = true;
|
||||||
|
|
||||||
|
int idx = dive_table_get_insertion_index(divelog.dives.get(), d.get());
|
||||||
|
fulltext_register(d.get()); // Register the dive's fulltext cache
|
||||||
|
invalidate_dive_cache(d.get()); // Ensure that dive is written in git_save()
|
||||||
|
add_to_dive_table(divelog.dives.get(), idx, d.get());
|
||||||
|
|
||||||
|
return d.release();
|
||||||
|
}
|
||||||
|
|
||||||
void process_loaded_dives()
|
void process_loaded_dives()
|
||||||
{
|
{
|
||||||
sort_dive_table(divelog.dives.get());
|
sort_dive_table(divelog.dives.get());
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#define DIVELIST_H
|
#define DIVELIST_H
|
||||||
|
|
||||||
#include "units.h"
|
#include "units.h"
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct dive;
|
struct dive;
|
||||||
|
@ -56,6 +57,7 @@ void report_datafile_version(int version);
|
||||||
void clear_dive_file_data();
|
void clear_dive_file_data();
|
||||||
void clear_dive_table(struct dive_table *table);
|
void clear_dive_table(struct dive_table *table);
|
||||||
struct dive *unregister_dive(int idx);
|
struct dive *unregister_dive(int idx);
|
||||||
|
struct dive *register_dive(std::unique_ptr<dive> d);
|
||||||
extern bool has_dive(unsigned int deviceid, unsigned int diveid);
|
extern bool has_dive(unsigned int deviceid, unsigned int diveid);
|
||||||
|
|
||||||
#endif // DIVELIST_H
|
#endif // DIVELIST_H
|
||||||
|
|
Loading…
Reference in a new issue