nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit aa108be09539e60529f18eb0cd2bbb51b2522223
parent 9dcdbe1401b5533918eac1a59c21263ceb23d4a5
Author: Samuel Walladge <samuel@swalladge.id.au>
Date:   Sat, 11 Feb 2017 16:41:49 +1030

fix sort mode resetting on notes list update

Diffstat:
Msimplenote_cli/notes_db.py | 5++---
Msimplenote_cli/sncli.py | 11++++++++---
Msimplenote_cli/view_titles.py | 4++--
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/simplenote_cli/notes_db.py b/simplenote_cli/notes_db.py @@ -89,7 +89,7 @@ def filtered_notes_sort(self, filtered_notes, sort_mode='date'): pinned = self.config.get_config('pinned_ontop') utils.sort_notes_by_tags(filtered_notes, pinned_ontop=pinned) - def filter_notes(self, search_string=None, search_mode='gstyle'): + def filter_notes(self, search_string=None, search_mode='gstyle', sort_mode='date'): """Return list of notes filtered with search string. Based on the search mode that has been selected in self.config, @@ -109,8 +109,7 @@ def filter_notes(self, search_string=None, search_mode='gstyle'): filtered_notes, match_regexp, active_notes = \ self.filter_notes_regex(search_string) - self.filtered_notes_sort(filtered_notes, - self.config.get_config('sort_mode')) + self.filtered_notes_sort(filtered_notes, sort_mode) return filtered_notes, match_regexp, active_notes diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -20,6 +20,7 @@ def __init__(self, do_server_sync, verbose=False, config_file=None): self.verbose = verbose self.do_gui = False force_full_sync = False + self.current_sort_mode = self.config.get_config('sort_mode') if not os.path.exists(self.config.get_config('db_path')): os.mkdir(self.config.get_config('db_path')) @@ -268,7 +269,8 @@ def gui_update_view(self): except IndexError as e: cur_key = None pass - self.view_titles.update_note_list(self.view_titles.search_string) + + self.view_titles.update_note_list(self.view_titles.search_string, sort_mode=self.current_sort_mode) self.view_titles.focus_note(cur_key) if self.gui_body_get().__class__ == view_note.ViewNote: @@ -339,7 +341,7 @@ def gui_search_input(self, args, search_string): self.search_direction = args[1] self.view_note.search_note_view_next(search_string=search_string, search_mode=args[0]) else: - self.view_titles.update_note_list(search_string, args[0]) + self.view_titles.update_note_list(search_string, args[0], sort_mode=self.current_sort_mode) self.gui_body_set(self.view_titles) def gui_version_input(self, args, version): @@ -845,25 +847,28 @@ def gui_frame_keypress(self, size, key): if self.gui_body_get().__class__ != view_titles.ViewTitles: return key - self.view_titles.update_note_list(None) + self.view_titles.update_note_list(None, sort_mode=self.current_sort_mode) self.gui_body_set(self.view_titles) elif key == self.config.get_keybind('sort_date'): if self.gui_body_get().__class__ != view_titles.ViewTitles: return key + self.current_sort_mode = 'date' self.view_titles.sort_note_list('date') elif key == self.config.get_keybind('sort_alpha'): if self.gui_body_get().__class__ != view_titles.ViewTitles: return key + self.current_sort_mode = 'alpha' self.view_titles.sort_note_list('alpha') elif key == self.config.get_keybind('sort_tags'): if self.gui_body_get().__class__ != view_titles.ViewTitles: return key + self.current_sort_mode = 'tags' self.view_titles.sort_note_list('tags') elif key == self.config.get_keybind('copy_note_text'): diff --git a/simplenote_cli/view_titles.py b/simplenote_cli/view_titles.py @@ -17,10 +17,10 @@ def __init__(self, config, args): super(ViewTitles, self).__init__( urwid.SimpleFocusListWalker(self.get_note_titles())) - def update_note_list(self, search_string, search_mode='gstyle'): + def update_note_list(self, search_string, search_mode='gstyle', sort_mode='date'): self.search_string = search_string self.note_list, self.match_regex, self.all_notes_cnt = \ - self.ndb.filter_notes(self.search_string, search_mode) + self.ndb.filter_notes(self.search_string, search_mode, sort_mode=sort_mode) self.body[:] = \ urwid.SimpleFocusListWalker(self.get_note_titles()) if len(self.note_list) == 0: