forked from csoriano1618/gtklesson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08 - BrowserLocation.js
executable file
·69 lines (54 loc) · 1.81 KB
/
08 - BrowserLocation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env gjs
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const WebKit2 = imports.gi.WebKit2;
/*
- Gtk.Entry
- notify::
*/
Gtk.init(null);
const HOME_PAGE = "http://www.duckduckgo.com"
const BrowserWindow = new Lang.Class({
Name: 'BrowserWindow',
Extends: Gtk.ApplicationWindow,
_init: function() {
this.parent();
const titlebar = new Gtk.HeaderBar();
titlebar.set_show_close_button(true);
this._urientry = new Gtk.Entry();
this._urientry.hexpand = true;
this._urientry.set_size_request(300, -1);
this._urientry.set_text(HOME_PAGE);
this._urientry.connect('activate', Lang.bind(this, this._urientryOnActivated));
titlebar.set_custom_title(this._urientry);
this.set_titlebar(titlebar);
this._webview = new WebKit2.WebView();
this._webview.load_uri(HOME_PAGE);
// "notify::" signals names are emitted for every change in a property.
// This is based on GObject
this._webview.connect('notify::uri', Lang.bind(this, this._webviewOnUriChanged));
this.add(this._webview);
this.show_all();
},
_urientryOnActivated: function() {
const uri = this._urientry.get_text();
this._webview.load_uri(uri);
},
_webviewOnUriChanged: function(signalSender, propertyValue) {
// property value using gi data structures
print('ss', signalSender);
print('pv', propertyValue);
this._urientry.set_text(this._webview.uri);
}
});
const Browser = new Lang.Class({
Name: 'Browser',
Extends: Gtk.Application,
_init: function() {
this.parent();
this._browserwindow = new BrowserWindow();
this._browserwindow.connect('delete-event', Gtk.main_quit);
}
})
const browser = new Browser();
Gtk.main();