static void windows_menu_display_reorder (GimpContainer *container, GimpDisplay *display, gint new_index, GimpUIManager *manager) { gint n_display = gimp_container_get_n_children (container); gint i; for (i = new_index; i < n_display; i++) { GimpObject *d = gimp_container_get_child_by_index (container, i); windows_menu_display_remove (container, GIMP_DISPLAY (d), manager); } /* If I don't ensure the menu items are effectively removed, adding * the same ones may simply cancel the effect of the removal, hence * losing the menu reordering. */ gtk_ui_manager_ensure_update (GTK_UI_MANAGER (manager)); for (i = new_index; i < n_display; i++) { GimpObject *d = gimp_container_get_child_by_index (container, i); windows_menu_display_add (container, GIMP_DISPLAY (d), manager); } }
static gboolean gimp_container_grid_view_move_by (GimpContainerGridView *grid_view, gint x, gint y) { GimpContainerView *view = GIMP_CONTAINER_VIEW (grid_view); GimpContainer *container; GimpViewable *item; gint index; if (! grid_view->selected_item) return FALSE; container = gimp_container_view_get_container (view); item = grid_view->selected_item->viewable; index = gimp_container_get_child_index (container, GIMP_OBJECT (item)); index += x; index = CLAMP (index, 0, gimp_container_get_n_children (container) - 1); index += y * grid_view->columns; while (index < 0) index += grid_view->columns; while (index >= gimp_container_get_n_children (container)) index -= grid_view->columns; item = (GimpViewable *) gimp_container_get_child_by_index (container, index); if (item) gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (view), item); return TRUE; }
GimpUndo * gimp_undo_stack_free_bottom (GimpUndoStack *stack, GimpUndoMode undo_mode) { GimpUndo *undo; gint n_children; g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL); n_children = gimp_container_num_children (GIMP_CONTAINER (stack->undos)); undo = (GimpUndo *) gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos), n_children - 1); if (undo) { gimp_container_remove (GIMP_CONTAINER (stack->undos), GIMP_OBJECT (undo)); gimp_undo_free (undo, undo_mode); return undo; } return NULL; }
static void gimp_filter_stack_remove (GimpContainer *container, GimpObject *object) { GimpFilterStack *stack = GIMP_FILTER_STACK (container); GimpFilter *filter = GIMP_FILTER (object); gint n_children; if (stack->graph) { gimp_filter_stack_remove_node (stack, filter); gegl_node_remove_child (stack->graph, gimp_filter_get_node (filter)); } GIMP_CONTAINER_CLASS (parent_class)->remove (container, object); gimp_filter_set_is_last_node (filter, FALSE); n_children = gimp_container_get_n_children (container); if (n_children > 0) { GimpFilter *last_node = (GimpFilter *) gimp_container_get_child_by_index (container, n_children - 1); gimp_filter_set_is_last_node (last_node, TRUE); } }
static void gimp_filter_stack_add_node (GimpFilterStack *stack, GimpFilter *filter) { GimpFilter *filter_below; GeglNode *node_above; GeglNode *node_below; GeglNode *node; gint index; node = gimp_filter_get_node (filter); index = gimp_container_get_child_index (GIMP_CONTAINER (stack), GIMP_OBJECT (filter)); if (index == 0) { node_above = gegl_node_get_output_proxy (stack->graph, "output"); } else { GimpFilter *filter_above = (GimpFilter *) gimp_container_get_child_by_index (GIMP_CONTAINER (stack), index - 1); node_above = gimp_filter_get_node (filter_above); } gegl_node_connect_to (node, "output", node_above, "input"); filter_below = (GimpFilter *) gimp_container_get_child_by_index (GIMP_CONTAINER (stack), index + 1); if (filter_below) { node_below = gimp_filter_get_node (filter_below); } else { node_below = gegl_node_get_input_proxy (stack->graph, "input"); } gegl_node_connect_to (node_below, "output", node, "input"); }
static void gimp_filter_stack_reorder (GimpContainer *container, GimpObject *object, gint new_index) { GimpFilterStack *stack = GIMP_FILTER_STACK (container); GimpFilter *filter = GIMP_FILTER (object); gint n_children; gint old_index; n_children = gimp_container_get_n_children (container); old_index = gimp_container_get_child_index (container, object); if (stack->graph) gimp_filter_stack_remove_node (stack, filter); if (old_index == n_children -1) { gimp_filter_set_is_last_node (filter, FALSE); } else if (new_index == n_children - 1) { GimpFilter *last_node = (GimpFilter *) gimp_container_get_child_by_index (container, n_children - 1); gimp_filter_set_is_last_node (last_node, FALSE); } GIMP_CONTAINER_CLASS (parent_class)->reorder (container, object, new_index); if (new_index == n_children - 1) { gimp_filter_set_is_last_node (filter, TRUE); } else if (old_index == n_children - 1) { GimpFilter *last_node = (GimpFilter *) gimp_container_get_child_by_index (container, n_children - 1); gimp_filter_set_is_last_node (last_node, TRUE); } if (stack->graph) gimp_filter_stack_add_node (stack, filter); }
GimpObject * action_select_object (GimpActionSelectType select_type, GimpContainer *container, GimpObject *current) { gint select_index; gint n_children; g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL); g_return_val_if_fail (current == NULL || GIMP_IS_OBJECT (current), NULL); if (! current) return NULL; n_children = gimp_container_get_n_children (container); if (n_children == 0) return NULL; switch (select_type) { case GIMP_ACTION_SELECT_FIRST: select_index = 0; break; case GIMP_ACTION_SELECT_LAST: select_index = n_children - 1; break; case GIMP_ACTION_SELECT_PREVIOUS: select_index = gimp_container_get_child_index (container, current) - 1; break; case GIMP_ACTION_SELECT_NEXT: select_index = gimp_container_get_child_index (container, current) + 1; break; case GIMP_ACTION_SELECT_SKIP_PREVIOUS: select_index = gimp_container_get_child_index (container, current) - 10; break; case GIMP_ACTION_SELECT_SKIP_NEXT: select_index = gimp_container_get_child_index (container, current) + 10; break; default: if ((gint) select_type >= 0) select_index = (gint) select_type; else g_return_val_if_reached (current); break; } select_index = CLAMP (select_index, 0, n_children - 1); return gimp_container_get_child_by_index (container, select_index); }
void file_open_recent_cmd_callback (GtkAction *action, gint value, gpointer data) { Gimp *gimp; GimpImagefile *imagefile; gint num_entries; return_if_no_gimp (gimp, data); num_entries = gimp_container_get_n_children (gimp->documents); if (value >= num_entries) return; imagefile = (GimpImagefile *) gimp_container_get_child_by_index (gimp->documents, value); if (imagefile) { GimpDisplay *display; GimpProgress *progress; GimpImage *image; GimpPDBStatusType status; GError *error = NULL; return_if_no_display (display, data); g_object_ref (display); g_object_ref (imagefile); progress = gimp_display_get_image (display) ? NULL : GIMP_PROGRESS (display); image = file_open_with_display (gimp, action_data_get_context (data), progress, gimp_object_get_name (imagefile), FALSE, &status, &error); if (! image && status != GIMP_PDB_CANCEL) { gchar *filename = file_utils_uri_display_name (gimp_object_get_name (imagefile)); gimp_message (gimp, G_OBJECT (display), GIMP_MESSAGE_ERROR, _("Opening '%s' failed:\n\n%s"), filename, error->message); g_clear_error (&error); g_free (filename); } g_object_unref (imagefile); g_object_unref (display); } }
GimpUndo * gimp_undo_stack_peek (GimpUndoStack *stack) { GimpObject *object; g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL); object = gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos), 0); return (object ? GIMP_UNDO (object) : NULL); }
void tool_options_edit_preset_cmd_callback (GtkAction *action, gint value, gpointer data) { GimpEditor *editor = GIMP_EDITOR (data); Gimp *gimp = gimp_editor_get_ui_manager (editor)->gimp; GimpContext *context = gimp_get_user_context (gimp); GimpToolInfo *tool_info = gimp_context_get_tool (context); GimpToolPreset *preset; preset = (GimpToolPreset *) gimp_container_get_child_by_index (tool_info->presets, value); if (preset) { tool_options_show_preset_editor (gimp, editor, preset); } }
void file_last_opened_cmd_callback (GtkAction *action, gint value, gpointer data) { Gimp *gimp; GimpImagefile *imagefile; gint num_entries; return_if_no_gimp (gimp, data); num_entries = gimp_container_num_children (gimp->documents); if (value >= num_entries) return; imagefile = (GimpImagefile *) gimp_container_get_child_by_index (gimp->documents, value); if (imagefile) { GimpImage *image; GimpPDBStatusType status; GError *error = NULL; image = file_open_with_display (gimp, action_data_get_context (data), NULL, GIMP_OBJECT (imagefile)->name, FALSE, &status, &error); if (! image && status != GIMP_PDB_CANCEL) { gchar *filename = file_utils_uri_display_name (GIMP_OBJECT (imagefile)->name); gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, _("Opening '%s' failed:\n\n%s"), filename, error->message); g_clear_error (&error); g_free (filename); } } }
void windows_show_display_previous_cmd_callback (GtkAction *action, gpointer data) { GimpDisplay *display; Gimp *gimp; gint index; return_if_no_display (display, data); return_if_no_gimp (gimp, data); index = gimp_container_get_child_index (gimp->displays, GIMP_OBJECT (display)); index--; if (index < 0) index = gimp_container_get_n_children (gimp->displays) - 1; display = GIMP_DISPLAY (gimp_container_get_child_by_index (gimp->displays, index)); gimp_display_shell_present (gimp_display_get_shell (display)); }
GimpUndo * gimp_undo_stack_pop_undo (GimpUndoStack *stack, GimpUndoMode undo_mode, GimpUndoAccumulator *accum) { GimpUndo *undo; g_return_val_if_fail (GIMP_IS_UNDO_STACK (stack), NULL); g_return_val_if_fail (accum != NULL, NULL); undo = (GimpUndo *) gimp_container_get_child_by_index (GIMP_CONTAINER (stack->undos), 0); if (undo) { gimp_container_remove (GIMP_CONTAINER (stack->undos), GIMP_OBJECT (undo)); gimp_undo_pop (undo, undo_mode, accum); return undo; } return NULL; }
void tool_options_delete_preset_cmd_callback (GtkAction *action, gint value, gpointer data) { GimpEditor *editor = GIMP_EDITOR (data); GimpContext *context = gimp_get_user_context (gimp_editor_get_ui_manager (editor)->gimp); GimpToolInfo *tool_info = gimp_context_get_tool (context); GimpToolPreset *preset; preset = (GimpToolPreset *) gimp_container_get_child_by_index (tool_info->presets, value); if (preset && gimp_data_is_deletable (GIMP_DATA (preset))) { GimpDataFactory *factory = context->gimp->tool_preset_factory; GtkWidget *dialog; dialog = data_delete_dialog_new (factory, GIMP_DATA (preset), NULL, GTK_WIDGET (editor)); gtk_widget_show (dialog); } }
static gboolean gimp_container_grid_view_move_cursor (GimpContainerGridView *grid_view, GtkMovementStep step, gint count) { GimpContainerView *view = GIMP_CONTAINER_VIEW (grid_view); GimpContainer *container; GimpViewable *item; if (! gtk_widget_has_focus (GTK_WIDGET (grid_view)) || count == 0) return FALSE; container = gimp_container_view_get_container (view); switch (step) { case GTK_MOVEMENT_PAGES: return gimp_container_grid_view_move_by (grid_view, 0, count * grid_view->visible_rows); case GTK_MOVEMENT_BUFFER_ENDS: count = count < 0 ? 0 : gimp_container_get_n_children (container) - 1; item = (GimpViewable *) gimp_container_get_child_by_index (container, count); if (item) gimp_container_view_item_selected (view, item); return TRUE; default: break; } return FALSE; }