Example #1
0
static void
file_open_dialog_response (GtkWidget *open_dialog,
                           gint       response_id,
                           Gimp      *gimp)
{
  GimpFileDialog *dialog  = GIMP_FILE_DIALOG (open_dialog);
  GSList         *uris;
  GSList         *list;
  gboolean        success = FALSE;

  g_object_set_data_full (G_OBJECT (gimp), "gimp-file-open-dialog-state",
                          gimp_file_dialog_get_state (dialog),
                          (GDestroyNotify) gimp_file_dialog_state_destroy);

  if (response_id != GTK_RESPONSE_OK)
    {
      if (! dialog->busy)
        gtk_widget_destroy (open_dialog);

      return;
    }

  uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (open_dialog));

  if (uris)
    g_object_set_data_full (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_URI_KEY,
                            g_strdup (uris->data), (GDestroyNotify) g_free);

  gimp_file_dialog_set_sensitive (dialog, FALSE);

  /* When we are going to open new image windows, unset the transient
   * window. We don't need it since we will use gdk_window_raise() to
   * keep the dialog on top. And if we don't do it, then the dialog
   * will pull the image window it was invoked from on top of all the
   * new opened image windows, and we don't want that to happen.
   */
  if (! dialog->open_as_layers)
    gtk_window_set_transient_for (GTK_WINDOW (open_dialog), NULL);

  for (list = uris; list; list = g_slist_next (list))
    {
      gchar *filename = file_utils_filename_from_uri (list->data);

      if (filename)
        {
          gboolean regular = g_file_test (filename, G_FILE_TEST_IS_REGULAR);

          g_free (filename);

          if (! regular)
            continue;
        }

      if (dialog->open_as_layers)
        {
          if (! dialog->image)
            {
              dialog->image = file_open_dialog_open_image (open_dialog,
                                                           gimp,
                                                           list->data,
                                                           dialog->file_proc);

              if (dialog->image)
                success = TRUE;
            }
          else if (file_open_dialog_open_layers (open_dialog,
                                                 dialog->image,
                                                 list->data,
                                                 dialog->file_proc))
            {
              success = TRUE;
            }
        }
      else
        {
          if (file_open_dialog_open_image (open_dialog,
                                           gimp,
                                           list->data,
                                           dialog->file_proc))
            {
              success = TRUE;

              /* Make the dialog stay on top of all images we open if
               * we open say 10 at once
               */
              gdk_window_raise (gtk_widget_get_window (open_dialog));
            }
        }

      if (dialog->canceled)
        break;
    }

  if (success)
    {
      if (dialog->open_as_layers && dialog->image)
        gimp_image_flush (dialog->image);

      gtk_widget_destroy (open_dialog);
    }
  else
    {
      gimp_file_dialog_set_sensitive (dialog, TRUE);
    }

  g_slist_free_full (uris, (GDestroyNotify) g_free);
}
Example #2
0
static void
file_open_dialog_response (GtkWidget *dialog,
                           gint       response_id,
                           Gimp      *gimp)
{
  GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
  GimpOpenDialog *open_dialog = GIMP_OPEN_DIALOG (dialog);
  GSList         *files;
  GSList         *list;
  gboolean        success = FALSE;

  gimp_file_dialog_save_state (GIMP_FILE_DIALOG (dialog),
                               "gimp-file-open-dialog-state");

  if (response_id != GTK_RESPONSE_OK)
    {
      if (! file_dialog->busy)
        gtk_widget_destroy (dialog);

      return;
    }

  files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));

  if (files)
    g_object_set_data_full (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_FILE_KEY,
                            g_object_ref (files->data),
                            (GDestroyNotify) g_object_unref);

  gimp_file_dialog_set_sensitive (file_dialog, FALSE);

  /* When we are going to open new image windows, unset the transient
   * window. We don't need it since we will use gdk_window_raise() to
   * keep the dialog on top. And if we don't do it, then the dialog
   * will pull the image window it was invoked from on top of all the
   * new opened image windows, and we don't want that to happen.
   */
  if (! open_dialog->open_as_layers)
    gtk_window_set_transient_for (GTK_WINDOW (dialog), NULL);

  for (list = files; list; list = g_slist_next (list))
    {
      GFile *file = list->data;

      if (open_dialog->open_as_layers)
        {
          if (! file_dialog->image)
            {
              file_dialog->image = file_open_dialog_open_image (dialog,
                                                                gimp,
                                                                file,
                                                                file_dialog->file_proc);

              if (file_dialog->image)
                success = TRUE;
            }
          else if (file_open_dialog_open_layers (dialog,
                                                 file_dialog->image,
                                                 file,
                                                 file_dialog->file_proc))
            {
              success = TRUE;
            }
        }
      else
        {
          if (file_open_dialog_open_image (dialog,
                                           gimp,
                                           file,
                                           file_dialog->file_proc))
            {
              success = TRUE;

              /* Make the dialog stay on top of all images we open if
               * we open say 10 at once
               */
              gdk_window_raise (gtk_widget_get_window (dialog));
            }
        }

      if (file_dialog->canceled)
        break;
    }

  if (success)
    {
      if (open_dialog->open_as_layers && file_dialog->image)
        gimp_image_flush (file_dialog->image);

      gtk_widget_destroy (dialog);
    }
  else
    {
      gimp_file_dialog_set_sensitive (file_dialog, TRUE);
    }

  g_slist_free_full (files, (GDestroyNotify) g_object_unref);
}