Skip to content

Commit

Permalink
glade/oscplot: Fix runtime GTK3 warning when creating plot
Browse files Browse the repository at this point in the history
The warning:
    (osc:17335): Gtk-WARNING **: 13:53:21.583: Content added to the action area of a dialog using header bars

The GtkDialogFileChooser that is being created via Glade has an built in GtkHeaderBar which has an action area where the 'Save' and 'Cancel' buttons are added. And this is not allowed, hence the above warning. The GTK2 version of the GtkDialogFileChooser didn't have a built in GtkHeaderBar.

The solution was to create in Glade a simple GtkDialog to which a GtkFileChooserWidget has been added. A GtkDialog does not have a built in GtkHeaderBar.

Signed-off-by: Dan Nechita <[email protected]>
  • Loading branch information
dNechita authored and cristina-suteu committed Feb 18, 2025
1 parent a962a88 commit fb1f9e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
25 changes: 18 additions & 7 deletions glade/oscplot.glade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkAdjustment" id="adj_add_to_sample">
Expand Down Expand Up @@ -1608,19 +1608,16 @@
</object>
</child>
</object>
<object class="GtkFileChooserDialog" id="saveas_dialog">
<object class="GtkDialog" id="saveas_dialog">
<property name="can-focus">False</property>
<property name="border-width">5</property>
<property name="title" translatable="yes">ADI IIO oscilloscope - Save As</property>
<property name="role">GtkFileChooserDialog</property>
<property name="modal">True</property>
<property name="icon-name">adi-osc</property>
<property name="type-hint">dialog</property>
<property name="action">save</property>
<property name="do-overwrite-confirmation">True</property>
<child internal-child="vbox">
<object class="GtkBox" id="filechooserdialog-vbox3">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="filechooserdialog-action_area3">
Expand Down Expand Up @@ -1653,7 +1650,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">1</property>
</packing>
</child>
</object>
Expand All @@ -1663,6 +1660,20 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFileChooserWidget" id="saveas_filechooser_widget">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="action">select-folder</property>
<property name="do-overwrite-confirmation">True</property>
<property name="search-mode">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox_ch_sel_label">
<property name="visible">True</property>
Expand Down
14 changes: 8 additions & 6 deletions oscplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ struct _OscPlotPrivate
GtkWidget *phase_label;
GtkWidget *saveas_button;
GtkWidget *saveas_dialog;
GtkFileChooser *saveas_filechooser;
GtkWidget *saveas_type_dialog;
GtkWidget *title_edit_dialog;
GtkWidget *fullscreen_button;
Expand Down Expand Up @@ -4550,14 +4551,14 @@ static void saveas_dialog_show(GtkWidget *w, OscPlot *plot)
{
OscPlotPrivate *priv = plot->priv;

gtk_file_chooser_set_action(GTK_FILE_CHOOSER (priv->saveas_dialog), GTK_FILE_CHOOSER_ACTION_SAVE);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(priv->saveas_dialog), TRUE);
gtk_file_chooser_set_action(priv->saveas_filechooser, GTK_FILE_CHOOSER_ACTION_SAVE);
gtk_file_chooser_set_do_overwrite_confirmation(priv->saveas_filechooser, TRUE);

if (!priv->saveas_filename) {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (priv->saveas_dialog), getenv("HOME"));
gtk_file_chooser_set_current_folder(priv->saveas_filechooser, getenv("HOME"));
} else {
if (!gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (priv->saveas_dialog), priv->saveas_filename))
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (priv->saveas_dialog), getenv("HOME"));
if (!gtk_file_chooser_set_filename(priv->saveas_filechooser, priv->saveas_filename))
gtk_file_chooser_set_current_folder(priv->saveas_filechooser, getenv("HOME"));
g_free(priv->saveas_filename);
priv->saveas_filename = NULL;
}
Expand Down Expand Up @@ -4794,7 +4795,7 @@ void cb_saveas_response(GtkDialog *dialog, gint response_id, OscPlot *plot)
/* Save as Dialog */
OscPlotPrivate *priv = plot->priv;

priv->saveas_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (priv->saveas_dialog));
priv->saveas_filename = gtk_file_chooser_get_filename(priv->saveas_filechooser);

if (response_id == GTK_RESPONSE_ACCEPT) {
gint type = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->cmb_saveas_type));
Expand Down Expand Up @@ -6985,6 +6986,7 @@ static void create_plot(OscPlot *plot)
priv->phase_label = GTK_WIDGET(gtk_builder_get_object(builder, "phase_info"));
priv->saveas_button = GTK_WIDGET(gtk_builder_get_object(builder, "save_as"));
priv->saveas_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "saveas_dialog"));
priv->saveas_filechooser = GTK_FILE_CHOOSER(gtk_builder_get_object(builder, "saveas_filechooser_widget"));
priv->title_edit_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "dialog_plot_title_edit"));
priv->fullscreen_button = GTK_WIDGET(gtk_builder_get_object(builder, "fullscreen"));
priv->menu_fullscreen = GTK_WIDGET(gtk_builder_get_object(builder, "menuitem_fullscreen"));
Expand Down

0 comments on commit fb1f9e2

Please sign in to comment.