mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: add get_picture_idx() function
A function that gets the index of a picture in a picture table given its filename. Since we are going to identify pictures by their filename, we will need this function in the undo code. Use the function in the remove_picture() function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
4e25912fd3
commit
db24f16686
2 changed files with 15 additions and 7 deletions
|
|
@ -58,14 +58,21 @@ void add_picture(struct picture_table *t, struct picture newpic)
|
|||
add_to_picture_table(t, idx, newpic);
|
||||
}
|
||||
|
||||
int get_picture_idx(const struct picture_table *t, const char *filename)
|
||||
{
|
||||
for (int i = 0; i < t->nr; ++i) {
|
||||
if (same_string(t->pictures[i].filename, filename))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Return true if picture was found and deleted
|
||||
bool remove_picture(struct picture_table *t, const char *filename)
|
||||
{
|
||||
for (int i = 0; i < t->nr; ++i) {
|
||||
if (same_string(t->pictures[i].filename, filename)) {
|
||||
remove_from_picture_table(t, i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
int idx = get_picture_idx(t, filename);
|
||||
if (idx < 0)
|
||||
return false;
|
||||
remove_from_picture_table(t, idx);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue