1 /**********************************************************************************************************
2 Copyright (c) 2002-2013 Abdul-Rahman Allouche. All rights reserved
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 documentation files (the Gabedit), to deal in the Software without restriction, including without limitation
6 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9   The above copyright notice and this permission notice shall be included in all copies or substantial portions
10   of the Software.
11 
12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
14 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
15 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
16 DEALINGS IN THE SOFTWARE.
17 ************************************************************************************************************/
18 
19 #include "../../Config.h"
20 #include <gtk/gtk.h>
21 #include "GabeditFileChooser.h"
22 
23 /********************************************************************************/
gabedit_file_chooser_new(gchar * title,GtkFileChooserAction action)24 GtkWidget* gabedit_file_chooser_new(gchar* title, GtkFileChooserAction action)
25 {
26 	gboolean multiple = FALSE;
27 	GtkWidget *dialog;
28 	dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "action", action, "file-system-backend", "gtk+", "select-multiple", multiple, NULL);
29 	if(title) gtk_window_set_title (GTK_WINDOW (dialog), title);
30 	if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
31 	{
32 		gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
33 	}
34 	else
35 	{
36 		gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
37 	}
38 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
39 
40 	return GTK_WIDGET(dialog);
41 
42 }
43 /*************************************************************************************/
gabedit_file_chooser_set_current_file(GabeditFileChooser * fileChooser,const gchar * fileName)44 void gabedit_file_chooser_set_current_file(GabeditFileChooser *fileChooser,const gchar *fileName)
45 {
46 
47 	GtkFileChooserAction action;
48 	g_return_if_fail (fileChooser != NULL);
49 	g_return_if_fail (GABEDIT_IS_FILE_CHOOSER(fileChooser));
50 	g_return_if_fail (fileName != NULL);
51 
52 	action = gtk_file_chooser_get_action((GtkFileChooser *)fileChooser);
53 	gtk_file_chooser_set_filename ((GtkFileChooser *)fileChooser, fileName);
54 	if(action == GTK_FILE_CHOOSER_ACTION_SAVE)
55 	{
56 		gchar* tmp = g_path_get_basename(fileName);
57 		gtk_file_chooser_set_current_name ((GtkFileChooser *)fileChooser, tmp);
58 		if(tmp) g_free(tmp);
59 	}
60 }
61 /********************************************************************************/
gabedit_file_chooser_get_current_file(GabeditFileChooser * fileChooser)62 gchar* gabedit_file_chooser_get_current_file(GabeditFileChooser *fileChooser)
63 {
64 	return gtk_file_chooser_get_filename((GtkFileChooser *)fileChooser);
65 }
66 /*****************************************************************************************/
gabedit_file_chooser_set_filters(GabeditFileChooser * fileChooser,gchar ** patterns)67 void gabedit_file_chooser_set_filters(GabeditFileChooser *fileChooser,gchar **patterns)
68 {
69 	GtkFileFilter *filter;
70 	GtkFileFilter *filter0 = NULL;
71 	gint n = 0;
72 
73 	g_return_if_fail (fileChooser != NULL);
74 	g_return_if_fail (GABEDIT_IS_FILE_CHOOSER(fileChooser));
75 	g_return_if_fail (patterns != NULL);
76 	while(patterns[n])
77 	{
78 		filter = gtk_file_filter_new ();
79 		gtk_file_filter_set_name (filter, patterns[n]);
80 		gtk_file_filter_add_pattern (filter, patterns[n]);
81 		gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fileChooser), filter);
82 		if(n==0) filter0 = filter;
83 		n++;
84 	}
85 	if(filter0)gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fileChooser), filter0);
86 }
87 /*************************************************************************************/
gabedit_file_chooser_set_filter(GabeditFileChooser * fileChooser,const gchar * pattern)88 void gabedit_file_chooser_set_filter(GabeditFileChooser *fileChooser, const gchar *pattern)
89 {
90 	GtkFileFilter *filter;
91 
92 	g_return_if_fail (fileChooser != NULL);
93 	g_return_if_fail (GABEDIT_IS_FILE_CHOOSER(fileChooser));
94 	g_return_if_fail (pattern != NULL);
95 
96 	filter = gtk_file_filter_new ();
97 	gtk_file_filter_set_name (filter, pattern);
98 	gtk_file_filter_add_pattern (filter, pattern);
99 	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fileChooser), filter);
100 	gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fileChooser), filter);
101 }
102 /*************************************************************************************/
gabedit_file_chooser_show_hidden(GabeditFileChooser * fileChooser)103 void gabedit_file_chooser_show_hidden(GabeditFileChooser *fileChooser)
104 {
105 
106 	/*
107 	gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER (fileChooser), TRUE);
108 	*/
109 }
110 /*************************************************************************************/
gabedit_file_chooser_hide_hidden(GabeditFileChooser * fileChooser)111 void gabedit_file_chooser_hide_hidden(GabeditFileChooser *fileChooser)
112 {
113 	/*
114 	gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER (fileChooser), FALSE);
115 	*/
116 }
117 /*************************************************************************************/
118