[gnome-builder/wip/gtk4-port: 1011/1774] libide/gui: add font preferences
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1011/1774] libide/gui: add font preferences
- Date: Mon, 11 Jul 2022 22:31:31 +0000 (UTC)
commit b9a628bb3874bfa081af1781c2b68db96fc9b227
Author: Christian Hergert <chergert redhat com>
Date: Fri May 13 23:52:42 2022 -0700
libide/gui: add font preferences
src/libide/gui/ide-preferences-builtin.c | 6 ++
src/libide/gui/ide-preferences-window.c | 90 ++++++++++++++++++++++
src/libide/gui/ide-preferences-window.h | 5 ++
.../editorui/gbp-editorui-preferences-addin.c | 5 ++
4 files changed, 106 insertions(+)
---
diff --git a/src/libide/gui/ide-preferences-builtin.c b/src/libide/gui/ide-preferences-builtin.c
index 1e89de475..f0262c985 100644
--- a/src/libide/gui/ide-preferences-builtin.c
+++ b/src/libide/gui/ide-preferences-builtin.c
@@ -743,6 +743,12 @@ static const IdePreferenceItemEntry items[] = {
N_("Builder"),
N_("Keyboard shortcuts similar to GNOME Text Editor"),
"org.gnome.builder.editor", NULL, "keybindings", "'default'" },
+
+ /* TODO: This belongs in plugins/terminal after it is ported */
+ { "appearance", "font", "terminal-font", 10, ide_preferences_window_font,
+ N_("Terminal Font"),
+ N_("The font used within terminals"),
+ "org.gnome.builder.terminal", NULL, "font-name" },
};
static gboolean
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index f9d0bea6b..914c956e4 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -1452,6 +1452,96 @@ ide_preferences_window_spin (const char *page_name,
g_settings_bind (settings, entry->key, adj, "value", G_SETTINGS_BIND_DEFAULT);
}
+static void
+on_font_response_cb (GtkFontChooserDialog *dialog,
+ int response_id,
+ GSettings *settings)
+{
+ const char *key = g_object_get_data (G_OBJECT (dialog), "SETTINGS_KEY");
+ const char *font = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (dialog));
+
+ if (response_id == GTK_RESPONSE_OK)
+ g_settings_set_string (settings, key, font);
+
+ gtk_window_destroy (GTK_WINDOW (dialog));
+}
+
+static void
+on_font_activate (GtkButton *button,
+ GSettings *settings)
+{
+ const char *key;
+ GtkWidget *dialog;
+ GtkRoot *root;
+
+ g_assert (GTK_IS_BUTTON (button));
+ g_assert (G_IS_SETTINGS (settings));
+
+ key = g_object_get_data (G_OBJECT (button), "SETTINGS_KEY");
+
+ root = gtk_widget_get_root (GTK_WIDGET (button));
+ dialog = gtk_font_chooser_dialog_new (_("Select Font"), GTK_WINDOW (root));
+ g_settings_bind (settings, key, dialog, "font", G_SETTINGS_BIND_GET);
+
+ g_signal_connect_object (dialog,
+ "response",
+ G_CALLBACK (on_font_response_cb),
+ settings,
+ 0);
+
+ g_object_set_data (G_OBJECT (dialog),
+ "SETTINGS_KEY",
+ (char *)g_intern_string (key));
+
+ gtk_window_present (GTK_WINDOW (dialog));
+}
+
+void
+ide_preferences_window_font (const char *page_name,
+ const IdePreferenceItemEntry *entry,
+ AdwPreferencesGroup *group,
+ gpointer user_data)
+{
+ IdePreferencesWindow *self = user_data;
+ g_autofree char *title_esc = NULL;
+ g_autofree char *subtitle_esc = NULL;
+ AdwActionRow *row;
+ GSettings *settings;
+ GtkWidget *child;
+
+ g_return_if_fail (entry != NULL);
+ g_return_if_fail (ADW_IS_PREFERENCES_GROUP (group));
+ g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (self));
+
+ if (!(settings = ide_preferences_window_get_settings (self, entry)))
+ return;
+
+ title_esc = g_markup_escape_text (entry->title ? entry->title : "", -1);
+ subtitle_esc = g_markup_escape_text (entry->subtitle ? entry->subtitle : "", -1);
+
+ child = g_object_new (GTK_TYPE_BUTTON,
+ "valign", GTK_ALIGN_CENTER,
+ NULL);
+ row = g_object_new (ADW_TYPE_ACTION_ROW,
+ "title", title_esc,
+ "subtitle", subtitle_esc,
+ "activatable-widget", child,
+ NULL);
+ adw_action_row_add_suffix (row, child);
+ adw_preferences_group_add (group, GTK_WIDGET (row));
+
+ g_settings_bind (settings, entry->key, child, "label", G_SETTINGS_BIND_GET);
+ g_object_set_data (G_OBJECT (child),
+ "SETTINGS_KEY",
+ (char *)g_intern_string (entry->key));
+
+ g_signal_connect_object (child,
+ "clicked",
+ G_CALLBACK (on_font_activate),
+ settings,
+ 0);
+}
+
IdePreferencesMode
ide_preferences_window_get_mode (IdePreferencesWindow *self)
{
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index 2aefa8821..5b8a0adb1 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -149,5 +149,10 @@ void ide_preferences_window_spin (const char
const IdePreferenceItemEntry *entry,
AdwPreferencesGroup *group,
gpointer user_data);
+IDE_AVAILABLE_IN_ALL
+void ide_preferences_window_font (const char *page_name,
+ const IdePreferenceItemEntry *entry,
+ AdwPreferencesGroup *group,
+ gpointer user_data);
G_END_DECLS
diff --git a/src/plugins/editorui/gbp-editorui-preferences-addin.c
b/src/plugins/editorui/gbp-editorui-preferences-addin.c
index 279a2c0fa..b2d8e6772 100644
--- a/src/plugins/editorui/gbp-editorui-preferences-addin.c
+++ b/src/plugins/editorui/gbp-editorui-preferences-addin.c
@@ -56,6 +56,11 @@ static const IdePreferenceGroupEntry lang_groups[] = {
};
static const IdePreferenceItemEntry items[] = {
+ { "appearance", "font", "font-name", 0, ide_preferences_window_font,
+ N_("Editor Font"),
+ N_("The font used within the source code editor"),
+ "org.gnome.builder.editor", NULL, "font-name" },
+
{ "appearance", "effects", "show-grid-lines", 10, ide_preferences_window_toggle,
N_("Show Grid Pattern"),
N_("Display a grid pattern underneath source code"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]