Add ability to rename user flags
This commit is contained in:
parent
65cf92298d
commit
0ef7eba6db
|
@ -529,6 +529,22 @@ void action_add_new_user_flag() {
|
|||
userFlags.push_back(UserFlag::create(db, name));
|
||||
}
|
||||
|
||||
void action_rename_user_flag() {
|
||||
std::vector<std::string> names;
|
||||
for(const UserFlag &flag: userFlags) {
|
||||
names.push_back(flag.name);
|
||||
}
|
||||
int index = get_selection("Select flag to rename", names);
|
||||
if(index < 0)
|
||||
return;
|
||||
UserFlag &flag = userFlags.at(index);
|
||||
std::string name = edit_string("Enter new name", std::string(), flag.name);
|
||||
if(name.empty())
|
||||
return;
|
||||
flag.name = name;
|
||||
flag.save(db);
|
||||
}
|
||||
|
||||
void action_manage_user_flags() {
|
||||
bool done = false;
|
||||
|
||||
|
@ -551,6 +567,7 @@ void action_manage_user_flags() {
|
|||
|
||||
std::vector<action> actions = {
|
||||
{TERMPAINT_EV_KEY, "F2", 0, action_add_new_user_flag, "Add new user flag"},
|
||||
{TERMPAINT_EV_KEY, "F3", 0, action_rename_user_flag, "Rename user flag"},
|
||||
{TERMPAINT_EV_KEY, "Escape", 0, [&]{ done = true; }, "Stop user flag management"},
|
||||
{TERMPAINT_EV_KEY, "ArrowUp", 0, [&]{ if(selected_channel > 0) selected_channel--; }, "Previous channel"},
|
||||
{TERMPAINT_EV_KEY, "ArrowDown", 0, [&]{ if(selected_channel < channels.size()) selected_channel++; }, "Next channel"},
|
||||
|
|
11
tui.cpp
11
tui.cpp
|
@ -308,7 +308,7 @@ Button operator&(const Button &a, const Button &b)
|
|||
return Button((int)a & (int)b);
|
||||
}
|
||||
|
||||
std::string get_string(const std::string &caption, const std::string &text, const Align align)
|
||||
std::string edit_string(const std::string &caption, const std::string &text, const std::string &value, const Align align)
|
||||
{
|
||||
const int cols = termpaint_surface_width(surface);
|
||||
const int rows = termpaint_surface_height(surface);
|
||||
|
@ -322,8 +322,8 @@ std::string get_string(const std::string &caption, const std::string &text, cons
|
|||
|
||||
const int input_row = y + 1 + !text.empty();
|
||||
|
||||
std::string input;
|
||||
size_t input_pos = 0;
|
||||
std::string input = value;
|
||||
size_t input_pos = value.size();
|
||||
termpaint_terminal_set_cursor_visible(terminal, true);
|
||||
termpaint_terminal_set_cursor_style(terminal, TERMPAINT_CURSOR_STYLE_BAR, true);
|
||||
|
||||
|
@ -380,6 +380,11 @@ std::string get_string(const std::string &caption, const std::string &text, cons
|
|||
return input;
|
||||
}
|
||||
|
||||
std::string get_string(const std::string &caption, const std::string &text, const Align align)
|
||||
{
|
||||
return edit_string(caption, text, std::string(), align);
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string &str, const char delim, const unsigned int max_splits=0)
|
||||
{
|
||||
std::vector<std::string> parts;
|
||||
|
|
1
tui.h
1
tui.h
|
@ -81,6 +81,7 @@ std::string text_wrap(const std::string &text, const size_t desired_width);
|
|||
Button message_box(const std::string &caption, const std::string &text, const Button buttons=Button::Ok, const Button default_button=Button::Ok, const Align align=Align::Center);
|
||||
void draw_box_with_caption(int x, int y, int w, int h, const std::string &caption=std::string());
|
||||
int get_selection(const std::string &caption, const std::vector<std::string> &choices, size_t selected=0, const Align align=Align::Center);
|
||||
std::string edit_string(const std::string &caption, const std::string &text, const std::string &value, const Align align=Align::Center);
|
||||
std::string get_string(const std::string &caption, const std::string &text=std::string(), const Align align=Align::Center);
|
||||
|
||||
struct progress_info;
|
||||
|
|
10
yt.cpp
10
yt.cpp
|
@ -15,6 +15,16 @@ struct yt_config yt_config;
|
|||
|
||||
UserFlag::UserFlag(sqlite3_stmt *row): id(get_int(row, 0)), name(get_string(row, 1)) {}
|
||||
|
||||
void UserFlag::save(sqlite3 *db) const
|
||||
{
|
||||
sqlite3_stmt *query;
|
||||
SC(sqlite3_prepare_v2(db, "UPDATE user_flags SET name = ?2 WHERE flagId = ?1;", -1, &query, nullptr));
|
||||
SC(sqlite3_bind_int(query, 1, id));
|
||||
SC(sqlite3_bind_text(query, 2, name.c_str(), -1, SQLITE_TRANSIENT));
|
||||
SC(sqlite3_step(query));
|
||||
SC(sqlite3_finalize(query));
|
||||
}
|
||||
|
||||
UserFlag UserFlag::create(sqlite3 *db, const std::string &name)
|
||||
{
|
||||
int next_flag = next_free(db);
|
||||
|
|
Loading…
Reference in New Issue