/** * gimp_list_sort_by_name: * @list: a #GimpList * * Sorts the #GimpObject elements of a #GimpList by their names. **/ void gimp_list_sort_by_name (GimpList *list) { g_return_if_fail (GIMP_IS_LIST (list)); gimp_list_sort (list, (GCompareFunc) gimp_object_name_collate); }
void gimp_templates_save (Gimp *gimp) { const gchar *header = "GIMP templaterc\n" "\n" "This file will be entirely rewritten each time you exit."; const gchar *footer = "end of templaterc"; GFile *file; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (GIMP_IS_LIST (gimp->templates)); file = gimp_directory_file ("templaterc", NULL); if (gimp->be_verbose) g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file)); if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (gimp->templates), file, header, footer, NULL, &error)) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); g_error_free (error); } g_object_unref (file); }
/** * gimp_list_reverse: * @list: a #GimpList * * Reverses the order of elements in a #GimpList. **/ void gimp_list_reverse (GimpList *list) { g_return_if_fail (GIMP_IS_LIST (list)); if (GIMP_CONTAINER (list)->num_children > 1) { gimp_container_freeze (GIMP_CONTAINER (list)); list->list = g_list_reverse (list->list); gimp_container_thaw (GIMP_CONTAINER (list)); } }
/** * gimp_list_sort: * @list: a #GimpList * @sort_func: a #GCompareFunc * * Sorts the elements of a #GimpList according to the given @sort_func. * See g_list_sort() for a detailed description of this function. **/ void gimp_list_sort (GimpList *list, GCompareFunc sort_func) { g_return_if_fail (GIMP_IS_LIST (list)); g_return_if_fail (sort_func != NULL); if (GIMP_CONTAINER (list)->num_children > 1) { gimp_container_freeze (GIMP_CONTAINER (list)); list->list = g_list_sort (list->list, sort_func); gimp_container_thaw (GIMP_CONTAINER (list)); } }
/** * gimp_list_set_sort_func: * @list: a #GimpList * @sort_func: a #GCompareFunc * * Sorts the elements of @list using gimp_list_sort() and remembers the * passed @sort_func in order to keep the list ordered across inserting * or renaming children. **/ void gimp_list_set_sort_func (GimpList *list, GCompareFunc sort_func) { g_return_if_fail (GIMP_IS_LIST (list)); if (sort_func != list->sort_func) { if (sort_func) gimp_list_sort (list, sort_func); list->sort_func = sort_func; g_object_notify (G_OBJECT (list), "sort-func"); } }
void gimp_templates_load (Gimp *gimp) { gchar *filename; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (GIMP_IS_LIST (gimp->templates)); filename = gimp_personal_rc_file ("templaterc"); if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename)); if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp->templates), filename, NULL, &error)) { if (error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT) { g_clear_error (&error); g_free (filename); filename = g_build_filename (gimp_sysconf_directory (), "templaterc", NULL); if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp->templates), filename, NULL, &error)) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); } } else { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); } g_clear_error (&error); } gimp_list_reverse (GIMP_LIST (gimp->templates)); g_free (filename); }
void gimp_templates_load (Gimp *gimp) { GFile *file; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (GIMP_IS_LIST (gimp->templates)); file = gimp_directory_file ("templaterc", NULL); if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file)); if (! gimp_config_deserialize_gfile (GIMP_CONFIG (gimp->templates), file, NULL, &error)) { if (error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT) { g_clear_error (&error); g_object_unref (file); file = gimp_sysconf_directory_file ("templaterc", NULL); if (! gimp_config_deserialize_gfile (GIMP_CONFIG (gimp->templates), file, NULL, &error)) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); } } else { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); } g_clear_error (&error); } gimp_list_reverse (GIMP_LIST (gimp->templates)); g_object_unref (file); }
/** * gimp_tagged_container_new: * @src_container: container to be filtered. * * Creates a new #GimpTaggedContainer object which creates filtered * data view of #GimpTagged objects. It filters @src_container for * objects containing all of the filtering tags. Synchronization with * @src_container data is performed automatically. * * Return value: a new #GimpTaggedContainer object. **/ GimpContainer * gimp_tagged_container_new (GimpContainer *src_container) { GimpTaggedContainer *tagged_container; GType children_type; GCompareFunc sort_func; g_return_val_if_fail (GIMP_IS_LIST (src_container), NULL); children_type = gimp_container_get_children_type (src_container); sort_func = GIMP_LIST (src_container)->sort_func; tagged_container = g_object_new (GIMP_TYPE_TAGGED_CONTAINER, "sort-func", sort_func, "children-type", children_type, "policy", GIMP_CONTAINER_POLICY_WEAK, "unique-names", FALSE, "src-container", src_container, NULL); return GIMP_CONTAINER (tagged_container); }
gboolean gimp_container_editor_construct (GimpContainerEditor *editor, GimpViewType view_type, GimpContainer *container, GimpContext *context, gint view_size, gint view_border_width, GimpMenuFactory *menu_factory, const gchar *menu_identifier, const gchar *ui_identifier) { g_return_val_if_fail (GIMP_IS_CONTAINER_EDITOR (editor), FALSE); g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE); g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE); g_return_val_if_fail (view_size > 0 && view_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, FALSE); g_return_val_if_fail (view_border_width >= 0 && view_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH, FALSE); g_return_val_if_fail (menu_factory == NULL || GIMP_IS_MENU_FACTORY (menu_factory), FALSE); switch (view_type) { case GIMP_VIEW_TYPE_GRID: #if 0 editor->view = GIMP_CONTAINER_VIEW (gimp_container_icon_view_new (container, context, view_size, view_border_width)); #else editor->view = GIMP_CONTAINER_VIEW (gimp_container_grid_view_new (container, context, view_size, view_border_width)); #endif break; case GIMP_VIEW_TYPE_LIST: editor->view = GIMP_CONTAINER_VIEW (gimp_container_tree_view_new (container, context, view_size, view_border_width)); break; default: g_warning ("%s: unknown GimpViewType passed", G_STRFUNC); return FALSE; } if (GIMP_IS_LIST (container)) gimp_container_view_set_reorderable (GIMP_CONTAINER_VIEW (editor->view), ! GIMP_LIST (container)->sort_func); if (menu_factory && menu_identifier && ui_identifier) gimp_editor_create_menu (GIMP_EDITOR (editor->view), menu_factory, menu_identifier, ui_identifier, editor); gtk_box_pack_start (GTK_BOX (editor), GTK_WIDGET (editor->view), TRUE, TRUE, 0); gtk_widget_show (GTK_WIDGET (editor->view)); g_signal_connect_object (editor->view, "select-item", G_CALLBACK (gimp_container_editor_select_item), editor, 0); g_signal_connect_object (editor->view, "activate-item", G_CALLBACK (gimp_container_editor_activate_item), editor, 0); g_signal_connect_object (editor->view, "context-item", G_CALLBACK (gimp_container_editor_context_item), editor, 0); { GimpObject *object = gimp_context_get_by_type (context, gimp_container_get_children_type (container)); gimp_container_editor_select_item (GTK_WIDGET (editor->view), (GimpViewable *) object, NULL, editor); } return TRUE; }
static void gimp_list_uniquefy_name (GimpList *gimp_list, GimpObject *object) { GList *list; GList *list2; gint unique_ext = 0; gchar *new_name = NULL; gchar *ext; g_return_if_fail (GIMP_IS_LIST (gimp_list)); g_return_if_fail (GIMP_IS_OBJECT (object)); for (list = gimp_list->list; list; list = g_list_next (list)) { GimpObject *object2 = GIMP_OBJECT (list->data); if (object != object2 && strcmp (gimp_object_get_name (GIMP_OBJECT (object)), gimp_object_get_name (GIMP_OBJECT (object2))) == 0) { ext = strrchr (object->name, '#'); if (ext) { gchar *ext_str; unique_ext = atoi (ext + 1); ext_str = g_strdup_printf ("%d", unique_ext); /* check if the extension really is of the form "#<n>" */ if (! strcmp (ext_str, ext + 1)) { *ext = '\0'; } else { unique_ext = 0; } g_free (ext_str); } else { unique_ext = 0; } do { unique_ext++; g_free (new_name); new_name = g_strdup_printf ("%s#%d", object->name, unique_ext); for (list2 = gimp_list->list; list2; list2 = g_list_next (list2)) { object2 = GIMP_OBJECT (list2->data); if (object == object2) continue; if (! strcmp (object2->name, new_name)) break; } } while (list2); gimp_object_take_name (object, new_name); break; } } }