Beispiel #1
0
static void
value_text_edited (GtkCellRendererText * cell,
                   const gchar * path,
                   const gchar * new_text, GladeEditorProperty * eprop)
{
  GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
  GtkTreeIter iter;
  gint colnum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column-number"));
  gint row;
  GNode *data_tree = NULL;
  GladeModelData *data;
  GValue *value;
  GladeProperty *property = glade_editor_property_get_property (eprop);

  if (!gtk_tree_model_get_iter_from_string
      (GTK_TREE_MODEL (eprop_data->store), &iter, path))
    return;

  gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter,
                      COLUMN_ROW, &row, -1);

  glade_property_get (property, &data_tree);

  /* if we are editing, then there is data in the datatree */
  g_assert (data_tree);

  data_tree = glade_model_data_tree_copy (data_tree);

  data = glade_model_data_tree_get_data (data_tree, row, colnum);

  /* Untranslate string and update value in tree. */
  if (G_VALUE_HOLDS_ENUM (&data->value) || G_VALUE_HOLDS_FLAGS (&data->value))
    value = glade_utils_value_from_string (G_VALUE_TYPE (&data->value),
                                           glade_get_value_from_displayable
                                           (G_VALUE_TYPE (&data->value),
                                            new_text),
                                           glade_widget_get_project (glade_property_get_widget (property)));
  else
    value =
        glade_utils_value_from_string (G_VALUE_TYPE (&data->value), new_text,
                                       glade_widget_get_project (glade_property_get_widget (property)));


  g_value_copy (value, &data->value);
  g_value_unset (value);
  g_free (value);

  eprop_data->editing_row = row;
  eprop_data->editing_column = colnum;
  if (eprop_data->pending_data_tree)
    glade_model_data_tree_free (eprop_data->pending_data_tree);

  eprop_data->pending_data_tree = data_tree;
  g_idle_add ((GSourceFunc) update_and_focus_data_tree_idle, eprop);
}
Beispiel #2
0
static void
glade_eprop_model_data_add_row (GladeEditorProperty * eprop)
{
  GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
  GValue value = { 0, };
  GNode *node = NULL;
  GList *columns = NULL;
  GladeProperty *property = glade_editor_property_get_property (eprop);

  glade_property_get (property, &node);
  glade_widget_property_get (glade_property_get_widget (property), "columns", &columns);

  if (!columns)
    return;

  clear_view (eprop);

  if (!node)
    node = g_node_new (NULL);
  else
    node = glade_model_data_tree_copy (node);

  append_row (node, columns);

  eprop_data->adding_row = TRUE;

  g_value_init (&value, GLADE_TYPE_MODEL_DATA_TREE);
  g_value_take_boxed (&value, node);
  glade_editor_property_commit (eprop, &value);
  g_value_unset (&value);

  eprop_data->adding_row = FALSE;
}
Beispiel #3
0
static void
value_filename_edited (GtkCellRendererText * cell,
                       const gchar * path,
                       const gchar * new_text, GladeEditorProperty * eprop)
{
  GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop);
  GladeProperty *property = glade_editor_property_get_property (eprop);
  GtkTreeIter iter;
  GladeIconSources *icon_sources = NULL;
  GtkIconSource *source;
  gchar *icon_name;
  gint index = -1;
  GValue *value;
  GdkPixbuf *pixbuf;
  GList *source_list;

  if (!new_text || !new_text[0])
    {
      g_idle_add ((GSourceFunc) reload_icon_sources_idle, eprop);
      return;
    }

  if (!gtk_tree_model_get_iter_from_string
      (GTK_TREE_MODEL (eprop_sources->store), &iter, path))
    return;

  gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter,
                      COLUMN_ICON_NAME, &icon_name,
                      COLUMN_LIST_INDEX, &index, -1);

  /* get new pixbuf value... */
  value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, new_text,
                                         glade_widget_get_project (glade_property_get_widget (property)));
  pixbuf = g_value_get_object (value);


  glade_property_get (property, &icon_sources);
  if (icon_sources)
    {
      icon_sources = glade_icon_sources_copy (icon_sources);

      if (index >= 0 &&
          (source = get_icon_source (icon_sources, icon_name, index)) != NULL)
        gtk_icon_source_set_pixbuf (source, pixbuf);
      else
        {

          source = gtk_icon_source_new ();
          gtk_icon_source_set_pixbuf (source, pixbuf);

          if ((source_list = g_hash_table_lookup (icon_sources->sources,
                                                  icon_name)) != NULL)
            {
              source_list = g_list_append (source_list, source);
            }
          else
            {
              source_list = g_list_prepend (NULL, source);
              g_hash_table_insert (icon_sources->sources, g_strdup (icon_name),
                                   source_list);
            }
        }
    }
  else
    {
      icon_sources = glade_icon_sources_new ();
      source = gtk_icon_source_new ();
      gtk_icon_source_set_pixbuf (source, pixbuf);

      source_list = g_list_prepend (NULL, source);
      g_hash_table_insert (icon_sources->sources, g_strdup (icon_name),
                           source_list);
    }

  g_value_unset (value);
  g_free (value);

  update_icon_sources (eprop, icon_sources);
}