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> <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>
<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"> <key name="scheme" type="s">
<default>'tango'</default> <default>'tango'</default>
<summary>Style Scheme</summary> <summary>Style Scheme</summary>

View File

@ -1118,6 +1118,22 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </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> <child>
<object class="GtkHBox" id="hbox115"> <object class="GtkHBox" id="hbox115">
<property name="visible">True</property> <property name="visible">True</property>
@ -1216,7 +1232,7 @@
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</object> </object>

View File

@ -80,6 +80,7 @@ struct _XedAppPrivate
GObject *settings; GObject *settings;
GSettings *window_settings; GSettings *window_settings;
GSettings *editor_settings;
PeasExtensionSet *extensions; PeasExtensionSet *extensions;
@ -168,6 +169,7 @@ xed_app_dispose (GObject *object)
XedApp *app = XED_APP (object); XedApp *app = XED_APP (object);
g_clear_object (&app->priv->window_settings); 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->settings);
g_clear_object (&app->priv->page_setup); g_clear_object (&app->priv->page_setup);
g_clear_object (&app->priv->print_settings); g_clear_object (&app->priv->print_settings);
@ -209,6 +211,18 @@ extension_removed (PeasExtensionSet *extensions,
peas_extension_call (exten, "deactivate"); 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 static void
xed_app_startup (GApplication *application) xed_app_startup (GApplication *application)
{ {
@ -248,6 +262,9 @@ xed_app_startup (GApplication *application)
/* Load settings */ /* Load settings */
app->priv->settings = xed_settings_new (); app->priv->settings = xed_settings_new ();
app->priv->window_settings = g_settings_new ("org.x.editor.state.window"); 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 * We use the default gtksourceview style scheme manager so that plugins

View File

@ -89,6 +89,7 @@ struct _XedPreferencesDialogPrivate
GtkWidget *font_hbox; GtkWidget *font_hbox;
/* Style Scheme */ /* Style Scheme */
GtkWidget *prefer_dark_theme_checkbutton;
GtkListStore *schemes_treeview_model; GtkListStore *schemes_treeview_model;
GtkWidget *schemes_treeview; GtkWidget *schemes_treeview;
GtkWidget *install_scheme_button; 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_font_section (dlg);
setup_font_colors_page_style_scheme_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 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->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_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->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->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->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")); 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); 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 static void
on_scheme_changed (GSettings *settings, on_scheme_changed (GSettings *settings,
const gchar *key, const gchar *key,
@ -375,6 +389,8 @@ xed_settings_init (XedSettings *xs)
G_CALLBACK (on_use_default_font_changed), xs); G_CALLBACK (on_use_default_font_changed), xs);
g_signal_connect (xs->priv->editor, "changed::editor-font", g_signal_connect (xs->priv->editor, "changed::editor-font",
G_CALLBACK (on_editor_font_changed), xs); 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_signal_connect (xs->priv->editor, "changed::scheme",
G_CALLBACK (on_scheme_changed), xs); G_CALLBACK (on_scheme_changed), xs);
g_signal_connect (xs->priv->editor, "changed::auto-save", g_signal_connect (xs->priv->editor, "changed::auto-save",

View File

@ -55,19 +55,10 @@ struct _XedSettingsClass
GObjectClass parent_class; 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; GType xed_settings_get_type (void) G_GNUC_CONST;
GObject *xed_settings_new (void); GObject *xed_settings_new (void);
// XedLockdownMask xed_settings_get_lockdown (XedSettings *xs);
gchar *xed_settings_get_system_font (XedSettings *xs); gchar *xed_settings_get_system_font (XedSettings *xs);
/* Utility functions */ /* Utility functions */
@ -81,6 +72,7 @@ void xed_settings_set_list (GSettings *settings,
/* key constants */ /* key constants */
#define XED_SETTINGS_USE_DEFAULT_FONT "use-default-font" #define XED_SETTINGS_USE_DEFAULT_FONT "use-default-font"
#define XED_SETTINGS_EDITOR_FONT "editor-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_SCHEME "scheme"
#define XED_SETTINGS_CREATE_BACKUP_COPY "create-backup-copy" #define XED_SETTINGS_CREATE_BACKUP_COPY "create-backup-copy"
#define XED_SETTINGS_AUTO_SAVE "auto-save" #define XED_SETTINGS_AUTO_SAVE "auto-save"