Revert to normal GtkFileChooserDialog for saving presentation
authorThomas White <taw@bitwiz.me.uk>
Tue, 30 Oct 2018 19:36:26 +0000 (20:36 +0100)
committerThomas White <taw@bitwiz.me.uk>
Tue, 30 Oct 2018 19:36:26 +0000 (20:36 +0100)
I didn't know about the "extra widget" thing.

data/colloquium.gresource.xml
data/savepresentation.ui [deleted file]
src/narrative_window.c
src/presentation.c

index 307a437..819a966 100644 (file)
@@ -4,7 +4,6 @@
     <file>sky.png</file>
     <file>menus.ui</file>
     <file>stylesheeteditor.ui</file>
-    <file>savepresentation.ui</file>
     <file>demo.sc</file>
     <file>demo.ss</file>
     <file>default.ss</file>
diff --git a/data/savepresentation.ui b/data/savepresentation.ui
deleted file mode 100644 (file)
index 32f43be..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.4 -->
-<interface>
-  <requires lib="gtk+" version="3.20"/>
-  <object class="GtkDialog" id="savepresentation">
-    <property name="can_focus">False</property>
-    <property name="destroy_with_parent">True</property>
-    <property name="type_hint">dialog</property>
-    <signal name="response" handler="saveas_response_sig" swapped="no"/>
-    <child internal-child="vbox">
-      <object class="GtkBox">
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox">
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="button2">
-                <property name="label">gtk-cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button1">
-                <property name="label">gtk-save</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkBox">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="orientation">vertical</property>
-            <property name="spacing">8</property>
-            <child>
-              <object class="GtkFileChooserWidget" id="filechooser">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="action">save</property>
-                <property name="do_overwrite_confirmation">True</property>
-                <property name="local_only">False</property>
-                <property name="preview_widget_active">False</property>
-                <property name="use_preview_label">False</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkRadioButton" id="privatess">
-                <property name="label" translatable="yes">Create/update private stylesheet for this presentation</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="active">True</property>
-                <property name="draw_indicator">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkRadioButton" id="folderss">
-                <property name="label" translatable="yes">Create/update default stylesheet for presentations in folder</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="active">True</property>
-                <property name="draw_indicator">True</property>
-                <property name="group">privatess</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkRadioButton" id="noss">
-                <property name="label" translatable="yes">Don't save stylesheet at all</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="active">True</property>
-                <property name="draw_indicator">True</property>
-                <property name="group">privatess</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">3</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-    <action-widgets>
-      <action-widget response="2">button2</action-widget>
-      <action-widget response="1">button1</action-widget>
-    </action-widgets>
-    <child>
-      <placeholder/>
-    </child>
-  </object>
-</interface>
index 98001a9..fe6d024 100644 (file)
@@ -102,7 +102,6 @@ static void update_toolbar(NarrativeWindow *nw)
 struct saveas_info
 {
        NarrativeWindow *nw;
-       GtkWidget *filechooser;
 
        /* Radio buttons for how to save stylesheet */
        GtkWidget *privatess;
@@ -114,9 +113,9 @@ struct saveas_info
 static gint saveas_response_sig(GtkWidget *d, gint response,
                                 struct saveas_info *si)
 {
-       if ( response == 1 ) {  /* hard-coded number in Glade file */
+       if ( response == GTK_RESPONSE_ACCEPT ) {
 
-               GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(si->filechooser));
+               GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(d));
                GFile *ssfile = NULL;
 
                if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(si->privatess)) ) {
@@ -149,7 +148,7 @@ static gint saveas_response_sig(GtkWidget *d, gint response,
 
                /* save_presentation keeps a reference to both of these */
                g_object_unref(file);
-               g_object_unref(ssfile);
+               if ( ssfile != NULL ) g_object_unref(ssfile);
 
        }
 
@@ -163,7 +162,7 @@ static gint saveas_response_sig(GtkWidget *d, gint response,
 static void saveas_sig(GSimpleAction *action, GVariant *parameter, gpointer vp)
 {
        GtkWidget *d;
-       GtkBuilder *builder;
+       GtkWidget *box;
        NarrativeWindow *nw = vp;
        struct saveas_info *si;
 
@@ -172,16 +171,30 @@ static void saveas_sig(GSimpleAction *action, GVariant *parameter, gpointer vp)
 
        si->nw = nw;
 
-       builder = gtk_builder_new_from_resource("/uk/me/bitwiz/Colloquium/savepresentation.ui");
-       gtk_builder_add_callback_symbol(builder, "saveas_response_sig",
-                                       G_CALLBACK(saveas_response_sig));
-       gtk_builder_connect_signals(builder, si);
-       d = GTK_WIDGET(gtk_builder_get_object(builder, "savepresentation"));
-       si->filechooser = GTK_WIDGET(gtk_builder_get_object(builder, "filechooser"));
-       si->privatess = GTK_WIDGET(gtk_builder_get_object(builder, "privatess"));
-       si->folderss = GTK_WIDGET(gtk_builder_get_object(builder, "folderss"));
-       si->noss = GTK_WIDGET(gtk_builder_get_object(builder, "noss"));
-       gtk_window_set_transient_for(GTK_WINDOW(d), GTK_WINDOW(nw->window));
+       d = gtk_file_chooser_dialog_new(_("Save presentation"),
+                                       GTK_WINDOW(nw->window),
+                                       GTK_FILE_CHOOSER_ACTION_SAVE,
+                                       _("_Cancel"), GTK_RESPONSE_CANCEL,
+                                       _("_Save"), GTK_RESPONSE_ACCEPT,
+                                       NULL);
+       gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(d),
+                                                      TRUE);
+
+       box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
+       gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(d), box);
+       si->privatess = gtk_radio_button_new_with_label(NULL,
+            _("Create/update private stylesheet for this presentation"));
+       gtk_box_pack_start(GTK_BOX(box), si->privatess, FALSE, FALSE, 0);
+       si->folderss = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(si->privatess),
+            _("Create/update default stylesheet for presentations in folder"));
+       gtk_box_pack_start(GTK_BOX(box), si->folderss, FALSE, FALSE, 0);
+       si->noss = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(si->privatess),
+            _("Don't save stylesheet at all"));
+       gtk_box_pack_start(GTK_BOX(box), si->noss, FALSE, FALSE, 0);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(si->privatess), TRUE);
+
+       g_signal_connect(G_OBJECT(d), "response",
+                        G_CALLBACK(saveas_response_sig), si);
 
        gtk_widget_show_all(d);
 }
index 28f82a2..ae3f044 100644 (file)
@@ -177,7 +177,7 @@ int save_presentation(struct presentation *p, GFile *file, GFile *ssfile)
                        g_object_ref(p->stylesheet_from);
                }
        } else {
-               fprintf(stderr, _("Not updating default stylesheet\n"));
+               fprintf(stderr, _("Not saving the stylesheet\n"));
                sr = 0;
        }