summarylogtreecommitdiffstats
path: root/explicit-extension.patch
blob: fe5bb70c78511652020a7660ecbf336b2c8fef04 (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
diff -rudp xarchiver-0.5.3.orig/src/new_dialog.c xarchiver-0.5.3/src/new_dialog.c
--- xarchiver-0.5.3.orig/src/new_dialog.c	2014-02-09 07:26:24.000000000 -0800
+++ xarchiver-0.5.3/src/new_dialog.c	2014-02-21 19:41:06.000000000 -0800
@@ -30,13 +30,34 @@ gchar *current_new_directory = NULL;
 gint  new_combo_box = -1;
 gchar *ComboArchiveType;
 
+void xa_change_archive_extension (GtkComboBox *combo_box, GtkWidget *xa_file_chooser) {
+	GList *Name;
+	gchar *path;
+	
+	Name = g_list_last(ArchiveType);
+	path = g_path_get_basename ( gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (xa_file_chooser) ));
+	
+	while (Name)
+	{
+		if (g_str_has_suffix(path, Name->data)) {
+			ComboArchiveType = gtk_combo_box_get_active_text (combo_box);
+			/* Replaces the valid extension present in the filename with the one just selected */
+			gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (xa_file_chooser), g_strconcat(g_strndup(path, strlen(path) - strlen(Name->data)), ComboArchiveType, NULL));
+			return;
+		}
+		Name = g_list_previous (Name);
+	}
+	
+	/* Appends the extension without taking anything out */
+	gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (xa_file_chooser), g_strconcat(path, ComboArchiveType, NULL));
+}
+
 XArchive *xa_new_archive_dialog (gchar *path, XArchive *archive_open[], gboolean flag)
 {
 	XArchive *archive = NULL;
 	GtkWidget *xa_file_chooser;
 	GtkWidget *hbox = NULL;
 	GtkWidget *combo_box = NULL;
-	GtkWidget *add_extension_cb = NULL;
 	GtkFileFilter *xa_new_archive_dialog_filter;
 	GtkTooltips *filter_tooltip;
 	GList *Suffix,*Name;
@@ -112,23 +133,25 @@ XArchive *xa_new_archive_dialog (gchar *
 
 	gtk_box_pack_start (GTK_BOX (hbox), combo_box, TRUE, TRUE, 0);
 
-	add_extension_cb = gtk_check_button_new_with_label (_("Add the archive extension to the filename"));
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(add_extension_cb),TRUE);
-	gtk_box_pack_start (GTK_BOX (hbox), add_extension_cb, TRUE, TRUE, 0);
 	gtk_widget_show_all (hbox);
 	gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (xa_file_chooser), hbox);
-
+	ComboArchiveType = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo_box));
+	g_signal_connect(G_OBJECT(combo_box), "changed", G_CALLBACK(xa_change_archive_extension), xa_file_chooser);
+	
 	if (path != NULL)
 	{
 		basepath = g_path_get_basename (path);
-		gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (xa_file_chooser),basepath);
+		gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (xa_file_chooser), g_strconcat(basepath, ".", ComboArchiveType, NULL));
 
 		current_dir = g_get_current_dir ();
 		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (xa_file_chooser),current_dir);
 
 		g_free (basepath);
 		g_free (current_dir);
+	} else {
+		gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (xa_file_chooser), g_strconcat(".", ComboArchiveType, NULL));
 	}
+	
 	gtk_window_set_modal (GTK_WINDOW (xa_file_chooser),TRUE);
 	if (current_new_directory != NULL)
 		gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER (xa_file_chooser),current_new_directory);
@@ -138,17 +161,6 @@ XArchive *xa_new_archive_dialog (gchar *
 	if (response == GTK_RESPONSE_ACCEPT)
 	{
 		my_path = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (xa_file_chooser) );
-		ComboArchiveType = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo_box));
-
-		if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (add_extension_cb)))
-		{
-			if ( ! g_str_has_suffix (my_path,ComboArchiveType))
-			{
-				my_path_ext = g_strconcat (my_path, ".",ComboArchiveType,NULL);
-				g_free (my_path);
-				my_path = my_path_ext;
-			}
-		}
 
 		if (xa_main_window)
 		{