Skip to content

Commit

Permalink
WIP - Launchers in Settings
Browse files Browse the repository at this point in the history
Add new 'bash.launchers' entry in bass.settings

Remove references to provisional file backend from bass.dirs and other places
  • Loading branch information
BGazotti committed Feb 6, 2024
1 parent 48fb9f8 commit 13057ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Mopy/bash/basher/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@
'bash.mods.export.skip': '',
'bash.mods.export.deprefix': '',
'bash.mods.export.skipcomments': False,
#--Custom Launchers
'bash.launchers': {},
#--Wrye Bash: Saves
'bash.saves.cols': ['File', 'Modified', 'Size', 'PlayTime', 'Player',
'Cell'],
Expand Down
35 changes: 21 additions & 14 deletions Mopy/bash/basher/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ def __init__(self, parent, page_desc):

# List of existing launchers, plus <New> item
# display name is just head of launcher path
#TODO swap to that listbox that can display icons
self._launcher_listbox = ListBox(self, isSort=True, isHScroll=True,
onSelect=self._handle_launcher_selected)

Expand Down Expand Up @@ -1610,7 +1611,10 @@ def __init__(self, parent, page_desc):
])]).apply_to(self)

def _populate_launcher_listbox(self):
self._launcher_listbox.lb_set_items(self.___filter())
items = self.___filter()
for custom_launcher in bass.settings['bash.launchers']:
items.append(custom_launcher)
self._launcher_listbox.lb_set_items(items)
#TODO retrieve launchers from settings

def ___filter(self): ##: todo temp we want to include all sb links that can be hidden
Expand All @@ -1628,18 +1632,20 @@ def _handle_launcher_selected(self, index: int, selected_str):
# make name and args not editable;
# change remove to reset which will restore the default path

if selected_str in BashStatusBar.all_sb_links:
if selected_str in BashStatusBar.all_sb_links: #TODO diff stock/custom
self._launcher_name_txt.editable = False
self._launcher_args_txt.editable = False
self._remove_launcher_btn.button_label = _('Reset')
self._remove_launcher_btn.tooltip = _('Restore default settings')
self._remove_launcher_btn.enabled = True #FIXME might not need to
# enable if the path wasn't changed, but here it is
selected_launcher = BashStatusBar.all_sb_links[selected_str]
else:
selected_launcher = bass.settings['bash.launchers'][selected_str]

# TODO join preconfigured and custom launchers
selected_launcher = BashStatusBar.all_sb_links[selected_str]
# copy launcher details to textfields
self._launcher_name_txt.text_content = selected_str
# TODO fix custom launchers being just tuples and not having app_path
self._launcher_path_txt.text_content= selected_launcher.app_path.s
self._launcher_args_txt.text_content = shlex.join(selected_launcher.app_cli(()))

Expand Down Expand Up @@ -1676,19 +1682,21 @@ def _new_launcher_mode(self, disable: bool = False):
# disable nonsense. It is, however, much more succinct like this. Just
# know we're toggling that alternate text mode.

## TODO validation/error handling
def _save_launcher(self):
# get values to save from text boxes.
# If path of current launcher is invalid, like <new>, show error dialog
# Update list after confirmed save.
return
launcher = launchers.Launcher(self._launcher_path_txt.text_content,
self._launcher_args_txt.text_content)
launcher_name = self._launcher_name_txt.text_content
if launcher_name in (_(u'<New...>'), u''): #TODO error out if name
# already exists, prompt user to edit existing instead
return
launchers.save_launcher(launcher_name, launcher)
self._populate_launcher_listbox()
launcher_path = self._launcher_path_txt.text_content
launcher_args = self._launcher_args_txt.text_content

if not launcher_name in BashStatusBar.all_sb_links:
bass.settings['bash.launchers'][launcher_name] = [launcher_path,
launcher_args,]
self._new_launcher_mode(True)
self._clear_textfields()
self._populate_launcher_listbox()

def _remove_or_cancel(self):
from ..gui import popups
Expand All @@ -1700,11 +1708,10 @@ def _remove_or_cancel(self):
if not popups.askYes(parent=self, message=_('Are you sure?'), title=_('Remove Launcher'), default_is_yes=False):
# user canceled in confirm dialog
return
return
launcher_name = self._launcher_name_txt.text_content
if launcher_name in (_(u'<New...>'), u''): # again, can't do that
return
launchers.remove_launcher(launcher_name)
del bass.settings['bash.launchers'][launcher_name]
self._clear_textfields()
self._populate_launcher_listbox()

Expand Down

0 comments on commit 13057ca

Please sign in to comment.