MCPcopy Index your code
hub / github.com/paperwm/PaperWM / createFileChooserButton

Method createFileChooserButton

prefs.js:764–800  ·  view source on GitHub ↗
(settings, key, iconName, symbolicIconName, properties)

Source from the content-addressed store, hash-verified

762 }
763
764 createFileChooserButton(settings, key, iconName, symbolicIconName, properties) {
765 const buttonIcon = Gtk.Image.new_from_icon_name(iconName);
766 const buttonLabel = new Gtk.Label();
767 const buttonBox = new Gtk.Box({
768 orientation: Gtk.Orientation.HORIZONTAL,
769 spacing: 8,
770 });
771
772 buttonBox.append(buttonIcon);
773 buttonBox.append(buttonLabel);
774 if (symbolicIconName) {
775 buttonBox.append(new Gtk.Image({ icon_name: symbolicIconName, margin_start: 8 }));
776 }
777
778 const button = new Gtk.Button({ child: buttonBox });
779
780 this.syncStringSetting(settings, key, path => {
781 buttonIcon.visible = path !== '';
782 buttonLabel.label = path === '' ? '(None)' : GLib.filename_display_basename(path);
783 });
784 button.connect('clicked', () => {
785 const chooser = new Gtk.FileChooserDialog(properties);
786 let path = settings.get_string(key);
787 if (path !== '')
788 chooser.set_file(Gio.File.new_for_path(path));
789 chooser.add_button('Open', Gtk.ResponseType.OK);
790 chooser.add_button('Cancel', Gtk.ResponseType.CANCEL);
791 chooser.connect('response', (dialog, response) => {
792 if (response === Gtk.ResponseType.OK) {
793 settings.set_string(key, chooser.get_file().get_path());
794 }
795 chooser.destroy();
796 });
797 chooser.show();
798 });
799 return button;
800 }
801
802 syncStringSetting(settings, key, callback) {
803 settings.connect(`changed::${key}`, () => {

Callers 1

createWorkspacePageMethod · 0.95

Calls 4

syncStringSettingMethod · 0.95
connectMethod · 0.80
destroyMethod · 0.45
showMethod · 0.45

Tested by

no test coverage detected