Ejemplo n.º 1
0
void set_img_file(SettingItem * item,gchar * f)
{
    g_free(item->fvalue);
    item->fvalue = g_strdup(f);
    gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(item->widget),f);
    check_file(item,f);
}
Ejemplo n.º 2
0
bool ChooseDirectory(
	fs::path&	outDirectory)
{
	GtkWidget* dialog = nil;
	bool result = false;

	try
	{
		dialog = 
			gtk_file_chooser_dialog_new(_("Select Folder"), nil,
				GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				NULL);
		
		THROW_IF_NIL(dialog);
	
		string currentFolder = gApp->GetCurrentFolder();
	
		if (currentFolder.length() > 0)
		{
			gtk_file_chooser_set_current_folder_uri(
				GTK_FILE_CHOOSER(dialog), currentFolder.c_str());
		}
		
		if (fs::exists(outDirectory) and outDirectory != fs::path())
		{
			gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(dialog),
				outDirectory.string().c_str());
		}
		
		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
		{
			char* uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
			if (uri != nil)
			{
				MFile url(uri, true);
				outDirectory = url.GetPath();
	
				g_free(uri);
	
				result = true;
			}
//
//			gApp->SetCurrentFolder(
//				gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER(dialog)));
		}
	}
	catch (exception& e)
	{
		if (dialog)
			gtk_widget_destroy(dialog);
		
		throw;
	}
	
	gtk_widget_destroy(dialog);

	return result;
}
Ejemplo n.º 3
0
G_MODULE_EXPORT gboolean on_button_dictionary_edit_clicked(GtkWidget *widget, worddic *worddic) {
  is_update = TRUE;
  GtkTreeView *treeview_dic = (GtkTreeView*)gtk_builder_get_object(worddic->definitions, 
                                                                   "treeview_dic");
  GtkTreeIter iter ;
  gint index = getsingleselect(treeview_dic, &iter);

  //init the edit dic dialog with the selected dic name and path
  GtkDialog *dialog_dic_edit = (GtkDialog*)gtk_builder_get_object(worddic->definitions, 
                                                                  "dialog_dic_edit");

  GtkEntry* entry_edit_dic_name = (GtkEntry*)gtk_builder_get_object(worddic->definitions, 
                                                                    "entry_edit_dic_name");
  GtkFileChooserButton *fcb_edit_dic_path = NULL;
  fcb_edit_dic_path = (GtkFileChooserButton *)gtk_builder_get_object(worddic->definitions, 
                                                                     "filechooserbutton_edit_dic_path");

  GSList *selected_element = g_slist_nth(worddic->conf->dicfile_list, index);
  WorddicDicfile *dic = selected_element->data;  

  gtk_entry_set_text(entry_edit_dic_name, dic->name);
  gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(fcb_edit_dic_path), dic->path);
  
  gtk_widget_show (GTK_WIDGET(dialog_dic_edit));
}
Php::Value GtkFileChooserDialog_::select_filename(Php::Parameters &parameters)
{
	std::string s_filename = parameters[0];
	gchar *filename = (gchar *)s_filename.c_str();

	gboolean ret = gtk_file_chooser_select_filename (GTK_FILE_CHOOSER(instance), filename);

	return ret;
}
Ejemplo n.º 5
0
/**
 * ask the name of the file to save it
 *
 * \param
 *
 * \return a newly allocated string containing the new name
 * */
static gchar *gsb_file_dialog_ask_name ( void )
{
    gchar *new_name;
    GtkWidget *dialog;
    gint result;

    dialog = gtk_file_chooser_dialog_new ( _("Name the accounts file"),
					   GTK_WINDOW ( run.window ),
					   GTK_FILE_CHOOSER_ACTION_SAVE,
					   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					   GTK_STOCK_SAVE, GTK_RESPONSE_OK,
					   NULL);

    gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( dialog ), gsb_file_get_last_path () );
    gtk_file_chooser_set_do_overwrite_confirmation ( GTK_FILE_CHOOSER ( dialog ), TRUE);
    gtk_window_set_position ( GTK_WINDOW ( dialog ), GTK_WIN_POS_CENTER_ON_PARENT );

    if ( ! nom_fichier_comptes )
    {
        gchar* tmp_str;

        tmp_str = g_strconcat ( titre_fichier, ".gsb", NULL );
        gtk_file_chooser_set_current_name ( GTK_FILE_CHOOSER ( dialog ), tmp_str);
        g_free ( tmp_str );
    }
    else
	gtk_file_chooser_select_filename ( GTK_FILE_CHOOSER (dialog), nom_fichier_comptes );

    result = gtk_dialog_run ( GTK_DIALOG ( dialog ));

    switch ( result )
    {
	case GTK_RESPONSE_OK :
	    new_name = file_selection_get_filename ( GTK_FILE_CHOOSER ( dialog ));
	    gsb_file_update_last_path (file_selection_get_last_directory (GTK_FILE_CHOOSER (dialog), TRUE));
	    gtk_widget_destroy ( GTK_WIDGET ( dialog ));
	    break;

	default :
	    gtk_widget_destroy ( GTK_WIDGET ( dialog ));
	    return NULL;
    }

    if ( ! g_strrstr ( new_name, "." ) )
    {
        gchar* tmpstr = new_name;
	new_name = g_strconcat ( tmpstr, ".gsb", NULL );
	g_free ( tmpstr );
    }

    return new_name;
}
Ejemplo n.º 6
0
static void dlg_set_tab_default_values(struct TermitTab* pTab, struct TermitDlgHelper* hlp)
{
    if (hlp->tab_title)
        termit_tab_set_title(pTab, hlp->tab_title);
    vte_terminal_set_default_colors(VTE_TERMINAL(pTab->vte));
    termit_tab_set_font(pTab, hlp->style.font_name);
    termit_tab_set_background_image(pTab, hlp->style.image_file);
    termit_tab_set_color_foreground(pTab, hlp->style.foreground_color);
    termit_tab_set_color_background(pTab, hlp->style.background_color);
    termit_tab_set_transparency(pTab, hlp->style.transparency);
    termit_tab_set_audible_bell(pTab, hlp->au_bell);
    termit_tab_set_visible_bell(pTab, hlp->vi_bell);
    if (hlp->style.image_file) {
        gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(hlp->btn_image_file), hlp->style.image_file);
    }
}
Ejemplo n.º 7
0
GSList *
file_chooser(char * title, GtkWidget * parent, GtkFileChooserAction action, int filter,
	     gint multiple, char * destpath) {

        GtkWidget * dialog;
	GSList * files = NULL;

        dialog = gtk_file_chooser_dialog_new(title,
                                             GTK_WINDOW(parent),
                                             action,
					     (action == GTK_FILE_CHOOSER_ACTION_SAVE) ? GTK_STOCK_SAVE : GTK_STOCK_OPEN,
					     GTK_RESPONSE_ACCEPT,
                                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                             NULL);

        gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
        gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), multiple);
        gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(dialog), destpath);

	if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
		char * bname = g_path_get_basename(destpath);
		gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), bname);
		g_free(bname);
	}

        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
	assign_fc_filters(GTK_FILE_CHOOSER(dialog), filter);

	if (options.show_hidden) {
		gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE);
	}

        if (aqualung_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {

		strncpy(destpath,
			gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)),
			MAXLEN-1);

		files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
        }

        gtk_widget_destroy(dialog);

	return files;
}
Ejemplo n.º 8
0
int
clip_GTK_FILECHOOSERSELECTFILENAME(ClipMachine * ClipMachineMemory)
{
   C_object *cchooser = _fetch_co_arg(ClipMachineMemory);

   gchar    *name = _clip_parc(ClipMachineMemory, 2);

   CHECKCOBJ(cchooser, GTK_IS_FILE_CHOOSER(cchooser->object));
   CHECKARG(2, CHARACTER_type_of_ClipVarType);

   LOCALE_TO_UTF(name);
   _clip_retl(ClipMachineMemory, gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(cchooser->object), name));
   FREE_TEXT(name);

   return 0;
 err:
   return 1;
}
Ejemplo n.º 9
0
static void dlg_set_default_values(struct TermitDlgHelper* hlp)
{
    gtk_entry_set_text(GTK_ENTRY(hlp->entry_title), hlp->tab_title);
    gtk_font_button_set_font_name(GTK_FONT_BUTTON(hlp->btn_font), hlp->style.font_name);
    if (hlp->style.foreground_color) {
        gtk_color_button_set_color(GTK_COLOR_BUTTON(hlp->btn_foreground), hlp->style.foreground_color);
    }
    if (hlp->style.background_color) {
        gtk_color_button_set_color(GTK_COLOR_BUTTON(hlp->btn_background), hlp->style.background_color);
    }
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(hlp->scale_transparency), hlp->style.transparency);
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hlp->audible_bell), hlp->au_bell);
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hlp->visible_bell), hlp->vi_bell);
    if (hlp->style.image_file) {
        gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(hlp->btn_image_file), hlp->style.image_file);
    } else {
        gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(hlp->btn_image_file));
    }
}
Ejemplo n.º 10
0
G_MODULE_EXPORT gboolean on_button_dictionary_add_clicked(GtkWidget *widget, worddic *worddic) {
  is_update = FALSE;
  
  GtkTreeView *treeview_dic = (GtkTreeView*)gtk_builder_get_object(worddic->definitions, 
                                                                   "treeview_dic");
  //set edit dialog widgets to blank
  GtkDialog* dialog_dic_edit = (GtkDialog*)gtk_builder_get_object(worddic->definitions, 
                                                                  "dialog_dic_edit");

  GtkEntry* entry_edit_dic_name = (GtkEntry*)gtk_builder_get_object(worddic->definitions, 
                                                                    "entry_edit_dic_name");
  GtkFileChooserButton* fcb_edit_dic_path = NULL;
  fcb_edit_dic_path = (GtkFileChooserButton*)gtk_builder_get_object(worddic->definitions, 
                                                                    "filechooserbutton_edit_dic_path");

  //clear the edit dialog widgets
  gtk_entry_set_text(entry_edit_dic_name, "");
  gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(fcb_edit_dic_path), "");
  
  gtk_widget_show (GTK_WIDGET(dialog_dic_edit));
}
Ejemplo n.º 11
0
static void
update_prefs_for_resource_path (GladeProjectProperties *properties)
{
  GladeProjectPropertiesPrivate *priv = properties->priv;
  const gchar *resource_path;

  resource_path = glade_project_get_resource_path (priv->project);
  
  if (resource_path == NULL)
    {
      gtk_entry_set_text (GTK_ENTRY (priv->relative_path_entry), "");
      gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->full_path_button));

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->resource_default_radio), TRUE);
      gtk_widget_set_sensitive (priv->full_path_button, FALSE);
      gtk_widget_set_sensitive (priv->relative_path_entry, FALSE);
    }
  else if (g_path_is_absolute (resource_path) &&
           g_file_test (resource_path, G_FILE_TEST_IS_DIR))
    {
      gtk_entry_set_text (GTK_ENTRY (priv->relative_path_entry), "");
      gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (priv->full_path_button),
                                        resource_path);

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->resource_fullpath_radio), TRUE);
      gtk_widget_set_sensitive (priv->full_path_button, TRUE);
      gtk_widget_set_sensitive (priv->relative_path_entry, FALSE);
    }
  else
    {
      if (g_strcmp0 (resource_path, gtk_entry_get_text (GTK_ENTRY (priv->relative_path_entry))))
        gtk_entry_set_text (GTK_ENTRY (priv->relative_path_entry), resource_path);

      gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->full_path_button));

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->resource_relative_radio), TRUE);
      gtk_widget_set_sensitive (priv->relative_path_entry, TRUE);
      gtk_widget_set_sensitive (priv->full_path_button, FALSE);
    }
}
Ejemplo n.º 12
0
void
directory_chooser(char * title, GtkWidget * parent, char * directory) {

        GtkWidget * dialog;
	const gchar * selected_directory;

        dialog = gtk_file_chooser_dialog_new(title,
                                             GTK_WINDOW(parent),
                                             GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
					     GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
                                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                             NULL);

        gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
        gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(dialog), directory);
        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);

	if (options.show_hidden) {
		gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), TRUE);
	}

        if (aqualung_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {

                char * utf8;

                selected_directory = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
		utf8 = g_filename_to_utf8(selected_directory, -1, NULL, NULL, NULL);

		if (utf8 == NULL) {
			gtk_widget_destroy(dialog);
		}

                strncpy(directory, selected_directory, MAXLEN-1);
		g_free(utf8);
        }

        gtk_widget_destroy(dialog);
}
Ejemplo n.º 13
0
JNIEXPORT jboolean JNICALL
Java_org_gnome_gtk_GtkFileChooser_gtk_1file_1chooser_1select_1filename
(
	JNIEnv* env,
	jclass cls,
	jlong _self,
	jstring _filename
)
{
	gboolean result;
	jboolean _result;
	GtkFileChooser* self;
	const char* filename;

	// convert parameter self
	self = (GtkFileChooser*) _self;

	// convert parameter filename
	filename = (const char*) bindings_java_getString(env, _filename);
	if (filename == NULL) {
		return  JNI_FALSE; // Java Exception already thrown
	}

	// call function
	result = gtk_file_chooser_select_filename(self, filename);

	// cleanup parameter self

	// cleanup parameter filename
	bindings_java_releaseString(filename);

	// translate return value to JNI type
	_result = (jboolean) result;

	// and finally
	return _result;
}
Ejemplo n.º 14
0
static void on_select_post (GtkEntry* entry, GtkEntryIconPosition icon_pos, GdkEvent* event, UgtkDownloadForm* dform)
{
	GtkWidget*	chooser;
	gchar*		path;
	gchar*		title;

	// disable sensitive of parent window
	// enable sensitive in function on_file_chooser_response()
	if (dform->parent)
		gtk_widget_set_sensitive ((GtkWidget*) dform->parent, FALSE);

	title = g_strconcat (UGTK_APP_NAME " - ", _("Select Post File"), NULL);
	chooser = gtk_file_chooser_dialog_new (title, dform->parent,
			GTK_FILE_CHOOSER_ACTION_OPEN,
			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			GTK_STOCK_OK,     GTK_RESPONSE_OK,
			NULL);
	g_free (title);
	gtk_window_set_transient_for ((GtkWindow*) chooser, dform->parent);
	gtk_window_set_destroy_with_parent ((GtkWindow*) chooser, TRUE);

	path = (gchar*) gtk_entry_get_text ((GtkEntry*) dform->post_entry);
	if (*path) {
		path = g_filename_from_utf8 (path, -1, NULL, NULL, NULL);
		gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (chooser), path);
		g_free (path);
	}
	g_signal_connect (chooser, "response",
			G_CALLBACK (on_select_post_response), dform);

	if (gtk_window_get_modal (dform->parent))
		gtk_dialog_run ((GtkDialog*) chooser);
	else {
		gtk_window_set_modal ((GtkWindow*) chooser, FALSE);
		gtk_widget_show (chooser);
	}
}
Ejemplo n.º 15
0
static gboolean
handle_file_chooser_open (XdpFileChooser *object,
                          GDBusMethodInvocation *invocation,
                          const gchar *arg_sender,
                          const gchar *arg_app_id,
                          const gchar *arg_parent_window,
                          const gchar *arg_title,
                          GVariant *arg_options)
{
  const gchar *method_name;
  GtkFileChooserAction action;
  gboolean multiple;
  GtkWidget *dialog;
  GdkWindow *foreign_parent = NULL;
  GtkWidget *fake_parent;
  FileDialogHandle *handle;
  XdpFileChooser *chooser = XDP_FILE_CHOOSER (g_dbus_method_invocation_get_user_data (invocation));
  const char *cancel_label;
  const char *accept_label;
  GVariantIter *iter;
  const char *current_name;
  const char *path;
  g_autoptr (GVariant) choices = NULL;

  method_name = g_dbus_method_invocation_get_method_name (invocation);

  g_print ("%s, app_id: %s, object: %p, user_data: %p\n",
           method_name, arg_app_id, object,
           g_dbus_method_invocation_get_user_data (invocation));

  fake_parent = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_object_ref_sink (fake_parent);

  action = GTK_FILE_CHOOSER_ACTION_OPEN;
  multiple = FALSE;

  if (strcmp (method_name, "SaveFile") == 0)
    action = GTK_FILE_CHOOSER_ACTION_SAVE;
  else if (strcmp (method_name, "OpenFiles") == 0)
    multiple = TRUE;

  if (!g_variant_lookup (arg_options, "accept_label", "&s", &accept_label))
    accept_label = _("_Open");

  cancel_label = _("_Cancel");

  dialog = gtk_file_chooser_dialog_new (arg_title, GTK_WINDOW (fake_parent), action,
                                        cancel_label, GTK_RESPONSE_CANCEL,
                                        accept_label, GTK_RESPONSE_OK,
                                        NULL);
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
  gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), multiple);

  handle = dialog_handle_new (arg_app_id, arg_sender, dialog, G_DBUS_INTERFACE_SKELETON (chooser));

  handle->dialog = dialog;
  handle->action = action;
  handle->multiple = multiple;

  choices = g_variant_lookup_value (arg_options, "choices", G_VARIANT_TYPE ("a(ssa(ss)s)"));
  if (choices)
    {
      int i;
      GtkWidget *box;

      box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
      gtk_widget_show (box);
      for (i = 0; i < g_variant_n_children (choices); i++)
        {
          GVariant *value = g_variant_get_child_value (choices, i);
          gtk_container_add (GTK_CONTAINER (box), deserialize_choice (value, handle));
        }

      gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), box);
    }

  if (g_variant_lookup (arg_options, "filters", "a(sa(us))", &iter))
    {
      GVariant *variant;

      while (g_variant_iter_next (iter, "@(sa(us))", &variant))
        {
          GtkFileFilter *filter;

          filter = gtk_file_filter_from_gvariant (variant);
          gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
          g_variant_unref (variant);
        }
      g_variant_iter_free (iter);
    }
  if (strcmp (method_name, "SaveFile") == 0)
    {
      if (g_variant_lookup (arg_options, "current_name", "&s", &current_name))
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), current_name);
      /* TODO: is this useful ?
       * In a sandboxed situation, the current folder and current file
       * are likely in the fuse filesystem
       */
      if (g_variant_lookup (arg_options, "current_folder", "&ay", &path))
        gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), path);
      if (g_variant_lookup (arg_options, "current_file", "&ay", &path))
        gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (dialog), path);
    }

  g_object_unref (fake_parent);

#ifdef GDK_WINDOWING_X11
  if (g_str_has_prefix (arg_parent_window, "x11:"))
    {
      int xid;

      if (sscanf (arg_parent_window, "x11:%x", &xid) != 1)
        g_warning ("invalid xid");
      else
        foreign_parent = gdk_x11_window_foreign_new_for_display (gtk_widget_get_display (dialog), xid);
    }
#endif
  else
    g_warning ("Unhandled parent window type %s\n", arg_parent_window);

  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);

  g_signal_connect (G_OBJECT (dialog), "response",
                    G_CALLBACK (handle_file_chooser_open_response), handle);

  if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
    {
      GtkWidget *readonly;

      readonly = gtk_check_button_new_with_label ("Open files read-only");
      gtk_widget_show (readonly);

      g_signal_connect (readonly, "toggled",
                        G_CALLBACK (read_only_toggled), handle);

      gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), readonly);
    }

  gtk_widget_realize (dialog);

  if (foreign_parent)
    gdk_window_set_transient_for (gtk_widget_get_window (dialog), foreign_parent);

  gtk_widget_show (dialog);

  xdp_file_chooser_complete_open_file (chooser,
                                       invocation,
                                       handle->base.id);

  return TRUE;
}
Ejemplo n.º 16
0
static int open(GtkWidget* parent_window, gboolean not_import)
{
    GtkWidget* dialog;
    int val;
    const char* title;
    char* filter = file_ops_join_ext("*", dish_file_extension());
    global_settings* settings = settings_get();

    if (not_import)
        title = "Open bank";
    else
        title = "Import bank";

    dialog = gtk_file_chooser_dialog_new( title,
                                          GTK_WINDOW(parent_window),
                                          GTK_FILE_CHOOSER_ACTION_OPEN,
                                          GTK_STOCK_CANCEL,
                                          GTK_RESPONSE_CANCEL,
                                          GTK_STOCK_OPEN,
                                          GTK_RESPONSE_ACCEPT, NULL);

    if (dish_file_has_state())
    {
        const char* tmp = 0;
        tmp = dish_file_state_is_full() ? dish_file_state_parent_dir()
                                        : dish_file_state_bank_dir();
        gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(dialog), tmp);
    }
    else
        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
                                           settings->last_bank_dir);

    file_chooser_add_filter(dialog, "Petri-Foo files", filter);
    file_chooser_add_filter(dialog, "All files", "*");

    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
    {

        char* name = (char*) gtk_file_chooser_get_filename(
                                        GTK_FILE_CHOOSER(dialog));

        val = (not_import)  ? dish_file_read(name)
                            : dish_file_import(name);
        if (val < 0)
        {
            GtkWidget* msg = gtk_message_dialog_new(GTK_WINDOW(dialog),
                                    GTK_DIALOG_MODAL,
                                    GTK_MESSAGE_ERROR,
                                    GTK_BUTTONS_CLOSE,
                                    "Failed to read bank %s\n.", name);

            g_signal_connect_swapped(G_OBJECT(msg), "response",
                                    G_CALLBACK(gtk_widget_destroy), msg);
            gtk_widget_show (msg);
        }
        else
        {
            if (recent_manager && not_import)
                gtk_recent_manager_add_item(recent_manager,
                                    g_filename_to_uri(name, NULL, NULL));

            if (settings->last_bank_dir)
                free(settings->last_bank_dir);

            settings->last_bank_dir = g_path_get_dirname(name);
        }
    }
    else
    {
        val = -1;
    }

    gtk_widget_destroy(dialog);

    free(filter);

    return val;
}
Ejemplo n.º 17
0
/*!
  \brief pops up a Filechooser dialog to select a file
  \param data is a pointer to a MtxFileIO structure which contains important
  bits like the path to start, the filter, default filename and so on
  \see MtxFileIO
  \returns the path to the file or NULL if cancelled
  */
gchar * choose_file(MtxFileIO *data)
{
	GtkWidget *dialog = NULL;
	GtkFileFilter *filter = NULL;
	GSList *filters = NULL;
	gchar *path = NULL;
	gchar *defdir = NULL;
	gchar *filename = NULL;
	gchar *tmpbuf = NULL;
	gchar **vector = NULL;
	const gchar *project = NULL;
	gint response = 0;
	gboolean res = FALSE;
	guint i = 0;

	ENTER();
	if (!GTK_IS_WINDOW(data->parent))
		data->parent = NULL;
	/*
	printf("choose_file\n");
	printf("parent %p\n",(void *)data->parent);
	printf("on_top %s\n",data->on_top? "TRUE":"FALSE");
	printf("filter %s\n",data->filter);
	printf("filename %s\n",data->filename);
	printf("default_filename %s\n",data->default_filename);
	printf("default_extension %s\n",data->default_extension);
	printf("absolute_path %s\n",data->absolute_path);
	printf("default_path %s\n",data->default_path);
	printf("external_path %s\n",data->external_path);
	printf("shortcut_folders %s\n",data->shortcut_folders);
	printf("project %s\n",data->project);
	printf("title %s\n",data->title);
	*/
	if (data->project)
		project = data->project;
	else
		project = DEFAULT_PROJECT;

	if (!data->title)
		data->title = g_strdup("Open File");

	if ((data->action == GTK_FILE_CHOOSER_ACTION_OPEN) || 
			(data->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER))
	{
		/*printf("ACTION_OPEN before gtk_file_chooser_dialog_new\n");*/
		dialog = gtk_file_chooser_dialog_new(data->title,
				/*GTK_WINDOW(data->parent), */
				0,
				data->action,
				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				NULL);
		/*printf("after gtk_file_chooser_dialog_new\n");*/
		if ((data->on_top) && (GTK_IS_WIDGET(data->parent)))
			gtk_window_set_transient_for(GTK_WINDOW(gtk_widget_get_toplevel(dialog)),GTK_WINDOW(data->parent));

		if ((data->absolute_path) && (!data->default_path))
			gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog),data->absolute_path);
		else if (data->default_path)
		{
			/*printf("should be using system path + %s\n",data->default_path);*/
			path = g_build_filename(MTXSYSDATA,data->default_path,NULL);
			if (!g_file_test(path,G_FILE_TEST_IS_DIR))
			{
				g_free(path);
				path = g_build_filename(HOME(),"mtx",data->project,data->default_path, NULL);
				/*printf("System path is not found, falling back to user path %s\n",path);*/
			}
			gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog),path);
			g_free(path);
		}
	}
	else if (data->action == GTK_FILE_CHOOSER_ACTION_SAVE)
	{
		/*printf("ACTION_SAVE calling gtk_file_chooser_dialog_new\n");*/
		dialog = gtk_file_chooser_dialog_new(data->title,
				/*GTK_WINDOW(data->parent), */
				0,
				data->action,
				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
				NULL);	
		/*printf("after gtk_file_chooser_dialog_new\n");*/

		/*		if ((data->on_top) && (GTK_IS_WIDGET(data->parent)))
					gtk_window_set_transient_for(GTK_WINDOW(gtk_widget_get_toplevel(dialog)),GTK_WINDOW(data->parent));
		*/

		if (data->default_path)
		{
			defdir = g_build_filename(HOME(),"mtx",data->project,data->default_path, NULL);
			if (!g_file_test(defdir,G_FILE_TEST_IS_DIR))
				g_mkdir(defdir,0755);
		}
		else
			defdir = g_build_filename(HOME(),"mtx",data->project, NULL);
		/* If filename passed check/adj path  */
		if (data->filename)
		{
			if (g_strrstr(data->filename,DATA_DIR) != NULL)
			{
				vector = g_strsplit(data->filename,PSEP,-1);
				tmpbuf = g_strconcat(defdir,PSEP,vector[g_strv_length(vector)-1],NULL);
				gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),defdir);
				gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),vector[g_strv_length(vector)-1]);
				g_strfreev(vector);
				g_free(tmpbuf);
			}
			else
				gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),data->filename);
		}
		else
		{
			gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),defdir);
			gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), data->default_filename );
		}
		g_free(defdir);

	}
	else
	{
		EXIT();
		return NULL;
	}
	/* Add shortcut folders...  */
	if (data->shortcut_folders)
	{
		vector = g_strsplit(data->shortcut_folders,",",-1);
		for (i=0;i<g_strv_length(vector);i++)
		{
			path = g_build_filename(MTXSYSDATA,vector[i],NULL);
			gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog),path,NULL);
			g_free(path);
			path = g_build_filename(HOME(),"mtx",data->project,vector[i],NULL);
			gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog),path,NULL);
			g_free(path);
		}
		g_strfreev(vector);
	}
	
	/* If default path switch to that place  */
	if ((data->external_path) && (!(data->default_path)))
	{
		/*printf("external path with no default path\n");*/
		path = g_build_filename(HOME(),"mtx",data->project,data->external_path,NULL);
		if (!g_file_test(path,G_FILE_TEST_IS_DIR))
			g_mkdir(path,0755);
		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog),path);
		g_free(path);

	}

	/* If filters, assign them 
	  CAUSES SEGFAULTS???
	  */
	/*
	if (data->filter)
	{
		printf("data->filter is set to \"%s\"\n",data->filter);
		vector = g_strsplit(data->filter,",",-1);
		if (g_strv_length(vector)%2 > 0)
			goto afterfilter;
		for (i=0;i<g_strv_length(vector);i+=2)
		{
			filter = gtk_file_filter_new();
			gtk_file_filter_add_pattern(GTK_FILE_FILTER(filter),vector[i]);
			printf("Filter glob is set to \"%s\"\n",vector[i]);
			gtk_file_filter_set_name(GTK_FILE_FILTER(filter),vector[i+1]);
			printf("Filter name is set to \"%s\"\n",vector[i+1]);
			gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter);
		}
		gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog),filter);
		g_strfreev(vector);
	}
	*/
afterfilter:
	/* Turn on overwriteconfirmation  */
	gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
	g_signal_connect(G_OBJECT(dialog),"confirm-overwrite",
			G_CALLBACK (confirm_overwrite_callback), NULL);
	if (data->action == GTK_FILE_CHOOSER_ACTION_OPEN)
	{
		if (data->default_filename)
		{
			/*printf("data->default_filename is set to \"%s\"\n",data->default_filename);*/
			gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(dialog),data->default_filename);
		}
	}

	/*printf("initiating dialog to run\n");*/
	response = gtk_dialog_run (GTK_DIALOG (dialog));
	/*printf("it returned \n");*/
	if (response == GTK_RESPONSE_ACCEPT)
	{
		tmpbuf = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
		if ((data->action == GTK_FILE_CHOOSER_ACTION_SAVE) && (data->default_extension))
		{
			if(!g_str_has_suffix (tmpbuf,data->default_extension))
				filename = g_strjoin(".",tmpbuf,data->default_extension,NULL);
			else
				filename = g_strdup(tmpbuf);
		}
		else
			filename = g_strdup(tmpbuf);
		g_free(tmpbuf);
	}
	filters = gtk_file_chooser_list_filters(GTK_FILE_CHOOSER(dialog));
	if (filters)
	{
		g_slist_foreach(filters, remove_filter ,dialog);
		g_slist_free(filters);
	}

	gtk_widget_destroy (dialog);
	EXIT();
	return (filename);
}
Ejemplo n.º 18
0
void termit_preferences_dialog(struct TermitTab *pTab)
{
    // store font_name, foreground, background
    struct TermitDlgHelper* hlp = termit_dlg_helper_new(pTab);

    GtkStockItem item = {};
    gtk_stock_lookup(GTK_STOCK_PREFERENCES, &item); // may be memory leak inside
    GtkWidget* dialog = gtk_dialog_new_with_buttons(item.label,
            GTK_WINDOW_TOPLEVEL,
            GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
            GTK_STOCK_CANCEL, GTK_RESPONSE_NONE,
            GTK_STOCK_OK, GTK_RESPONSE_OK,
            NULL);
    g_signal_connect(G_OBJECT(dialog), "key-press-event", G_CALLBACK(dlg_key_press), dialog);
    GtkWidget* dlg_table = gtk_table_new(5, 2, FALSE);

#define TERMIT_PREFERENCE_ROW(pref_name, widget) \
    gtk_table_attach(GTK_TABLE(dlg_table), gtk_label_new(pref_name), 0, 1, row, row + 1, 0, 0, 0, 0); \
    gtk_table_attach_defaults(GTK_TABLE(dlg_table), widget, 1, 2, row, row + 1); \
    hlp->widget = widget; \
    row++;
#define TERMIT_PREFERENCE_ROW2(pref_widget, widget) \
    gtk_table_attach(GTK_TABLE(dlg_table), pref_widget, 0, 1, row, row + 1, 0, 0, 0, 0); \
    gtk_table_attach_defaults(GTK_TABLE(dlg_table), widget, 1, 2, row, row + 1); \
    hlp->widget = widget; \
    row++;

    gboolean apply_to_all_tabs_flag = FALSE;
    GtkWidget* entry_title = gtk_entry_new();
    guint row = 0;
    { // tab title
        gtk_entry_set_text(GTK_ENTRY(entry_title), hlp->tab_title);
        TERMIT_PREFERENCE_ROW(_("Title"), entry_title);
    }

    // font selection
    GtkWidget* btn_font = gtk_font_button_new_with_font(pTab->style.font_name);
    g_signal_connect(btn_font, "font-set", G_CALLBACK(dlg_set_font), pTab);
    TERMIT_PREFERENCE_ROW(_("Font"), btn_font);

    // foreground
    GtkWidget* btn_foreground = (pTab->style.foreground_color)
        ? gtk_color_button_new_with_color(pTab->style.foreground_color)
        : gtk_color_button_new();
    g_signal_connect(btn_foreground, "color-set", G_CALLBACK(dlg_set_foreground), pTab);
    TERMIT_PREFERENCE_ROW(_("Foreground"), btn_foreground);

    // background
    GtkWidget* btn_background = (pTab->style.background_color)
        ? gtk_color_button_new_with_color(pTab->style.background_color)
        : gtk_color_button_new();
    g_signal_connect(btn_background, "color-set", G_CALLBACK(dlg_set_background), pTab);
    TERMIT_PREFERENCE_ROW(_("Background"), btn_background);

    // background image
    GtkWidget* btn_image_file = gtk_file_chooser_button_new(pTab->style.image_file,
        GTK_FILE_CHOOSER_ACTION_OPEN);
    GtkFileFilter* filter = gtk_file_filter_new();
    gtk_file_filter_set_name(filter, _("images"));
    gtk_file_filter_add_mime_type(filter, "image/*");
    if (pTab->style.image_file) {
        gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(btn_image_file), pTab->style.image_file);
    }
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(btn_image_file), filter);
    g_signal_connect(btn_image_file, "file-set", G_CALLBACK(dlg_set_image_file), pTab);
    g_signal_connect(btn_image_file, "key-press-event", G_CALLBACK(dlg_clear_image_file), pTab);
    GtkWidget* btn_switch_image_file = gtk_check_button_new_with_label(_("Background image"));
    if (pTab->style.image_file) {
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(btn_switch_image_file), TRUE);
    }
    /*g_signal_connect(btn_switch_image_file, "toggled", G_CALLBACK(dlg_switch_image_file), btn_image_file);*/
    /*TERMIT_PREFERENCE_ROW2(btn_switch_image_file, btn_image_file);*/
    TERMIT_PREFERENCE_ROW(_("Image"), btn_image_file);

    // transparency
    GtkWidget* scale_transparency = gtk_spin_button_new_with_range(0, 1, 0.05);
    gtk_spin_button_set_value(GTK_SPIN_BUTTON(scale_transparency), pTab->style.transparency);
    g_signal_connect(scale_transparency, "value-changed", G_CALLBACK(dlg_set_transparency), pTab);
    TERMIT_PREFERENCE_ROW(_("Transparency"), scale_transparency);

    // audible_bell
    GtkWidget* audible_bell = gtk_check_button_new();
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(audible_bell), pTab->audible_bell);
    g_signal_connect(audible_bell, "toggled", G_CALLBACK(dlg_set_audible_bell), pTab);
    TERMIT_PREFERENCE_ROW(_("Audible bell"), audible_bell);

    // visible_bell
    GtkWidget* visible_bell = gtk_check_button_new();
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(visible_bell), pTab->visible_bell);
    g_signal_connect(visible_bell, "toggled", G_CALLBACK(dlg_set_visible_bell), pTab);
    TERMIT_PREFERENCE_ROW(_("Visible bell"), visible_bell);

    // apply to al tabs
    GtkWidget* btn_apply_to_all_tabs = gtk_check_button_new();
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(btn_apply_to_all_tabs), FALSE);
    g_signal_connect(btn_apply_to_all_tabs, "toggled", G_CALLBACK(dlg_set_apply_to_all_tabs), &apply_to_all_tabs_flag);
    TERMIT_PREFERENCE_ROW(_("Apply to all tabs"), btn_apply_to_all_tabs);

    GtkWidget* btn_restore = gtk_button_new_from_stock(GTK_STOCK_REVERT_TO_SAVED);
    g_signal_connect(G_OBJECT(btn_restore), "clicked", G_CALLBACK(dlg_restore_defaults), hlp);
    gtk_table_attach(GTK_TABLE(dlg_table), btn_restore, 1, 2, row, row + 1, 0, 0, 0, 0);

    gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), dlg_table);

    gtk_widget_show_all(dialog);
    if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
        dlg_set_tab_default_values(pTab, hlp);
    } else {
        if (apply_to_all_tabs_flag) {
            gint page_num = gtk_notebook_get_n_pages(GTK_NOTEBOOK(termit.notebook));
            gint i=0;
            for (; i<page_num; ++i) {
                TERMIT_GET_TAB_BY_INDEX(pTab, i, continue);
                dlg_set_font(GTK_FONT_BUTTON(btn_font), pTab);
                dlg_set_foreground(GTK_COLOR_BUTTON(btn_foreground), pTab);
                dlg_set_background(GTK_COLOR_BUTTON(btn_background), pTab);
                dlg_set_transparency(GTK_SPIN_BUTTON(scale_transparency), pTab);
                dlg_set_image_file(GTK_FILE_CHOOSER_BUTTON(btn_image_file), pTab);
                dlg_set_audible_bell(GTK_TOGGLE_BUTTON(audible_bell), pTab);
                dlg_set_visible_bell(GTK_TOGGLE_BUTTON(visible_bell), pTab);
            }
        }
        // insane title flag
        if (pTab->title ||
                (!pTab->title &&
                 strcmp(gtk_label_get_text(GTK_LABEL(pTab->tab_name)),
                     gtk_entry_get_text(GTK_ENTRY(entry_title))) != 0)) {
            termit_tab_set_title(pTab, gtk_entry_get_text(GTK_ENTRY(entry_title)));
        }
    }
    termit_dlg_helper_free(hlp);
    gtk_widget_destroy(dialog);
}
Ejemplo n.º 19
0
/*!
  \brief pops up a Filechooser dialog to select a file
  \param data is a pointer to a MtxFileIO structure which contains important
  bits like the path to start, the filter, default filename and so on
  \see MtxFileIO
  \returns the path to the file or NULL if cancelled
  */
gchar * choose_file(MtxFileIO *data)
{
	GtkWidget *dialog = NULL;
	GtkFileFilter *filter = NULL;
	gchar * path = NULL;
	gchar * defdir = NULL;
	gchar *filename = NULL;
	gchar *tmpbuf = NULL;
	gchar **vector = NULL;
	gint response = 0;
	gboolean res = FALSE;
	guint i = 0;

	if (!GTK_IS_WINDOW(data->parent))
		data->parent = NULL;
	/*
	   printf("choose_file\n");
	   printf("filter %s\n",data->filter);
	   printf("filename %s\n",data->filename);
	   printf("default_path %s\n",data->default_path);
	   printf("title %s\n",data->title);
	   */
	if (!data->project)
		data->project = DEFAULT_PROJECT;

	if (!data->title)
		data->title = g_strdup("Open File");

	if ((data->action == GTK_FILE_CHOOSER_ACTION_OPEN) || 
			(data->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER))
	{
		dialog = gtk_file_chooser_dialog_new(data->title,
				GTK_WINDOW(data->parent),
				data->action,
				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				NULL);
		if ((data->on_top) && (GTK_IS_WIDGET(data->parent)))
			gtk_window_set_transient_for(GTK_WINDOW(gtk_widget_get_toplevel(dialog)),GTK_WINDOW(data->parent));

		if ((data->absolute_path) && (!data->default_path))
			gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog),data->absolute_path);
		else if (data->default_path)
		{
			path = g_build_filename(MTXSYSDATA,data->default_path,NULL);
			gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog),path);
			g_free(path);
		}
	}
	else if (data->action == GTK_FILE_CHOOSER_ACTION_SAVE)
	{
		dialog = gtk_file_chooser_dialog_new(data->title,
				GTK_WINDOW(data->parent),
				data->action,
				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
				NULL);	

		if ((data->on_top) && (GTK_IS_WIDGET(data->parent)))
			gtk_window_set_transient_for(GTK_WINDOW(gtk_widget_get_toplevel(dialog)),GTK_WINDOW(data->parent));

		defdir = g_build_filename(HOME(),"mtx",data->project,data->default_path, NULL);
		if (!g_file_test(defdir,G_FILE_TEST_IS_DIR))
			g_mkdir(defdir,0755);
		/* If filename passed check/adj path */
		if (data->filename)
		{
#ifdef __WIN32__	/* Disallows modifying distributed files */
			if (g_strrstr(data->filename,"dist") != NULL)
#else
				if (g_strrstr(data->filename,DATA_DIR) != NULL)
#endif
				{
					vector = g_strsplit(data->filename,PSEP,-1);
					tmpbuf = g_strconcat(defdir,PSEP,vector[g_strv_length(vector)-1],NULL);
					gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),defdir);
					gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),vector[g_strv_length(vector)-1]);
					g_strfreev(vector);
					g_free(tmpbuf);
				}
				else
					gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),data->filename);
		}
		else
		{
			gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),defdir);
			gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), data->default_filename );
		}
		g_free(defdir);

	}
	else
		return NULL;
	/* Add shortcut folders... */
	if (data->shortcut_folders)
	{

		vector = g_strsplit(data->shortcut_folders,",",-1);
		for (i=0;i<g_strv_length(vector);i++)
		{
			path = g_build_filename(MTXSYSDATA,vector[i],NULL);
			gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog),path,NULL);
			g_free(path);
			path = g_build_filename(HOME(),"mtx",data->project,vector[i],NULL);
			gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog),path,NULL);
			g_free(path);
		}
		g_strfreev(vector);
	}
	/* If default path switch to that place */
	if ((data->external_path) && (!(data->default_path)))
	{
		path = g_build_filename(HOME(),"mtx",data->project,data->external_path,NULL);
		if (!g_file_test(path,G_FILE_TEST_IS_DIR))
			g_mkdir(path,0755);
		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog),path);
		g_free(path);

	}

	/* If filters, assign them */
	if (data->filter)
	{
		vector = g_strsplit(data->filter,",",-1);
		if (g_strv_length(vector)%2 > 0)
			goto afterfilter;
		for (i=0;i<g_strv_length(vector);i+=2)
		{
			filter = gtk_file_filter_new();
			gtk_file_filter_add_pattern(GTK_FILE_FILTER(filter),vector[i]);
			gtk_file_filter_set_name(GTK_FILE_FILTER(filter),vector[i+1]);
			gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter);
		}
		gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog),filter);
		g_strfreev(vector);
	}
afterfilter:
	/* Turn on overwriteconfirmation */
	gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
	g_signal_connect(G_OBJECT(dialog),"confirm-overwrite",
			G_CALLBACK (confirm_overwrite_callback), NULL);
	if (data->action == GTK_FILE_CHOOSER_ACTION_OPEN)
		if (data->default_filename)
			gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(dialog),data->default_filename);

	response = gtk_dialog_run (GTK_DIALOG (dialog));
	if (response == GTK_RESPONSE_ACCEPT)
	{
		tmpbuf = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
		if ((data->action == GTK_FILE_CHOOSER_ACTION_SAVE) && (data->default_extension))
		{
			if(!g_str_has_suffix (tmpbuf,data->default_extension))
				filename = g_strjoin(".",tmpbuf,data->default_extension,NULL);
			else
				filename = g_strdup(tmpbuf);
		}
		else
			filename = g_strdup(tmpbuf);
		g_free(tmpbuf);
	}
	gtk_widget_destroy (dialog);

	return (filename);
}