Blame plugins/gtk+/glade-store-editor.c

Packit 1e8aac
/*
Packit 1e8aac
 * Copyright (C) 2008 Tristan Van Berkom.
Packit 1e8aac
 *
Packit 1e8aac
 * This library is free software; you can redistribute it and/or modify it
Packit 1e8aac
 * under the terms of the GNU Lesser General Public License as
Packit 1e8aac
 * published by the Free Software Foundation; either version 2.1 of
Packit 1e8aac
 * the License, or (at your option) any later version.
Packit 1e8aac
 *
Packit 1e8aac
 * This library is distributed in the hope that it will be useful, but
Packit 1e8aac
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 1e8aac
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 1e8aac
 * Lesser General Public License for more details.
Packit 1e8aac
 *
Packit 1e8aac
 * You should have received a copy of the GNU Lesser General Public 
Packit 1e8aac
 * License along with this program; if not, write to the Free Software
Packit 1e8aac
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 1e8aac
 *
Packit 1e8aac
 * Authors:
Packit 1e8aac
 *   Tristan Van Berkom <tvb@gnome.org>
Packit 1e8aac
 */
Packit 1e8aac
Packit 1e8aac
#include <config.h>
Packit 1e8aac
#include <gladeui/glade.h>
Packit 1e8aac
#include <glib/gi18n-lib.h>
Packit 1e8aac
#include <gdk/gdkkeysyms.h>
Packit 1e8aac
Packit 1e8aac
#include "glade-store-editor.h"
Packit 1e8aac
Packit 1e8aac
Packit 1e8aac
static void glade_store_editor_finalize (GObject * object);
Packit 1e8aac
Packit 1e8aac
static void glade_store_editor_editable_init (GladeEditableIface * iface);
Packit 1e8aac
Packit 1e8aac
static void glade_store_editor_grab_focus (GtkWidget * widget);
Packit 1e8aac
Packit 1e8aac
Packit 1e8aac
static GladeEditableIface *parent_editable_iface;
Packit 1e8aac
Packit 1e8aac
G_DEFINE_TYPE_WITH_CODE (GladeStoreEditor, glade_store_editor, GTK_TYPE_BOX,
Packit 1e8aac
                         G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE,
Packit 1e8aac
                                                glade_store_editor_editable_init));
Packit 1e8aac
Packit 1e8aac
Packit 1e8aac
static void
Packit 1e8aac
glade_store_editor_class_init (GladeStoreEditorClass * klass)
Packit 1e8aac
{
Packit 1e8aac
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
Packit 1e8aac
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
Packit 1e8aac
Packit 1e8aac
  object_class->finalize = glade_store_editor_finalize;
Packit 1e8aac
  widget_class->grab_focus = glade_store_editor_grab_focus;
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
static void
Packit 1e8aac
glade_store_editor_init (GladeStoreEditor * self)
Packit 1e8aac
{
Packit 1e8aac
  gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
Packit 1e8aac
				  GTK_ORIENTATION_VERTICAL);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
static void
Packit 1e8aac
glade_store_editor_load (GladeEditable * editable, GladeWidget * widget)
Packit 1e8aac
{
Packit 1e8aac
  GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (editable);
Packit 1e8aac
  GList *l;
Packit 1e8aac
Packit 1e8aac
  /* Chain up to default implementation */
Packit 1e8aac
  parent_editable_iface->load (editable, widget);
Packit 1e8aac
Packit 1e8aac
  /* load the embedded editable... */
Packit 1e8aac
  if (store_editor->embed)
Packit 1e8aac
    glade_editable_load (GLADE_EDITABLE (store_editor->embed), widget);
Packit 1e8aac
Packit 1e8aac
  for (l = store_editor->properties; l; l = l->next)
Packit 1e8aac
    glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data),
Packit 1e8aac
                                          widget);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
static void
Packit 1e8aac
glade_store_editor_set_show_name (GladeEditable * editable, gboolean show_name)
Packit 1e8aac
{
Packit 1e8aac
  GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (editable);
Packit 1e8aac
Packit 1e8aac
  glade_editable_set_show_name (GLADE_EDITABLE (store_editor->embed),
Packit 1e8aac
                                show_name);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
static void
Packit 1e8aac
glade_store_editor_editable_init (GladeEditableIface * iface)
Packit 1e8aac
{
Packit 1e8aac
  parent_editable_iface = g_type_default_interface_peek (GLADE_TYPE_EDITABLE);
Packit 1e8aac
Packit 1e8aac
  iface->load = glade_store_editor_load;
Packit 1e8aac
  iface->set_show_name = glade_store_editor_set_show_name;
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
static void
Packit 1e8aac
glade_store_editor_finalize (GObject * object)
Packit 1e8aac
{
Packit 1e8aac
  GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (object);
Packit 1e8aac
Packit 1e8aac
  if (store_editor->properties)
Packit 1e8aac
    g_list_free (store_editor->properties);
Packit 1e8aac
  store_editor->properties = NULL;
Packit 1e8aac
  store_editor->embed = NULL;
Packit 1e8aac
Packit 1e8aac
  glade_editable_load (GLADE_EDITABLE (object), NULL);
Packit 1e8aac
Packit 1e8aac
  G_OBJECT_CLASS (glade_store_editor_parent_class)->finalize (object);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
static void
Packit 1e8aac
glade_store_editor_grab_focus (GtkWidget * widget)
Packit 1e8aac
{
Packit 1e8aac
  GladeStoreEditor *store_editor = GLADE_STORE_EDITOR (widget);
Packit 1e8aac
Packit 1e8aac
  gtk_widget_grab_focus (store_editor->embed);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
GtkWidget *
Packit 1e8aac
glade_store_editor_new (GladeWidgetAdaptor * adaptor, GladeEditable * embed)
Packit 1e8aac
{
Packit 1e8aac
  GladeStoreEditor *store_editor;
Packit 1e8aac
  GladeEditorProperty *eprop;
Packit 1e8aac
  GtkWidget *frame, *alignment, *label, *vbox;
Packit 1e8aac
Packit 1e8aac
  g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
Packit 1e8aac
  g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL);
Packit 1e8aac
Packit 1e8aac
  /* Pack the parent on top... */
Packit 1e8aac
  store_editor = g_object_new (GLADE_TYPE_STORE_EDITOR, NULL);
Packit 1e8aac
  store_editor->embed = GTK_WIDGET (embed);
Packit 1e8aac
  gtk_box_pack_start (GTK_BOX (store_editor), GTK_WIDGET (embed), FALSE, FALSE,
Packit 1e8aac
                      0);
Packit 1e8aac
Packit 1e8aac
  /* -------------- The columns area here -------------- */
Packit 1e8aac
  /* Label item in frame label widget on top.. */
Packit 1e8aac
  eprop =
Packit 1e8aac
      glade_widget_adaptor_create_eprop_by_name (adaptor, "columns", FALSE,
Packit 1e8aac
                                                 TRUE);
Packit 1e8aac
  store_editor->properties = g_list_prepend (store_editor->properties, eprop);
Packit 1e8aac
  frame = gtk_frame_new (NULL);
Packit 1e8aac
  gtk_frame_set_label_widget (GTK_FRAME (frame), glade_editor_property_get_item_label (eprop));
Packit 1e8aac
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
Packit 1e8aac
  gtk_box_pack_start (GTK_BOX (store_editor), frame, FALSE, FALSE, 12);
Packit 1e8aac
Packit 1e8aac
  /* Alignment/Vbox in frame... */
Packit 1e8aac
  alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F);
Packit 1e8aac
  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0);
Packit 1e8aac
  gtk_container_add (GTK_CONTAINER (frame), alignment);
Packit 1e8aac
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
Packit 1e8aac
  gtk_container_add (GTK_CONTAINER (alignment), vbox);
Packit 1e8aac
Packit 1e8aac
  /* Add descriptive label */
Packit 1e8aac
  label = gtk_label_new (_("Define columns for your liststore; "
Packit 1e8aac
                           "giving them meaningful names will help you to retrieve "
Packit 1e8aac
                           "them when setting cell renderer attributes (press the "
Packit 1e8aac
                           "Delete key to remove the selected column)"));
Packit 1e8aac
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
Packit 1e8aac
  gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD);
Packit 1e8aac
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6);
Packit 1e8aac
  gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4);
Packit 1e8aac
Packit 1e8aac
Packit 1e8aac
  if (glade_widget_adaptor_get_object_type (adaptor) == GTK_TYPE_LIST_STORE ||
Packit 1e8aac
      g_type_is_a (glade_widget_adaptor_get_object_type (adaptor), GTK_TYPE_LIST_STORE))
Packit 1e8aac
    {
Packit 1e8aac
      /* -------------- The data area here -------------- */
Packit 1e8aac
      /* Label item in frame label widget on top.. */
Packit 1e8aac
      eprop =
Packit 1e8aac
          glade_widget_adaptor_create_eprop_by_name (adaptor, "data", FALSE,
Packit 1e8aac
                                                     TRUE);
Packit 1e8aac
      store_editor->properties =
Packit 1e8aac
          g_list_prepend (store_editor->properties, eprop);
Packit 1e8aac
      frame = gtk_frame_new (NULL);
Packit 1e8aac
      gtk_frame_set_label_widget (GTK_FRAME (frame), glade_editor_property_get_item_label (eprop));
Packit 1e8aac
      gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
Packit 1e8aac
      gtk_box_pack_start (GTK_BOX (store_editor), frame, FALSE, FALSE, 12);
Packit 1e8aac
Packit 1e8aac
      /* Alignment/Vbox in frame... */
Packit 1e8aac
      alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F);
Packit 1e8aac
      gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0);
Packit 1e8aac
      gtk_container_add (GTK_CONTAINER (frame), alignment);
Packit 1e8aac
      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
Packit 1e8aac
      gtk_container_add (GTK_CONTAINER (alignment), vbox);
Packit 1e8aac
Packit 1e8aac
      /* Add descriptive label */
Packit 1e8aac
      label =
Packit 1e8aac
          gtk_label_new (_
Packit 1e8aac
                         ("Add remove and edit rows of data (you can optionally use Ctrl+N to add "
Packit 1e8aac
                          "new rows and the Delete key to remove the selected row)"));
Packit 1e8aac
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
Packit 1e8aac
      gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD);
Packit 1e8aac
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6);
Packit 1e8aac
      gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4);
Packit 1e8aac
    }
Packit 1e8aac
Packit 1e8aac
  gtk_widget_show_all (GTK_WIDGET (store_editor));
Packit 1e8aac
Packit 1e8aac
  return GTK_WIDGET (store_editor);
Packit 1e8aac
}