Move the splitting code into python

Less code and more robust
This commit is contained in:
Kovid Goyal 2022-03-20 14:40:02 +05:30
parent f952694ffd
commit 51e7c8c136
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 15 deletions

View File

@ -463,9 +463,9 @@ class Boss:
w = self.active_window_for_cwd
self._new_os_window(args, CwdRequest(w))
def new_os_window_with_wd(self, wd: Union[str, List[str]]) -> None:
def new_os_window_with_wd(self, wd: Union[str, List[str]], str_is_multiple_paths: bool = False) -> None:
if isinstance(wd, str):
wd = [wd]
wd = wd.split(os.pathsep) if str_is_multiple_paths else [wd]
for path in wd:
special_window = SpecialWindow(None, cwd=path)
self._new_os_window(special_window)
@ -1851,11 +1851,11 @@ class Boss:
def new_tab_with_cwd(self, *args: str) -> None:
self._create_tab(list(args), cwd_from=CwdRequest(self.active_window_for_cwd))
def new_tab_with_wd(self, wd: Union[str, List[str]]) -> None:
def new_tab_with_wd(self, wd: Union[str, List[str]], str_is_multiple_paths: bool = False) -> None:
if not self.os_window_map:
self.add_os_window()
if isinstance(wd, str):
wd = [wd]
wd = wd.split(os.pathsep) if str_is_multiple_paths else [wd]
for path in wd:
special_window = SpecialWindow(None, cwd=path)
self._new_tab(special_window)

View File

@ -1041,17 +1041,8 @@ process_cocoa_pending_actions(void) {
if (cocoa_pending_actions[TOGGLE_MACOS_SECURE_KEYBOARD_ENTRY]) { call_boss(toggle_macos_secure_keyboard_entry, NULL); }
if (cocoa_pending_actions[TOGGLE_FULLSCREEN]) { call_boss(toggle_fullscreen, NULL); }
if (cocoa_pending_actions_data.wd) {
#define C(a, f) \
if (cocoa_pending_actions[a]) { \
PyObject *wds = PyUnicode_FromString(cocoa_pending_actions_data.wd); \
PyObject *sep = PyUnicode_FromString(":"); \
PyObject *paths = PyUnicode_Split(wds, sep, -1); \
call_boss(f, "O", paths); \
Py_DECREF(paths); Py_DECREF(sep); Py_DECREF(wds); \
}
C(NEW_OS_WINDOW_WITH_WD, new_os_window_with_wd);
C(NEW_TAB_WITH_WD, new_tab_with_wd);
#undef C
if (cocoa_pending_actions[NEW_OS_WINDOW_WITH_WD]) { call_boss(new_os_window_with_wd, "sO", cocoa_pending_actions.wd, Py_True); }
if (cocoa_pending_actions[NEW_TAB_WITH_WD]) { call_boss(new_tab_with_wd, "sO", cocoa_pending_actions.wd, Py_True); }
free(cocoa_pending_actions_data.wd);
cocoa_pending_actions_data.wd = NULL;
}