From c922a56b6d97b21e45e191aae526499298f77255 Mon Sep 17 00:00:00 2001 From: furrtek Date: Fri, 23 Jun 2017 00:13:13 +0100 Subject: [PATCH] High frequency load/save bugfix Editing widgets hidden if freqman category is empty Textentry now trims strings up to cursor --- firmware/application/freqman.cpp | 6 ++-- firmware/application/ui_freqman.cpp | 43 +++++++++++++++++++++------ firmware/application/ui_freqman.hpp | 3 ++ firmware/application/ui_textentry.cpp | 3 +- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/firmware/application/freqman.cpp b/firmware/application/freqman.cpp index a9c3eea4..930655b8 100644 --- a/firmware/application/freqman.cpp +++ b/firmware/application/freqman.cpp @@ -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; diff --git a/firmware/application/ui_freqman.cpp b/firmware/application/ui_freqman.cpp index 2c432804..1b27a943 100644 --- a/firmware/application/ui_freqman.cpp +++ b/firmware/application/ui_freqman.cpp @@ -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); }; diff --git a/firmware/application/ui_freqman.hpp b/firmware/application/ui_freqman.hpp index 6e8c6096..87e74f08 100644 --- a/firmware/application/ui_freqman.hpp +++ b/firmware/application/ui_freqman.hpp @@ -52,6 +52,7 @@ protected: options_t categories { }; std::function on_change_category { nullptr }; std::function on_select_frequency { nullptr }; + std::function on_refresh_widgets { nullptr }; std::vector 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); diff --git a/firmware/application/ui_textentry.cpp b/firmware/application/ui_textentry.cpp index 8100ac8c..0e51e271 100644 --- a/firmware/application/ui_textentry.cpp +++ b/firmware/application/ui_textentry.cpp @@ -100,7 +100,7 @@ TextEntryView::TextEntryView( _str->erase(std::find_if(_str->rbegin(), _str->rend(), std::not1(std::ptr_fun(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();