Add option to choose executable via file picker
This commit is contained in:
@@ -109,32 +109,43 @@ template $DetailsWindow : Adw.Window {
|
|||||||
Adw.EntryRow executable {
|
Adw.EntryRow executable {
|
||||||
title: _("Executable");
|
title: _("Executable");
|
||||||
|
|
||||||
|
[suffix]
|
||||||
|
Gtk.Button file_chooser_button {
|
||||||
|
valign: center;
|
||||||
|
icon-name: "folder-symbolic";
|
||||||
|
tooltip-text: _("Select File");
|
||||||
|
|
||||||
|
styles [
|
||||||
|
"flat"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[suffix]
|
[suffix]
|
||||||
Gtk.MenuButton exec_info_button {
|
Gtk.MenuButton exec_info_button {
|
||||||
valign: center;
|
valign: center;
|
||||||
icon-name: "help-about-symbolic";
|
icon-name: "help-about-symbolic";
|
||||||
tooltip-text: _("More Info");
|
tooltip-text: _("More Info");
|
||||||
|
|
||||||
popover: Popover exec_info_popover {
|
popover: Popover exec_info_popover {
|
||||||
focusable: true;
|
focusable: true;
|
||||||
|
|
||||||
Label exec_info_label {
|
Label exec_info_label {
|
||||||
use-markup: true;
|
use-markup: true;
|
||||||
wrap: true;
|
wrap: true;
|
||||||
max-width-chars: 50;
|
max-width-chars: 50;
|
||||||
halign: center;
|
halign: center;
|
||||||
valign: center;
|
valign: center;
|
||||||
margin-top: 6;
|
margin-top: 6;
|
||||||
margin-bottom: 6;
|
margin-bottom: 6;
|
||||||
margin-start: 6;
|
margin-start: 6;
|
||||||
margin-end: 6;
|
margin-end: 6;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
styles [
|
styles [
|
||||||
"flat"
|
"flat"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
from time import time
|
from time import time
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ class DetailsWindow(Adw.Window):
|
|||||||
|
|
||||||
exec_info_label = Gtk.Template.Child()
|
exec_info_label = Gtk.Template.Child()
|
||||||
exec_info_popover = Gtk.Template.Child()
|
exec_info_popover = Gtk.Template.Child()
|
||||||
|
file_chooser_button = Gtk.Template.Child()
|
||||||
|
|
||||||
apply_button = Gtk.Template.Child()
|
apply_button = Gtk.Template.Child()
|
||||||
|
|
||||||
@@ -83,10 +85,22 @@ class DetailsWindow(Adw.Window):
|
|||||||
image_filter.add_suffix(extension[1:])
|
image_filter.add_suffix(extension[1:])
|
||||||
image_filter.add_suffix("svg") # Gdk.Texture supports .svg but PIL doesn't
|
image_filter.add_suffix("svg") # Gdk.Texture supports .svg but PIL doesn't
|
||||||
|
|
||||||
file_filters = Gio.ListStore.new(Gtk.FileFilter)
|
exec_filter = Gtk.FileFilter(name=_("Executables"))
|
||||||
file_filters.append(image_filter)
|
exec_filter.add_mime_type("application/x-executable")
|
||||||
|
|
||||||
|
image_filters = Gio.ListStore.new(Gtk.FileFilter)
|
||||||
|
image_filters.append(image_filter)
|
||||||
|
|
||||||
|
exec_filters = Gio.ListStore.new(Gtk.FileFilter)
|
||||||
|
exec_filters.append(exec_filter)
|
||||||
|
|
||||||
self.file_dialog = Gtk.FileDialog()
|
self.file_dialog = Gtk.FileDialog()
|
||||||
self.file_dialog.set_filters(file_filters)
|
self.file_dialog.set_filters(image_filters)
|
||||||
|
self.file_dialog.set_default_filter(image_filter)
|
||||||
|
|
||||||
|
self.exec_file_dialog = Gtk.FileDialog()
|
||||||
|
self.exec_file_dialog.set_filters(exec_filters)
|
||||||
|
self.exec_file_dialog.set_default_filter(exec_filter)
|
||||||
|
|
||||||
# Translate this string as you would translate "file"
|
# Translate this string as you would translate "file"
|
||||||
file_name = _("file.txt")
|
file_name = _("file.txt")
|
||||||
@@ -128,6 +142,7 @@ class DetailsWindow(Adw.Window):
|
|||||||
|
|
||||||
self.cover_button_delete.connect("clicked", self.delete_pixbuf)
|
self.cover_button_delete.connect("clicked", self.delete_pixbuf)
|
||||||
self.cover_button_edit.connect("clicked", self.choose_cover)
|
self.cover_button_edit.connect("clicked", self.choose_cover)
|
||||||
|
self.file_chooser_button.connect("clicked", self.choose_executable)
|
||||||
self.apply_button.connect("clicked", self.apply_preferences)
|
self.apply_button.connect("clicked", self.apply_preferences)
|
||||||
|
|
||||||
self.name.connect("entry-activated", self.focus_executable)
|
self.name.connect("entry-activated", self.focus_executable)
|
||||||
@@ -276,5 +291,16 @@ class DetailsWindow(Adw.Window):
|
|||||||
self.toggle_loading()
|
self.toggle_loading()
|
||||||
GLib.Thread.new(None, resize)
|
GLib.Thread.new(None, resize)
|
||||||
|
|
||||||
|
def set_executable(self, _source: Any, result: Gio.Task, *_args: Any) -> None:
|
||||||
|
try:
|
||||||
|
path = self.exec_file_dialog.open_finish(result).get_path()
|
||||||
|
except GLib.GError:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.executable.set_text(shlex.quote(path))
|
||||||
|
|
||||||
|
def choose_executable(self, *_args: Any) -> None:
|
||||||
|
self.exec_file_dialog.open(self, None, self.set_executable)
|
||||||
|
|
||||||
def choose_cover(self, *_args: Any) -> None:
|
def choose_cover(self, *_args: Any) -> None:
|
||||||
self.file_dialog.open(self, None, self.set_cover)
|
self.file_dialog.open(self, None, self.set_cover)
|
||||||
|
|||||||
Reference in New Issue
Block a user