mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 07:42:23 +02:00
Add open URI dialog
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { Gio, GObject, Gtk } = imports.gi;
|
||||
const { GObject, Gtk } = imports.gi;
|
||||
|
||||
var FileChooser = GObject.registerClass(
|
||||
class ClapperFileChooser extends Gtk.FileChooserNative
|
||||
|
@@ -2,9 +2,11 @@ const { GObject, Gst, Gtk } = imports.gi;
|
||||
const Misc = imports.clapper_src.misc;
|
||||
const Prefs = imports.clapper_src.prefs;
|
||||
const { FileChooser } = imports.clapper_src.filechooser;
|
||||
const { UriDialog } = imports.clapper_src.uridialog;
|
||||
|
||||
var actions = [
|
||||
openLocal,
|
||||
openUri,
|
||||
prefs,
|
||||
about,
|
||||
];
|
||||
@@ -19,6 +21,12 @@ function openLocal(window, appName)
|
||||
fileChooser.present();
|
||||
}
|
||||
|
||||
function openUri(window, appName)
|
||||
{
|
||||
let uriDialog = new UriDialog(window);
|
||||
uriDialog.present();
|
||||
}
|
||||
|
||||
function prefs(window, appName)
|
||||
{
|
||||
let prefsWidget = Prefs.buildPrefsWidget();
|
||||
|
66
clapper_src/uridialog.js
Normal file
66
clapper_src/uridialog.js
Normal file
@@ -0,0 +1,66 @@
|
||||
const { GObject, Gtk, Gst } = imports.gi;
|
||||
|
||||
var UriDialog = GObject.registerClass(
|
||||
class ClapperUriDialog extends Gtk.Dialog
|
||||
{
|
||||
_init(window, appName)
|
||||
{
|
||||
super._init({
|
||||
transient_for: window,
|
||||
title: 'Open URI',
|
||||
default_width: 460,
|
||||
});
|
||||
|
||||
let box = new Gtk.Box({
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
valign: Gtk.Align.CENTER,
|
||||
spacing: 6,
|
||||
});
|
||||
box.add_css_class('uridialogbox');
|
||||
|
||||
let linkEntry = new Gtk.Entry({
|
||||
activates_default: true,
|
||||
truncate_multiline: true,
|
||||
width_request: 220,
|
||||
height_request: 36,
|
||||
hexpand: true,
|
||||
});
|
||||
linkEntry.set_placeholder_text("Enter or drop URI here");
|
||||
linkEntry.connect('notify::text', this._onTextNotify.bind(this));
|
||||
box.append(linkEntry);
|
||||
|
||||
let openButton = new Gtk.Button({
|
||||
label: "Open",
|
||||
halign: Gtk.Align.END,
|
||||
sensitive: false,
|
||||
});
|
||||
openButton.connect('clicked', this._onOpenButtonClicked.bind(this));
|
||||
box.append(openButton);
|
||||
|
||||
this.set_child(box);
|
||||
}
|
||||
|
||||
openUri(uri)
|
||||
{
|
||||
let { player } = this.get_transient_for().get_child();
|
||||
player.set_media(uri);
|
||||
|
||||
this.close();
|
||||
}
|
||||
|
||||
_onTextNotify(entry)
|
||||
{
|
||||
let isUriValid = (entry.text.length)
|
||||
? Gst.uri_is_valid(entry.text)
|
||||
: false;
|
||||
|
||||
let button = entry.get_next_sibling();
|
||||
button.set_sensitive(isUriValid);
|
||||
}
|
||||
|
||||
_onOpenButtonClicked(button)
|
||||
{
|
||||
let entry = button.get_prev_sibling();
|
||||
this.openUri(entry.text);
|
||||
}
|
||||
});
|
@@ -130,3 +130,8 @@ scale marks {
|
||||
.prefssubpage header {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
/* Open URI Dialog */
|
||||
.uridialogbox {
|
||||
margin: 12px;
|
||||
}
|
||||
|
@@ -6,6 +6,10 @@
|
||||
<attribute name="label" translatable="yes">Open Local File...</attribute>
|
||||
<attribute name="action">app.openLocal</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Open URI...</attribute>
|
||||
<attribute name="action">app.openUri</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
<menu id="settingsMenu">
|
||||
|
Reference in New Issue
Block a user