forked from AuroraMiddleware/gtk
inspector: Port to async dialog API
This commit is contained in:
parent
9ab732ce2d
commit
9839aca0bd
@ -29,8 +29,8 @@
|
||||
#include "gtkcssprovider.h"
|
||||
#include "gtkstyleprovider.h"
|
||||
#include "gtktextview.h"
|
||||
#include "gtkmessagedialog.h"
|
||||
#include "gtkfilechooserdialog.h"
|
||||
#include "gtkalertdialog.h"
|
||||
#include "gtkfiledialog.h"
|
||||
#include "gtktogglebutton.h"
|
||||
#include "gtklabel.h"
|
||||
#include "gtktooltip.h"
|
||||
@ -201,17 +201,12 @@ save_to_file (GtkInspectorCssEditor *ce,
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkAlertDialog *alert;
|
||||
|
||||
dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (ce))),
|
||||
GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_INFO,
|
||||
GTK_BUTTONS_OK,
|
||||
_("Saving CSS failed"));
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||
"%s", error->message);
|
||||
g_signal_connect (dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
|
||||
gtk_widget_show (dialog);
|
||||
alert = gtk_alert_dialog_new (_("Saving CSS failed"));
|
||||
gtk_alert_dialog_set_detail (alert, error->message);
|
||||
gtk_alert_dialog_show (alert, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (ce))));
|
||||
g_object_unref (alert);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
@ -219,39 +214,41 @@ save_to_file (GtkInspectorCssEditor *ce,
|
||||
}
|
||||
|
||||
static void
|
||||
save_response (GtkWidget *dialog,
|
||||
int response,
|
||||
GtkInspectorCssEditor *ce)
|
||||
save_response (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer data)
|
||||
{
|
||||
gtk_widget_hide (dialog);
|
||||
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
|
||||
GtkInspectorCssEditor *ce = data;
|
||||
GError *error = NULL;
|
||||
GFile *file;
|
||||
|
||||
if (response == GTK_RESPONSE_ACCEPT)
|
||||
file = gtk_file_dialog_save_finish (dialog, result, &error);
|
||||
if (file)
|
||||
{
|
||||
GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
||||
save_to_file (ce, file);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (dialog));
|
||||
else
|
||||
{
|
||||
g_print ("Error saving css: %s\n", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
save_clicked (GtkButton *button,
|
||||
GtkInspectorCssEditor *ce)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkFileDialog *dialog;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new ("",
|
||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (ce))),
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
||||
_("_Save"), GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "custom.css");
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
|
||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||
g_signal_connect (dialog, "response", G_CALLBACK (save_response), ce);
|
||||
gtk_widget_show (dialog);
|
||||
dialog = gtk_file_dialog_new ();
|
||||
gtk_file_dialog_save (dialog,
|
||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (ce))),
|
||||
NULL, "custom.css",
|
||||
NULL,
|
||||
save_response, ce);
|
||||
g_object_unref (dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -30,10 +30,8 @@
|
||||
#include "deprecated/gtkcombobox.h"
|
||||
#include "deprecated/gtkiconview.h"
|
||||
#include "deprecated/gtktreeview.h"
|
||||
#include "gtkcolorbutton.h"
|
||||
#include "gtkcolorchooser.h"
|
||||
#include "gtkfontbutton.h"
|
||||
#include "gtkfontchooser.h"
|
||||
#include "gtkcolordialogbutton.h"
|
||||
#include "gtkfontdialogbutton.h"
|
||||
#include "gtklabel.h"
|
||||
#include "gtkpopover.h"
|
||||
#include "gtkscrolledwindow.h"
|
||||
@ -745,7 +743,7 @@ object_properties (GtkInspectorPropEditor *self)
|
||||
}
|
||||
|
||||
static void
|
||||
rgba_modified (GtkColorButton *cb, GParamSpec *ignored, ObjectProperty *p)
|
||||
rgba_modified (GtkColorDialogButton *cb, GParamSpec *ignored, ObjectProperty *p)
|
||||
{
|
||||
GValue val = G_VALUE_INIT;
|
||||
|
||||
@ -761,25 +759,23 @@ rgba_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
||||
GtkColorChooser *cb = GTK_COLOR_CHOOSER (data);
|
||||
GValue val = G_VALUE_INIT;
|
||||
GdkRGBA *color;
|
||||
GdkRGBA cb_color;
|
||||
|
||||
g_value_init (&val, GDK_TYPE_RGBA);
|
||||
get_property_value (object, pspec, &val);
|
||||
|
||||
color = g_value_get_boxed (&val);
|
||||
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (cb), &cb_color);
|
||||
|
||||
if (color != NULL && !gdk_rgba_equal (color, &cb_color))
|
||||
if (color != NULL)
|
||||
{
|
||||
block_controller (G_OBJECT (cb));
|
||||
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cb), color);
|
||||
gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (cb), color);
|
||||
unblock_controller (G_OBJECT (cb));
|
||||
}
|
||||
g_value_unset (&val);
|
||||
}
|
||||
|
||||
static void
|
||||
font_modified (GtkFontChooser *fb, GParamSpec *pspec, ObjectProperty *p)
|
||||
font_modified (GtkFontDialogButton *fb, GParamSpec *pspec, ObjectProperty *p)
|
||||
{
|
||||
GValue val = G_VALUE_INIT;
|
||||
|
||||
@ -792,28 +788,20 @@ font_modified (GtkFontChooser *fb, GParamSpec *pspec, ObjectProperty *p)
|
||||
static void
|
||||
font_changed (GObject *object, GParamSpec *pspec, gpointer data)
|
||||
{
|
||||
GtkFontChooser *fb = GTK_FONT_CHOOSER (data);
|
||||
GtkFontDialogButton *fb = GTK_FONT_DIALOG_BUTTON (data);
|
||||
GValue val = G_VALUE_INIT;
|
||||
const PangoFontDescription *font_desc;
|
||||
PangoFontDescription *fb_font_desc;
|
||||
|
||||
g_value_init (&val, PANGO_TYPE_FONT_DESCRIPTION);
|
||||
get_property_value (object, pspec, &val);
|
||||
|
||||
font_desc = g_value_get_boxed (&val);
|
||||
fb_font_desc = gtk_font_chooser_get_font_desc (fb);
|
||||
|
||||
if (font_desc == NULL ||
|
||||
(fb_font_desc != NULL &&
|
||||
!pango_font_description_equal (fb_font_desc, font_desc)))
|
||||
{
|
||||
block_controller (G_OBJECT (fb));
|
||||
gtk_font_chooser_set_font_desc (fb, font_desc);
|
||||
unblock_controller (G_OBJECT (fb));
|
||||
}
|
||||
block_controller (G_OBJECT (fb));
|
||||
gtk_font_dialog_button_set_font_desc (fb, font_desc);
|
||||
unblock_controller (G_OBJECT (fb));
|
||||
|
||||
g_value_unset (&val);
|
||||
pango_font_description_free (fb_font_desc);
|
||||
}
|
||||
|
||||
static char *
|
||||
@ -1177,8 +1165,7 @@ property_editor (GObject *object,
|
||||
else if (type == G_TYPE_PARAM_BOXED &&
|
||||
G_PARAM_SPEC_VALUE_TYPE (spec) == GDK_TYPE_RGBA)
|
||||
{
|
||||
prop_edit = gtk_color_button_new ();
|
||||
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (prop_edit), TRUE);
|
||||
prop_edit = gtk_color_dialog_button_new (gtk_color_dialog_new ());
|
||||
|
||||
g_object_connect_property (object, spec,
|
||||
G_CALLBACK (rgba_changed),
|
||||
@ -1190,7 +1177,7 @@ property_editor (GObject *object,
|
||||
else if (type == G_TYPE_PARAM_BOXED &&
|
||||
G_PARAM_SPEC_VALUE_TYPE (spec) == PANGO_TYPE_FONT_DESCRIPTION)
|
||||
{
|
||||
prop_edit = gtk_font_button_new ();
|
||||
prop_edit = gtk_font_dialog_button_new (gtk_font_dialog_new ());
|
||||
|
||||
g_object_connect_property (object, spec,
|
||||
G_CALLBACK (font_changed),
|
||||
|
@ -23,14 +23,14 @@
|
||||
#include <gtk/gtkbox.h>
|
||||
#include <gtk/gtkdragsource.h>
|
||||
#include <gtk/gtkeventcontroller.h>
|
||||
#include <gtk/gtkfilechooserdialog.h>
|
||||
#include <gtk/gtkfiledialog.h>
|
||||
#include <gtk/gtkinscription.h>
|
||||
#include <gtk/gtkimage.h>
|
||||
#include <gtk/gtklabel.h>
|
||||
#include <gtk/gtklistbox.h>
|
||||
#include <gtk/gtklistitem.h>
|
||||
#include <gtk/gtklistview.h>
|
||||
#include <gtk/gtkmessagedialog.h>
|
||||
#include <gtk/gtkalertdialog.h>
|
||||
#include <gtk/gtkpicture.h>
|
||||
#include <gtk/gtkpopover.h>
|
||||
#include <gtk/gtksignallistitemfactory.h>
|
||||
@ -1803,18 +1803,21 @@ render_node_list_selection_changed (GtkListBox *list,
|
||||
}
|
||||
|
||||
static void
|
||||
render_node_save_response (GtkWidget *dialog,
|
||||
int response,
|
||||
GskRenderNode *node)
|
||||
render_node_save_response (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer data)
|
||||
{
|
||||
gtk_widget_hide (dialog);
|
||||
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
|
||||
GskRenderNode *node = data;
|
||||
GFile *file;
|
||||
GError *error = NULL;
|
||||
|
||||
if (response == GTK_RESPONSE_ACCEPT)
|
||||
file = gtk_file_dialog_save_finish (dialog, result, &error);
|
||||
if (file)
|
||||
{
|
||||
GBytes *bytes = gsk_render_node_serialize (node);
|
||||
GError *error = NULL;
|
||||
|
||||
if (!g_file_replace_contents (gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)),
|
||||
if (!g_file_replace_contents (file,
|
||||
g_bytes_get_data (bytes, NULL),
|
||||
g_bytes_get_size (bytes),
|
||||
NULL,
|
||||
@ -1824,24 +1827,23 @@ render_node_save_response (GtkWidget *dialog,
|
||||
NULL,
|
||||
&error))
|
||||
{
|
||||
GtkWidget *message_dialog;
|
||||
GtkAlertDialog *alert;
|
||||
|
||||
message_dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_window_get_transient_for (GTK_WINDOW (dialog))),
|
||||
GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_INFO,
|
||||
GTK_BUTTONS_OK,
|
||||
_("Saving RenderNode failed"));
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message_dialog),
|
||||
"%s", error->message);
|
||||
g_signal_connect (message_dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
|
||||
gtk_widget_show (message_dialog);
|
||||
alert = gtk_alert_dialog_new (_("Saving RenderNode failed"));
|
||||
gtk_alert_dialog_set_detail (alert, error->message);
|
||||
gtk_alert_dialog_show (alert, GTK_WINDOW (gtk_window_get_transient_for (GTK_WINDOW (dialog))));
|
||||
g_object_unref (alert);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_bytes_unref (bytes);
|
||||
g_object_unref (file);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print ("Error saving nodes: %s\n", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (dialog));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1849,28 +1851,23 @@ render_node_save (GtkButton *button,
|
||||
GtkInspectorRecorder *recorder)
|
||||
{
|
||||
GskRenderNode *node;
|
||||
GtkWidget *dialog;
|
||||
GtkFileDialog *dialog;
|
||||
char *filename, *nodename;
|
||||
|
||||
node = get_selected_node (recorder);
|
||||
if (node == NULL)
|
||||
return;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new ("",
|
||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (recorder))),
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
||||
_("_Save"), GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
nodename = node_name (node);
|
||||
filename = g_strdup_printf ("%s.node", nodename);
|
||||
g_free (nodename);
|
||||
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
|
||||
g_free (filename);
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
|
||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||
g_signal_connect (dialog, "response", G_CALLBACK (render_node_save_response), node);
|
||||
gtk_widget_show (dialog);
|
||||
|
||||
dialog = gtk_file_dialog_new ();
|
||||
gtk_file_dialog_save (dialog,
|
||||
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (recorder))),
|
||||
NULL, filename,
|
||||
NULL,
|
||||
render_node_save_response, node);
|
||||
g_object_unref (dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user