diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-07-03 16:47:47 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-07-03 16:47:47 +0300 |
| commit | c882b4ff71103609ea8cb6fc646129113c9884f8 (patch) | |
| tree | db642476bf318e0f36a3e6521ab0471a77cfc706 | |
| parent | 3682560cf34cda253ca9454756e4830095f25d1a (diff) | |
| download | fungus-launcher-c882b4ff71103609ea8cb6fc646129113c9884f8.tar.gz fungus-launcher-c882b4ff71103609ea8cb6fc646129113c9884f8.tar.xz | |
move shortcut stuff to a context menu item, checkbox-based UX was rather weird
| -rw-r--r-- | fungus/add_game_dialog.py | 47 | ||||
| -rw-r--r-- | fungus/main_window.py | 85 |
2 files changed, 75 insertions, 57 deletions
diff --git a/fungus/add_game_dialog.py b/fungus/add_game_dialog.py index 36bc115..a1161f3 100644 --- a/fungus/add_game_dialog.py +++ b/fungus/add_game_dialog.py @@ -22,8 +22,6 @@ from fungus.logger import get_logger log = get_logger(__name__) from fungus.constants import ( - app_dir, - desktop_dir, fungus_png, fungus_run, icons_dir, @@ -120,14 +118,6 @@ class AddGame(EntryTooltipMixin, Gtk.Dialog): self.grid_runner.set_margin_end(10) self.grid_runner.set_margin_top(10) - self.grid_shortcut = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL) - self.grid_shortcut.set_row_spacing(10) - self.grid_shortcut.set_column_spacing(10) - self.grid_shortcut.set_margin_start(10) - self.grid_shortcut.set_margin_end(10) - self.grid_shortcut.set_margin_top(10) - self.grid_shortcut.set_margin_bottom(10) - self.grid_shortcut_icon = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL) self.grid_shortcut_icon.set_row_spacing(10) self.grid_shortcut_icon.set_column_spacing(10) @@ -270,19 +260,6 @@ class AddGame(EntryTooltipMixin, Gtk.Dialog): self.button_run.connect("clicked", self.on_button_run_clicked) self.button_run.set_tooltip_text("Run a file inside the prefix") - # Button for creating shortcut - self.label_shortcut = Gtk.Label(label="Shortcut") - self.label_shortcut.set_margin_start(10) - self.label_shortcut.set_margin_end(10) - self.label_shortcut.set_margin_top(10) - self.label_shortcut.set_halign(Gtk.Align.START) - self.checkbox_shortcut_desktop = Gtk.CheckButton(label="Desktop") - self.checkbox_shortcut_desktop.set_tooltip_text( - "Add or remove a shortcut from the Desktop.") - self.checkbox_shortcut_appmenu = Gtk.CheckButton(label="App Menu") - self.checkbox_shortcut_appmenu.set_tooltip_text( - "Add or remove a shortcut from the Application Menu.") - # Button for selection shortcut icon self.button_shortcut_icon = Gtk.Button() self.button_shortcut_icon.set_size_request(120, -1) @@ -362,23 +339,15 @@ class AddGame(EntryTooltipMixin, Gtk.Dialog): self.grid_runner.attach(self.combobox_runner, 0, 1, 1, 1) self.combobox_runner.set_hexpand(True) - self.label_shortcut.set_hexpand(True) - self.grid_shortcut.add(self.checkbox_shortcut_desktop) - self.grid_shortcut.add(self.checkbox_shortcut_appmenu) self.grid_shortcut_icon.add(self.button_shortcut_icon) self.grid_shortcut_icon.set_valign(Gtk.Align.CENTER) - self.box_shortcut = Gtk.Box() - self.box_shortcut.pack_start(self.grid_shortcut, False, False, 0) - self.box_shortcut.pack_end(self.grid_shortcut_icon, False, False, 0) - page1.add(self.grid_launcher) page1.add(self.grid_title) page1.add(self.grid_path) page1.add(self.grid_prefix) page1.add(self.grid_runner) - page1.add(self.label_shortcut) - page1.add(self.box_shortcut) + page1.add(self.grid_shortcut_icon) self.grid_protonfix.attach(self.label_protonfix, 0, 0, 1, 1) self.grid_protonfix.attach(self.entry_protonfix, 0, 1, 3, 1) @@ -694,20 +663,6 @@ class AddGame(EntryTooltipMixin, Gtk.Dialog): else: dialog.set_preview_widget_active(False) - def check_existing_shortcut(self): - """Mark the desktop/appmenu checkboxes if a shortcut already exists.""" - title = self.entry_title.get_text().strip() - if not title: - return - - # Build a minimal Game-like object for the lookup - gameid = format_title(title) - desktop_exists = os.path.exists(f"{desktop_dir}/{gameid}.desktop") - appmenu_exists = os.path.exists(f"{app_dir}/{gameid}.desktop") - - self.checkbox_shortcut_desktop.set_active(desktop_exists) - self.checkbox_shortcut_appmenu.set_active(appmenu_exists) - def on_button_winecfg_clicked(self, widget): """Launch winecfg inside the Wine prefix via fungus_run.""" self.set_sensitive(False) diff --git a/fungus/main_window.py b/fungus/main_window.py index a496ba5..fe52421 100644 --- a/fungus/main_window.py +++ b/fungus/main_window.py @@ -25,6 +25,8 @@ from fungus.constants import ( icons_dir, umu_run, fungus_version, + desktop_dir, + app_dir, ) from fungus.dialogs import ( GameDirectoriesNotConfiguredDialog, @@ -116,6 +118,8 @@ class Main(Gtk.ApplicationWindow): self.menu_item_delete.connect("activate", self.on_context_menu_delete) self.context_menu.append(self.menu_item_delete) + self.context_menu.append(Gtk.SeparatorMenuItem()) + self.menu_item_hide = Gtk.MenuItem(label="Hide") self.menu_item_hide.connect("activate", self.on_context_menu_hide) self.context_menu.append(self.menu_item_hide) @@ -124,6 +128,8 @@ class Main(Gtk.ApplicationWindow): self.menu_item_favorite.connect("activate", self.on_context_menu_favorite) self.context_menu.append(self.menu_item_favorite) + self.context_menu.append(Gtk.SeparatorMenuItem()) + self.menu_item_game = Gtk.MenuItem(label="Open game location") self.menu_item_game.connect("activate", self.on_context_menu_game) self.context_menu.append(self.menu_item_game) @@ -132,6 +138,16 @@ class Main(Gtk.ApplicationWindow): self.menu_item_prefix.connect("activate", self.on_context_menu_prefix) self.context_menu.append(self.menu_item_prefix) + self.context_menu.append(Gtk.SeparatorMenuItem()) + + self.menu_item_desktop = Gtk.MenuItem(label="Add to Desktop") + self.menu_item_desktop.connect("activate", self.on_context_menu_desktop) + self.context_menu.append(self.menu_item_desktop) + + self.menu_item_appmenu = Gtk.MenuItem(label="Add to App Menu") + self.menu_item_appmenu.connect("activate", self.on_context_menu_appmenu) + self.context_menu.append(self.menu_item_appmenu) + self.context_menu.show_all() self.small_interface() @@ -351,6 +367,19 @@ class Main(Gtk.ApplicationWindow): self.menu_item_prefix.set_sensitive(False) self.current_prefix = None + # Shortcut menu items — toggle label based on existence + desktop_path = f"{desktop_dir}/{game.gameid}.desktop" + appmenu_path = f"{app_dir}/{game.gameid}.desktop" + if os.path.exists(desktop_path): + self.menu_item_desktop.get_child().set_text("Remove from Desktop") + else: + self.menu_item_desktop.get_child().set_text("Add to Desktop") + + if os.path.exists(appmenu_path): + self.menu_item_appmenu.get_child().set_text("Remove from App Menu") + else: + self.menu_item_appmenu.get_child().set_text("Add to App Menu") + self.context_menu.popup_at_pointer(event) # ── Game List Rendering ────────────────────────────────────────────── @@ -576,6 +605,44 @@ class Main(Gtk.ApplicationWindow): return subprocess.run(["xdg-open", self.current_prefix], check=True) + def on_context_menu_desktop(self, menu_item): + """Toggle the desktop shortcut for the selected game.""" + selected = self.flowbox.get_selected_children() + if not selected: + return + + game = selected[0].game + if not game: + return + + desktop_path = f"{desktop_dir}/{game.gameid}.desktop" + if os.path.exists(desktop_path): + remove_shortcut(game, "desktop") + else: + icon_final = f'{icons_dir}/{game.gameid}.ico' + create_shortcut(game, True, "desktop", "", icon_final) + + self.update_list() + + def on_context_menu_appmenu(self, menu_item): + """Toggle the application menu shortcut for the selected game.""" + selected = self.flowbox.get_selected_children() + if not selected: + return + + game = selected[0].game + if not game: + return + + appmenu_path = f"{app_dir}/{game.gameid}.desktop" + if os.path.exists(appmenu_path): + remove_shortcut(game, "appmenu") + else: + icon_final = f'{icons_dir}/{game.gameid}.ico' + create_shortcut(game, True, "appmenu", "", icon_final) + + self.update_list() + # ── Button Handlers (Add / Edit / Delete / Play / Kill / Settings) ─── def on_button_settings_clicked(self, widget): @@ -888,19 +955,17 @@ class Main(Gtk.ApplicationWindow): playtime, hidden, favorite, ) - desktop_shortcut_state = add_game_dialog.checkbox_shortcut_desktop.get_active() - appmenu_shortcut_state = add_game_dialog.checkbox_shortcut_appmenu.get_active() - icon_temp = os.path.expanduser(add_game_dialog.icon_temp) icon_final = f'{add_game_dialog.icons_path}/{title_formatted}.ico' + # Copy icon to final location (shortcut creation is now a context-menu action) + if os.path.isfile(icon_temp): + shutil.copyfile(icon_temp, icon_final) + self.backup_games() save_games_json(games_json, [*self.games, game]) self.games.append(game) - self.add_shortcut(game, desktop_shortcut_state, "desktop", icon_temp, icon_final) - self.add_shortcut(game, appmenu_shortcut_state, "appmenu", icon_temp, icon_final) - self.add_item_list(game) self.update_list() self.select_game_by_title(title) @@ -935,11 +1000,9 @@ class Main(Gtk.ApplicationWindow): icon_temp = os.path.expanduser(edit_game_dialog.icon_temp) icon_final = f'{edit_game_dialog.icons_path}/{title_formatted}.ico' - desktop_shortcut_state = edit_game_dialog.checkbox_shortcut_desktop.get_active() - appmenu_shortcut_state = edit_game_dialog.checkbox_shortcut_appmenu.get_active() - - self.add_shortcut(game, desktop_shortcut_state, "desktop", icon_temp, icon_final) - self.add_shortcut(game, appmenu_shortcut_state, "appmenu", icon_temp, icon_final) + # Copy icon to final location (shortcut creation is now a context-menu action) + if os.path.isfile(icon_temp): + shutil.copyfile(icon_temp, icon_final) save_games_json(games_json, self.games) self.update_list() |
