Code

Updated overwrite confirmation dialog to be similar to the new stock GTK+ one
authorjoncruz <joncruz@users.sourceforge.net>
Sat, 7 Apr 2007 08:28:41 +0000 (08:28 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Sat, 7 Apr 2007 08:28:41 +0000 (08:28 +0000)
addresses RFE 1692837

src/desktop.cpp
src/desktop.h
src/interface.cpp

index 187dcd010d4e441a98506f926bf1eaecce1b5135..15d5bc9e3423bd8276bcc7e10ebc727eca68273b 100644 (file)
@@ -989,6 +989,11 @@ SPDesktop::setWindowTransient (void *p, int transient_policy)
     _widget->setTransient (p, transient_policy);
 }
 
+void SPDesktop::getToplevel( GtkWidget*& toplevel )
+{
+    toplevel = GTK_WIDGET( _widget->getWindow() );
+}
+
 void
 SPDesktop::presentWindow()
 {
index 1770af9f5d7b45aa84d27f4629e037fdc01d01e8..797e74a331677080c5f84e405e7dae7d9a27a8b5 100644 (file)
@@ -35,6 +35,8 @@
 
 class NRRect;
 class SPCSSAttr;
+struct _GtkWidget;
+typedef struct _GtkWidget GtkWidget;
 struct SPCanvas;
 struct SPCanvasItem;
 struct SPCanvasGroup;
@@ -227,6 +229,7 @@ struct SPDesktop : public Inkscape::UI::View::View
     void setWindowPosition (NR::Point p);
     void setWindowSize (gint w, gint h);
     void setWindowTransient (void* p, int transient_policy=1);
+    void getToplevel( GtkWidget*& toplevel );
     void presentWindow();
     bool warnDialog (gchar *text);
     void toggleRulers();
index c6b2aaf8601fac20fb8794edd704a954847b1116..fa41e5898bbe81268ce036ee0cab0ab34b375bfb 100644 (file)
@@ -1254,52 +1254,39 @@ bool
 sp_ui_overwrite_file(gchar const *filename)
 {
     bool return_value = FALSE;
-    GtkWidget *dialog;
-    GtkWidget *hbox;
-    GtkWidget *boxdata;
-    gchar *title;
-    gchar *text;
 
     if (Inkscape::IO::file_test(filename, G_FILE_TEST_EXISTS)) {
-
-        title = g_strdup_printf(_("Overwrite %s"), filename);
-        dialog = gtk_dialog_new_with_buttons(title,
-                                             NULL,
-                                             (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
-                                             GTK_STOCK_NO,
-                                             GTK_RESPONSE_NO,
-                                             GTK_STOCK_YES,
-                                             GTK_RESPONSE_YES,
-                                             NULL);
-        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
-
-        sp_transientize(dialog);
-        gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
-
-        hbox = gtk_hbox_new(FALSE, 5);
-
-        // TODO - replace with Inkscape-specific call
-        boxdata = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
-
-        gtk_widget_show(boxdata);
-        gtk_box_pack_start(GTK_BOX(hbox), boxdata, TRUE, TRUE, 5);
-        text = g_strdup_printf(_("The file %s already exists.  Do you want to overwrite that file with the current document?"), filename);
-        boxdata = gtk_label_new(text);
-        gtk_label_set_line_wrap(GTK_LABEL(boxdata), TRUE);
-        gtk_widget_show(boxdata);
-        gtk_box_pack_start(GTK_BOX(hbox), boxdata, FALSE, FALSE, 5);
-        gtk_widget_show(hbox);
-        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE, 5);
-
-        if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_YES) {
+        GtkWidget* ancestor = 0;
+        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        if ( desktop ) {
+            desktop->getToplevel( ancestor );
+        }
+        GtkWindow *window = GTK_WIDGET_TOPLEVEL(ancestor) ? GTK_WINDOW( ancestor ) : 0;
+        gchar* baseName = g_path_get_basename( filename );
+        gchar* dirName = g_path_get_dirname( filename );
+        GtkWidget* dialog = gtk_message_dialog_new_with_markup( window,
+                                                                (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
+                                                                GTK_MESSAGE_QUESTION,
+                                                                GTK_BUTTONS_NONE,
+                                                                _( "<span weight=\"bold\" size=\"larger\">A file named \"%s\" already exists. Do you want to replace it?</span>\n\n"
+                                                                   "The file already exists in \"%s\". Replacing it will overwrite its contents." ),
+                                                                baseName,
+                                                                dirName
+            );
+        gtk_dialog_add_buttons( GTK_DIALOG(dialog),
+                                GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
+                                _("Replace"), GTK_RESPONSE_YES,
+                                NULL );
+        gtk_dialog_set_default_response( GTK_DIALOG(dialog), GTK_RESPONSE_YES );
+
+        if ( gtk_dialog_run( GTK_DIALOG(dialog) ) == GTK_RESPONSE_YES ) {
             return_value = TRUE;
         } else {
             return_value = FALSE;
         }
-
         gtk_widget_destroy(dialog);
-        g_free(title);
-        g_free(text);
+        g_free( baseName );
+        g_free( dirName );
     } else {
         return_value = TRUE;
     }