[gnome-builder] libide/gui: add tweaks application action



commit 6203790cb63ab009880a2e3833c04f3984d871e9
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 10 17:18:20 2022 -0700

    libide/gui: add tweaks application action
    
    This is the start of the scaffolding to use IdeTweaks instead of
    IdePreferences. Eventually, once it's ready, we can delete IdePreferences
    and switch the actions to use this.

 src/libide/gui/ide-application-actions.c | 72 +++++++++++++++++++++++
 src/libide/gui/libide-gui.gresource.xml  |  1 +
 src/libide/gui/meson.build               |  1 +
 src/libide/gui/tweaks.ui                 | 98 ++++++++++++++++++++++++++++++++
 4 files changed, 172 insertions(+)
---
diff --git a/src/libide/gui/ide-application-actions.c b/src/libide/gui/ide-application-actions.c
index b3e3ea530..e8fad4881 100644
--- a/src/libide/gui/ide-application-actions.c
+++ b/src/libide/gui/ide-application-actions.c
@@ -26,7 +26,9 @@
 #include <glib/gi18n.h>
 
 #include <ide-build-ident.h>
+
 #include <libide-projects.h>
+#include <libide-tweaks.h>
 
 #include "ide-application.h"
 #include "ide-application-credits.h"
@@ -36,6 +38,75 @@
 #include "ide-primary-workspace.h"
 #include "ide-support-private.h"
 
+static void
+ide_application_actions_tweaks (GSimpleAction *action,
+                                GVariant      *parameter,
+                                gpointer       user_data)
+{
+  IdeApplication *self = user_data;
+  g_autoptr(GListStore) languages = NULL;
+  g_autoptr(IdeTweaks) tweaks = NULL;
+  g_autoptr(GError) error = NULL;
+  g_autoptr(GFile) tweaks_file = NULL;
+  IdeTweaksWindow *window;
+  GtkWindow *toplevel = NULL;
+  const GList *windows;
+
+  IDE_ENTRY;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_APPLICATION (self));
+
+  /* Locate a toplevel for a transient-for property, or a previous
+   * tweaks window to display.
+   */
+  windows = gtk_application_get_windows (GTK_APPLICATION (self));
+  for (; windows; windows = windows->next)
+    {
+      if (IDE_IS_TWEAKS_WINDOW (windows->data))
+        {
+          gtk_window_present (windows->data);
+          return;
+        }
+
+      if (toplevel == NULL && IDE_IS_PRIMARY_WORKSPACE (windows->data))
+        toplevel = windows->data;
+    }
+
+  tweaks = ide_tweaks_new ();
+
+  /* Setup access to sourceview languages */
+  {
+    GtkSourceLanguageManager *lm = gtk_source_language_manager_get_default ();
+    const char * const *ids = gtk_source_language_manager_get_language_ids (lm);
+    const char * const *allowed = IDE_STRV_INIT ("c", "chdr", "css", "xml");
+
+    languages = g_list_store_new (GTK_SOURCE_TYPE_LANGUAGE);
+
+    for (guint i = 0; ids[i]; i++)
+      {
+        if (g_strv_contains (allowed, ids[i]))
+          g_list_store_append (languages, gtk_source_language_manager_get_language (lm, ids[i]));
+      }
+
+    ide_tweaks_expose_object (tweaks, "GtkSourceLanguages", G_OBJECT (languages));
+  }
+
+  /* Load our base tweaks scaffolding */
+  tweaks_file = g_file_new_for_uri ("resource:///org/gnome/libide-gui/tweaks.ui");
+  ide_tweaks_load_from_file (tweaks, tweaks_file, NULL, &error);
+  g_assert_no_error (error);
+
+  /* Now display window */
+  window = g_object_new (IDE_TYPE_TWEAKS_WINDOW,
+                         "tweaks", tweaks,
+                         NULL);
+  gtk_application_add_window (GTK_APPLICATION (self), GTK_WINDOW (window));
+  gtk_window_present (GTK_WINDOW (window));
+
+  IDE_EXIT;
+}
+
 static void
 ide_application_actions_preferences (GSimpleAction *action,
                                      GVariant      *parameter,
@@ -385,6 +456,7 @@ static const GActionEntry IdeApplicationActions[] = {
   { "load-project", ide_application_actions_load_project, "s"},
   { "preferences", ide_application_actions_preferences },
   { "preferences-page", ide_application_actions_preferences, "s" },
+  { "tweaks", ide_application_actions_tweaks },
   { "quit", ide_application_actions_quit },
   { "help", ide_application_actions_help },
   { "dark", ide_application_actions_dark },
diff --git a/src/libide/gui/libide-gui.gresource.xml b/src/libide/gui/libide-gui.gresource.xml
index 41e6944d7..61f5aea1c 100644
--- a/src/libide/gui/libide-gui.gresource.xml
+++ b/src/libide/gui/libide-gui.gresource.xml
@@ -8,6 +8,7 @@
     <file>images/style-preview-default.png</file>
     <file>images/style-preview-light.png</file>
     <file>style.css</file>
+    <file preprocess="xml-stripblanks">tweaks.ui</file>
   </gresource>
   <gresource prefix="/org/gnome/libide-gui/ui">
     <file preprocess="xml-stripblanks">ide-environment-editor-row.ui</file>
diff --git a/src/libide/gui/meson.build b/src/libide/gui/meson.build
index 3a7d6f312..ce31fb298 100644
--- a/src/libide/gui/meson.build
+++ b/src/libide/gui/meson.build
@@ -174,6 +174,7 @@ libide_gui_deps = [
   libide_projects_dep,
   libide_search_dep,
   libide_sourceview_dep,
+  libide_tweaks_dep,
 ]
 
 if get_option('webkit').enabled()
diff --git a/src/libide/gui/tweaks.ui b/src/libide/gui/tweaks.ui
new file mode 100644
index 000000000..222f70c16
--- /dev/null
+++ b/src/libide/gui/tweaks.ui
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="IdeTweaks">
+    <child>
+      <object class="IdeTweaksSection" id="visual_section">
+        <child>
+          <object class="IdeTweaksPage" id="appearance_page">
+            <property name="icon-name">preferences-desktop-appearance-symbolic</property>
+            <property name="title" translatable="yes">Appearance</property>
+            <child>
+              <object class="IdeTweaksSettings">
+                <property name="schema-id">org.gnome.builder</property>
+                <property name="application-only">true</property>
+              </object>
+            </child>
+            <child>
+              <object class="IdeTweaksSettings">
+                <property name="schema-id">org.gnome.builder.editor</property>
+                <property name="application-only">true</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="IdeTweaksPage" id="editor_page">
+            <property name="icon-name">document-edit-symbolic</property>
+            <property name="title" translatable="yes">Text Editor</property>
+          </object>
+        </child>
+        <child>
+          <object class="IdeTweaksPage" id="shortcuts_page">
+            <property name="icon-name">preferences-desktop-keyboard-shortcuts-symbolic</property>
+            <property name="title" translatable="yes">Keyboard Shortcuts</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="IdeTweaksSection" id="code_section">
+        <child>
+          <object class="IdeTweaksPage" id="languages_page">
+            <property name="icon-name">text-x-javascript-symbolic</property>
+            <property name="title" translatable="yes">Programming Languages</property>
+            <child>
+              <object class="IdeTweaksFactory" id="language_page_factory">
+                <property name="model">GtkSourceLanguages</property>
+                <child>
+                  <object class="IdeTweaksPage" id="language_page">
+                    <binding name="title">
+                      <lookup name="name" type="GtkSourceLanguage">
+                        <lookup name="item">language_page_factory</lookup>
+                      </lookup>
+                    </binding>
+                    <child>
+                      <object class="IdeTweaksSettings" id="language_page_settings">
+                        <property name="schema-id">org.gnome.builder.editor.language</property>
+                        <binding name="schema-path">
+                          <closure type="gchararray" function="format">
+                            <constant type="gchararray">/org/gnome/builder/editor/languages/%s/</constant>
+                            <lookup name="id" type="GtkSourceLanguage">
+                              <lookup name="item">language_page_factory</lookup>
+                            </lookup>
+                          </closure>
+                        </binding>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="IdeTweaksSection" id="projects_section">
+      </object>
+    </child>
+    <child>
+      <object class="IdeTweaksSection" id="foundry_section">
+      </object>
+    </child>
+    <child>
+      <object class="IdeTweaksSection" id="external_section">
+      </object>
+    </child>
+    <child>
+      <object class="IdeTweaksSection" id="plugins_section">
+        <child>
+          <object class="IdeTweaksPage" id="plugins_page">
+            <property name="icon-name">builder-plugin-symbolic</property>
+            <property name="title" translatable="yes">Plugins</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]