Skip to content

Commit

Permalink
Add setting for using the dark variant of a theme
Browse files Browse the repository at this point in the history
  • Loading branch information
JMoerman committed Nov 18, 2016
1 parent cd7e18f commit d0bc75d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/SettingsManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,31 @@ public class SettingsManager {
public bool use_header_bar {
owned get {
var use_header_bar = get_value (
GROUP_UI, "use_header_bar", header_bar_default()
GROUP_UI, "use_header_bar", header_bar_default ()
);
return bool.parse (use_header_bar);
}
set {
set_value (GROUP_UI, "use_header_bar", value.to_string ());
}
}
public bool use_dark_theme {
owned get {
var use_dark = get_value (
GROUP_UI, "use_dark_theme", "false"
);
return bool.parse (use_dark);
}
set {
set_value (GROUP_UI, "use_dark_theme", value.to_string ());
use_dark_theme_changed (value);
}
}

/* Signals */
public signal void todo_txt_location_changed ();
public signal void timer_duration_changed ();
public signal void use_dark_theme_changed (bool use_dark);

/**
* Constructs a SettingsManager object from a configuration file.
Expand Down
16 changes: 15 additions & 1 deletion src/view/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class MainWindow : Gtk.ApplicationWindow {
this.task_manager = task_manager;
this.task_timer = task_timer;
this.settings = settings;
this.use_header_bar = settings.use_header_bar;

apply_settings ();

setup_window ();
setup_menu ();
Expand All @@ -77,6 +78,19 @@ class MainWindow : Gtk.ApplicationWindow {
Notify.init (GOFI.APP_NAME);
}

private void apply_settings () {
this.use_header_bar = settings.use_header_bar;

if (settings.use_dark_theme) {
unowned Gtk.Settings gtk_settings = Gtk.Settings.get_default();
gtk_settings.gtk_application_prefer_dark_theme = true;
}
settings.use_dark_theme_changed.connect ( (use_dark_theme) => {
unowned Gtk.Settings gtk_settings = Gtk.Settings.get_default();
gtk_settings.gtk_application_prefer_dark_theme = use_dark_theme;
});
}

public override bool delete_event (Gdk.EventAny event) {
bool dont_exit = false;

Expand Down
24 changes: 24 additions & 0 deletions src/view/SettingsDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class SettingsDialog : Gtk.Dialog {
int row = 0;
setup_txt_settings_widgets (main_layout, ref row);
setup_timer_settings_widgets (main_layout, ref row);
setup_appearance_settings_widgets (main_layout, ref row);
#if HAS_GTK310
setup_csd_settings_widgets (main_layout, ref row);
#endif
Expand Down Expand Up @@ -185,6 +186,29 @@ public class SettingsDialog : Gtk.Dialog {
add_option (grid, reminder_lbl, reminder_spin, ref row);
}

private void setup_appearance_settings_widgets (Gtk.Grid grid, ref int row) {
Gtk.Label appearance_sect_lbl;
Gtk.Label dark_theme_lbl;
Gtk.Switch dark_theme_switch;

/* Instantiation */
appearance_sect_lbl = new Gtk.Label (_("Appearance"));
dark_theme_lbl = new Gtk.Label (_("Dark theme"));
dark_theme_switch = new Gtk.Switch ();

/* Configuration */
dark_theme_switch.active = settings.use_dark_theme;

/* Signal Handling */
dark_theme_switch.notify["active"].connect ( () => {
settings.use_dark_theme = dark_theme_switch.active;
});

/* Add widgets */
add_section (grid, appearance_sect_lbl, ref row);
add_option (grid, dark_theme_lbl, dark_theme_switch, ref row);
}

#if HAS_GTK310
private void setup_csd_settings_widgets (Gtk.Grid grid, ref int row) {
Gtk.Label csd_sect_lbl;
Expand Down

0 comments on commit d0bc75d

Please sign in to comment.