Better handling for wine based shortcuts.

This commit is contained in:
Storm Dragon committed 2026-10-19 00:46:09 -04:00
1 parent d2c5695221
commit fb2e1cc55c
3 files changed
+91 -9

No files matched your search

+46 -4
View File
@@ -12,8 +12,8 @@ gi.require_version("Gdk", "3.0")
gi.require_version("Gtk", "3.0")
from gi.repository import Gdk, GLib, Gtk
from shortcuts import (clipboard_target, create_shortcut, fetch_page_title,
installed_applications, parse_target)
from shortcuts import (clipboard_target, create_shortcut, detect_wine_prefix, fetch_page_title,
installed_applications, parse_target, validate_wine_prefix)
class ApplicationDialog(Gtk.Dialog):
@@ -132,6 +132,15 @@ class ShortcutWindow(Gtk.Window):
self.add_field(box, "_Target (path, program, or web URL):", self.targetEntry)
self.nameEntry = Gtk.Entry()
self.add_field(box, "Shortcut _name:", self.nameEntry)
self.wineBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.wineBox.set_no_show_all(True)
self.wineEntry = Gtk.Entry()
self.wineEntry.set_activates_default(True)
self.add_field(self.wineBox, "_Wine prefix (bottle) folder:", self.wineEntry)
wineButton = Gtk.Button.new_with_mnemonic("_Browse for Wine Prefix")
wineButton.connect("clicked", self.on_wine_prefix)
self.wineBox.pack_start(wineButton, False, False, 0)
box.pack_start(self.wineBox, False, False, 0)
self.targetEntry.connect("changed", self.on_target_changed)
self.targetEntry.connect("activate", self.on_target_activate)
self.nameEntry.connect("changed", self.on_name_changed)
@@ -181,6 +190,8 @@ class ShortcutWindow(Gtk.Window):
self.createButton.set_sensitive(False)
self.terminalCheck.set_active(False)
self.terminalCheck.set_sensitive(False)
self.wineBox.hide()
self.wineEntry.set_text("")
self.statusLabel.set_text("Press Enter to check the target, or choose a source above.")
def on_name_changed(self, _entry):
@@ -191,10 +202,21 @@ class ShortcutWindow(Gtk.Window):
self.targetEntry.set_text(target.value)
self.target = target
self.nameEntry.set_text(target.name)
self.terminalCheck.set_sensitive(target.kind == "Program")
self.terminalCheck.set_sensitive(target.kind in ("Program", "Windows program"))
self.statusLabel.set_text("{}: {}".format(target.kind, target.value))
self.nameEntry.grab_focus()
self.nameEntry.select_region(0, -1)
if target.kind == "Windows program":
winePrefix = detect_wine_prefix(target.value)
self.wineEntry.set_text(winePrefix or "")
self.wineBox.set_no_show_all(False)
self.wineBox.show_all()
self.wineBox.set_no_show_all(True)
if winePrefix:
self.statusLabel.set_text("Windows program: {}. Wine prefix: {}".format(target.value, winePrefix))
else:
self.statusLabel.set_text("Choose the Wine prefix (bottle) folder before creating this shortcut.")
self.wineEntry.grab_focus()
if target.kind == "Web link":
requestNumber = self.requestNumber
nameVersion = self.nameVersion
@@ -289,6 +311,18 @@ class ShortcutWindow(Gtk.Window):
def on_folder(self, _button):
self.choose_path(True)
def on_wine_prefix(self, _button):
dialog = Gtk.FileChooserDialog(title="Choose Wine prefix (bottle) folder",
transient_for=self, modal=True,
action=Gtk.FileChooserAction.SELECT_FOLDER)
dialog.add_buttons("_Cancel", Gtk.ResponseType.CANCEL, "_Select", Gtk.ResponseType.OK)
dialog.set_local_only(True)
dialog.set_show_hidden(True)
if dialog.run() == Gtk.ResponseType.OK:
self.wineEntry.set_text(dialog.get_filename())
dialog.destroy()
self.wineEntry.grab_focus()
def on_application(self, _button):
self.requestNumber += 1
try:
@@ -303,9 +337,17 @@ class ShortcutWindow(Gtk.Window):
def on_create(self, _button):
if self.target is None:
return
winePrefix = None
if self.target.kind == "Windows program":
try:
winePrefix = validate_wine_prefix(self.wineEntry.get_text())
except ValueError as error:
self.show_message(str(error), error=True)
self.wineEntry.grab_focus()
return
try:
destination = create_shortcut(self.target, self.nameEntry.get_text(), self.fileManager,
self.terminalCheck.get_active())
self.terminalCheck.get_active(), winePrefix=winePrefix)
except (ValueError, OSError, GLib.Error) as error:
self.show_message(str(error), error=True)
return