added refresh button

This commit is contained in:
Artem Anufrij 2018-10-26 21:55:23 +02:00
parent c78302acb5
commit f49db24518
2 changed files with 76 additions and 69 deletions

View file

@ -191,5 +191,13 @@ namespace Webpin.Widgets {
public bool can_go_forward () { public bool can_go_forward () {
return web_view.can_go_forward (); return web_view.can_go_forward ();
} }
public void reload () {
web_view.reload ();
}
public void reload_bypass_cache () {
web_view.reload_bypass_cache ();
}
} }
} }

View file

@ -54,10 +54,9 @@ namespace Webpin.Windows {
var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU); var copy_url = new Gtk.Button.from_icon_name ("insert-link-symbolic", Gtk.IconSize.MENU);
copy_url.valign = Gtk.Align.CENTER; copy_url.valign = Gtk.Align.CENTER;
copy_url.tooltip_text = _ ("Copy URL into clipboard"); copy_url.tooltip_text = _ ("Copy URL into clipboard");
copy_url.clicked.connect ( copy_url.clicked.connect (() => {
() => { Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (browser.web_view.uri, -1);
Gtk.Clipboard.get_default (Gdk.Display.get_default ()).set_text (browser.web_view.uri, -1); });
});
headerbar.pack_end (copy_url); headerbar.pack_end (copy_url);
var stay_open = new Gtk.ToggleButton (); var stay_open = new Gtk.ToggleButton ();
@ -65,18 +64,26 @@ namespace Webpin.Windows {
stay_open.active = desktop_file.hide_on_close; stay_open.active = desktop_file.hide_on_close;
stay_open.tooltip_text = _ ("Run in background if closed"); stay_open.tooltip_text = _ ("Run in background if closed");
stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU); stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU);
stay_open.toggled.connect ( stay_open.toggled.connect (() => {
() => { desktop_file.edit_property ("X-Webpin-StayOpen", stay_open.active.to_string ());
desktop_file.edit_property ("X-Webpin-StayOpen", stay_open.active.to_string ()); desktop_file.save_to_file ();
desktop_file.save_to_file (); });
});
headerbar.pack_end (stay_open); headerbar.pack_end (stay_open);
var button_refresh = new Gtk.Button.from_icon_name ("view-refresh-symbolic", Gtk.IconSize.MENU);
button_refresh.tooltip_text = _("Reload");
button_refresh.valign = Gtk.Align.CENTER;
button_refresh.clicked.connect (() => {
browser.reload ();
});
headerbar.pack_end (button_refresh);
spinner = new Gtk.Spinner (); spinner = new Gtk.Spinner ();
spinner.set_size_request (16, 16); spinner.set_size_request (16, 16);
headerbar.pack_end (spinner); headerbar.pack_end (spinner);
var button_back = new Gtk.Button.from_icon_name ("go-previous-symbolic", Gtk.IconSize.MENU); var button_back = new Gtk.Button.from_icon_name ("go-previous-symbolic", Gtk.IconSize.MENU);
button_back.tooltip_text = _("Back");
button_back.sensitive = false; button_back.sensitive = false;
button_back.valign = Gtk.Align.CENTER; button_back.valign = Gtk.Align.CENTER;
button_back.clicked.connect (() => { button_back.clicked.connect (() => {
@ -85,6 +92,7 @@ namespace Webpin.Windows {
headerbar.pack_start (button_back); headerbar.pack_start (button_back);
var button_home = new Gtk.Button.from_icon_name ("go-home-symbolic", Gtk.IconSize.MENU); var button_home = new Gtk.Button.from_icon_name ("go-home-symbolic", Gtk.IconSize.MENU);
button_home.tooltip_text = _("Home");
button_home.valign = Gtk.Align.CENTER; button_home.valign = Gtk.Align.CENTER;
button_home.clicked.connect (() => { button_home.clicked.connect (() => {
browser.go_home (); browser.go_home ();
@ -92,70 +100,62 @@ namespace Webpin.Windows {
headerbar.pack_start (button_home); headerbar.pack_start (button_home);
var button_forward = new Gtk.Button.from_icon_name ("go-next-symbolic", Gtk.IconSize.MENU); var button_forward = new Gtk.Button.from_icon_name ("go-next-symbolic", Gtk.IconSize.MENU);
button_forward.tooltip_text = _("Forward");
button_forward.sensitive = false; button_forward.sensitive = false;
button_forward.valign = Gtk.Align.CENTER; button_forward.valign = Gtk.Align.CENTER;
button_forward.clicked.connect (() => { button_forward.clicked.connect (() => {
browser.go_forward (); browser.go_forward ();
}); });
headerbar.pack_start (button_forward); headerbar.pack_start (button_forward);
this.set_titlebar (headerbar); this.set_titlebar (headerbar);
this.delete_event.connect ( this.delete_event.connect (() => {
() => { save_settings ();
save_settings (); if (desktop_file.hide_on_close) {
if (desktop_file.hide_on_close) { this.hide_on_delete ();
this.hide_on_delete (); }
} return desktop_file.hide_on_close;
return desktop_file.hide_on_close; });
});
this.window_state_event.connect ( this.window_state_event.connect ((event) => {
(event) => { current_state = event.new_window_state;
current_state = event.new_window_state; return false;
return false; });
});
browser.external_request.connect ( browser.external_request.connect ((action) => {
(action) => { try {
debug ("Web app external request: %s", action.get_request ().uri); Process.spawn_command_line_async ("xdg-open " + action.get_request ().uri);
try { } catch (Error e) {
Process.spawn_command_line_async ("xdg-open " + action.get_request ().uri); warning (e.message);
} catch (Error e) { }
warning (e.message); });
}
});
browser.desktop_notification.connect ( browser.desktop_notification.connect ((title, body, icon) => {
(title, body, icon) => { var desktop_notification = new Notification (title);
var desktop_notification = new Notification (title); desktop_notification.set_body (body);
desktop_notification.set_body (body); desktop_notification.set_icon (icon);
desktop_notification.set_icon (icon); desktop_notification.add_button_with_target_value (_ ("Open %s").printf (desktop_file.name), "app.open-web-app", new GLib.Variant.string (desktop_file.url));
desktop_notification.add_button_with_target_value (_ ("Open %s").printf (desktop_file.name), "app.open-web-app", new GLib.Variant.string (desktop_file.url)); WebpinApp.instance.send_notification (null, desktop_notification);
WebpinApp.instance.send_notification (null, desktop_notification); });
});
browser.request_begin.connect ( browser.request_begin.connect (() => {
() => { spinner.active = true;
spinner.active = true; });
});
browser.request_finished.connect ( browser.request_finished.connect (() => {
() => { spinner.active = false;
spinner.active = false; button_back.sensitive = browser.can_go_back ();
button_back.sensitive = browser.can_go_back (); button_forward.sensitive = browser.can_go_forward ();
button_forward.sensitive = browser.can_go_forward (); });
});
browser.found_website_color.connect ( browser.found_website_color.connect ((color) => {
(color) => { stdout.printf ("%s\n", color.to_string ());
stdout.printf ("%s\n", color.to_string ()); int gray_val = (int)(desktop_file.color.red * 255);
int gray_val = (int)(desktop_file.color.red * 255); if (desktop_file.color == null || ((gray_val == 222 || gray_val == 255) && desktop_file.color.red == desktop_file.color.green && desktop_file.color.red == desktop_file.color.blue)) {
if (desktop_file.color == null || ((gray_val == 222 || gray_val == 255) && desktop_file.color.red == desktop_file.color.green && desktop_file.color.red == desktop_file.color.blue)) { set_color (color);
set_color (color); desktop_file.color = color;
desktop_file.color = color; }
} });
});
this.add (browser); this.add (browser);
@ -163,14 +163,13 @@ namespace Webpin.Windows {
this.show_all (); this.show_all ();
this.show.connect ( this.show.connect (() => {
() => { var x = desktop_file.get_property ("X-Webpin-WindowX");
var x = desktop_file.get_property ("X-Webpin-WindowX"); var y = desktop_file.get_property ("X-Webpin-WindowY");
var y = desktop_file.get_property ("X-Webpin-WindowY"); if (x != null && y != null) {
if (x != null && y != null) { this.move (int.parse (x), int.parse (y));
this.move (int.parse (x), int.parse (y)); }
} });
});
} }
private void set_color (Gdk.RGBA color) { private void set_color (Gdk.RGBA color) {
@ -271,9 +270,9 @@ namespace Webpin.Windows {
break; break;
case Gdk.Key.F5 : case Gdk.Key.F5 :
if (Gdk.ModifierType.CONTROL_MASK in event.state) { if (Gdk.ModifierType.CONTROL_MASK in event.state) {
browser.web_view.reload (); browser.reload ();
} else { } else {
browser.web_view.reload_bypass_cache (); browser.reload_bypass_cache ();
} }
return true; return true;
case Gdk.Key.Left : case Gdk.Key.Left :