Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/menu/selection_menu.py
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/menu/selection_menu.py
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/menu/selection_menu.py')
-rw-r--r--archinstall/lib/menu/selection_menu.py16
1 files changed, 15 insertions, 1 deletions
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