theme switcher

This commit is contained in:
Artem Anufrij 2018-10-30 20:46:35 +01:00
parent 5a74722c39
commit d61c4b0b7f
5 changed files with 19 additions and 105 deletions

View file

@ -33,6 +33,14 @@
</screenshot>
</screenshots>
<releases>
<release version="1.0.3" date="2018-11-15">
<description>
<p>New:</p>
<ul>
<li>Theme switcher</li>
</ul>
</description>
</release>
<release version="1.0.2" date="2018-11-02">
<description>
<p>New:</p>

View file

@ -4,6 +4,5 @@ src/Widgets/Views/Editor.vala
src/Widgets/Browser.vala
src/Windows/WebApp.vala
src/Objects/DesktopFile.vala
src/Dialogs/Preferences.vala
src/Services/DesktopFilesManager.vala
src/MainWindow.vala

View file

@ -1,77 +0,0 @@
/*-
* Copyright (c) 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 <https://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.Dialogs {
public class Preferences : Gtk.Dialog {
Webpin.Settings settings;
construct {
settings = Webpin.Settings.get_default ();
}
public Preferences (Gtk.Window parent) {
Object (
transient_for: parent
);
build_ui ();
this.response.connect ((source, response_id) => {
switch (response_id) {
case Gtk.ResponseType.CLOSE:
destroy ();
break;
}
});
}
private void build_ui () {
this.resizable = false;
var content = get_content_area () as Gtk.Box;
var grid = new Gtk.Grid ();
grid.column_spacing = 12;
grid.row_spacing = 12;
grid.margin = 12;
var use_dark_theme_label = new Gtk.Label (_("Use Dark Theme"));
use_dark_theme_label.halign = Gtk.Align.START;
var use_dark_theme = new Gtk.Switch ();
use_dark_theme.active = settings.use_dark_theme;
use_dark_theme.notify["active"].connect (() => {
settings.use_dark_theme = use_dark_theme.active;
});
grid.attach (use_dark_theme_label, 0, 0);
grid.attach (use_dark_theme, 1, 0);
content.pack_start (grid, false, false, 0);
this.add_button (_("_Close"), Gtk.ResponseType.CLOSE);
this.show_all ();
}
}
}

View file

@ -34,7 +34,6 @@ namespace Webpin {
Gtk.HeaderBar headerbar;
Gtk.Button back_button;
Gtk.Button add_button;
Gtk.MenuButton app_menu;
Widgets.Views.Editor editor;
Widgets.Views.WebItemsView web_items_view;
@ -43,11 +42,6 @@ namespace Webpin {
settings = Settings.get_default ();
settings.notify["use-dark-theme"].connect (() => {
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.use_dark_theme;
if (settings.use_dark_theme) {
app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu-symbolic", Gtk.IconSize.LARGE_TOOLBAR));
} else {
app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu", Gtk.IconSize.LARGE_TOOLBAR));
}
});
}
@ -75,26 +69,7 @@ namespace Webpin {
add_button.tooltip_text = _("Add a new Web App");
headerbar.pack_start (add_button);
// SETTINGS MENU
app_menu = new Gtk.MenuButton ();
if (settings.use_dark_theme) {
app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu-symbolic", Gtk.IconSize.LARGE_TOOLBAR));
} else {
app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu", Gtk.IconSize.LARGE_TOOLBAR));
}
var settings_menu = new Gtk.Menu ();
var menu_item_preferences = new Gtk.MenuItem.with_label (_("Preferences"));
menu_item_preferences.activate.connect (() => {
var preferences = new Dialogs.Preferences (this);
preferences.run ();
});
settings_menu.append (menu_item_preferences);
settings_menu.show_all ();
app_menu.popup = settings_menu;
headerbar.pack_end (app_menu);
header_build_style_switcher ();
var welcome = new Granite.Widgets.Welcome (_("No Web Apps Available"), _("Manage your web apps."));
welcome.append ("document-new", _("Create App"), _("Create a new web app with Webpin"));
@ -171,6 +146,16 @@ namespace Webpin {
this.present ();
}
private void header_build_style_switcher () {
var mode_switch = new Granite.ModeSwitch.from_icon_name ("display-brightness-symbolic", "weather-clear-night-symbolic");
mode_switch.valign = Gtk.Align.CENTER;
mode_switch.active = settings.use_dark_theme;
mode_switch.notify["active"].connect (() => {
settings.use_dark_theme = mode_switch.active;
});
headerbar.pack_end (mode_switch);
}
public void show_assistant (DesktopFile? desktop_file = null) {
stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
stack.set_visible_child_name("editor");

View file

@ -5,7 +5,6 @@ sources = files(
'Widgets/Browser.vala',
'Windows/WebApp.vala',
'Objects/DesktopFile.vala',
'Dialogs/Preferences.vala',
'Services/DesktopFilesManager.vala',
'Settings.vala',
'MainWindow.vala',