Make the recent list functional

This commit is contained in:
Kovid Goyal 2021-08-07 15:31:03 +05:30
parent 3287798efe
commit a597a8d86b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 0 deletions

View File

@ -201,6 +201,9 @@ class Theme:
def save_in_dir(self, dirpath: str) -> None:
atomic_save(self.raw.encode('utf-8'), os.path.join(dirpath, f'{self.name}.conf'))
def save_in_conf(self, confdir: str) -> None:
atomic_save(self.raw.encode('utf-8'), os.path.join(confdir, 'current-theme.conf'))
class Themes:

View File

@ -146,6 +146,13 @@ class ThemesHandler(Handler):
self.line_edit = LineEdit()
self.tabs = tuple('all dark light recent'.split())
def update_recent(self) -> None:
r = list(self.cached_values.get('recent', ()))
if self.themes_list:
name = self.themes_list.current_theme.name
r = [name] + [x for x in r if x != name]
self.cached_values['recent'] = r[:20]
def enforce_cursor_state(self) -> None:
self.cmd.set_cursor_visible(self.state == State.fetching)
@ -452,6 +459,12 @@ class ThemesHandler(Handler):
return
if key_event.matches('p'):
self.themes_list.current_theme.save_in_dir(config_dir)
self.update_recent()
self.quit_loop(0)
return
if key_event.matches('m'):
self.themes_list.current_theme.save_in_conf(config_dir)
self.update_recent()
self.quit_loop(0)
return
# }}}