split to Application.vala and MainWindow.vala

This commit is contained in:
Artem Anufrij 2017-07-31 22:14:19 +02:00
parent 82d34bdb1f
commit 1ca44285a5
8 changed files with 550 additions and 210 deletions

View file

@ -1,5 +1,5 @@
install (FILES com.github.artemanufrij.webpin.desktop DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/applications) install (FILES com.github.artemanufrij.webpin.desktop DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/applications)
install (FILES com.github.artemanufrij.webpin.appdata.xml DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/metainfo) #install (FILES com.github.artemanufrij.webpin.appdata.xml DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/metainfo)
install (FILES icons/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/) install (FILES icons/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/)
install (FILES icons/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/48x48/apps/) install (FILES icons/artemanufrij.webpin.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/48x48/apps/)

View file

@ -1,20 +1,11 @@
[Desktop Entry] [Desktop Entry]
Version=1.0 Name=Webpin
Name=Webby GenericName=Webpin
GenericName=Webby Comment=Pin your websites on your desktop
Comment=Create your apps
Keywords=internet;webapp; Keywords=internet;webapp;
Exec=webby %u Exec=com.github.artemanufrij.webpin %u
Icon=webby Icon=artemanufrij.webpin
Terminal=false Terminal=false
Type=Application Type=Application
Categories=Network;GNOME;GTK; Categories=Network;GNOME;GTK;
X-GIO-NoFuse=true X-GNOME-Gettext-Domain=webpin
X-GNOME-Gettext-Domain=webby
X-GNOME-FullName=Webby
StartupWMClass=Webby
Actions=AboutDialog;
[Desktop Action AboutDialog]
Exec=webby --about
Name=About Webby

77
src/Application.vala Normal file
View file

@ -0,0 +1,77 @@
/*-
* Copyright (c) 2015 Erasmo Marín <erasmo.marin@gmail.com>
* Copyright (c) 2017-2017 Artem Anufrij <artem.anufrij@live.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The Noise authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Noise. This permission is above and beyond the permissions granted
* by the GPL license by which Noise is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Authored by: Artem Anufrij <artem.anufrij@live.de>
*/
namespace Webpin {
public class WebpinApp : Granite.Application {
static WebpinApp _instance = null;
public static WebpinApp instance {
get {
if (_instance == null)
_instance = new WebpinApp ();
return _instance;
}
}
construct {
program_name = "Image Burner";
exec_name = "com.github.artemanufrij.webpin";
application_id = "com.github.artemanufrij.webpin";
app_launcher = application_id + ".desktop";
}
public Gtk.Window mainwindow;
protected override void activate () {
if (mainwindow != null) {
mainwindow.present ();
return;
}
mainwindow = new MainWindow ();
mainwindow.set_application(this);
}
}
}
static int main (string[] args) {
Gtk.init (ref args);
if (args.length < 2 || args[1] == "--about" || args[1] == "-d") {
var app = Webpin.WebpinApp.instance;
return app.run (args);
} else {
var app_info = DesktopFile.get_app_by_url (args[1]);
var app = new Webpin.WebAppWindow(app_info.get_display_name (), args[1]);
app.show_all ();
}
Gtk.main ();
return 0;
}

View file

@ -1,7 +1,8 @@
vala_precompile(VALA_C ${CMAKE_PROJECT_NAME} vala_precompile(VALA_C ${CMAKE_PROJECT_NAME}
Widgets/ApplicationIcon.vala Widgets/ApplicationIcon.vala
Widgets/ApplicationsView.vala Widgets/ApplicationsView.vala
AppWindow.vala Application.vala
MainWindow.vala
Assistant.vala Assistant.vala
DesktopFile.vala DesktopFile.vala
InfoDialog.vala InfoDialog.vala
@ -9,7 +10,6 @@ vala_precompile(VALA_C ${CMAKE_PROJECT_NAME}
UrlEntry.vala UrlEntry.vala
WebApp.vala WebApp.vala
WebBar.vala WebBar.vala
Webby.vala
WebAppWindow.vala WebAppWindow.vala
PACKAGES PACKAGES
gtk+-3.0 gtk+-3.0

185
src/MainWindow.vala Normal file
View file

@ -0,0 +1,185 @@
/*-
* Copyright (c) 2015 Erasmo Marín <erasmo.marin@gmail.com>
* Copyright (c) 2017-2017 Artem Anufrij <artem.anufrij@live.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The Noise authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Noise. This permission is above and beyond the permissions granted
* by the GPL license by which Noise is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Authored by: Artem Anufrij <artem.anufrij@live.de>
*/
namespace Webpin {
public class MainWindow : Gtk.ApplicationWindow {
private Settings settings;
private Gtk.Stack stack;
private Gtk.HeaderBar headerbar;
private Gtk.Button back_button;
private Gtk.Button add_button;
private WebbyAssistant assistant;
private ApplicationsView apps_view;
public MainWindow () {
settings = Settings.get_default ();
build_ui ();
}
private void build_ui () {
set_default_size (700, 500);
//headerbar
headerbar = new Gtk.HeaderBar ();
headerbar.show_close_button = true;
headerbar.title = "Webpin";
set_titlebar (headerbar);
back_button = new Gtk.Button.with_label (_("Applications"));
back_button.get_style_context ().add_class ("back-button");
headerbar.pack_start (back_button);
add_button = new Gtk.Button ();
add_button.image = new Gtk.Image.from_icon_name ("add", Gtk.IconSize.LARGE_TOOLBAR);
add_button.tooltip_text = _("Add a new Web App");
headerbar.pack_start (add_button);
var welcome = new Granite.Widgets.Welcome (_("No Web Apps Availible"), _("Create a new Webby Web App."));
welcome.append ("add", _("Create App"), _("Create a new Webby web app."));
welcome.activated.connect ((index) => {
switch (index) {
case 0:
show_assistant ();
break;
}
});
apps_view = new ApplicationsView();
assistant = new WebbyAssistant();
stack = new Gtk.Stack ();
stack.set_transition_duration (500);
stack.add_named (welcome, "welcome");
stack.add_named (apps_view, "apps_view");
stack.add_named (assistant, "assistant");
add (stack);
apps_view.add_request.connect (() => {
show_assistant ();
});
apps_view.edit_request.connect ((desktop_file) => {
show_assistant (desktop_file);
});
apps_view.app_deleted.connect (() => {
if (!apps_view.has_items) {
show_welcome_view (Gtk.StackTransitionType.NONE);
}
});
assistant.application_created.connect ((new_file) => {
apps_view.add_button (new_file);
apps_view.select_last_item ();
show_apps_view ();
});
assistant.application_edited.connect ((edited_file) => {
apps_view.update_button (edited_file);
show_apps_view ();
});
back_button.clicked.connect (() => {
if (apps_view.has_items)
show_apps_view ();
else
show_welcome_view ();
});
add_button.clicked.connect (() => {
show_assistant ();
});
delete_event.connect (() => {
this.store_settings ();
return false;
});
this.restore_settings ();
show_all ();
if (apps_view.has_items)
show_apps_view (Gtk.StackTransitionType.NONE);
else
show_welcome_view (Gtk.StackTransitionType.NONE);
this.present ();
}
private void show_assistant (DesktopFile? desktop_file = null) {
stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
stack.set_visible_child_name("assistant");
back_button.show_all ();
add_button.hide ();
//fix ugly border at the bottom of headerbar
queue_draw ();
if (desktop_file != null)
assistant.edit_desktop_file (desktop_file);
}
private void show_apps_view (Gtk.StackTransitionType slide = Gtk.StackTransitionType.SLIDE_RIGHT) {
stack.set_transition_type (slide);
stack.set_visible_child_name ("apps_view");
back_button.hide ();
add_button.show_all ();
assistant.reset_fields ();
//fix ugly border at the bottom of headerbar
queue_draw ();
}
private void show_welcome_view (Gtk.StackTransitionType slide = Gtk.StackTransitionType.SLIDE_RIGHT) {
stack.set_transition_type (slide);
stack.set_visible_child_name ("welcome");
back_button.hide ();
add_button.hide ();
assistant.reset_fields ();
//fix ugly border at the bottom of headerbar
queue_draw ();
}
private void restore_settings () {
this.set_default_size (settings.window_width, settings.window_height);
if (settings.window_state == Settings.WindowState.MAXIMIZED)
this.maximize ();
}
private void store_settings () {
settings.window_state = (this.is_maximized ? Settings.WindowState.MAXIMIZED: Settings.WindowState.NORMAL);
if (settings.window_state == Settings.WindowState.NORMAL) {
settings.window_height = this.get_allocated_height ();
settings.window_width = this.get_allocated_width ();
}
}
}
}

View file

@ -1,23 +1,53 @@
public class Settings : Granite.Services.Settings { /*-
* Copyright (c) 2015 Erasmo Marín <erasmo.marin@gmail.com>
* Copyright (c) 2017-2017 Artem Anufrij <artem.anufrij@live.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The Noise authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Noise. This permission is above and beyond the permissions granted
* by the GPL license by which Noise is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Authored by: Artem Anufrij <artem.anufrij@live.de>
*/
private static Settings settings; namespace Webpin {
public static Settings get_default () { public class Settings : Granite.Services.Settings {
if (settings == null)
settings = new Settings ();
return settings; private static Settings settings;
} public static Settings get_default () {
public int window_width { get; set; } if (settings == null)
public int window_height { get; set; } settings = new Settings ();
public WindowState window_state { get; set; }
private Settings () { return settings;
base ("com.github.artemanufrij.webpin"); }
} public int window_width { get; set; }
public int window_height { get; set; }
public WindowState window_state { get; set; }
public enum WindowState { private Settings () {
NORMAL, base ("com.github.artemanufrij.webpin");
MAXIMIZED, }
FULLSCREEN
public enum WindowState {
NORMAL,
MAXIMIZED,
FULLSCREEN
}
} }
} }

View file

@ -1,142 +1,172 @@
public class WebAppWindow : Gtk.ApplicationWindow { /*-
* Copyright (c) 2015 Erasmo Marín <erasmo.marin@gmail.com>
* Copyright (c) 2017-2017 Artem Anufrij <artem.anufrij@live.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The Noise authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Noise. This permission is above and beyond the permissions granted
* by the GPL license by which Noise is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Authored by: Artem Anufrij <artem.anufrij@live.de>
*/
private bool is_full_screen = false; namespace Webpin {
public class WebAppWindow : Gtk.ApplicationWindow {
private string style_str = """@define-color titlebar_color @titlebar_color;"""; private bool is_full_screen = false;
//widgets private string style_str = """@define-color titlebar_color @titlebar_color;""";
private WebApp web_app;
private WebBar headerbar;
public WebAppWindow (string webapp_name, string webapp_uri) { //widgets
private WebApp web_app;
private WebBar headerbar;
set_wmclass(webapp_uri, webapp_uri); public WebAppWindow (string webapp_name, string webapp_uri) {
web_app = new WebApp(webapp_name, webapp_uri);
headerbar = new WebBar(web_app.external_view); set_wmclass(webapp_uri, webapp_uri);
headerbar.show_close_button = true; web_app = new WebApp(webapp_name, webapp_uri);
headerbar.title = webapp_name;
headerbar.set_title_mode (WebBar.title_mode.TITLE);
//style headerbar = new WebBar(web_app.external_view);
if (web_app.ui_color != "none") { headerbar.show_close_button = true;
try { headerbar.title = webapp_name;
print("set color");
var style_cp = style_str.replace ("@titlebar_color", web_app.ui_color);
var style_provider = new Gtk.CssProvider ();
style_provider.load_from_data (style_cp, -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));
} catch (GLib.Error err) {
warning("Loading style failed");
}
}
web_app.theme_color_changed.connect( (color)=> {
try {
print("set color");
var style_cp = style_str.replace ("@titlebar_color", color);
var style_provider = new Gtk.CssProvider ();
style_provider.load_from_data (style_cp, -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));
} catch (GLib.Error err) {
warning("Loading style failed");
}
});
this.set_titlebar (headerbar);
var info = DesktopFile.get_app_by_url(webapp_uri);
var width = info.get_string("WebbyWindowWidth");
var height = info.get_string("WebbyWindowHeight");
if(width !=null && height != null)
set_default_size (int.parse(width), int.parse(height));
else
set_default_size (1000, 600);
this.delete_event.connect (() => {
update_window_state(this.get_allocated_width (), this.get_allocated_height () );
return false;
});
this.destroy.connect(Gtk.main_quit);
web_app.external_request.connect ( () => {
print("Web app external request\n");
web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
headerbar.set_title_mode (WebBar.title_mode.BROWSER);
web_app.set_visible_child_name ("external");
});
headerbar.back_event.connect ( () => {
print ("back");
headerbar.set_title_mode (WebBar.title_mode.TITLE); headerbar.set_title_mode (WebBar.title_mode.TITLE);
web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT);
web_app.set_visible_child_name ("app"); //style
//wait the animation to end before "cleaning" the web view if (web_app.ui_color != "none") {
GLib.Timeout.add(web_app.get_transition_duration(), () => { try {
web_app.external_view.load_uri ("about:blank"); print("set color");
return false; var style_cp = style_str.replace ("@titlebar_color", web_app.ui_color);
var style_provider = new Gtk.CssProvider ();
style_provider.load_from_data (style_cp, -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));
} catch (GLib.Error err) {
warning("Loading style failed");
}
}
web_app.theme_color_changed.connect( (color)=> {
try {
print("set color");
var style_cp = style_str.replace ("@titlebar_color", color);
var style_provider = new Gtk.CssProvider ();
style_provider.load_from_data (style_cp, -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));
} catch (GLib.Error err) {
warning("Loading style failed");
}
}); });
});
add(web_app); this.set_titlebar (headerbar);
show_all();
}
public new void fullscreen () { var info = DesktopFile.get_app_by_url(webapp_uri);
is_full_screen = true; var width = info.get_string("WebbyWindowWidth");
base.fullscreen(); var height = info.get_string("WebbyWindowHeight");
}
public new void unfullscreen () { if(width !=null && height != null)
is_full_screen = false; set_default_size (int.parse(width), int.parse(height));
base.unfullscreen(); else
} set_default_size (1000, 600);
this.delete_event.connect (() => {
update_window_state(this.get_allocated_width (), this.get_allocated_height () );
return false;
});
public void toggle_fullscreen() { this.destroy.connect(Gtk.main_quit);
if(is_full_screen)
unfullscreen();
else
fullscreen();
is_full_screen = !is_full_screen;
}
public void update_window_state (int width, int height) { web_app.external_request.connect ( () => {
var file = web_app.get_desktop_file(); print("Web app external request\n");
file.edit_propertie ("WebbyWindowWidth", width.to_string()); web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
file.edit_propertie ("WebbyWindowHeight", height.to_string()); headerbar.set_title_mode (WebBar.title_mode.BROWSER);
} web_app.set_visible_child_name ("external");
});
public override bool key_press_event (Gdk.EventKey event) { headerbar.back_event.connect ( () => {
bool handled = true; print ("back");
switch (event.keyval) { headerbar.set_title_mode (WebBar.title_mode.TITLE);
case Gdk.Key.Escape: web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT);
unfullscreen(); web_app.set_visible_child_name ("app");
break; //wait the animation to end before "cleaning" the web view
case Gdk.Key.F11: GLib.Timeout.add(web_app.get_transition_duration(), () => {
toggle_fullscreen(); web_app.external_view.load_uri ("about:blank");
break; return false;
default: });
handled = false; });
break;
add(web_app);
show_all();
} }
if (handled) public new void fullscreen () {
return true; is_full_screen = true;
base.fullscreen();
}
return (base.key_press_event != null) ? base.key_press_event (event) : true; public new void unfullscreen () {
} is_full_screen = false;
base.unfullscreen();
}
private bool should_use_dark_theme (string theme_color) { public void toggle_fullscreen() {
Gdk.RGBA color = {}; if(is_full_screen)
color.parse (theme_color); unfullscreen();
else
fullscreen();
is_full_screen = !is_full_screen;
}
double prom = (color.red + color.blue + color.green)/3; public void update_window_state (int width, int height) {
var file = web_app.get_desktop_file();
file.edit_propertie ("WebbyWindowWidth", width.to_string());
file.edit_propertie ("WebbyWindowHeight", height.to_string());
}
if (prom < 0.5) public override bool key_press_event (Gdk.EventKey event) {
return true; bool handled = true;
return false; switch (event.keyval) {
case Gdk.Key.Escape:
unfullscreen();
break;
case Gdk.Key.F11:
toggle_fullscreen();
break;
default:
handled = false;
break;
}
if (handled)
return true;
return (base.key_press_event != null) ? base.key_press_event (event) : true;
}
private bool should_use_dark_theme (string theme_color) {
Gdk.RGBA color = {};
color.parse (theme_color);
double prom = (color.red + color.blue + color.green)/3;
if (prom < 0.5)
return true;
return false;
}
} }
} }

View file

@ -1,70 +1,97 @@
public class WebBar : Gtk.HeaderBar { /*-
* Copyright (c) 2015 Erasmo Marín <erasmo.marin@gmail.com>
* Copyright (c) 2017-2017 Artem Anufrij <artem.anufrij@live.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The Noise authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Noise. This permission is above and beyond the permissions granted
* by the GPL license by which Noise is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Authored by: Artem Anufrij <artem.anufrij@live.de>
*/
namespace Webpin {
public class WebBar : Gtk.HeaderBar {
public enum title_mode { public enum title_mode {
TITLE, TITLE,
BROWSER; BROWSER;
} }
UrlEntry url_entry; UrlEntry url_entry;
Gtk.Button share_button; Gtk.Button share_button;
Gtk.Button back_button; Gtk.Button back_button;
WebKit.WebView webview; WebKit.WebView webview;
public signal void back_event(); public signal void back_event();
public WebBar (WebKit.WebView webview) { public WebBar (WebKit.WebView webview) {
this.get_style_context ().remove_class ("header-bar");
this.webview = webview;
url_entry = new UrlEntry();
url_entry.show_all();
share_button = new Gtk.Button.from_icon_name ("application-menu-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
share_button.margin_left = 15;
share_button.show_all ();
back_button = new Gtk.Button.from_icon_name ("go-next-symbolic-rtl", Gtk.IconSize.SMALL_TOOLBAR);
back_button.margin_right = 15;
back_button.show_all ();
pack_start (back_button);
pack_start (url_entry);
pack_end (share_button);
custom_title = new Gtk.Label(null);
connect_signals ();
show();
}
private void connect_signals () {
webview.load_changed.connect ( (event) => {
if (event == WebKit.LoadEvent.STARTED)
url_entry.set_text (webview.uri);
});
back_button.clicked.connect( () => { back_event(); });
back_button.activate.connect( () => { back_event(); });
}
public void set_title_mode (title_mode mode) {
if (mode == title_mode.TITLE) {
custom_title = null;
remove (share_button);
remove (back_button);
remove (url_entry);
this.get_style_context ().remove_class ("header-bar"); this.get_style_context ().remove_class ("header-bar");
} else { this.webview = webview;
url_entry = new UrlEntry();
url_entry.show_all();
share_button = new Gtk.Button.from_icon_name ("application-menu-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
share_button.margin_left = 15;
share_button.show_all ();
back_button = new Gtk.Button.from_icon_name ("go-next-symbolic-rtl", Gtk.IconSize.SMALL_TOOLBAR);
back_button.margin_right = 15;
back_button.show_all ();
pack_start (back_button); pack_start (back_button);
pack_start (url_entry); pack_start (url_entry);
pack_end (share_button); pack_end (share_button);
custom_title = new Gtk.Label(null); custom_title = new Gtk.Label(null);
this.get_style_context ().add_class ("header-bar"); connect_signals ();
show();
}
private void connect_signals () {
webview.load_changed.connect ( (event) => {
if (event == WebKit.LoadEvent.STARTED)
url_entry.set_text (webview.uri);
});
back_button.clicked.connect( () => { back_event(); });
back_button.activate.connect( () => { back_event(); });
}
public void set_title_mode (title_mode mode) {
if (mode == title_mode.TITLE) {
custom_title = null;
remove (share_button);
remove (back_button);
remove (url_entry);
this.get_style_context ().remove_class ("header-bar");
} else {
pack_start (back_button);
pack_start (url_entry);
pack_end (share_button);
custom_title = new Gtk.Label(null);
this.get_style_context ().add_class ("header-bar");
}
} }
} }
} }