Esempio n. 1
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;
}
Esempio n. 2
0
static void
eprop_model_data_generate_columns (GladeEditorProperty * eprop)
{
  GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
  GladeProperty *property = glade_editor_property_get_property (eprop);
  GladeModelData *iter_data;
  GtkTreeViewColumn *column;
  GNode *data_tree = NULL, *iter_node;
  gint colnum;

  glade_property_get (property, &data_tree);

  if (!data_tree || !data_tree->children || !data_tree->children->children)
    return;

  /* Append new columns */
  for (colnum = 0, iter_node = data_tree->children->children; iter_node;
       colnum++, iter_node = iter_node->next)
    {
      iter_data = iter_node->data;

      column = eprop_model_generate_column (eprop, colnum, iter_data);
      gtk_tree_view_append_column (eprop_data->view, column);
    }
}
Esempio n. 3
0
static void
glade_eprop_model_data_delete_selected (GladeEditorProperty * eprop)
{
  GtkTreeIter iter;
  GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
  GladeProperty *property = glade_editor_property_get_property (eprop);
  GNode *data_tree = NULL, *row;
  gint rownum = -1;

  /* NOTE: This will trigger row-deleted below... */
  if (!gtk_tree_selection_get_selected (eprop_data->selection, NULL, &iter))
    return;

  gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter,
                      COLUMN_ROW, &rownum, -1);
  g_assert (rownum >= 0);

  /* if theres a sected row, theres data... */
  glade_property_get (property, &data_tree);
  g_assert (data_tree);

  data_tree = glade_model_data_tree_copy (data_tree);
  row = g_node_nth_child (data_tree, rownum);

  g_node_unlink (row);
  glade_model_data_tree_free (row);

  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_data_tree_idle, eprop);
}
Esempio n. 4
0
static void
icon_name_entry_activated (GtkEntry * entry,
                           GladeEPropIconSources * eprop_sources)
{
  const gchar *text = gtk_entry_get_text (entry);
  GladeProperty *property;
  GladeIconSources *sources = NULL;

  if (!text || !text[0])
    return;

  property = glade_editor_property_get_property (GLADE_EDITOR_PROPERTY (eprop_sources));
  if (!property)
    return;

  glade_property_get (property, &sources);
  if (sources == NULL || g_hash_table_lookup (sources->sources, text) == NULL)
    {
      /* Add the new source if it doesnt already exist */
      gtk_combo_box_text_insert (GTK_COMBO_BOX_TEXT (eprop_sources->combo), -1, text, text);
    }

  /* Set the active id whether it existed or not */
  gtk_combo_box_set_active_id (GTK_COMBO_BOX (eprop_sources->combo), text);
}
Esempio n. 5
0
static void
value_attribute_toggled (GtkCellRendererToggle * cell_renderer,
                         gchar * path, 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, edit_column;
  gboolean edit_column_active = FALSE;

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

  edit_column =
      GPOINTER_TO_INT (g_object_get_data
                       (G_OBJECT (cell_renderer), "attribute-column"));
  gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter,
                      COLUMN_ICON_NAME, &icon_name, COLUMN_LIST_INDEX, &index,
                      edit_column, &edit_column_active, -1);

  glade_property_get (property, &icon_sources);

  if (icon_sources)
    icon_sources = glade_icon_sources_copy (icon_sources);

  if (icon_sources &&
      (source = get_icon_source (icon_sources, icon_name, index)) != NULL)
    {
      /* Note the reverse meaning of active toggles vs. wildcarded sources... */
      switch (edit_column)
        {
          case COLUMN_DIRECTION_ACTIVE:
            gtk_icon_source_set_direction_wildcarded (source,
                                                      edit_column_active);
            break;
          case COLUMN_SIZE_ACTIVE:
            gtk_icon_source_set_size_wildcarded (source, edit_column_active);
            break;
          case COLUMN_STATE_ACTIVE:
            gtk_icon_source_set_state_wildcarded (source, edit_column_active);
            break;
          default:
            break;
        }

      update_icon_sources (eprop, icon_sources);
      g_free (icon_name);
      return;
    }

  if (icon_sources)
    glade_icon_sources_free (icon_sources);
  g_free (icon_name);
  return;
}
Esempio n. 6
0
static gboolean
reload_icon_sources_idle (GladeEditorProperty * eprop)
{
  GladeProperty *property = glade_editor_property_get_property (eprop);

  glade_editor_property_load (eprop, property);
  return FALSE;
}
Esempio n. 7
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);
}
Esempio n. 8
0
static void
value_i18n_activate (GladeCellRendererIcon * cell,
                     const gchar * path, 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;
  gchar *new_text;
  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);
  g_assert (G_VALUE_TYPE (&data->value) == G_TYPE_STRING);

  new_text = g_value_dup_string (&data->value);

  if (glade_editor_property_show_i18n_dialog (NULL,
                                              &new_text,
                                              &data->i18n_context,
                                              &data->i18n_comment,
                                              &data->i18n_translatable))
    {
      g_value_set_string (&data->value, new_text);

      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);
    }
  else
    glade_model_data_tree_free (data_tree);

  g_free (new_text);
}
Esempio n. 9
0
static void
delete_clicked (GtkWidget * button, GladeEditorProperty * eprop)
{
  GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop);
  GladeProperty *property = glade_editor_property_get_property (eprop);
  GtkTreeIter iter;
  GladeIconSources *icon_sources = NULL;
  GList *list, *sources, *new_list_head;
  gchar *icon_name;
  gint index = 0;

  /* NOTE: This will trigger row-deleted below... */
  if (!gtk_tree_selection_get_selected
      (gtk_tree_view_get_selection (eprop_sources->view), NULL, &iter))
    return;

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

  /* Could be the user pressed add and then delete without touching the
   * new item.
   */
  if (index < 0)
    {
      g_idle_add ((GSourceFunc) reload_icon_sources_idle, eprop);
      return;
    }

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

      if ((sources =
           g_hash_table_lookup (icon_sources->sources, icon_name)) != NULL)
        {
          new_list_head = icon_set_copy (sources);

          list = g_list_nth (new_list_head, index);
          new_list_head = g_list_remove_link (new_list_head, list);

          gtk_icon_source_free ((GtkIconSource *) list->data);
          g_list_free (list);

          /* We copied all that above cause this will free the old list */
          g_hash_table_insert (icon_sources->sources, g_strdup (icon_name),
                               new_list_head);

        }
      update_icon_sources (eprop, icon_sources);
    }
  g_free (icon_name);
}
Esempio n. 10
0
static void
sync_object (GladeEPropAttrs *eprop_attrs, gboolean use_command)
{
  GList *attributes = NULL;
  GladeAttribute *gattr;
  GtkTreeIter iter;
  PangoAttrType type;
  AttrEditType edit_type;
  gchar *strval = NULL;
  gboolean valid;

  valid = gtk_tree_model_iter_children (eprop_attrs->model, &iter, NULL);

  while (valid)
    {
      if (!is_empty_row (eprop_attrs->model, &iter))
        {
          gtk_tree_model_get (eprop_attrs->model, &iter,
                              COLUMN_TYPE, &type,
                              COLUMN_EDIT_TYPE, &edit_type,
                              COLUMN_TEXT, &strval, -1);

          gattr =
              glade_gtk_attribute_from_string (type,
                                               (edit_type ==
                                                EDIT_TOGGLE) ? "" : strval);
          strval = (g_free (strval), NULL);

          attributes = g_list_prepend (attributes, gattr);

        }
      valid = gtk_tree_model_iter_next (eprop_attrs->model, &iter);
    }

  if (use_command)
    {
      GValue value = { 0, };

      g_value_init (&value, GLADE_TYPE_ATTR_GLIST);
      g_value_take_boxed (&value, g_list_reverse (attributes));
      glade_editor_property_commit (GLADE_EDITOR_PROPERTY (eprop_attrs),
                                    &value);
      g_value_unset (&value);
    }
  else
    {
      GladeProperty *property = 
	glade_editor_property_get_property (GLADE_EDITOR_PROPERTY (eprop_attrs));

      glade_property_set (property, g_list_reverse (attributes));
      glade_attr_list_free (attributes);
    }
}
Esempio n. 11
0
static gboolean
update_and_focus_data_tree_idle (GladeEditorProperty * eprop)
{
  GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
  GladeProperty       *property = glade_editor_property_get_property (eprop);

  eprop_data->want_focus = TRUE;

  update_data_tree_idle (eprop);

  /* XXX Have to load it regardless if it changed, this is a slow and redundant way... */
  glade_editor_property_load (eprop, property);

  eprop_data->want_focus = FALSE;

  return FALSE;
}
Esempio n. 12
0
static void
id_edited (GtkCellRendererText *renderer,
	   gchar               *path,
	   gchar               *new_text,
	   GladeEditorProperty *eprop)
{
  GladeEPropStringList *eprop_string_list = GLADE_EPROP_STRING_LIST (eprop);
  GtkTreePath          *tree_path = gtk_tree_path_new_from_string (path);
  GtkTreeIter           iter;
  guint                 index;
  GladeProperty        *property = glade_editor_property_get_property (eprop);
  GList                *string_list = NULL;
  GladeString          *string;

  gtk_tree_model_get_iter (eprop_string_list->model, &iter, tree_path);
  gtk_tree_model_get (eprop_string_list->model, &iter,
		      COLUMN_INDEX, &index,
		      -1);

  glade_property_get (property, &string_list);

  if (string_list)
    string_list = glade_string_list_copy (string_list);

  string = g_list_nth_data (string_list, index);

  g_free (string->id);

  if (new_text && new_text[0])
    string->id = g_strdup (new_text);
  else
    string->id = NULL;

  eprop_string_list->editing_index = index;

  if (eprop_string_list->pending_string_list)
    glade_string_list_free (eprop_string_list->pending_string_list);
  eprop_string_list->pending_string_list = string_list;

  if (eprop_string_list->update_id == 0)
    eprop_string_list->update_id = 
      g_idle_add ((GSourceFunc) update_string_list_idle, eprop);

  gtk_tree_path_free (tree_path);
}
Esempio n. 13
0
static void
i18n_icon_activate (GtkCellRenderer     *renderer,
		    const gchar         *path,
		    GladeEditorProperty *eprop)
{
  GladeEPropStringList *eprop_string_list = GLADE_EPROP_STRING_LIST (eprop);
  GtkTreePath          *tree_path = gtk_tree_path_new_from_string (path);
  GtkTreeIter           iter;
  guint                 index;
  GladeProperty        *property = glade_editor_property_get_property (eprop);
  GList                *string_list = NULL;
  GladeString          *string;

  gtk_tree_model_get_iter (eprop_string_list->model, &iter, tree_path);
  gtk_tree_model_get (eprop_string_list->model, &iter,
		      COLUMN_INDEX, &index,
		      -1);

  glade_property_get (property, &string_list);
  string_list = glade_string_list_copy (string_list);

  string = g_list_nth_data (string_list, index);

  if (glade_editor_property_show_i18n_dialog (NULL,
                                              &string->string,
                                              &string->context,
                                              &string->comment,
                                              &string->translatable))
    {
      eprop_string_list->editing_index = index;

      if (eprop_string_list->pending_string_list)
	glade_string_list_free (eprop_string_list->pending_string_list);
      eprop_string_list->pending_string_list = string_list;

      if (eprop_string_list->update_id == 0)
	eprop_string_list->update_id = 
	  g_idle_add ((GSourceFunc) update_string_list_idle, eprop);
    }
  else
    glade_string_list_free (string_list);

  gtk_tree_path_free (tree_path);
}
Esempio n. 14
0
static gboolean
data_changed_idle (GladeEditorProperty *eprop)
{
  GladeEPropStringList *eprop_string_list = GLADE_EPROP_STRING_LIST (eprop);
  GladeProperty        *property = glade_editor_property_get_property (eprop);
  GladeString          *string, *copy;
  GList                *string_list = NULL;
  GList                *new_list = NULL;
  GtkTreeIter           iter;
  guint                 index;

  /* Create a new list based on the order and contents
   * of the model state */
  glade_property_get (property, &string_list);

  if (gtk_tree_model_get_iter_first (eprop_string_list->model, &iter))
    {
      do
        {
          gtk_tree_model_get (eprop_string_list->model, &iter,
                              COLUMN_INDEX, &index, -1);

          if ((string = g_list_nth_data (string_list, index)) != NULL)
            {
	      copy = glade_string_copy (string);
	      new_list = g_list_prepend (new_list, copy);
            }
        }
      while (gtk_tree_model_iter_next (eprop_string_list->model, &iter));
    }

  new_list = g_list_reverse (new_list);

  if (eprop_string_list->pending_string_list)
    glade_string_list_free (eprop_string_list->pending_string_list);
  eprop_string_list->pending_string_list = new_list;

  /* We're already in an idle, just call it directly here */
  update_string_list_idle (eprop);

  eprop_string_list->changed_id = 0;
  return FALSE;
}
Esempio n. 15
0
static void
icon_sources_populate_store (GladeEPropIconSources * eprop_sources)
{
  GladeIconSources *sources = NULL;
  GladeProperty *property;

  gtk_tree_store_clear (eprop_sources->store);
  gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (eprop_sources->combo));

  property = glade_editor_property_get_property (GLADE_EDITOR_PROPERTY (eprop_sources));
  if (!property)
    return;

  glade_property_get (property, &sources);

  if (sources)
    g_hash_table_foreach (sources->sources, (GHFunc) populate_store_foreach,
                          eprop_sources);

}
Esempio n. 16
0
static gboolean
data_changed_idle (GladeEditorProperty * eprop)
{
  GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
  GladeProperty *property = glade_editor_property_get_property (eprop);
  GNode *data_tree = NULL, *new_tree, *row;
  GtkTreeIter iter;
  gint rownum;

  glade_property_get (property, &data_tree);
  g_assert (data_tree);

  new_tree = g_node_new (NULL);

  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_data->store), &iter))
    {
      do
        {
          gtk_tree_model_get (GTK_TREE_MODEL (eprop_data->store), &iter,
                              COLUMN_ROW, &rownum, -1);


          if ((row = g_node_nth_child (data_tree, rownum)) != NULL)
            {
              /* Make a new tree by copying row by row... */
              row = glade_model_data_tree_copy (row);
              g_node_append (new_tree, row);
            }
        }
      while (gtk_tree_model_iter_next
             (GTK_TREE_MODEL (eprop_data->store), &iter));
    }

  /* Were already in an idle, no need to idle from here...  */
  if (eprop_data->pending_data_tree)
    glade_model_data_tree_free (eprop_data->pending_data_tree);
  eprop_data->pending_data_tree = new_tree;
  update_data_tree_idle (eprop);

  return FALSE;
}
Esempio n. 17
0
static void
value_toggled (GtkCellRendererToggle * cell,
               gchar * path, 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;
  gboolean active;
  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, NUM_COLUMNS + colnum, &active, -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);

  g_value_set_boolean (&data->value, !active);

  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);
}
Esempio n. 18
0
static gboolean
update_data_tree_idle (GladeEditorProperty * eprop)
{
  GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
  GladeProperty       *property = glade_editor_property_get_property (eprop);
  GValue value = { 0, };

  g_value_init (&value, GLADE_TYPE_MODEL_DATA_TREE);
  g_value_take_boxed (&value, eprop_data->pending_data_tree);

  /* Only commit the value if it changed, otherwise this
   * can trigger a load.. which we dont handle well in this
   * editor 
   */
  if (!glade_property_equals_value (property, &value))
    glade_editor_property_commit (eprop, &value);

  g_value_unset (&value);

  eprop_data->pending_data_tree = NULL;
  return FALSE;
}
Esempio n. 19
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);
}
Esempio n. 20
0
static void
string_edited (GtkCellRendererText *renderer,
	       gchar               *path,
	       gchar               *new_text,
	       GladeEditorProperty *eprop)
{
  GladeEPropStringList *eprop_string_list = GLADE_EPROP_STRING_LIST (eprop);
  GtkTreePath          *tree_path = gtk_tree_path_new_from_string (path);
  GtkTreeIter           iter;
  gboolean              dummy;
  guint                 index;
  GladeProperty        *property = glade_editor_property_get_property (eprop);
  GList                *string_list = NULL;

  gtk_tree_model_get_iter (eprop_string_list->model, &iter, tree_path);
  gtk_tree_model_get (eprop_string_list->model, &iter,
		      COLUMN_INDEX, &index,
		      COLUMN_DUMMY, &dummy,
		      -1);

  glade_property_get (property, &string_list);

  if (string_list)
    string_list = glade_string_list_copy (string_list);

  if (dummy)
    {
      if (new_text && new_text[0] && strcmp (new_text, _("<Type Here>")) != 0)
	string_list = 
	  glade_string_list_append (string_list,
				    new_text, NULL, NULL, 
				    eprop_string_list->translatable,
				    NULL);
    }
  else if (new_text && new_text[0])
    {
      GladeString *string = 
	g_list_nth_data (string_list, index);

      g_free (string->string);
      string->string = g_strdup (new_text);
    }
  else
    {
      GList *node = g_list_nth (string_list, index);
      glade_string_free (node->data);
      string_list = 
	g_list_delete_link (string_list, node);
    }

  eprop_string_list->editing_index = index;

  if (eprop_string_list->pending_string_list)
    glade_string_list_free (eprop_string_list->pending_string_list);
  eprop_string_list->pending_string_list = string_list;

  if (eprop_string_list->update_id == 0)
    eprop_string_list->update_id = 
      g_idle_add ((GSourceFunc) update_string_list_idle, eprop);

  gtk_tree_path_free (tree_path);
}
Esempio n. 21
0
static void
value_attribute_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, edit_column;

  if (!new_text || !new_text[0])
    return;

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

  edit_column =
      GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "attribute-column"));
  gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter,
                      COLUMN_ICON_NAME, &icon_name, COLUMN_LIST_INDEX, &index,
                      -1);

  glade_property_get (property, &icon_sources);

  if (icon_sources)
    icon_sources = glade_icon_sources_copy (icon_sources);

  if (icon_sources &&
      (source = get_icon_source (icon_sources, icon_name, index)) != NULL)
    {
      GtkTextDirection direction;
      GtkIconSize size;
      GtkStateType state;

      switch (edit_column)
        {
          case COLUMN_DIRECTION:
            direction =
                glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION,
                                                    new_text);
            gtk_icon_source_set_direction (source, direction);
            break;
          case COLUMN_SIZE:
            size =
                glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE,
                                                    new_text);
            gtk_icon_source_set_size (source, size);
            break;
          case COLUMN_STATE:
            state =
                glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE,
                                                    new_text);
            gtk_icon_source_set_state (source, state);
            break;
          default:
            break;
        }

      update_icon_sources (eprop, icon_sources);
      g_free (icon_name);
      return;
    }

  if (icon_sources)
    glade_icon_sources_free (icon_sources);
  g_free (icon_name);
  return;
}
Esempio n. 22
0
static void
glade_eprop_accel_populate_view (GladeEditorProperty * eprop,
                                 GtkTreeView * view)
{
  GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
  GladeSignalClass *sclass;
  GladePropertyClass *pclass = glade_editor_property_get_pclass (eprop);
  GladeProperty      *property = glade_editor_property_get_property (eprop);
  GladeWidgetAdaptor *adaptor = glade_property_class_get_adaptor (pclass);
  GtkTreeStore *model = (GtkTreeStore *) gtk_tree_view_get_model (view);
  GtkTreeIter iter;
  GladeEpropIterTab *parent_tab;
  GladeAccelInfo *info;
  GList *l, *found, *accelerators;
  gchar *name, *accel_text;
  const GList *list;

  accelerators = g_value_get_boxed (glade_property_inline_value (property));

  /* First make parent iters...
   */
  for (list = glade_widget_adaptor_get_signals (adaptor); list; list = list->next)
    {
      sclass = list->data;

      /* Special case for GtkAction accelerators  */
      if (glade_widget_adaptor_get_object_type (adaptor) == GTK_TYPE_ACTION ||
          g_type_is_a (glade_widget_adaptor_get_object_type (adaptor), GTK_TYPE_ACTION))
        {
          if (g_strcmp0 (glade_signal_class_get_type (sclass), "GtkAction") != 0 ||
              g_strcmp0 (glade_signal_class_get_name (sclass), "activate") != 0)
            continue;
        }
      /* Only action signals have accelerators. */
      else if ((glade_signal_class_get_flags (sclass) & G_SIGNAL_ACTION) == 0)
        continue;

      if (g_list_find_custom (eprop_accel->parent_iters,
                              glade_signal_class_get_type (sclass),
                              (GCompareFunc) eprop_find_iter) == NULL)
        {
          gtk_tree_store_append (model, &iter, NULL);
          gtk_tree_store_set (model, &iter,
                              ACCEL_COLUMN_SIGNAL, glade_signal_class_get_type (sclass),
                              ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_BOLD,
                              ACCEL_COLUMN_VISIBLE, FALSE, -1);

          parent_tab = g_new0 (GladeEpropIterTab, 1);
          parent_tab->name = glade_signal_class_get_type (sclass);
          parent_tab->iter = gtk_tree_iter_copy (&iter);

          eprop_accel->parent_iters =
              g_list_prepend (eprop_accel->parent_iters, parent_tab);
        }
    }

  /* Now we populate...
   */
  for (list = glade_widget_adaptor_get_signals (adaptor); list; list = list->next)
    {
      sclass = list->data;

      /* Special case for GtkAction accelerators  */
      if (glade_widget_adaptor_get_object_type (adaptor) == GTK_TYPE_ACTION ||
          g_type_is_a (glade_widget_adaptor_get_object_type (adaptor), GTK_TYPE_ACTION))
        {
          if (g_strcmp0 (glade_signal_class_get_type (sclass), "GtkAction") != 0 ||
              g_strcmp0 (glade_signal_class_get_name (sclass), "activate") != 0)
            continue;
        }
      /* Only action signals have accelerators. */
      else if ((glade_signal_class_get_flags (sclass) & G_SIGNAL_ACTION) == 0)
        continue;

      if ((found = g_list_find_custom (eprop_accel->parent_iters,
                                       glade_signal_class_get_type (sclass),
                                       (GCompareFunc) eprop_find_iter)) != NULL)
        {
          parent_tab = found->data;
          name = g_strdup_printf ("    %s", glade_signal_class_get_name (sclass));

          /* Populate from accelerator list
           */
          for (l = accelerators; l; l = l->next)
            {
              info = l->data;

              if (g_strcmp0 (info->signal, glade_signal_class_get_name (sclass)))
                continue;

              accel_text = gtk_accelerator_name (info->key, info->modifiers);

              gtk_tree_store_append (model, &iter, parent_tab->iter);
              gtk_tree_store_set
                  (model, &iter,
                   ACCEL_COLUMN_SIGNAL, name,
                   ACCEL_COLUMN_REAL_SIGNAL, glade_signal_class_get_name (sclass),
                   ACCEL_COLUMN_TEXT, accel_text,
                   ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL,
                   ACCEL_COLUMN_STYLE, PANGO_STYLE_NORMAL,
                   ACCEL_COLUMN_FOREGROUND, "Black",
                   ACCEL_COLUMN_VISIBLE, TRUE,
                   ACCEL_COLUMN_KEYCODE, info->key,
                   ACCEL_COLUMN_MODIFIERS, info->modifiers,
                   ACCEL_COLUMN_KEY_ENTERED, TRUE, -1);

              g_free (accel_text);
            }

          /* Special case for GtkAction accelerators  */
          if ((glade_widget_adaptor_get_object_type (adaptor) == GTK_TYPE_ACTION ||
               g_type_is_a (glade_widget_adaptor_get_object_type (adaptor), GTK_TYPE_ACTION)) &&
              g_list_length (accelerators) > 0)
            continue;

          /* Append a new empty slot at the end */
          gtk_tree_store_append (model, &iter, parent_tab->iter);
          gtk_tree_store_set
              (model, &iter,
               ACCEL_COLUMN_SIGNAL, name,
               ACCEL_COLUMN_REAL_SIGNAL, glade_signal_class_get_name (sclass),
               ACCEL_COLUMN_TEXT, _("<choose a key>"),
               ACCEL_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL,
               ACCEL_COLUMN_STYLE, PANGO_STYLE_ITALIC,
               ACCEL_COLUMN_FOREGROUND, "Grey",
               ACCEL_COLUMN_VISIBLE, TRUE,
               ACCEL_COLUMN_KEYCODE, 0,
               ACCEL_COLUMN_MODIFIERS, 0, ACCEL_COLUMN_KEY_ENTERED, FALSE, -1);

          g_free (name);
        }
    }
}
Esempio n. 23
0
static void
glade_eprop_attrs_show_dialog (GtkWidget *dialog_button,
                               GladeEditorProperty *eprop)
{
  GladeEPropAttrs *eprop_attrs = GLADE_EPROP_ATTRS (eprop);
  GtkWidget *dialog, *parent, *vbox, *sw, *tree_view;
  GladeProperty *property;
  GList *old_attributes;
  gint res;

  property = glade_editor_property_get_property (eprop);
  parent   = gtk_widget_get_toplevel (GTK_WIDGET (eprop));


  /* Keep a copy for commit time... */
  old_attributes = g_value_dup_boxed (glade_property_inline_value (property));

  dialog = gtk_dialog_new_with_buttons (_("Setup Text Attributes"),
                                        GTK_WINDOW (parent),
                                        GTK_DIALOG_MODAL |
                                        GTK_DIALOG_DESTROY_WITH_PARENT,
                                        GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR,
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                        GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_widget_show (vbox);

  gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);

  gtk_box_pack_start (GTK_BOX
                      (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), vbox,
                      TRUE, TRUE, 0);

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_show (sw);
  gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
  gtk_widget_set_size_request (sw, 400, 200);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);

  tree_view = glade_eprop_attrs_view (eprop);
  glade_eprop_attrs_populate_view (eprop, GTK_TREE_VIEW (tree_view));

  gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));

  gtk_widget_show (tree_view);
  gtk_container_add (GTK_CONTAINER (sw), tree_view);

  /* Run the dialog */
  res = gtk_dialog_run (GTK_DIALOG (dialog));
  if (res == GTK_RESPONSE_OK)
    {
      /* Update from old attributes so that there a property change 
       * sitting on the undo stack.
       */
      glade_property_set (property, old_attributes);
      sync_object (eprop_attrs, TRUE);
    }
  else if (res == GLADE_RESPONSE_CLEAR)
    {
      GValue value = { 0, };
      g_value_init (&value, GLADE_TYPE_ATTR_GLIST);
      g_value_set_boxed (&value, NULL);
      glade_editor_property_commit (eprop, &value);
      g_value_unset (&value);
    }

  /* Clean up ...
   */
  gtk_widget_destroy (dialog);

  g_object_unref (G_OBJECT (eprop_attrs->model));
  eprop_attrs->model = NULL;

  glade_attr_list_free (old_attributes);
}
Esempio n. 24
0
static GtkListStore *
eprop_model_data_generate_store (GladeEditorProperty * eprop)
{
  GtkListStore *store = NULL;
  GladeModelData *iter_data;
  GNode *data_tree = NULL, *iter_node, *row_node;
  GArray *gtypes = g_array_new (FALSE, TRUE, sizeof (GType));
  GtkTreeIter iter;
  gint column_num, row_num;
  GType index_type = G_TYPE_INT, string_type = G_TYPE_STRING, pointer_type = G_TYPE_POINTER;
  GladeProperty *property = glade_editor_property_get_property (eprop);

  glade_property_get (property, &data_tree);

  if (!data_tree || !data_tree->children || !data_tree->children->children)
    return NULL;

  /* Generate store with tailored column types */
  g_array_append_val (gtypes, index_type);
  for (iter_node = data_tree->children->children; iter_node;
       iter_node = iter_node->next)
    {
      iter_data = iter_node->data;
      if (G_VALUE_TYPE (&iter_data->value) == 0)
        g_array_append_val (gtypes, pointer_type);
      else if (G_VALUE_TYPE (&iter_data->value) == GDK_TYPE_PIXBUF)
        g_array_append_val (gtypes, string_type);
      else
        g_array_append_val (gtypes, G_VALUE_TYPE (&iter_data->value));
    }
  store = gtk_list_store_newv (gtypes->len, (GType *) gtypes->data);
  g_array_free (gtypes, TRUE);

  /* Now populate the store with data */
  for (row_num = 0, row_node = data_tree->children; row_node;
       row_num++, row_node = row_node->next)
    {
      gtk_list_store_append (store, &iter);
      gtk_list_store_set (store, &iter, COLUMN_ROW, row_num, -1);

      for (column_num = NUM_COLUMNS, iter_node = row_node->children; iter_node;
           column_num++, iter_node = iter_node->next)
        {
          iter_data = iter_node->data;

          if (G_VALUE_TYPE (&iter_data->value) == 0)
            continue;

          /* Special case, show the filename in the cellrenderertext */
          if (G_VALUE_TYPE (&iter_data->value) == GDK_TYPE_PIXBUF)
            {
              GObject *object = g_value_get_object (&iter_data->value);
              gchar *filename = NULL;
              if (object)
                filename = g_object_get_data (object, "GladeFileName");

              gtk_list_store_set (store, &iter, column_num, filename, -1);
            }
          else
            gtk_list_store_set_value (store, &iter, column_num,
                                      &iter_data->value);
        }
    }
  return store;
}
Esempio n. 25
0
static void
glade_eprop_attrs_populate_view (GladeEditorProperty *eprop, GtkTreeView *view)
{
  GList *attributes, *list;
  GtkListStore *model = (GtkListStore *) gtk_tree_view_get_model (view);
  GtkTreeIter *iter;
  GladeAttribute *gattr;
  GladeProperty *property;
  gchar *text;

  property   = glade_editor_property_get_property (eprop);
  attributes = g_value_get_boxed (glade_property_inline_value (property));

  append_empty_row (model, PANGO_ATTR_FONT_DESC);
  append_empty_row (model, PANGO_ATTR_STYLE);
  append_empty_row (model, PANGO_ATTR_WEIGHT);
  append_empty_row (model, PANGO_ATTR_VARIANT);
  append_empty_row (model, PANGO_ATTR_LANGUAGE);
  append_empty_row (model, PANGO_ATTR_STRETCH);
  append_empty_row (model, PANGO_ATTR_SCALE);
  append_empty_row (model, PANGO_ATTR_UNDERLINE);
  append_empty_row (model, PANGO_ATTR_STRIKETHROUGH);
  append_empty_row (model, PANGO_ATTR_FOREGROUND);
  append_empty_row (model, PANGO_ATTR_BACKGROUND);
  append_empty_row (model, PANGO_ATTR_UNDERLINE_COLOR);
  append_empty_row (model, PANGO_ATTR_STRIKETHROUGH_COLOR);
  append_empty_row (model, PANGO_ATTR_GRAVITY);
  append_empty_row (model, PANGO_ATTR_GRAVITY_HINT);
  append_empty_row (model, PANGO_ATTR_SIZE);
  append_empty_row (model, PANGO_ATTR_ABSOLUTE_SIZE);
  append_empty_row (model, PANGO_ATTR_SHAPE);

  /* XXX Populate here ...
   */
  for (list = attributes; list; list = list->next)
    {
      gattr = list->data;

      if ((iter = get_row_by_type (GTK_TREE_MODEL (model), gattr->type)))
        {
          text = glade_gtk_string_from_attr (gattr);

          gtk_list_store_set (GTK_LIST_STORE (model), iter,
                              COLUMN_NAME_WEIGHT, PANGO_WEIGHT_BOLD,
                              COLUMN_TEXT, text,
                              COLUMN_TEXT_STYLE, PANGO_STYLE_NORMAL,
                              COLUMN_TEXT_FG, "Black", -1);

          if (gattr->type == PANGO_ATTR_UNDERLINE ||
              gattr->type == PANGO_ATTR_STRIKETHROUGH)
            gtk_list_store_set (GTK_LIST_STORE (model), iter,
                                COLUMN_TOGGLE_DOWN,
                                g_value_get_boolean (&(gattr->value)), -1);

          g_free (text);
          gtk_tree_iter_free (iter);
        }

    }

}