1 /*
2  * This file is part of gedit
3  *
4  * Copyright (C) 2020 Sébastien Wilmet <swilmet@gnome.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "gedit-file-chooser-open.h"
21 #include "gedit-file-chooser-open-dialog.h"
22 #include "gedit-file-chooser-open-native.h"
23 
24 /* Common code for file choosers that *open* files. */
25 
G_DEFINE_TYPE(GeditFileChooserOpen,_gedit_file_chooser_open,GEDIT_TYPE_FILE_CHOOSER)26 G_DEFINE_TYPE (GeditFileChooserOpen, _gedit_file_chooser_open, GEDIT_TYPE_FILE_CHOOSER)
27 
28 static GtkFileChooser *
29 get_gtk_file_chooser (GeditFileChooserOpen *chooser)
30 {
31 	return _gedit_file_chooser_get_gtk_file_chooser (GEDIT_FILE_CHOOSER (chooser));
32 }
33 
34 static void
_gedit_file_chooser_open_constructed(GObject * object)35 _gedit_file_chooser_open_constructed (GObject *object)
36 {
37 	GeditFileChooserOpen *chooser = GEDIT_FILE_CHOOSER_OPEN (object);
38 
39 	if (G_OBJECT_CLASS (_gedit_file_chooser_open_parent_class)->constructed != NULL)
40 	{
41 		G_OBJECT_CLASS (_gedit_file_chooser_open_parent_class)->constructed (object);
42 	}
43 
44 	gtk_file_chooser_set_select_multiple (get_gtk_file_chooser (chooser), TRUE);
45 }
46 
47 static void
_gedit_file_chooser_open_class_init(GeditFileChooserOpenClass * klass)48 _gedit_file_chooser_open_class_init (GeditFileChooserOpenClass *klass)
49 {
50 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
51 
52 	object_class->constructed = _gedit_file_chooser_open_constructed;
53 }
54 
55 static void
_gedit_file_chooser_open_init(GeditFileChooserOpen * chooser)56 _gedit_file_chooser_open_init (GeditFileChooserOpen *chooser)
57 {
58 }
59 
60 GeditFileChooserOpen *
_gedit_file_chooser_open_new(void)61 _gedit_file_chooser_open_new (void)
62 {
63 	if (_gedit_file_chooser_is_native ())
64 	{
65 		return _gedit_file_chooser_open_native_new ();
66 	}
67 
68 	return _gedit_file_chooser_open_dialog_new ();
69 }
70 
71 GSList *
_gedit_file_chooser_open_get_files(GeditFileChooserOpen * chooser)72 _gedit_file_chooser_open_get_files (GeditFileChooserOpen *chooser)
73 {
74 	g_return_val_if_fail (GEDIT_IS_FILE_CHOOSER_OPEN (chooser), NULL);
75 
76 	return gtk_file_chooser_get_files (get_gtk_file_chooser (chooser));
77 }
78