Skip to content

Commit a007f92

Browse files
committed
Add insert and update functions
1 parent 6bb8791 commit a007f92

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/gui/menu_string_array.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
#include "gui/menu_string_array.hpp"
1818

19+
#include <boost/format.hpp>
20+
21+
#include "util/log.hpp"
1922
#include "gui/menu_item.hpp"
2023
#include "util/gettext.hpp"
2124

2225
StringArrayMenu::StringArrayMenu(std::vector<std::string>& items) :
2326
m_array_items(items),
24-
m_text()
27+
m_text(),
28+
m_selected_item(-1)
2529
{
2630
reload();
2731
}
@@ -32,13 +36,30 @@ StringArrayMenu::menu_action(MenuItem& item)
3236
int id = item.get_id();
3337
if (id >= 0)
3438
{
35-
m_array_items.erase(m_array_items.begin() + id);
36-
reload();
39+
m_text = m_array_items[id];
40+
m_selected_item = id;
41+
get_item_by_id(-2).set_text(str(boost::format(_("Selected item: %s")) % (m_selected_item >= 0 ? m_array_items[m_selected_item] : _("None"))));
3742
}
38-
else if (id == -2 && m_text.length() > 0)
43+
else if (m_text.length() > 0 && id < -2)
3944
{
40-
m_array_items.push_back(m_text);
45+
if (id == -3)
46+
{
47+
m_array_items.push_back(m_text);
48+
}
49+
else if (id == -4 && m_selected_item >= 0)
50+
{
51+
m_array_items.insert(m_array_items.begin() + m_selected_item + 1, m_text);
52+
}
53+
else if (id == -5 && m_selected_item >= 0)
54+
{
55+
m_array_items[m_selected_item] = m_text;
56+
}
57+
else if (id == -6 && m_selected_item >= 0)
58+
{
59+
m_array_items.erase(m_array_items.begin() + m_selected_item);
60+
}
4161
m_text = "";
62+
m_selected_item = -1;
4263
reload();
4364
}
4465
}
@@ -55,7 +76,12 @@ StringArrayMenu::reload()
5576
}
5677
add_hl();
5778
add_textfield(_("Text"), &m_text);
58-
add_entry(-2, _("Add"));
79+
add_entry(-2, str(boost::format(_("Selected item: %s")) % (m_selected_item >= 0 ? m_array_items[m_selected_item] : _("None"))));
80+
add_entry(-3, _("Add"));
81+
add_entry(-4, _("Insert"));
82+
add_entry(-5, _("Update"));
83+
add_entry(-6, _("Delete"));
84+
add_hl();
5985
add_back(_("OK"));
6086
}
6187
/* EOF */

src/gui/menu_string_array.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class StringArrayMenu final : public Menu
3030
private:
3131
std::vector<std::string>& m_array_items;
3232
std::string m_text;
33+
int m_selected_item;
3334

3435
void reload();
3536
private:

0 commit comments

Comments
 (0)