add pin button for webapps

This commit is contained in:
Artem Anufrij 2017-09-03 19:16:39 +02:00
parent a1157abcef
commit eac57a1711
3 changed files with 14 additions and 8 deletions

View file

@ -50,7 +50,6 @@ namespace Webpin {
public string name { get; private set; } public string name { get; private set; }
public string url { get; private set; } public string url { get; private set; }
public string icon { get; private set; } public string icon { get; private set; }
public bool stay_open { get; private set; }
public bool hide_on_close { public bool hide_on_close {
get { get {
this.file = new GLib.KeyFile(); this.file = new GLib.KeyFile();
@ -68,7 +67,6 @@ namespace Webpin {
this.name = name; this.name = name;
this.url = url.replace ("%", "%%"); this.url = url.replace ("%", "%%");
this.icon = icon; this.icon = icon;
this.stay_open = stay_open;
file = new GLib.KeyFile(); file = new GLib.KeyFile();
try { try {
@ -98,7 +96,6 @@ namespace Webpin {
this.icon = info.get_icon ().to_string (); this.icon = info.get_icon ().to_string ();
try { try {
this.url = file.get_string ("Desktop Entry", "Exec").substring (31); this.url = file.get_string ("Desktop Entry", "Exec").substring (31);
this.stay_open = file.get_string ("Desktop Entry", "WebpinStayOpen") == "true";
} catch (Error e) { } catch (Error e) {
warning (e.message); warning (e.message);
} }

View file

@ -31,7 +31,7 @@ namespace Webpin {
private bool is_full_screen = false; private bool is_full_screen = false;
private string style_str = """@define-color titlebar_color @titlebar_color;"""; private string style_str = """@define-color titlebar_color @titlebar_color;""";
//widgets //widgets
private WebApp web_app; private WebApp web_app;
@ -55,6 +55,15 @@ namespace Webpin {
spinner.set_size_request (16, 16); spinner.set_size_request (16, 16);
headerbar.pack_end (spinner); headerbar.pack_end (spinner);
var stay_open = new Gtk.ToggleButton ();
stay_open.active = desktop_file.hide_on_close;
stay_open.toggled.connect (() => {
desktop_file.edit_propertie ("WebpinStayOpen", stay_open.active.to_string ());
desktop_file.save_to_file ();
});
stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU);
headerbar.pack_start (stay_open);
//style //style
if (web_app.ui_color != "none") { if (web_app.ui_color != "none") {
try { try {
@ -63,7 +72,7 @@ namespace Webpin {
var style_provider = new Gtk.CssProvider (); var style_provider = new Gtk.CssProvider ();
style_provider.load_from_data (style_cp, -1); style_provider.load_from_data (style_cp, -1);
headerbar.get_style_context ().add_provider (style_provider, -1); headerbar.get_style_context ().add_provider (style_provider, -1);
Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (web_app.ui_color)); Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = should_use_dark_theme (web_app.ui_color);
} catch (GLib.Error err) { } catch (GLib.Error err) {
warning("Loading style failed"); warning("Loading style failed");
} }
@ -76,7 +85,7 @@ namespace Webpin {
var style_provider = new Gtk.CssProvider (); var style_provider = new Gtk.CssProvider ();
style_provider.load_from_data (style_cp, -1); style_provider.load_from_data (style_cp, -1);
headerbar.get_style_context ().add_provider (style_provider, -1); headerbar.get_style_context ().add_provider (style_provider, -1);
Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (color)); Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = should_use_dark_theme (color);
} catch (GLib.Error err) { } catch (GLib.Error err) {
warning("Loading style failed"); warning("Loading style failed");
} }
@ -106,7 +115,7 @@ namespace Webpin {
this.delete_event.connect (() => { this.delete_event.connect (() => {
update_window_state(this.get_allocated_width (), this.get_allocated_height (), this.is_maximized); update_window_state(this.get_allocated_width (), this.get_allocated_height (), this.is_maximized);
if (desktop_file.hide_on_close) { if (desktop_file.hide_on_close) {
this.hide (); this.hide_on_delete ();
} }
return desktop_file.hide_on_close; return desktop_file.hide_on_close;
}); });

View file

@ -326,7 +326,7 @@ namespace Webpin {
app_name_entry.set_sensitive (false); app_name_entry.set_sensitive (false);
app_url_entry.text = desktop_file.url.replace ("%%", "%"); app_url_entry.text = desktop_file.url.replace ("%%", "%");
icon_name_entry.text = desktop_file.icon; icon_name_entry.text = desktop_file.icon;
stay_open_when_closed.active = desktop_file.stay_open; stay_open_when_closed.active = desktop_file.hide_on_close;
update_app_icon (); update_app_icon ();
} }
} }