예제 #1
0
static void
gradients_save_as_pov_ray_response (GtkWidget    *dialog,
                                    gint          response_id,
                                    GimpGradient *gradient)
{
  if (response_id == GTK_RESPONSE_OK)
    {
      GFile  *file  = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
      GError *error = NULL;

      if (! gimp_gradient_save_pov (gradient, file, &error))
        {
          gimp_message_literal (g_object_get_data (G_OBJECT (dialog), "gimp"),
                                G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
                                error->message);
          g_clear_error (&error);
          g_object_unref (file);
          return;
        }

      g_object_unref (file);
    }

  gtk_widget_destroy (dialog);
}
static void
add_file_chooser_response (GtkDialog *widget,
                           GtkResponseType response,
                           gpointer user_data)
{
  Place *place;
  GPtrArray *new_values;

  if (response != GTK_RESPONSE_OK)
    {
      gtk_widget_destroy (GTK_WIDGET (widget));
      return;
    }

  place = g_slice_new0 (Place);
  place->location = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));
  place->settings_key = TRACKER_KEY_RECURSIVE_DIRECTORIES;
  place->display_name = g_file_get_basename (place->location);

  new_values = place_get_new_settings_values (place, FALSE);
  g_settings_set_strv (tracker_preferences, place->settings_key, (const gchar **) new_values->pdata);

  g_ptr_array_unref (new_values);
  gtk_widget_destroy (GTK_WIDGET (widget));
  place_free (place);
}
예제 #3
0
static void
text_tool_load_dialog_response (GtkWidget    *dialog,
                                gint          response_id,
                                GimpTextTool *tool)
{
  if (response_id == GTK_RESPONSE_OK)
    {
      GFile  *file  = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
      GError *error = NULL;

      if (! gimp_text_buffer_load (tool->buffer, file, &error))
        {
          gimp_message (GIMP_TOOL (tool)->tool_info->gimp, G_OBJECT (dialog),
                        GIMP_MESSAGE_ERROR,
                        _("Could not open '%s' for reading: %s"),
                        gimp_file_get_utf8_name (file),
                        error->message);
          g_clear_error (&error);
          g_object_unref (file);
          return;
        }

      g_object_unref (file);
    }

  gtk_widget_hide (dialog);
}
예제 #4
0
파일: testappchooser.c 프로젝트: BYC/gtk
static void
button_clicked (GtkButton *b,
                gpointer   user_data)
{
  GtkWidget *w;
  gchar *path;

  w = gtk_file_chooser_dialog_new ("Select file",
                                   GTK_WINDOW (toplevel),
                                   GTK_FILE_CHOOSER_ACTION_OPEN,
                                   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                   GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                                   NULL);

  gtk_dialog_run (GTK_DIALOG (w));
  file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (w));
  path = g_file_get_path (file);
  gtk_button_set_label (GTK_BUTTON (file_l), path);

  gtk_widget_destroy (w);

  gtk_widget_set_sensitive (open, TRUE);

  g_free (path);
}
예제 #5
0
void cb_open (GtkWidget *p_widget)
{
	GtkWidget *p_dialog;

	p_dialog = gtk_file_chooser_dialog_new ("Image selection", NULL,
			GTK_FILE_CHOOSER_ACTION_OPEN,
			("_Cancel"), GTK_RESPONSE_CANCEL,
			("_Open"), GTK_RESPONSE_ACCEPT,
			NULL);
	if (gtk_dialog_run (GTK_DIALOG (p_dialog)) == GTK_RESPONSE_ACCEPT)
	{

		//file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (p_dialog));
		file_name = g_file_get_path(gtk_file_chooser_get_file(GTK_FILE_CHOOSER(p_dialog)));
		if(pImage)
			gtk_widget_destroy(pImage);

		GdkPixbuf *pBuf = gdk_pixbuf_new_from_file_at_scale (file_name,500,330,TRUE,NULL);
		pImage = gtk_image_new_from_pixbuf(pBuf);
		g_object_unref (pBuf);

		//permet de centrer l'image
		GdkPixbuf *pBufFcd = gtk_image_get_pixbuf (GTK_IMAGE(pImage));
		int w = gdk_pixbuf_get_width(pBufFcd);
                int h = gdk_pixbuf_get_height(pBufFcd);

		gtk_layout_put(GTK_LAYOUT(layout), pImage, 273-(w/2), 196-(h/2));  
		gtk_widget_show_all(pImage);
		//g_free(file_name), file_name=NULL;
	}
	gtk_widget_destroy (p_dialog);

	(void)p_widget;
}
예제 #6
0
void
gb_editor_tab_open (GbEditorTab *tab,
                    GFile       *file)
{
   GbEditorTabPrivate *priv;
   GtkWidget *dialog;
   GtkWidget *toplevel;
   GFile *file_copy = NULL;

   g_return_if_fail (GB_IS_EDITOR_TAB (tab));

   priv = tab->priv;

   if (!file) {
      toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab));

      dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
                             "action", GTK_FILE_CHOOSER_ACTION_OPEN,
                             "local-only", FALSE,
                             "title", _("Open"),
                             "transient-for", toplevel,
                             "visible", TRUE,
                             NULL);

      gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                              _("Cancel"), GTK_RESPONSE_CANCEL,
                              _("Open"), GTK_RESPONSE_OK,
                              NULL);

      if (GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog))) {
         file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
         file_copy = file;
      }

      gtk_widget_destroy (dialog);

      if (!file) {
         return;
      }
   }

   gb_editor_tab_set_file (tab, file);

   gb_editor_document_load_from_file_async (priv->document,
                                            file,
                                            NULL,
#if 0
                                            gb_gtk_progress_bar_file_progress_callback,
                                            priv->progress_bar,
#else
                                            NULL,
                                            NULL,
#endif
                                            gb_editor_tab_load_from_file_cb,
                                            g_object_ref (tab));

   g_clear_object (&file_copy);

   priv->is_empty = FALSE;
}
예제 #7
0
static void
open_file_response_cb (GtkWidget *w,
		       int        response,
		       GtkWidget *file_sel)
{
	FrWindow *window = NULL;
	GFile    *file;

	if ((response == GTK_RESPONSE_CANCEL) || (response == GTK_RESPONSE_DELETE_EVENT)) {
		gtk_widget_destroy (file_sel);
		return;
	}

	window = g_object_get_data (G_OBJECT (file_sel), "fr_window");
	file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (file_sel));

	if ((window == NULL) || (file == NULL))
		return;

	if (fr_window_archive_is_present (window))
		window = (FrWindow *) fr_window_new ();
	g_signal_connect (G_OBJECT (window),
			  "archive_loaded",
			  G_CALLBACK (window_archive_loaded_cb),
			  file_sel);
	fr_window_archive_open (window, file, GTK_WINDOW (file_sel));

	g_object_unref (file);
}
예제 #8
0
static void
error_console_save_response (GtkWidget        *dialog,
                             gint              response_id,
                             GimpErrorConsole *console)
{
  if (response_id == GTK_RESPONSE_OK)
    {
      GFile  *file  = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
      GError *error = NULL;

      if (! gimp_text_buffer_save (GIMP_TEXT_BUFFER (console->text_buffer),
                                   file,
                                   console->save_selection, &error))
        {
          gimp_message (console->gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
                        _("Error writing file '%s':\n%s"),
                        gimp_file_get_utf8_name (file),
                        error->message);
          g_clear_error (&error);
          g_object_unref (file);
          return;
        }

      g_object_unref (file);
    }

  gtk_widget_destroy (dialog);
}
예제 #9
0
/* Finish up the user's Release command by choosing a location to store the
project. This is a callback and the GDK lock is held when entering this
 function. */
void
i7_story_save_compiler_output(I7Story *story, const gchar *dialog_title)
{
    I7_STORY_USE_PRIVATE(story, priv);

    GFile *file = NULL;
    if(priv->copy_blorb_dest_file == NULL) {
        /* ask the user for a release file name if cBlorb didn't provide one */

        /* Create a file chooser */
        GtkFileFilter *filter = gtk_file_filter_new();
        if(i7_story_get_story_format(story) == I7_STORY_FORMAT_GLULX) {
            gtk_file_filter_set_name(filter, _("Glulx games (.ulx,.gblorb)"));
            gtk_file_filter_add_pattern(filter, "*.ulx");
            gtk_file_filter_add_pattern(filter, "*.gblorb");
        } else {
            gtk_file_filter_set_name(filter, _("Z-code games (.z?,.zblorb)"));
            gtk_file_filter_add_pattern(filter, "*.z?");
            gtk_file_filter_add_pattern(filter, "*.zblorb");
        }
        GtkWidget *dialog = gtk_file_chooser_dialog_new(dialog_title,
                            GTK_WINDOW(story), GTK_FILE_CHOOSER_ACTION_SAVE,
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                            NULL);
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
        char *curfilename = g_file_get_basename(priv->compiler_output_file);
        gchar *title = i7_document_get_display_name(I7_DOCUMENT(story));
        char *extension = strrchr(curfilename, '.'); /* not allocated */
        char *suggestname;
        if(title != NULL) {
            *(strrchr(title, '.')) = '\0';
            suggestname = g_strconcat(title, extension, NULL);
            g_free(title);
        } else {
            suggestname = g_strconcat("Untitled", extension, NULL);
        }
        g_free(curfilename);
        gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), suggestname);
        g_free(suggestname);
        gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);

        if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
            file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog));

        gtk_widget_destroy(dialog);
    } else {
        file = g_object_ref(priv->copy_blorb_dest_file);
    }

    if(file) {
        /* Move the finished file to the release location */
        GError *err = NULL;
        if(!g_file_move(priv->compiler_output_file, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &err)) {
            IO_ERROR_DIALOG(GTK_WINDOW(story), file, err, _("copying compiler output"));
        }
        g_object_unref(file);
    }
}
예제 #10
0
static void
gs_editor_button_import_clicked_cb (GtkApplication *application, GsEditor *self)
{
	GtkFileFilter *filter;
	GtkWindow *window;
	GtkWidget *dialog;
	gint res;
	g_autoptr(GFile) file = NULL;

	/* import warning */
	window = GTK_WINDOW (gtk_builder_get_object (self->builder,
						     "window_main"));
	if (as_store_get_size (self->store) > 0) {
		dialog = gtk_message_dialog_new (window,
						 GTK_DIALOG_MODAL |
						 GTK_DIALOG_DESTROY_WITH_PARENT,
						 GTK_MESSAGE_WARNING,
						 GTK_BUTTONS_CANCEL,
						 /* TRANSLATORS: window title */
						 _("Unsaved changes"));
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
							  _("The application list is already loaded."));

		gtk_dialog_add_button (GTK_DIALOG (dialog),
				       /* TRANSLATORS: button text */
				       _("Merge documents"),
				       GTK_RESPONSE_ACCEPT);
		gtk_dialog_add_button (GTK_DIALOG (dialog),
				       /* TRANSLATORS: button text */
				       _("Throw away changes"),
				       GTK_RESPONSE_YES);
		res = gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);

		if (res == GTK_RESPONSE_CANCEL)
			return;
		if (res == GTK_RESPONSE_YES)
			as_store_remove_all (self->store);
	}

	/* import the new file */
	dialog = gtk_file_chooser_dialog_new (_("Open AppStream File"),
					      window,
					      GTK_FILE_CHOOSER_ACTION_OPEN,
					      _("_Cancel"), GTK_RESPONSE_CANCEL,
					      _("_Open"), GTK_RESPONSE_ACCEPT,
					      NULL);
	filter = gtk_file_filter_new ();
	gtk_file_filter_add_pattern (filter, "*.xml");
	gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
	res = gtk_dialog_run (GTK_DIALOG (dialog));
	if (res != GTK_RESPONSE_ACCEPT) {
		gtk_widget_destroy (dialog);
		return;
	}
	file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
	gs_editor_button_import_file (self, file);
	gtk_widget_destroy (dialog);
}
예제 #11
0
void
gb_editor_tab_save (GbEditorTab *tab)
{
   GbEditorTabPrivate *priv;
   GtkWidget *toplevel;
   GtkWidget *dialog;
   GFile *file = NULL;

   g_return_if_fail (GB_IS_EDITOR_TAB(tab));

   priv = tab->priv;

   if (!priv->file) {
      toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab));

      dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
                             "action", GTK_FILE_CHOOSER_ACTION_SAVE,
                             "local-only", FALSE,
                             "title", _("Save"),
                             "transient-for", toplevel,
                             "visible", TRUE,
                             NULL);

      gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                              _("Cancel"), GTK_RESPONSE_CANCEL,
                              _("Save"), GTK_RESPONSE_OK,
                              NULL);

      if (GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog))) {
         file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
      }

      gtk_widget_destroy (dialog);

      if (!file) {
         return;
      }

      gb_editor_tab_set_file (tab, file);

      g_clear_object (&file);
   }

   gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress_bar), 0.0);
   gtk_widget_show (priv->progress_bar);

   gb_editor_document_save_to_file_async (priv->document,
                                          priv->file,
                                          NULL,
                                          gb_gtk_progress_bar_file_progress_callback,
                                          priv->progress_bar,
                                          gb_editor_tab_save_to_file_cb,
                                          g_object_ref (tab));

   priv->is_empty = FALSE;
}
예제 #12
0
static void
ok_clicked_cb (GtkWidget  *widget,
	       DialogData *data)
{
	ResizeData  *resize_data;
	GtkTreeIter  iter;
	char        *mime_type;
	GthTask     *resize_task;
	GthTask     *list_task;

	resize_data = g_new0 (ResizeData, 1);
	resize_data->width = gtk_spin_button_get_value (GTK_SPIN_BUTTON (GET_WIDGET ("width_spinbutton")));
	resize_data->height = gtk_spin_button_get_value (GTK_SPIN_BUTTON (GET_WIDGET ("height_spinbutton")));
	resize_data->unit = units[gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("unit_combobox")))];
	resize_data->keep_aspect_ratio = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_ratio_checkbutton")));
	resize_data->allow_swap = FALSE;

	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (GET_WIDGET ("mime_type_combobox")), &iter);
	gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("mime_type_liststore")), &iter,
			    MIME_TYPE_COLUMN_TYPE, &mime_type,
			    -1);

	g_settings_set_int (data->settings, PREF_RESIZE_IMAGES_SERIES_WIDTH, resize_data->width);
	g_settings_set_int (data->settings, PREF_RESIZE_IMAGES_SERIES_HEIGHT, resize_data->height);
	g_settings_set_enum (data->settings, PREF_RESIZE_IMAGES_UNIT, resize_data->unit);
	g_settings_set_boolean (data->settings, PREF_RESIZE_IMAGES_KEEP_RATIO, resize_data->keep_aspect_ratio);
	g_settings_set_string (data->settings, PREF_RESIZE_IMAGES_MIME_TYPE, mime_type ? mime_type : "");

	resize_task = gth_image_task_new (_("Resizing images"),
					  NULL,
					  exec_resize,
					  NULL,
					  resize_data,
					  g_free);
	list_task = gth_image_list_task_new (data->browser,
					     data->file_list,
					     GTH_IMAGE_TASK (resize_task));
	gth_image_list_task_set_overwrite_mode (GTH_IMAGE_LIST_TASK (list_task), GTH_OVERWRITE_ASK);
	gth_image_list_task_set_output_mime_type (GTH_IMAGE_LIST_TASK (list_task), mime_type);
	if (data->use_destination) {
		GFile *destination;

		destination = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (GET_WIDGET ("destination_filechooserbutton")));
		gth_image_list_task_set_destination (GTH_IMAGE_LIST_TASK (list_task), destination);

		g_object_unref (destination);
	}
	gth_browser_exec_task (data->browser, list_task, FALSE);

	g_object_unref (list_task);
	g_object_unref (resize_task);
	g_free (mime_type);
	gtk_widget_destroy (data->dialog);
}
예제 #13
0
void save_file_as_ok(GtkFileChooser *file_selection_box)
{
    gchar *uri=gtk_file_chooser_get_uri(file_selection_box);
    // Set the filename of the current document to be that
    document_set_GFile(document_manager_get_current_document(main_window.docmg), gtk_file_chooser_get_file(file_selection_box));
    document_set_untitled(document_manager_get_current_document(main_window.docmg), FALSE);
    gchar *basename = filename_get_basename(uri);
    g_free(uri);
    document_set_shortfilename(document_manager_get_current_document(main_window.docmg), basename);

    // Call Save method to actually save it now it has a filename
    on_save1_activate(NULL);
}
예제 #14
0
static void
ide_workbench_actions_open_with_dialog (GSimpleAction *action,
                                        GVariant      *param,
                                        gpointer       user_data)
{
  IdeWorkbench *self = user_data;
  GtkWidget *button;
  GtkWidget *dialog;
  gint ret;

  IDE_ENTRY;

  g_assert (IDE_IS_WORKBENCH (self));

  dialog = gtk_file_chooser_dialog_new (_("Open File"),
                                        GTK_WINDOW (self),
                                        GTK_FILE_CHOOSER_ACTION_OPEN,
                                        _("Cancel"), GTK_RESPONSE_CANCEL,
                                        _("Open"), GTK_RESPONSE_OK,
                                        NULL);

  gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);

  button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
  gtk_style_context_add_class (gtk_widget_get_style_context (button),
                               GTK_STYLE_CLASS_SUGGESTED_ACTION);

  /*
   * TODO: Allow workbench addins to specify file filters?
   *       Do we want to move this to a custom interface and use that
   *       for file loading as well?
   */

  ret = gtk_dialog_run (GTK_DIALOG (dialog));

  if (ret == GTK_RESPONSE_OK)
    {
      g_autoptr(GFile) file = NULL;

      IDE_PROBE;

      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
      ide_workbench_open_files_async (self, &file, 1, NULL, NULL,
                                      ide_workbench_actions_open_with_dialog_cb,
                                      NULL);
    }

  gtk_widget_destroy (dialog);

  IDE_EXIT;
}
예제 #15
0
void
on_style_add_clicked(GtkButton *button, I7App *app)
{
	/* From gedit/dialogs/gedit-preferences-dialog.c */
	GtkWidget *chooser = gtk_file_chooser_dialog_new(_("Add Color Scheme"),
		GTK_WINDOW(app->prefs->window),	GTK_FILE_CHOOSER_ACTION_OPEN,
		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
		GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT,
		NULL);
	gtk_window_set_destroy_with_parent(GTK_WINDOW(chooser), TRUE);

	/* Filters */
	GtkFileFilter *filter = gtk_file_filter_new();
	gtk_file_filter_set_name(filter, _("Color Scheme Files"));
	gtk_file_filter_add_pattern(filter, "*.xml");
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), filter);
	gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(chooser), filter);

	filter = gtk_file_filter_new();
	gtk_file_filter_set_name(filter, _("All Files"));
	gtk_file_filter_add_pattern(filter, "*");
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), filter);

	gtk_dialog_set_default_response(GTK_DIALOG(chooser), GTK_RESPONSE_ACCEPT);

	if(gtk_dialog_run(GTK_DIALOG(chooser)) != GTK_RESPONSE_ACCEPT) {
		gtk_widget_destroy(chooser);
		return;
	}

	GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(chooser));
	if(!file)
		return;

	gtk_widget_destroy(chooser);

	const char *scheme_id = i7_app_install_color_scheme(app, file);
	g_object_unref(file);

	if(!scheme_id) {
		error_dialog(GTK_WINDOW(app->prefs->window), NULL, _("The selected color scheme cannot be installed."));
		return;
	}

	populate_schemes_list(app->prefs->schemes_list);

	I7App *theapp = i7_app_get();
	GSettings *prefs = i7_app_get_prefs(theapp);
	g_settings_set_string(prefs, PREFS_STYLE_SCHEME, scheme_id);
}
예제 #16
0
파일: fm-gtk-utils.c 프로젝트: lxde/libfm
/* TODO: support selecting multiple files */
FmPath* fm_select_file(GtkWindow* parent, 
                        const char* title, 
                        const char* default_folder,
                        gboolean local_only,
                        gboolean show_preview,
                        /* filter1, filter2, ..., NULL */ ...)
{
    FmPath* path;
    GtkFileChooser* chooser;
    GtkFileFilter* filter;
    gulong handler_id = 0;
    va_list args;

    chooser = (GtkFileChooser*)gtk_file_chooser_dialog_new(
                                        title, parent, GTK_FILE_CHOOSER_ACTION_OPEN,
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                        GTK_STOCK_OK, GTK_RESPONSE_OK,
                                        NULL);
    gtk_dialog_set_alternative_button_order(GTK_DIALOG(chooser),
                                        GTK_RESPONSE_CANCEL,
                                        GTK_RESPONSE_OK, NULL);
    if(local_only)
        gtk_file_chooser_set_local_only(chooser, TRUE);

    if(default_folder)
        gtk_file_chooser_set_current_folder(chooser, default_folder);

    va_start(args, show_preview);
    while((filter = va_arg(args, GtkFileFilter*)))
    {
        gtk_file_chooser_add_filter(chooser, filter);
    }
    va_end (args);

    if(show_preview)
        handler_id = fm_add_image_preview_to_file_chooser(chooser);

    if(gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_OK)
    {
        GFile* file = gtk_file_chooser_get_file(chooser);
        path = fm_path_new_for_gfile(file);
        g_object_unref(file);
    }
    else
        path = NULL;
    if(handler_id > 0)
        g_signal_handler_disconnect(chooser, handler_id);
    gtk_widget_destroy(GTK_WIDGET(chooser));
    return path;
}
예제 #17
0
GFile *
gtkhtml_editor_run_open_dialog (GtkhtmlEditor *editor,
                                const gchar *title,
                                GtkCallback customize_func,
                                gpointer customize_data)
{
	GtkFileChooser *file_chooser;
	GFile *chosen_file = NULL;
	GtkWidget *dialog;
	gchar *uri;

	g_return_val_if_fail (GTKHTML_IS_EDITOR (editor), NULL);

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

	file_chooser = GTK_FILE_CHOOSER (dialog);

	gtk_dialog_set_default_response (
		GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);

	gtk_file_chooser_set_local_only (file_chooser, FALSE);

	/* Restore the current folder from the previous file chooser. */
	uri = (gchar *) gtkhtml_editor_get_current_folder (editor);
	if (uri != NULL)
		gtk_file_chooser_set_current_folder_uri (file_chooser, uri);

	/* Allow further customizations before running the dialog. */
	if (customize_func != NULL)
		customize_func (dialog, customize_data);

	if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT)
		goto exit;

	chosen_file = gtk_file_chooser_get_file (file_chooser);

	/* Save the current folder for subsequent file choosers. */
	uri = gtk_file_chooser_get_current_folder_uri (file_chooser);
	gtkhtml_editor_set_current_folder (editor, uri);
	g_free (uri);

exit:
	gtk_widget_destroy (dialog);

	return chosen_file;
}
static void
save_temp_response (GtkWidget *widget,
                    gint       response,
                    gpointer   user_data)
{
  g_autoptr(IdeEditorView) self = user_data;
  g_autoptr(GFile) target = NULL;
  g_autoptr(IdeProgress) progress = NULL;
  GtkFileChooser *chooser = (GtkFileChooser *)widget;

  g_assert (GTK_IS_FILE_CHOOSER (chooser));
  g_assert (IDE_IS_EDITOR_VIEW (self));

  switch (response)
    {
    case GTK_RESPONSE_OK:
      target = gtk_file_chooser_get_file (chooser);
      break;

    case GTK_RESPONSE_CANCEL:
    default:
      break;
    }

  if (target != NULL)
    {
      IdeBufferManager *buffer_manager;
      IdeContext *context;
      IdeProject *project;
      IdeBuffer *buffer = IDE_BUFFER (self->document);
      g_autoptr(IdeFile) file = NULL;

      context = ide_buffer_get_context (buffer);
      project = ide_context_get_project (context);
      buffer_manager = ide_context_get_buffer_manager (context);
      file = ide_project_get_project_file (project, target);

      ide_buffer_set_file (buffer, file);

      ide_buffer_manager_save_file_async (buffer_manager,
                                          buffer,
                                          file,
                                          &progress,
                                          NULL,
                                          ide_editor_view_actions__save_temp_cb,
                                          g_object_ref (self));
    }

  gtk_widget_destroy (widget);
}
예제 #19
0
파일: file-pdf-save.c 프로젝트: mardy/gimb
/* A function that is called when the button for browsing for file
 * locations was clicked */
static void
choose_file_call (GtkWidget *browse_button,
                  gpointer   file_entry)
{
  GFile *file = g_file_new_for_path (gtk_entry_get_text (GTK_ENTRY (file_entry)));
  gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (file_choose), g_file_get_uri (file));

  if (gtk_dialog_run (GTK_DIALOG (file_choose)) == GTK_RESPONSE_OK)
    {
      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (file_choose));
      gtk_entry_set_text (GTK_ENTRY (file_entry), g_file_get_path (file));
    };

  file_name = g_file_get_path (file);
  gtk_widget_hide (file_choose);
}
예제 #20
0
static void
folder_chooser_file_set_cb (GtkFileChooserButton *widget,
			    gpointer              user_data)
{
	DialogData *data = user_data;
	GFile      *folder;

	folder = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));
	if (folder == NULL)
		return;

	_g_object_unref (data->source);
	data->source = g_object_ref (folder);;
	load_file_list (data);

	g_object_unref (folder);
}
예제 #21
0
static void
gs_editor_button_save_clicked_cb (GtkApplication *application, GsEditor *self)
{
	GtkFileFilter *filter;
	GtkWidget *dialog;
	GtkWindow *window;
	gint res;
	g_autoptr(GError) error = NULL;
	g_autoptr(GFile) file = NULL;

	/* export a new file */
	window = GTK_WINDOW (gtk_builder_get_object (self->builder,
						     "window_main"));
	dialog = gtk_file_chooser_dialog_new (_("Open AppStream File"),
					      window,
					      GTK_FILE_CHOOSER_ACTION_SAVE,
					      _("_Cancel"), GTK_RESPONSE_CANCEL,
					      _("_Save"), GTK_RESPONSE_ACCEPT,
					      NULL);
	filter = gtk_file_filter_new ();
	gtk_file_filter_add_pattern (filter, "*.xml");
	gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
	res = gtk_dialog_run (GTK_DIALOG (dialog));
	if (res != GTK_RESPONSE_ACCEPT) {
		gtk_widget_destroy (dialog);
		return;
	}
	file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
	gtk_widget_destroy (dialog);
	if (!as_store_to_file (self->store,
			       file,
			       AS_NODE_TO_XML_FLAG_ADD_HEADER |
			       AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE |
			       AS_NODE_TO_XML_FLAG_FORMAT_INDENT,
			       self->cancellable,
			       &error)) {
		/* TRANSLATORS: error dialog title */
		gs_editor_error_message (self, _("Failed to save file"), error->message);
		return;
	}
	self->pending_changes = FALSE;
	gs_editor_refresh_file (self, file);
	gs_editor_refresh_details (self);
}
예제 #22
0
static void
file_manager_send_file_response_cb (GtkDialog *widget,
    gint response_id,
    EmpathyContact *contact)
{
  GFile *file;

  if (response_id == GTK_RESPONSE_OK)
    {
      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));

      empathy_send_file (contact, file);

      g_object_unref (file);
    }

  g_object_unref (contact);
  gtk_widget_destroy (GTK_WIDGET (widget));
}
예제 #23
0
GFile * ImageOpenDlg::show(GtkWindow * win, Settings * settings, bool localOnly, bool * attach) {
    GtkWidget * dialog = gtk_file_chooser_dialog_new(_("Open Image"), win, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
                         GTK_RESPONSE_OK, NULL);
    gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), localOnly);

    GtkFileFilter * filterSupported = gtk_file_filter_new();
    gtk_file_filter_set_name(filterSupported, _("Images"));
    gtk_file_filter_add_pixbuf_formats(filterSupported);
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filterSupported);

    if (!settings->getLastImagePath().isEmpty()) {
        gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(dialog), settings->getLastImagePath().c_str());
    }

    GtkWidget * cbAttach = NULL;
    if (attach) {
        cbAttach = gtk_check_button_new_with_label(_("Attach file to the journal"));
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbAttach), false);
        gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), cbAttach);
    }

    GtkWidget * image = gtk_image_new();
    gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), image);
    g_signal_connect(dialog, "update-preview", G_CALLBACK(updatePreviewCallback), NULL);

    gtk_window_set_transient_for(GTK_WINDOW(dialog), win);
    if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
        gtk_widget_destroy(dialog);
        return NULL;
    }
    GFile * file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog));
    if (attach) {
        *attach = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbAttach));
    }

    char * folder = gtk_file_chooser_get_current_folder_uri(GTK_FILE_CHOOSER(dialog));
    settings->setLastImagePath(folder);
    g_free(folder);

    gtk_widget_destroy(dialog);

    return file;
}
예제 #24
0
EogURIConverter*
eog_save_as_dialog_get_converter (GtkWidget *dlg)
{
	EogURIConverter *conv;

	SaveAsData *data;
	const char *format_str;
	gboolean convert_spaces;
	gulong   counter_start;
	GdkPixbufFormat *format;
	GFile *base_file;

	data = g_object_get_data (G_OBJECT (dlg), "data");
	g_assert (data != NULL);

	/* obtain required dialog data */
	format_str = gtk_entry_get_text (GTK_ENTRY (data->token_entry));

	convert_spaces = gtk_toggle_button_get_active
		(GTK_TOGGLE_BUTTON (data->replace_spaces_check));

	counter_start = gtk_spin_button_get_value_as_int
		(GTK_SPIN_BUTTON (data->counter_spin));

	format = get_selected_format (GTK_COMBO_BOX (data->format_combobox));

	base_file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (data->dir_chooser));

	/* create converter object */
	conv = eog_uri_converter_new (base_file, format, format_str);

	/* set other properties */
	g_object_set (G_OBJECT (conv),
		      "convert-spaces", convert_spaces,
		      "space-character", '_',
		      "counter-start", counter_start,
		      "n-images", data->n_images,
		      NULL);

	g_object_unref (base_file);

	return conv;
}
예제 #25
0
/* File->Import Into Skein... */
void
action_import_into_skein(GtkAction *action, I7Story *story)
{
	GError *err = NULL;

	/* Ask the user for a file to import */
	/* TRANSLATORS: File->Import Into Skein... */
	GtkWidget *dialog = gtk_file_chooser_dialog_new(
	  _("Select the file to import into the skein"),
	  GTK_WINDOW(story),
	  GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
	  GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);
	/* Create appropriate file filters */
	GtkFileFilter *filter1 = gtk_file_filter_new();
	gtk_file_filter_set_name(filter1, _("Interpreter recording files (*.rec)"));
	gtk_file_filter_add_pattern(filter1, "*.rec");
	GtkFileFilter *filter2 = gtk_file_filter_new();
	gtk_file_filter_set_name(filter2, _("All Files"));
	gtk_file_filter_add_pattern(filter2, "*");
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter1);
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter2);

	if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
		gtk_widget_destroy(dialog);
		return;
	}

	GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog));
	gtk_widget_destroy(dialog);
	if(!file)
		return; /* Fail silently */

	/* Provide some visual feedback that the command did something */
	if(!i7_skein_import(i7_story_get_skein(story), file, &err))
		error_dialog_file_operation(GTK_WINDOW(story), file, err, I7_FILE_ERROR_OPEN, NULL);
	else
		i7_story_show_pane(story, I7_PANE_SKEIN);

	g_object_unref(file);
}
예제 #26
0
파일: actions.c 프로젝트: GNOME/gthumb
static void
folder_chooser_response_cb (GtkDialog *dialog,
			    int        response_id,
			    gpointer   user_data)
{
	GthBrowser *browser = user_data;
	GFile      *folder;

	if (response_id != GTK_RESPONSE_OK) {
		gtk_widget_destroy (GTK_WIDGET (dialog));
		return;
	}

	folder = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
	if (folder != NULL) {
		dlg_photo_importer_from_folder (browser, folder);
		g_object_unref (folder);
	}

	gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
gimp_color_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog,
                                          gint                           response,
                                          GimpColorProfileComboBox      *combo)
{
  if (response == GTK_RESPONSE_ACCEPT)
    {
      GFile *file;

      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));

      if (file)
        {
          gimp_color_profile_combo_box_set_active_file (combo, file, NULL);

          g_object_unref (file);
        }
    }

  gtk_widget_hide (GTK_WIDGET (dialog));
}
예제 #28
0
/**
 * e_shell_run_open_dialog:
 * @shell: an #EShell
 * @title: file chooser dialog title
 * @customize_func: optional dialog customization function
 * @customize_data: optional data to pass to @customize_func
 *
 * Runs a #GtkFileChooserDialog in open mode with the given title and
 * returns the selected #GFile.  If @customize_func is provided, the
 * function is called just prior to running the dialog (the file chooser
 * is the first argument, @customize data is the second).  If the user
 * cancels the dialog the function will return %NULL.
 *
 * Returns: the #GFile to open, or %NULL
 **/
GFile *
e_shell_run_open_dialog (EShell *shell,
                         const gchar *title,
                         GtkCallback customize_func,
                         gpointer customize_data)
{
    GtkFileChooser *file_chooser;
    GFile *chosen_file = NULL;
    GtkWidget *dialog;
    GtkWindow *parent;

    g_return_val_if_fail (E_IS_SHELL (shell), NULL);

    parent = e_shell_get_active_window (shell);

    dialog = gtk_file_chooser_dialog_new (
                 title, parent,
                 GTK_FILE_CHOOSER_ACTION_OPEN,
                 _("_Cancel"), GTK_RESPONSE_CANCEL,
                 _("_Open"), GTK_RESPONSE_ACCEPT, NULL);

    file_chooser = GTK_FILE_CHOOSER (dialog);

    gtk_dialog_set_default_response (
        GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);

    gtk_file_chooser_set_local_only (file_chooser, FALSE);

    /* Allow further customizations before running the dialog. */
    if (customize_func != NULL)
        customize_func (dialog, customize_data);

    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
        chosen_file = gtk_file_chooser_get_file (file_chooser);

    gtk_widget_destroy (dialog);

    return chosen_file;
}
예제 #29
0
파일: application.c 프로젝트: Therzok/gtk
static void
open_response_cb (GtkNativeDialog *dialog,
                  gint response_id,
                  gpointer user_data)
{
  GtkFileChooserNative *native = user_data;
  GApplication *app = g_object_get_data (G_OBJECT (native), "app");
  GtkWidget *message_dialog;
  GFile *file;
  char *contents;
  GError *error = NULL;

  if (response_id == GTK_RESPONSE_ACCEPT)
    {
      file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (native));

      if (g_file_load_contents (file, NULL, &contents, NULL, NULL, &error))
        {
          create_window (app, contents);
          g_free (contents);
        }
      else
        {
          message_dialog = gtk_message_dialog_new (NULL,
                                                   GTK_DIALOG_DESTROY_WITH_PARENT,
                                                   GTK_MESSAGE_ERROR,
                                                   GTK_BUTTONS_CLOSE,
                                                   "Error loading file: \"%s\"",
                                                   error->message);
          g_signal_connect (message_dialog, "response",
                            G_CALLBACK (gtk_widget_destroy), NULL);
          gtk_widget_show (message_dialog);
          g_error_free (error);
        }
    }

  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
  g_object_unref (native);
}
예제 #30
0
파일: testwindows.c 프로젝트: nacho/gtk-
static void
save_clicked (GtkWidget *button,
              gpointer data)
{
    GString *s;
    GtkWidget *dialog;
    GFile *file;

    s = g_string_new ("");

    save_children (s, gtk_widget_get_window (darea));

    dialog = gtk_file_chooser_dialog_new ("Filename for window data",
                                          NULL,
                                          GTK_FILE_CHOOSER_ACTION_SAVE,
                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                          GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                                          NULL);

    gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);

    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
    {
        file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));

        g_file_replace_contents (file,
                                 s->str, s->len,
                                 NULL, FALSE,
                                 0, NULL, NULL, NULL);

        g_object_unref (file);
    }

    gtk_widget_destroy (dialog);
    g_string_free (s, TRUE);
}