Esempio n. 1
0
static void
gimp_image_prop_view_label_set_filetype (GtkWidget *label,
                                         GimpImage *image)
{
  GimpPlugInManager   *manager = image->gimp->plug_in_manager;
  GimpPlugInProcedure *proc;

  proc = gimp_image_get_save_proc (image);

  if (! proc)
    proc = gimp_image_get_load_proc (image);

  if (! proc)
    {
      gchar *filename = gimp_image_get_filename (image);

      if (filename)
        {
          proc = file_procedure_find (manager->load_procs, filename, NULL);
          g_free (filename);
        }
    }

  gtk_label_set_text (GTK_LABEL (label),
                      proc ? gimp_plug_in_procedure_get_label (proc) : NULL);
}
Esempio n. 2
0
void
file_save_cmd_callback (GtkAction *action,
                        gint       value,
                        gpointer   data)
{
  Gimp         *gimp;
  GimpDisplay  *display;
  GimpImage    *image;
  GtkWidget    *widget;
  GimpSaveMode  save_mode;
  const gchar  *uri;
  gboolean      saved = FALSE;
  return_if_no_gimp (gimp, data);
  return_if_no_display (display, data);
  return_if_no_widget (widget, data);

  image = gimp_display_get_image (display);

  save_mode = (GimpSaveMode) value;

  if (! gimp_image_get_active_drawable (image))
    return;

  uri = gimp_image_get_uri (image);

  switch (save_mode)
    {
    case GIMP_SAVE_MODE_SAVE:
    case GIMP_SAVE_MODE_SAVE_AND_CLOSE:
      /*  Only save if the image has been modified, or if it is new.  */
      if ((gimp_image_is_dirty (image) ||
           ! GIMP_GUI_CONFIG (image->gimp->config)->trust_dirty_flag) ||
          uri == NULL)
        {
          GimpPlugInProcedure *save_proc = gimp_image_get_save_proc (image);

          if (uri && ! save_proc)
            {
              save_proc =
                file_procedure_find (image->gimp->plug_in_manager->save_procs,
                                     uri, NULL);
            }

          if (uri && save_proc)
            {
              saved = file_save_dialog_save_image (GIMP_PROGRESS (display),
                                                   gimp, image, uri,
                                                   save_proc,
                                                   GIMP_RUN_WITH_LAST_VALS,
                                                   TRUE, FALSE, FALSE, TRUE);
              break;
            }

          /* fall thru */
        }
      else
        {
          gimp_message_literal (image->gimp,
				G_OBJECT (display), GIMP_MESSAGE_INFO,
				_("No changes need to be saved"));
          saved = TRUE;
          break;
        }

    case GIMP_SAVE_MODE_SAVE_AS:
      file_save_dialog_show (gimp, image, widget,
                             _("Save Image"), FALSE,
                             save_mode == GIMP_SAVE_MODE_SAVE_AND_CLOSE, display);
      break;

    case GIMP_SAVE_MODE_SAVE_A_COPY:
      file_save_dialog_show (gimp, image, widget,
                             _("Save a Copy of the Image"), TRUE,
                             FALSE, display);
      break;

    case GIMP_SAVE_MODE_EXPORT:
      file_export_dialog_show (gimp, image, widget);
      break;

    case GIMP_SAVE_MODE_EXPORT_TO:
    case GIMP_SAVE_MODE_OVERWRITE:
      {
        const gchar         *uri = NULL;
        GimpPlugInProcedure *export_proc;
        gboolean             overwrite;

        if (save_mode == GIMP_SAVE_MODE_EXPORT_TO)
          {
            uri = gimp_image_get_exported_uri (image);

            if (! uri)
              {
                /* Behave as if Export... was invoked */
                file_export_dialog_show (gimp, image, widget);
                break;
              }

            overwrite = FALSE;
          }
        else if (save_mode == GIMP_SAVE_MODE_OVERWRITE)
          {
            uri = gimp_image_get_imported_uri (image);

            overwrite = TRUE;
          }

        if (uri)
          {
            export_proc =
              file_procedure_find (image->gimp->plug_in_manager->export_procs,
                                   uri, NULL);
          }

        if (uri && export_proc)
          {
            char *uri_copy;

            /* The memory that 'uri' points to can be freed by
               file_save_dialog_save_image(), when it eventually calls
               gimp_image_set_imported_uri() to reset the imported uri,
               resulting in garbage. So make a duplicate of it here. */

            uri_copy = g_strdup (uri);

            saved = file_save_dialog_save_image (GIMP_PROGRESS (display),
                                                 gimp, image, uri_copy,
                                                 export_proc,
                                                 GIMP_RUN_WITH_LAST_VALS,
                                                 FALSE,
                                                 overwrite, ! overwrite,
                                                 TRUE);
            g_free (uri_copy);
          }
      }
      break;
    }

  if (save_mode == GIMP_SAVE_MODE_SAVE_AND_CLOSE &&
      saved &&
      ! gimp_image_is_dirty (image))
    {
      gimp_display_close (display);
    }
}
Esempio n. 3
0
void
file_save_cmd_callback (GtkAction *action,
                        gint       value,
                        gpointer   data)
{
  GimpDisplay  *display;
  GimpImage    *image;
  GtkWidget    *widget;
  GimpSaveMode  save_mode;
  gboolean      saved = FALSE;
  return_if_no_display (display, data);
  return_if_no_widget (widget, data);

  image = display->image;

  save_mode = (GimpSaveMode) value;

  if (! gimp_image_get_active_drawable (image))
    return;

  switch (save_mode)
    {
    case GIMP_SAVE_MODE_SAVE:
    case GIMP_SAVE_MODE_SAVE_AND_CLOSE:
      /*  Only save if the image has been modified  */
      if (image->dirty ||
          ! GIMP_GUI_CONFIG (image->gimp->config)->trust_dirty_flag)
        {
          const gchar         *uri;
          GimpPlugInProcedure *save_proc = NULL;

          uri       = gimp_object_get_name (GIMP_OBJECT (image));
          save_proc = gimp_image_get_save_proc (image);

          if (uri && ! save_proc)
            save_proc =
              file_procedure_find (image->gimp->plug_in_manager->save_procs,
                                   uri, NULL);

          if (uri && save_proc)
            {
              GimpPDBStatusType  status;
              GError            *error = NULL;
              GList             *list;

              for (list = gimp_action_groups_from_name ("file");
                   list;
                   list = g_list_next (list))
                {
                  gimp_action_group_set_action_sensitive (list->data,
                                                          "file-quit",
                                                          FALSE);
                }

              status = file_save (image, action_data_get_context (data),
                                  GIMP_PROGRESS (display),
                                  uri, save_proc,
                                  GIMP_RUN_WITH_LAST_VALS, FALSE, &error);

              switch (status)
                {
                case GIMP_PDB_SUCCESS:
                  saved = TRUE;
                  break;

                case GIMP_PDB_CANCEL:
                  gimp_message (image->gimp, G_OBJECT (display),
                                GIMP_MESSAGE_INFO,
                                _("Saving canceled"));
                  break;

                default:
                  {
                    gchar *filename = file_utils_uri_display_name (uri);

                    gimp_message (image->gimp, G_OBJECT (display),
                                  GIMP_MESSAGE_ERROR,
                                  _("Saving '%s' failed:\n\n%s"),
                                  filename, error->message);
                    g_free (filename);
                    g_clear_error (&error);
                  }
                  break;
                }

              for (list = gimp_action_groups_from_name ("file");
                   list;
                   list = g_list_next (list))
                {
                  gimp_action_group_set_action_sensitive (list->data,
                                                          "file-quit",
                                                          TRUE);
                }

              break;
            }

          /* fall thru */
        }
      else
        {
          saved = TRUE;
          break;
        }

    case GIMP_SAVE_MODE_SAVE_AS:
      file_save_dialog_show (display->image, widget,
                             _("Save Image"), FALSE,
                             save_mode == GIMP_SAVE_MODE_SAVE_AND_CLOSE);
      break;

    case GIMP_SAVE_MODE_SAVE_A_COPY:
      file_save_dialog_show (display->image, widget,
                             _("Save a Copy of the Image"), TRUE,
                             FALSE);
      break;
    }

  if (save_mode == GIMP_SAVE_MODE_SAVE_AND_CLOSE &&
      saved && ! display->image->dirty)
    {
      gimp_display_delete (display);
    }
}