Add a preference to allow using the dark variant of a theme if available

This commit is contained in:
JosephMcc 2017-02-09 13:58:08 -08:00
parent 69f71de2de
commit 3a83594498
6 changed files with 65 additions and 10 deletions

View File

@ -41,6 +41,12 @@
<description>A custom font that will be used for the editing area. This will only take effect if the "Use Default Font" option is turned off.</description>
</key>
<key name="prefer-dark-theme" type="b">
<default>false</default>
<summary>Prefer Dark Theme</summary>
<description>Whether xed should prefer the dark variation of the current Gtk theme if available.</description>
</key>
<key name="scheme" type="s">
<default>'tango'</default>
<summary>Style Scheme</summary>

View File

@ -1118,6 +1118,22 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="prefer_dark_theme_checkbutton">
<property name="label" translatable="yes">Use dark theme variant (if available)</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="margin_left">12</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox115">
<property name="visible">True</property>
@ -1216,7 +1232,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>

View File

@ -80,6 +80,7 @@ struct _XedAppPrivate
GObject *settings;
GSettings *window_settings;
GSettings *editor_settings;
PeasExtensionSet *extensions;
@ -168,6 +169,7 @@ xed_app_dispose (GObject *object)
XedApp *app = XED_APP (object);
g_clear_object (&app->priv->window_settings);
g_clear_object (&app->priv->editor_settings);
g_clear_object (&app->priv->settings);
g_clear_object (&app->priv->page_setup);
g_clear_object (&app->priv->print_settings);
@ -209,6 +211,18 @@ extension_removed (PeasExtensionSet *extensions,
peas_extension_call (exten, "deactivate");
}
static void
set_initial_theme_style (XedApp *app)
{
if (g_settings_get_boolean (app->priv->editor_settings, XED_SETTINGS_PREFER_DARK_THEME))
{
GtkSettings *gtk_settings;
gtk_settings = gtk_settings_get_default ();
g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", TRUE, NULL);
}
}
static void
xed_app_startup (GApplication *application)
{
@ -248,6 +262,9 @@ xed_app_startup (GApplication *application)
/* Load settings */
app->priv->settings = xed_settings_new ();
app->priv->window_settings = g_settings_new ("org.x.editor.state.window");
app->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor");
set_initial_theme_style (app);
/*
* We use the default gtksourceview style scheme manager so that plugins

View File

@ -89,6 +89,7 @@ struct _XedPreferencesDialogPrivate
GtkWidget *font_hbox;
/* Style Scheme */
GtkWidget *prefer_dark_theme_checkbutton;
GtkListStore *schemes_treeview_model;
GtkWidget *schemes_treeview;
GtkWidget *install_scheme_button;
@ -1050,6 +1051,12 @@ setup_font_colors_page (XedPreferencesDialog *dlg)
{
setup_font_colors_page_font_section (dlg);
setup_font_colors_page_style_scheme_section (dlg);
g_settings_bind (dlg->priv->editor,
XED_SETTINGS_PREFER_DARK_THEME,
dlg->priv->prefer_dark_theme_checkbutton,
"active",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
}
static void
@ -1127,6 +1134,7 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg)
dlg->priv->default_font_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "default_font_checkbutton"));
dlg->priv->font_button = GTK_WIDGET (gtk_builder_get_object (builder, "font_button"));
dlg->priv->font_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "font_hbox"));
dlg->priv->prefer_dark_theme_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "prefer_dark_theme_checkbutton"));
dlg->priv->schemes_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "schemes_treeview"));
dlg->priv->install_scheme_button = GTK_WIDGET (gtk_builder_get_object (builder, "install_scheme_button"));
dlg->priv->uninstall_scheme_button = GTK_WIDGET (gtk_builder_get_object (builder, "uninstall_scheme_button"));

View File

@ -176,6 +176,20 @@ on_editor_font_changed (GSettings *settings,
g_free (font);
}
static void
on_prefer_dark_theme_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GtkSettings *gtk_settings;
gboolean prefer_dark_theme;
prefer_dark_theme = g_settings_get_boolean (xs->priv->editor, XED_SETTINGS_PREFER_DARK_THEME);
gtk_settings = gtk_settings_get_default ();
g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", prefer_dark_theme, NULL);
}
static void
on_scheme_changed (GSettings *settings,
const gchar *key,
@ -375,6 +389,8 @@ xed_settings_init (XedSettings *xs)
G_CALLBACK (on_use_default_font_changed), xs);
g_signal_connect (xs->priv->editor, "changed::editor-font",
G_CALLBACK (on_editor_font_changed), xs);
g_signal_connect (xs->priv->editor, "changed::prefer-dark-theme",
G_CALLBACK (on_prefer_dark_theme_changed), xs);
g_signal_connect (xs->priv->editor, "changed::scheme",
G_CALLBACK (on_scheme_changed), xs);
g_signal_connect (xs->priv->editor, "changed::auto-save",

View File

@ -55,19 +55,10 @@ struct _XedSettingsClass
GObjectClass parent_class;
};
// typedef enum {
// XED_TOOLBAR_SYSTEM = 0,
// XED_TOOLBAR_ICONS,
// XED_TOOLBAR_ICONS_AND_TEXT,
// XED_TOOLBAR_ICONS_BOTH_HORIZ
// } XedToolbarSetting;
GType xed_settings_get_type (void) G_GNUC_CONST;
GObject *xed_settings_new (void);
// XedLockdownMask xed_settings_get_lockdown (XedSettings *xs);
gchar *xed_settings_get_system_font (XedSettings *xs);
/* Utility functions */
@ -81,6 +72,7 @@ void xed_settings_set_list (GSettings *settings,
/* key constants */
#define XED_SETTINGS_USE_DEFAULT_FONT "use-default-font"
#define XED_SETTINGS_EDITOR_FONT "editor-font"
#define XED_SETTINGS_PREFER_DARK_THEME "prefer-dark-theme"
#define XED_SETTINGS_SCHEME "scheme"
#define XED_SETTINGS_CREATE_BACKUP_COPY "create-backup-copy"
#define XED_SETTINGS_AUTO_SAVE "auto-save"