Fix off-by-one error in toolbar customization

Fix the behaviour that any addition to the toolbar during customization
would show one position further to the right after reopening the
application.
(Notable exception: the very first position)
upstream-master
idotobi 5 years ago committed by Roland Lötscher
parent 4f82402107
commit ca1c9da41c
  1. 11
      src/gui/toolbarMenubar/model/ToolbarEntry.cpp

@ -30,9 +30,7 @@ ToolbarEntry& ToolbarEntry::operator=(ToolbarEntry&& e) {
ToolbarEntry::~ToolbarEntry() { clearList(); }
void ToolbarEntry::clearList() {
for (ToolbarItem* item: entries) {
delete item;
}
for (ToolbarItem* item: entries) { delete item; }
entries.clear();
}
@ -60,6 +58,13 @@ auto ToolbarEntry::removeItemById(int id) -> bool {
auto ToolbarEntry::insertItem(string item, int position) -> int {
auto* it = new ToolbarItem(std::move(item));
// This is required as the position generated by gtk_toolbar_get_drop_index
// is 1 indexed with the notable exception that the beginning of the toolbar
// is still 0.
// Hence, the possible input positions are [0, 2, 3, 4, ...] which need to be mapped
// to [0, 1, 2, 3, ...] to work consistently with the the entries vector.
if (position >= 1)
position--;
if (position >= static_cast<int>(entries.size())) {
entries.push_back(it);
return it->getId();

Loading…
Cancel
Save