[glade] Added GladeFontButtonEditor



commit 154d10d0e4840c7bdb989e27354d2d797e977a0b
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sat May 4 23:38:46 2013 +0900

    Added GladeFontButtonEditor
    
    Embeds a GladeFontChooserEditor and formats some other properties

 plugins/gtk+/Makefile.am                       |    3 +
 plugins/gtk+/glade-font-button-editor.c        |   48 +++++++
 plugins/gtk+/glade-font-button-editor.h        |   57 ++++++++
 plugins/gtk+/glade-font-button-editor.ui       |  177 ++++++++++++++++++++++++
 plugins/gtk+/glade-gtk-button.c                |   25 ++++-
 plugins/gtk+/glade-gtk-resources.gresource.xml |    1 +
 plugins/gtk+/gtk+.xml.in                       |   17 ++-
 po/POTFILES.in                                 |    2 +
 8 files changed, 328 insertions(+), 2 deletions(-)
---
diff --git a/plugins/gtk+/Makefile.am b/plugins/gtk+/Makefile.am
index 2170d1c..84eaa1a 100644
--- a/plugins/gtk+/Makefile.am
+++ b/plugins/gtk+/Makefile.am
@@ -36,6 +36,7 @@ libgladegtk_la_SOURCES =              \
        glade-file-chooser-editor.c     \
        glade-file-chooser-widget-editor.c \
        glade-fixed.c                   \
+       glade-font-button-editor.c      \
        glade-font-chooser-dialog-editor.c \
        glade-font-chooser-editor.c     \
        glade-font-chooser-widget-editor.c \
@@ -125,6 +126,7 @@ noinst_HEADERS =                    \
        glade-file-chooser-editor.h     \
        glade-file-chooser-widget-editor.h \
        glade-fixed.h                   \
+       glade-font-button-editor.h      \
        glade-font-chooser-dialog-editor.h \
        glade-font-chooser-editor.h     \
        glade-font-chooser-widget-editor.h \
@@ -183,6 +185,7 @@ UI_FILES =                          \
        glade-file-chooser-dialog-editor.ui \
        glade-file-chooser-editor.ui    \
        glade-file-chooser-widget-editor.ui \
+       glade-font-button-editor.ui     \
        glade-font-chooser-dialog-editor.ui \
        glade-font-chooser-editor.ui    \
        glade-font-chooser-widget-editor.ui \
diff --git a/plugins/gtk+/glade-font-button-editor.c b/plugins/gtk+/glade-font-button-editor.c
new file mode 100644
index 0000000..67b6bc7
--- /dev/null
+++ b/plugins/gtk+/glade-font-button-editor.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2013 Tristan Van Berkom.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public 
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors:
+ *   Tristan Van Berkom <tvb gnome org>
+ */
+
+#include <config.h>
+#include <gladeui/glade.h>
+#include <glib/gi18n-lib.h>
+
+#include "glade-font-button-editor.h"
+
+G_DEFINE_TYPE (GladeFontButtonEditor, glade_font_button_editor, GLADE_TYPE_EDITOR_SKELETON)
+
+static void
+glade_font_button_editor_class_init (GladeFontButtonEditorClass * klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/gladegtk/glade-font-button-editor.ui");
+}
+
+static void
+glade_font_button_editor_init (GladeFontButtonEditor * self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GtkWidget *
+glade_font_button_editor_new (void)
+{
+  return g_object_new (GLADE_TYPE_FONT_BUTTON_EDITOR, NULL);
+}
diff --git a/plugins/gtk+/glade-font-button-editor.h b/plugins/gtk+/glade-font-button-editor.h
new file mode 100644
index 0000000..9e146c8
--- /dev/null
+++ b/plugins/gtk+/glade-font-button-editor.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 Tristan Van Berkom.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public 
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors:
+ *   Tristan Van Berkom <tvb gnome org>
+ */
+#ifndef _GLADE_FONT_BUTTON_EDITOR_H_
+#define _GLADE_FONT_BUTTON_EDITOR_H_
+
+#include <gtk/gtk.h>
+#include <gladeui/glade.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_FONT_BUTTON_EDITOR              (glade_font_button_editor_get_type ())
+#define GLADE_FONT_BUTTON_EDITOR(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GLADE_TYPE_FONT_BUTTON_EDITOR, GladeFontButtonEditor))
+#define GLADE_FONT_BUTTON_EDITOR_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), 
GLADE_TYPE_FONT_BUTTON_EDITOR, GladeFontButtonEditorClass))
+#define GLADE_IS_FONT_BUTTON_EDITOR(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GLADE_TYPE_FONT_BUTTON_EDITOR))
+#define GLADE_IS_FONT_BUTTON_EDITOR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GLADE_TYPE_FONT_BUTTON_EDITOR))
+#define GLADE_FONT_BUTTON_EDITOR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GLADE_TYPE_FONT_BUTTON_EDITOR, GladeFontButtonEditorClass))
+
+typedef struct _GladeFontButtonEditor        GladeFontButtonEditor;
+typedef struct _GladeFontButtonEditorClass   GladeFontButtonEditorClass;
+typedef struct _GladeFontButtonEditorPrivate GladeFontButtonEditorPrivate;
+
+struct _GladeFontButtonEditor
+{
+  GladeEditorSkeleton  parent;
+
+  GladeFontButtonEditorPrivate *priv;
+};
+
+struct _GladeFontButtonEditorClass
+{
+  GladeEditorSkeletonClass parent;
+};
+
+GType            glade_font_button_editor_get_type (void) G_GNUC_CONST;
+GtkWidget       *glade_font_button_editor_new      (void);
+
+G_END_DECLS
+
+#endif  /* _GLADE_FONT_BUTTON_EDITOR_H_ */
diff --git a/plugins/gtk+/glade-font-button-editor.ui b/plugins/gtk+/glade-font-button-editor.ui
new file mode 100644
index 0000000..e850edc
--- /dev/null
+++ b/plugins/gtk+/glade-font-button-editor.ui
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="glade">
+  <!-- interface-requires gladeui 0.0 -->
+  <!-- interface-requires gtk+ 3.10 -->
+  <!-- interface-requires glade-gtk-plugin 0.0 -->
+  <template class="GladeFontButtonEditor" parent="GladeEditorSkeleton">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkGrid" id="grid1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="row_spacing">6</property>
+        <property name="column_spacing">6</property>
+        <child>
+          <object class="GladeEditorTable" id="embed">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">6</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladeFontChooserEditor" id="fontchoosereditor">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">5</property>
+            <property name="width">6</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="title">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="valign">center</property>
+            <property name="label" translatable="yes">Font Button Attributes</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">6</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyLabel" id="title_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="hexpand">False</property>
+            <property name="property_name">title</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyShell" id="title_editor">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="property_name">title</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">2</property>
+            <property name="width">5</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyShell" id="use_font_editor">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="hexpand">False</property>
+            <property name="property_name">use-font</property>
+            <property name="editor_type">GladeEpropCheck</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">3</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyShell" id="use_size_editor">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="property_name">use-size</property>
+            <property name="editor_type">GladeEpropCheck</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">3</property>
+            <property name="width">3</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyShell" id="show_style_editor">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="hexpand">False</property>
+            <property name="property_name">show-style</property>
+            <property name="editor_type">GladeEpropCheck</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">4</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyShell" id="show_size_editor">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="property_name">show-size</property>
+            <property name="editor_type">GladeEpropCheck</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">4</property>
+            <property name="width">3</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child-editors>
+      <editor id="embed"/>
+      <editor id="fontchoosereditor"/>
+      <editor id="title_label"/>
+      <editor id="title_editor"/>
+      <editor id="use_font_editor"/>
+      <editor id="use_size_editor"/>
+      <editor id="show_style_editor"/>
+      <editor id="show_size_editor"/>
+    </child-editors>
+  </template>
+</interface>
diff --git a/plugins/gtk+/glade-gtk-button.c b/plugins/gtk+/glade-gtk-button.c
index 3797be2..bd5f866 100644
--- a/plugins/gtk+/glade-gtk-button.c
+++ b/plugins/gtk+/glade-gtk-button.c
@@ -26,6 +26,7 @@
 #include <gladeui/glade.h>
 
 #include "glade-button-editor.h"
+#include "glade-font-button-editor.h"
 #include "glade-gtk.h"
 #include "glade-gtk-button.h"
 
@@ -119,7 +120,12 @@ glade_gtk_button_create_editable (GladeWidgetAdaptor * adaptor,
 {
   if (type == GLADE_PAGE_GENERAL)
     {
-      return (GladeEditable *) glade_button_editor_new (adaptor, NULL);
+      GType type = glade_widget_adaptor_get_object_type (adaptor);
+
+      if (g_type_is_a (type, GTK_TYPE_FONT_BUTTON))
+       return (GladeEditable *) glade_font_button_editor_new ();
+      else
+       return (GladeEditable *) glade_button_editor_new (adaptor, NULL);
     }
 
   return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type);
@@ -213,6 +219,8 @@ void
 glade_gtk_button_read_widget (GladeWidgetAdaptor * adaptor,
                               GladeWidget * widget, GladeXmlNode * node)
 {
+  GObject *object;
+
   if (!(glade_xml_node_verify_silent (node, GLADE_XML_TAG_WIDGET) ||
        glade_xml_node_verify_silent (node, GLADE_XML_TAG_TEMPLATE)))
     return;
@@ -221,6 +229,21 @@ glade_gtk_button_read_widget (GladeWidgetAdaptor * adaptor,
   GWA_GET_CLASS (GTK_TYPE_CONTAINER)->read_widget (adaptor, widget, node);
 
   glade_gtk_button_update_stock (widget);
+
+  /* Fold "font-name" property into the "font" propery */
+  object = glade_widget_get_object (widget);
+  if (GTK_IS_FONT_BUTTON (object))
+    {
+      gchar *font_prop_value = NULL;
+
+      glade_widget_property_get (widget, "font-name", &font_prop_value);
+
+      if (font_prop_value != NULL)
+       {
+         glade_widget_property_set (widget, "font", font_prop_value);
+         glade_widget_property_set (widget, "font-name", NULL);
+       }
+    }
 }
 
 void
diff --git a/plugins/gtk+/glade-gtk-resources.gresource.xml b/plugins/gtk+/glade-gtk-resources.gresource.xml
index af34cdd..fb11e28 100644
--- a/plugins/gtk+/glade-gtk-resources.gresource.xml
+++ b/plugins/gtk+/glade-gtk-resources.gresource.xml
@@ -9,6 +9,7 @@
     <file compressed="true" preprocess="xml-stripblanks">glade-file-chooser-dialog-editor.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-file-chooser-editor.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-file-chooser-widget-editor.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">glade-font-button-editor.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-font-chooser-dialog-editor.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-font-chooser-editor.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">glade-font-chooser-widget-editor.ui</file>
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 1b01c72..1ddf25b 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -1456,10 +1456,25 @@ embedded in another object</_tooltip>
     </glade-widget-class>
 
     <glade-widget-class name="GtkFontButton" generic-name="fontbutton" _title="Font Button">
-      <create-editable-function>glade_gtk_container_create_editable</create-editable-function>
+      <create-editable-function>glade_gtk_button_create_editable</create-editable-function>
       <properties>
        <property id="title" translatable="True"/>
 
+       <!-- This one is never displayed, use the GtkFontChooser:font property instead -->
+       <property id="font-name" save="False" custom-layout="True" ignore="True"/>
+
+       <!-- Claim the GladeFontButtonEditor properties -->
+       <property id="title" custom-layout="True"/>
+       <property id="use-font" custom-layout="True"/>
+       <property id="use-size" custom-layout="True"/>
+       <property id="show-style" custom-layout="True"/>
+       <property id="show-size" custom-layout="True"/>
+
+       <!-- Claim the GladeFontChooserEditor properties -->
+       <property id="font" custom-layout="True"/>
+       <property id="preview-text" custom-layout="True"/>
+       <property id="show-preview-entry" custom-layout="True"/>
+
        <!-- These props dont apply to font buttons -->
        <property id="glade-type" disabled="True"/>
        <property id="label" disabled="True"/>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index dc4ba84..8ef7412 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -65,6 +65,7 @@ plugins/gtk+/glade-file-chooser-dialog-editor.c
 plugins/gtk+/glade-file-chooser-editor.c
 plugins/gtk+/glade-file-chooser-widget-editor.c
 plugins/gtk+/glade-fixed.c
+plugins/gtk+/glade-font-button-editor.c
 plugins/gtk+/glade-font-chooser-dialog-editor.c
 plugins/gtk+/glade-font-chooser-editor.c
 plugins/gtk+/glade-font-chooser-widget-editor.c
@@ -146,6 +147,7 @@ plugins/gtk+/gtk+.xml.in
 [type: gettext/glade]plugins/gtk+/glade-file-chooser-dialog-editor.ui
 [type: gettext/glade]plugins/gtk+/glade-file-chooser-editor.ui
 [type: gettext/glade]plugins/gtk+/glade-file-chooser-widget-editor.ui
+[type: gettext/glade]plugins/gtk+/glade-font-button-editor.ui
 [type: gettext/glade]plugins/gtk+/glade-font-chooser-dialog-editor.ui
 [type: gettext/glade]plugins/gtk+/glade-font-chooser-editor.ui
 [type: gettext/glade]plugins/gtk+/glade-image-editor.ui


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