Re: Confirming file overwrite with Gtk::FileChooser



On Sat, 2005-01-08 at 13:09 +0100, ERDI Gergo wrote:
> I remember last week someone working on this, here's what I did:

Thanks for the example code.

> bool IO::uri_exists (const Glib::ustring &uri)
> {
>      try {
>  	Glib::RefPtr<Gnome::Vfs::FileInfo> fileinfo = Gnome::Vfs::Handle::get_file_info (uri);
>  	return true;
>      } catch (...) {
>      }
> 
>      return false;
> }
> 
> bool UI::confirm_save (Gtk::FileChooserDialog &file_chooser)
> {
>      if (file_chooser.run () == Gtk::RESPONSE_ACCEPT)
>      {
>  	Glib::ustring uri = file_chooser.get_uri ();
>  	if (IO::uri_exists (uri))
>  	{
>  	    Glib::ScopedPtr<char> message (
>  		g_strdup_printf (_("<b><big>\"%s\" already exists</big></b>\n"
>  				   "Would you like to overwrite it?"),
>  				 UI::visible_filename (uri).c_str ()));
>  	    Gtk::MessageDialog *confirm = new Gtk::MessageDialog (file_chooser,
>  								  message.get (), true,
>  								  Gtk::MESSAGE_QUESTION,
>  								  Gtk::BUTTONS_YES_NO,

Of courrse, explicitly named buttons are better than Yes/No buttons, as
are full HIG dialogs.

Bakery does all of this for you already, in a reusable way, by the way.

>  								  true);
>  	    int response = confirm->run ();
>  	    delete confirm;
> 
>  	    if (response == Gtk::RESPONSE_YES)
>  		return true;
>  	    else
>  		return confirm_save (file_chooser);
> 
>  	} else {
>  	    return true;
>  	}
>      }
> 
>      return false;
> }
> 
-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com




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