void gimp_tools_exit (Gimp *gimp) { GList *default_order; GList *list; g_return_if_fail (GIMP_IS_GIMP (gimp)); default_order = g_object_get_data (G_OBJECT (gimp), "gimp-tools-default-order"); g_list_free_full (default_order, (GDestroyNotify) g_free); g_object_set_data (G_OBJECT (gimp), "gimp-tools-default-order", NULL); for (list = gimp_get_tool_info_iter (gimp); list; list = g_list_next (list)) { GimpToolInfo *tool_info = list->data; GtkWidget *options_gui; options_gui = gimp_tools_get_tool_options_gui (tool_info->tool_options); gtk_widget_destroy (options_gui); gimp_tools_set_tool_options_gui (tool_info->tool_options, NULL); } tool_manager_exit (gimp); }
gboolean gimp_tools_clear (Gimp *gimp, GError **error) { GList *list; gboolean success = TRUE; g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE); for (list = gimp_get_tool_info_iter (gimp); list && success; list = g_list_next (list)) { GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data); success = gimp_tool_options_delete (tool_info->tool_options, NULL); } if (success) success = gimp_contexts_clear (gimp, error); if (success) tool_options_deleted = TRUE; return success; }
void tool_options_reset_all_cmd_callback (GtkAction *action, gpointer data) { GimpEditor *editor = GIMP_EDITOR (data); GtkWidget *dialog; dialog = gimp_message_dialog_new (_("Reset All Tool Options"), GIMP_STOCK_QUESTION, GTK_WIDGET (editor), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, gimp_standard_help_func, NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GIMP_STOCK_RESET, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); g_signal_connect_object (gtk_widget_get_toplevel (GTK_WIDGET (editor)), "unmap", G_CALLBACK (gtk_widget_destroy), dialog, G_CONNECT_SWAPPED); gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box, _("Do you really want to reset all " "tool options to default values?")); if (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK) { Gimp *gimp = gimp_editor_get_ui_manager (editor)->gimp; GList *list; for (list = gimp_get_tool_info_iter (gimp); list; list = g_list_next (list)) { GimpToolInfo *tool_info = list->data; gimp_config_reset (GIMP_CONFIG (tool_info->tool_options)); } } gtk_widget_destroy (dialog); }
void gimp_tools_save (Gimp *gimp, gboolean save_tool_options, gboolean always_save) { GFile *file; g_return_if_fail (GIMP_IS_GIMP (gimp)); if (save_tool_options && (! tool_options_deleted || always_save)) { GList *list; GError *error = NULL; if (! gimp_contexts_save (gimp, &error)) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_WARNING, error->message); g_clear_error (&error); } gimp_tool_options_create_folder (); for (list = gimp_get_tool_info_iter (gimp); list; list = g_list_next (list)) { GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data); gimp_tool_options_serialize (tool_info->tool_options, NULL); } } file = gimp_directory_file ("toolrc", NULL); if (gimp->be_verbose) g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file)); gimp_config_serialize_to_gfile (GIMP_CONFIG (gimp->tool_info_list), file, "GIMP toolrc", "end of toolrc", NULL, NULL); g_object_unref (file); }
void gimp_tools_restore (Gimp *gimp) { GimpContainer *gimp_list; GimpObject *object; GFile *file; GList *list; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); gimp_list = gimp_list_new (GIMP_TYPE_TOOL_INFO, FALSE); file = gimp_directory_file ("toolrc", NULL); if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file)); if (gimp_config_deserialize_gfile (GIMP_CONFIG (gimp_list), file, NULL, NULL)) { gint n = gimp_container_get_n_children (gimp->tool_info_list); gint i; gimp_list_reverse (GIMP_LIST (gimp_list)); for (list = GIMP_LIST (gimp_list)->list, i = 0; list; list = g_list_next (list), i++) { const gchar *name; name = gimp_object_get_name (list->data); object = gimp_container_get_child_by_name (gimp->tool_info_list, name); if (object) { g_object_set (object, "visible", GIMP_TOOL_INFO (list->data)->visible, NULL); gimp_container_reorder (gimp->tool_info_list, object, MIN (i, n - 1)); } } } g_object_unref (file); g_object_unref (gimp_list); /* make the generic operation tool invisible by default */ object = gimp_container_get_child_by_name (gimp->tool_info_list, "gimp-operation-tool"); if (object) g_object_set (object, "visible", FALSE, NULL); for (list = gimp_get_tool_info_iter (gimp); list; list = g_list_next (list)) { GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data); /* get default values from prefs (see bug #120832) */ gimp_config_reset (GIMP_CONFIG (tool_info->tool_options)); } if (! gimp_contexts_load (gimp, &error)) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_WARNING, error->message); g_clear_error (&error); } /* make sure there is always a tool active, so broken config files * can't leave us with no initial tool */ if (! gimp_context_get_tool (gimp_get_user_context (gimp))) { gimp_context_set_tool (gimp_get_user_context (gimp), gimp_get_tool_info_iter (gimp)->data); } for (list = gimp_get_tool_info_iter (gimp); list; list = g_list_next (list)) { GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data); GimpToolOptionsGUIFunc options_gui_func; GtkWidget *options_gui; /* copy all context properties except those the tool actually * uses, because the subsequent deserialize() on the tool * options will only set the properties that were set to * non-default values at the time of saving, and we want to * keep these default values as if they have been saved. * (see bug #541586). */ gimp_context_copy_properties (gimp_get_user_context (gimp), GIMP_CONTEXT (tool_info->tool_options), GIMP_CONTEXT_PROP_MASK_ALL &~ (tool_info->context_props | GIMP_CONTEXT_PROP_MASK_TOOL | GIMP_CONTEXT_PROP_MASK_PAINT_INFO)); gimp_tool_options_deserialize (tool_info->tool_options, NULL); options_gui_func = g_object_get_data (G_OBJECT (tool_info), "gimp-tool-options-gui-func"); if (options_gui_func) { options_gui = (* options_gui_func) (tool_info->tool_options); } else { GtkWidget *label; options_gui = gimp_tool_options_gui (tool_info->tool_options); label = gtk_label_new (_("This tool has\nno options.")); gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER); gimp_label_set_attributes (GTK_LABEL (label), PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC, -1); gtk_box_pack_start (GTK_BOX (options_gui), label, FALSE, FALSE, 6); gtk_widget_show (label); } gimp_tools_set_tool_options_gui (tool_info->tool_options, g_object_ref_sink (options_gui)); } }
void gimp_tools_init (Gimp *gimp) { GimpToolRegisterFunc register_funcs[] = { /* register tools in reverse order */ /* color tools */ gimp_operation_tool_register, gimp_gegl_tool_register, gimp_curves_tool_register, gimp_levels_tool_register, gimp_threshold_tool_register, gimp_brightness_contrast_tool_register, gimp_colorize_tool_register, gimp_hue_saturation_tool_register, gimp_color_balance_tool_register, /* paint tools */ gimp_dodge_burn_tool_register, gimp_smudge_tool_register, gimp_convolve_tool_register, gimp_perspective_clone_tool_register, gimp_heal_tool_register, gimp_clone_tool_register, gimp_mybrush_tool_register, gimp_ink_tool_register, gimp_airbrush_tool_register, gimp_eraser_tool_register, gimp_paintbrush_tool_register, gimp_pencil_tool_register, gimp_blend_tool_register, gimp_bucket_fill_tool_register, gimp_text_tool_register, gimp_seamless_clone_tool_register, /* transform tools */ gimp_n_point_deformation_tool_register, gimp_warp_tool_register, gimp_cage_tool_register, gimp_flip_tool_register, gimp_perspective_tool_register, gimp_handle_transform_tool_register, gimp_shear_tool_register, gimp_scale_tool_register, gimp_rotate_tool_register, gimp_unified_transform_tool_register, gimp_crop_tool_register, gimp_align_tool_register, gimp_move_tool_register, /* non-modifying tools */ gimp_measure_tool_register, gimp_magnify_tool_register, gimp_color_picker_tool_register, /* path tool */ gimp_vector_tool_register, /* selection tools */ gimp_foreground_select_tool_register, gimp_iscissors_tool_register, gimp_by_color_select_tool_register, gimp_fuzzy_select_tool_register, gimp_free_select_tool_register, gimp_ellipse_select_tool_register, gimp_rectangle_select_tool_register }; GList *default_order = NULL; GList *list; gint i; g_return_if_fail (GIMP_IS_GIMP (gimp)); gimp_tool_options_create_folder (); tool_manager_init (gimp); gimp_container_freeze (gimp->tool_info_list); for (i = 0; i < G_N_ELEMENTS (register_funcs); i++) { register_funcs[i] (gimp_tools_register, gimp); } gimp_container_thaw (gimp->tool_info_list); for (list = gimp_get_tool_info_iter (gimp); list; list = g_list_next (list)) { const gchar *identifier = gimp_object_get_name (list->data); default_order = g_list_prepend (default_order, g_strdup (identifier)); } default_order = g_list_reverse (default_order); g_object_set_data (G_OBJECT (gimp), "gimp-tools-default-order", default_order); }
void tools_actions_setup (GimpActionGroup *group) { GtkAction *action; GList *list; gimp_action_group_add_actions (group, "tools-action", tools_actions, G_N_ELEMENTS (tools_actions)); gimp_action_group_add_string_actions (group, "tools-action", tools_alternative_actions, G_N_ELEMENTS (tools_alternative_actions), G_CALLBACK (tools_select_cmd_callback)); action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), "tools-by-color-select-short"); gtk_action_set_accel_path (action, "<Actions>/tools/tools-by-color-select"); gimp_action_group_add_enum_actions (group, NULL, tools_color_average_radius_actions, G_N_ELEMENTS (tools_color_average_radius_actions), G_CALLBACK (tools_color_average_radius_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_paint_brush_size_actions, G_N_ELEMENTS (tools_paint_brush_size_actions), G_CALLBACK (tools_paint_brush_size_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_paint_brush_angle_actions, G_N_ELEMENTS (tools_paint_brush_angle_actions), G_CALLBACK (tools_paint_brush_angle_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_paint_brush_aspect_ratio_actions, G_N_ELEMENTS (tools_paint_brush_aspect_ratio_actions), G_CALLBACK (tools_paint_brush_aspect_ratio_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_ink_blob_size_actions, G_N_ELEMENTS (tools_ink_blob_size_actions), G_CALLBACK (tools_ink_blob_size_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_ink_blob_aspect_actions, G_N_ELEMENTS (tools_ink_blob_aspect_actions), G_CALLBACK (tools_ink_blob_aspect_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_ink_blob_angle_actions, G_N_ELEMENTS (tools_ink_blob_angle_actions), G_CALLBACK (tools_ink_blob_angle_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_foreground_select_brush_size_actions, G_N_ELEMENTS (tools_foreground_select_brush_size_actions), G_CALLBACK (tools_fg_select_brush_size_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_transform_preview_opacity_actions, G_N_ELEMENTS (tools_transform_preview_opacity_actions), G_CALLBACK (tools_transform_preview_opacity_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_value_1_actions, G_N_ELEMENTS (tools_value_1_actions), G_CALLBACK (tools_value_1_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_value_2_actions, G_N_ELEMENTS (tools_value_2_actions), G_CALLBACK (tools_value_2_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_value_3_actions, G_N_ELEMENTS (tools_value_3_actions), G_CALLBACK (tools_value_3_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_value_4_actions, G_N_ELEMENTS (tools_value_4_actions), G_CALLBACK (tools_value_4_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_object_1_actions, G_N_ELEMENTS (tools_object_1_actions), G_CALLBACK (tools_object_1_cmd_callback)); gimp_action_group_add_enum_actions (group, NULL, tools_object_2_actions, G_N_ELEMENTS (tools_object_2_actions), G_CALLBACK (tools_object_2_cmd_callback)); for (list = gimp_get_tool_info_iter (group->gimp); list; list = g_list_next (list)) { GimpToolInfo *tool_info = list->data; if (tool_info->menu_path) { GimpStringActionEntry entry; const gchar *stock_id; const gchar *identifier; gchar *tmp; gchar *name; stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info)); identifier = gimp_object_get_name (tool_info); tmp = g_strndup (identifier + strlen ("gimp-"), strlen (identifier) - strlen ("gimp--tool")); name = g_strdup_printf ("tools-%s", tmp); g_free (tmp); entry.name = name; entry.stock_id = stock_id; entry.label = tool_info->menu_path; entry.accelerator = tool_info->menu_accel; entry.tooltip = tool_info->help; entry.help_id = tool_info->help_id; entry.value = identifier; gimp_action_group_add_string_actions (group, NULL, &entry, 1, G_CALLBACK (tools_select_cmd_callback)); g_free (name); } } }