High frequency load/save bugfix

Editing widgets hidden if freqman category is empty
Textentry now trims strings up to cursor
This commit is contained in:
furrtek 2017-06-23 00:13:13 +01:00
parent 08391bba4f
commit c922a56b6d
4 changed files with 43 additions and 12 deletions

View File

@ -70,7 +70,7 @@ bool load_freqman_file(std::string& file_stem, freqman_db &db) {
// Read frequency
pos += 2;
value = strtol(pos, nullptr, 10);
value = strtoll(pos, nullptr, 10);
// Read description until , or LF
pos = strstr(file_data, "d=");
@ -99,12 +99,14 @@ bool load_freqman_file(std::string& file_stem, freqman_db &db) {
bool save_freqman_file(std::string& file_stem, freqman_db &db) {
File freqman_file;
std::string item_string;
rf::Frequency f;
if (!create_freqman_file(file_stem, freqman_file))
return false;
for (size_t n = 0; n < db.entries.size(); n++) {
item_string = "f=" + to_string_dec_uint(db.entries[n].value);
f = db.entries[n].value;
item_string = "f=" + to_string_dec_uint(f / 1000) + to_string_dec_uint(f % 1000UL, 3, '0'); // Please forgive me
if (db.entries[n].description.size())
item_string += ",d=" + db.entries[n].description;

View File

@ -106,13 +106,11 @@ void FreqManBaseView::change_category(int32_t category_id) {
void FreqManBaseView::refresh_list() {
if (!database.entries.size()) {
menu_view.hidden(true);
text_empty.hidden(false);
display.fill_rectangle(menu_view.screen_rect(), Color::black());
return;
if (on_refresh_widgets)
on_refresh_widgets(true);
} else {
menu_view.hidden(false);
text_empty.hidden(true);
if (on_refresh_widgets)
on_refresh_widgets(false);
menu_view.clear();
@ -142,8 +140,8 @@ void FrequencySaveView::on_save_name() {
void FrequencySaveView::on_save_timestamp() {
database.entries.push_back({ value_, "", str_timestamp });
nav_.pop();
save_freqman_file(file_list[current_category_id], database);
nav_.pop();
}
void FrequencySaveView::on_tick_second() {
@ -197,21 +195,34 @@ FrequencySaveView::FrequencySaveView(
};
}
void FrequencyLoadView::refresh_widgets(const bool v) {
menu_view.hidden(v);
text_empty.hidden(!v);
//display.fill_rectangle(menu_view.screen_rect(), Color::black());
set_dirty();
}
FrequencyLoadView::FrequencyLoadView(
NavigationView& nav
) : FreqManBaseView(nav, options_category)
{
on_refresh_widgets = [this](bool v) {
refresh_widgets(v);
};
add_children({
&menu_view,
&text_empty
});
// Resize menu view to fill screen
menu_view.set_parent_rect({ 0, 3 * 8, 240, 29 * 8 });
// Just to allow exit on left
menu_view.on_left = [&nav, this]() {
nav.pop();
};
text_empty.hidden(true);
change_category(0);
refresh_list();
@ -251,6 +262,16 @@ void FrequencyManagerView::on_delete() {
refresh_list();
}
void FrequencyManagerView::refresh_widgets(const bool v) {
button_edit_freq.hidden(v);
button_edit_desc.hidden(v);
button_delete.hidden(v);
menu_view.hidden(v);
text_empty.hidden(!v);
//display.fill_rectangle(menu_view.screen_rect(), Color::black());
set_dirty();
}
FrequencyManagerView::~FrequencyManagerView() {
//save_freqman_file(file_list[current_category_id], database);
}
@ -259,6 +280,10 @@ FrequencyManagerView::FrequencyManagerView(
NavigationView& nav
) : FreqManBaseView(nav, options_category)
{
on_refresh_widgets = [this](bool v) {
refresh_widgets(v);
};
add_children({
&labels,
&button_new_category,
@ -274,7 +299,6 @@ FrequencyManagerView::FrequencyManagerView(
nav.pop();
};
text_empty.hidden(true);
change_category(0);
refresh_list();
@ -283,6 +307,7 @@ FrequencyManagerView::FrequencyManagerView(
};
button_new_category.on_select = [this, &nav](Button&) {
desc_buffer = "";
on_new_category(nav);
};

View File

@ -52,6 +52,7 @@ protected:
options_t categories { };
std::function<void(int32_t category_id)> on_change_category { nullptr };
std::function<void(void)> on_select_frequency { nullptr };
std::function<void(bool)> on_refresh_widgets { nullptr };
std::vector<std::string> file_list { };
int32_t current_category_id { 0 };
@ -133,6 +134,7 @@ public:
FrequencyLoadView(NavigationView& nav);
private:
void refresh_widgets(const bool v);
};
class FrequencyManagerView : public FreqManBaseView {
@ -143,6 +145,7 @@ public:
private:
std::string desc_buffer { };
void refresh_widgets(const bool v);
void on_edit_freq(rf::Frequency f);
void on_edit_desc(NavigationView& nav);
void on_new_category(NavigationView& nav);

View File

@ -100,7 +100,7 @@ TextEntryView::TextEntryView(
_str->erase(std::find_if(_str->rbegin(), _str->rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _str->end());
_cursor_pos = _str->length();
_str->resize(_max_length, 0);
_str->reserve(_max_length);
add_children({
&text_input,
@ -108,6 +108,7 @@ TextEntryView::TextEntryView(
});
button_ok.on_select = [this, &nav](Button&) {
_str->substr(0, _cursor_pos);
if (on_changed)
on_changed(_str);
nav.pop();