save as file submenu query




Dear friends,
In my project, I have created a SAVE AS file submenu.
I have two question:
1) This "save as" does not have any key board shortcut(Ctrl+S as
standard) like open or new file submenu, which are also created in the
same way, using accel group. Why this is so?
2) Though the file copying is working fine, I would love to receive some
comment about if this is a dependable(in sense of failsafe and fast)
process of copying file.
The code is as follows:


//In Main
accel_group = gtk_accel_group_new();
    gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
    save = gtk_image_menu_item_new_from_stock(GTK_STOCK_SAVE_AS,
accel_group);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save);
    g_signal_connect(G_OBJECT(save), "activate",
G_CALLBACK(rename_file), NULL);



//the called function
static void rename_file(GtkWidget *widget, gpointer data)
{
   gchar *fname=NULL, *str; 
   gchar *cts;
   GError *Err=NULL;
   GtkWidget *dialog;
   gsize length;
   dialog=gtk_file_chooser_dialog_new("Save File", GTK_WINDOW(window), 
                                      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)
   {
      g_file_get_contents(filename, &cts, &length, &Err);
      filename=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
      g_file_set_contents(filename, cts, -1, &Err);
      g_free(cts);
      if (Err)
      {
        caution("Failed to save in %s",filename);
         {g_free(str); g_error_free(Err);}
      }
   }
   gtk_widget_destroy(dialog);
}



                                                        Report this post




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