summaryrefslogtreecommitdiffstats
path: root/app/widgets/gimpopendialog.c
blob: 7525ab1d7e5a26608b209b3b5179782566bc64d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * gimpopendialog.c
 * Copyright (C) 2015 Jehan <jehan@girinstud.io>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include "config.h"

#include <gegl.h>
#include <gtk/gtk.h>

#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"

#include "widgets-types.h"

#include "core/gimp.h"
#include "core/gimpimage.h"

#include "gimphelp-ids.h"
#include "gimpopendialog.h"

#include "gimp-intl.h"


/*  local function prototypes  */

static void   gimp_open_dialog_dispose (GObject *object);


G_DEFINE_TYPE (GimpOpenDialog, gimp_open_dialog,
               GIMP_TYPE_FILE_DIALOG)

#define parent_class gimp_open_dialog_parent_class


/*  private functions  */

static void
gimp_open_dialog_class_init (GimpOpenDialogClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = gimp_open_dialog_dispose;
}

static void
gimp_open_dialog_init (GimpOpenDialog *dialog)
{
}

static void
gimp_open_dialog_dispose (GObject *object)
{
  gimp_open_dialog_set_image (GIMP_OPEN_DIALOG (object), NULL, FALSE);

  G_OBJECT_CLASS (parent_class)->dispose (object);
}


/*  public functions  */

GtkWidget *
gimp_open_dialog_new (Gimp *gimp)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  return g_object_new (GIMP_TYPE_OPEN_DIALOG,
                       "gimp",                  gimp,
                       "title",                 _("Open Image"),
                       "role",                  "gimp-file-open",
                       "help-id",               GIMP_HELP_FILE_OPEN,
                       "ok-button-label",       _("_Open"),

                       "automatic-label",       _("Automatically Detected"),
                       "automatic-help-id",     GIMP_HELP_FILE_OPEN_BY_EXTENSION,

                       "action",                GTK_FILE_CHOOSER_ACTION_OPEN,
                       "file-procs",            GIMP_FILE_PROCEDURE_GROUP_OPEN,
                       "file-procs-all-images", GIMP_FILE_PROCEDURE_GROUP_NONE,
                       "file-filter-label",     NULL,
                       NULL);
}

void
gimp_open_dialog_set_image (GimpOpenDialog *dialog,
                            GimpImage      *image,
                            gboolean        open_as_layers)
{
  GimpFileDialog *file_dialog;

  g_return_if_fail (GIMP_IS_OPEN_DIALOG (dialog));
  g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));

  file_dialog = GIMP_FILE_DIALOG (dialog);

  if (file_dialog->image)
    {
      g_object_remove_weak_pointer (G_OBJECT (file_dialog->image),
                                    (gpointer *) &file_dialog->image);
    }

  file_dialog->image     = image;
  dialog->open_as_layers = open_as_layers;

  if (file_dialog->image)
    {
      g_object_add_weak_pointer (G_OBJECT (file_dialog->image),
                                 (gpointer *) &file_dialog->image);
    }
}