From bbedc0bb19a75b937b49001e8845c6b73bccb25b Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 22 Apr 2022 21:24:43 +1000 Subject: Flexible order of menu options (#1078) * Allow custom ordering of the menu entries * Update Co-authored-by: Daniel Girtler --- archinstall/lib/menu/global_menu.py | 11 +++-------- archinstall/lib/menu/selection_menu.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/menu/global_menu.py b/archinstall/lib/menu/global_menu.py index fba0ce29..0c7c1c20 100644 --- a/archinstall/lib/menu/global_menu.py +++ b/archinstall/lib/menu/global_menu.py @@ -43,8 +43,7 @@ class GlobalMenu(GeneralMenu): Selector( _('Select Archinstall language'), lambda x: self._select_archinstall_language('English'), - default='English', - enabled=True) + default='English') self._menu_options['keyboard-layout'] = \ Selector(_('Select keyboard layout'), lambda preset: select_language('us',preset), default='us') self._menu_options['mirror-region'] = \ @@ -153,24 +152,20 @@ class GlobalMenu(GeneralMenu): lambda preset: self._select_ntp(preset), default=True) self._menu_options['__separator__'] = \ - Selector( - '', - enabled=True) + Selector('') self._menu_options['save_config'] = \ Selector( _('Save configuration'), lambda preset: save_config(self._data_store), - enabled=True, no_store=True) self._menu_options['install'] = \ Selector( self._install_text(), exec_func=lambda n,v: True if len(self._missing_configs()) == 0 else False, preview_func=self._prev_install_missing_config, - enabled=True, no_store=True) - self._menu_options['abort'] = Selector(_('Abort'), exec_func=lambda n,v:exit(1), enabled=True) + self._menu_options['abort'] = Selector(_('Abort'), exec_func=lambda n,v:exit(1)) def _update_install_text(self, name :str = None, result :Any = None): text = self._install_text() diff --git a/archinstall/lib/menu/selection_menu.py b/archinstall/lib/menu/selection_menu.py index ca48fda2..37e54685 100644 --- a/archinstall/lib/menu/selection_menu.py +++ b/archinstall/lib/menu/selection_menu.py @@ -181,6 +181,7 @@ class GeneralMenu: ;type preview_size: float (range 0..1) """ + self._enabled_order = [] self._translation = Translation.load_nationalization() self.is_context_mgr = False self._data_store = data_store if data_store is not None else {} @@ -239,10 +240,15 @@ class GeneralMenu: if arg is not None: self._menu_options[selector_name].set_current_selection(arg) + def _update_enabled_order(self, selector_name: str): + self._enabled_order.append(selector_name) + def enable(self, selector_name :str, omit_if_set :bool = False , mandatory :bool = False): """ activates menu options """ if self._menu_options.get(selector_name, None): self._menu_options[selector_name].set_enabled(True) + self._update_enabled_order(selector_name) + if mandatory: self._menu_options[selector_name].set_mandatory(True) self.synch(selector_name,omit_if_set) @@ -372,7 +378,15 @@ class GeneralMenu: if self._verify_selection_enabled(name): enabled_menus[name] = selection - return enabled_menus + # sort the enabled menu by the order we enabled them in + # we'll add the entries that have been enabled via the selector constructor at the top + enabled_keys = [i for i in enabled_menus.keys() if i not in self._enabled_order] + # and then we add the ones explicitly enabled by the enable function + enabled_keys += [i for i in self._enabled_order if i in enabled_menus.keys()] + + ordered_menus = {k: enabled_menus[k] for k in enabled_keys} + + return ordered_menus def option(self,name :str) -> Selector: # TODO check inexistent name -- cgit v1.2.3-70-g09d2