Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
authorDaniel <blackrabbit256@gmail.com>2022-04-22 21:24:43 +1000
committerGitHub <noreply@github.com>2022-04-22 13:24:43 +0200
commitbbedc0bb19a75b937b49001e8845c6b73bccb25b (patch)
treecbb7fef3be7e45362b11cb1c228a6a8b33c02e90 /archinstall/lib
parent477b5b120e120766d789a691fce60cec843aff43 (diff)
Flexible order of menu options (#1078)
* Allow custom ordering of the menu entries * Update Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/menu/global_menu.py11
-rw-r--r--archinstall/lib/menu/selection_menu.py16
2 files changed, 18 insertions, 9 deletions
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