From dee093db579c1e28c4695351c0e16eda968291a2 Mon Sep 17 00:00:00 2001 From: Sebastian Wiesner Date: Mon, 29 Dec 2025 22:33:57 +0100 Subject: [PATCH] Extract duplicated code into single helper Extract duplicated code from the two different menu item hooks into a single helper function, and then inline _make_item, as it's only used once now. --- dist/linux/ghostty_nautilus.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/dist/linux/ghostty_nautilus.py b/dist/linux/ghostty_nautilus.py index e993d0aaa..80ec84ac3 100644 --- a/dist/linux/ghostty_nautilus.py +++ b/dist/linux/ghostty_nautilus.py @@ -42,27 +42,24 @@ def get_paths_to_open(files): return paths -class OpenInGhosttyAction(GObject.GObject, Nautilus.MenuProvider): - def _make_item(self, name, paths): +def get_items_for_files(name, files): + paths = get_paths_to_open(files) + if paths: item = Nautilus.MenuItem(name=name, label='Open in Ghostty', icon='com.mitchellh.ghostty') item.connect('activate', open_in_ghostty_activated, paths) - return item + return [item] + else: + return [] + +class OpenInGhosttyAction(GObject.GObject, Nautilus.MenuProvider): def get_file_items(self, *args): # Nautilus 3.0 API passes args (window, files), 4.0 API just passes files files = args[0] if len(args) == 1 else args[1] - paths = get_paths_to_open(files) - if paths: - return [self._make_item(name='GhosttyNautilus::open_in_ghostty', paths=paths)] - else: - return [] + return get_items_for_files('GhosttyNautilus::open_in_ghostty', files) def get_background_items(self, *args): # Nautilus 3.0 API passes args (window, file), 4.0 API just passes file file = args[0] if len(args) == 1 else args[1] - paths = get_paths_to_open([file]) - if paths: - return [self._make_item(name='GhosttyNautilus::open_folder_in_ghostty', paths=paths)] - else: - return [] + return get_items_for_files('GhosttyNautilus::open_folder_in_ghostty', [file])