RE: folder selection




-----Original Message-----
From: gtk-app-devel-list-bounces gnome org
[mailto:gtk-app-devel-list-bounces gnome org]On Behalf Of srinivas
Sent: Friday, May 13, 2005 12:45 AM
To: gtk-app-devel-list gnome org
Subject: folder selection


hi ;

can i use gtk_file_selection to select the folder, if so can i have an
example of it.

bye;

vasu.

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


    Wow, I think this is a question that I can answer!  Use
gtk_file_selection_set_filename().  If you give it a directory path, the last
character in the string should be '/'.  Below are the guts of two callback
functions.  The first is called when the File/Open menu item is picked and
the second is called when the OK button is clicked on the file_select_dialog.

I hope this helps,

Nathan Prewitt



char *_ipar_dir_path = 0;

void
on_file_open_activate(GtkMenuItem *menuitem, gpointer user_data)
{
  GtkWidget *file_select_dialog;

  file_select_dialog = create_file_select_dialog();

  if (_ipar_dir_path)
  {
    gtk_file_selection_set_filename((GtkFileSelection *)file_select_dialog,
                                    _ipar_dir_path);
  }

  gtk_widget_show(file_select_dialog);
}

void
on_file_select_ok_button_clicked(GtkButton *button, gpointer user_data)
{
  int n;
  const gchar *filename;

  filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(
                                             gtk_widget_get_toplevel(
                                             GTK_WIDGET(button))));

  /* if the last character is / no file was chosen */
  n = strlen(filename);

  if (filename[n-1] == '/') return;

  /* save the directory name as the default path */
  while (filename[n] != '/')
  {
    n--;
  }

  _ipar_dir_path = (char *)realloc(_ipar_dir_path,(n+2)*sizeof(char));
  strncpy(_ipar_dir_path, filename, n+1);
  _ipar_dir_path[n+1] = 0;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]