Improved open URI dialog

This commit is contained in:
Rafał Dzięgiel
2021-09-02 17:22:09 +02:00
parent e264304c9d
commit 3aab01d35c
2 changed files with 25 additions and 43 deletions

View File

@@ -304,7 +304,7 @@ scale trough slider {
/* Open URI Dialog */ /* Open URI Dialog */
.uridialogbox { .uridialogbox {
margin: 12px; margin: 10px;
} }
/* Tweaks */ /* Tweaks */

View File

@@ -132,51 +132,48 @@ class ClapperUriDialog extends Gtk.Dialog
{ {
super._init({ super._init({
transient_for: window, transient_for: window,
destroy_with_parent: true,
modal: true, modal: true,
use_header_bar: true,
title: _('Open URI'), title: _('Open URI'),
default_width: 460, default_width: 400,
}); });
const box = new Gtk.Box({ const contentBox = this.get_content_area();
orientation: Gtk.Orientation.HORIZONTAL, contentBox.vexpand = true;
valign: Gtk.Align.CENTER, contentBox.add_css_class('uridialogbox');
spacing: 6,
});
box.add_css_class('uridialogbox');
const linkEntry = new Gtk.Entry({ const linkEntry = new Gtk.Entry({
activates_default: true, activates_default: true,
truncate_multiline: true, truncate_multiline: true,
width_request: 220, height_request: 38,
height_request: 36,
hexpand: true, hexpand: true,
valign: Gtk.Align.CENTER,
input_purpose: Gtk.InputPurpose.URL,
placeholder_text: _('Enter or drop URI here'),
}); });
linkEntry.set_placeholder_text(_('Enter or drop URI here'));
linkEntry.connect('notify::text', this._onTextNotify.bind(this)); linkEntry.connect('notify::text', this._onTextNotify.bind(this));
box.append(linkEntry); contentBox.append(linkEntry);
const openButton = new Gtk.Button({ this.add_button(_('Cancel'), Gtk.ResponseType.CANCEL);
label: _('Open'), this.add_button(_('Open'), Gtk.ResponseType.OK);
halign: Gtk.Align.END,
sensitive: false,
});
openButton.connect('clicked', this._onOpenButtonClicked.bind(this));
box.append(openButton);
const area = this.get_content_area(); this.set_default_response(Gtk.ResponseType.OK);
area.append(box); this.set_response_sensitive(Gtk.ResponseType.OK, false);
this.closeSignal = this.connect('close-request', this._onCloseRequest.bind(this));
this.show(); this.show();
} }
openUri(uri) vfunc_response(respId)
{ {
const { player } = this.get_transient_for().get_child(); if(respId === Gtk.ResponseType.OK) {
player.set_playlist([uri]); const contentBox = this.get_content_area();
const linkEntry = contentBox.get_last_child();
const { player } = this.transient_for.child;
this.close(); player.set_playlist([linkEntry.text]);
}
this.destroy();
} }
_onTextNotify(entry) _onTextNotify(entry)
@@ -185,22 +182,7 @@ class ClapperUriDialog extends Gtk.Dialog
? Gst.uri_is_valid(entry.text) ? Gst.uri_is_valid(entry.text)
: false; : false;
const button = entry.get_next_sibling(); this.set_response_sensitive(Gtk.ResponseType.OK, isUriValid);
button.set_sensitive(isUriValid);
}
_onOpenButtonClicked(button)
{
const entry = button.get_prev_sibling();
this.openUri(entry.text);
}
_onCloseRequest(dialog)
{
debug('closing URI dialog');
dialog.disconnect(this.closeSignal);
this.closeSignal = null;
} }
}); });