plug-ins: g_object_[gs]et_data() in help-browser replaced with aux bytes arg.

This commit is contained in:
Jehan 2023-10-24 22:20:27 +02:00
parent 56e5ed4559
commit afef78b62c
3 changed files with 31 additions and 12 deletions

View File

@ -76,6 +76,8 @@ struct _GimpHelpBrowserDialog
GMenuModel *popup_menu_model;
GMenuModel *copy_popup_menu_model;
GimpProcedureConfig *config;
};
G_DEFINE_TYPE (GimpHelpBrowserDialog, gimp_help_browser_dialog, GTK_TYPE_APPLICATION_WINDOW)
@ -403,14 +405,19 @@ gimp_help_browser_dialog_finalize (GObject *object)
GimpHelpBrowserDialog *
gimp_help_browser_dialog_new (const gchar *plug_in_binary,
GApplication *app)
GApplication *app,
GimpProcedureConfig *config)
{
GimpHelpBrowserDialog *window;
GBytes *bytes = NULL;
DialogData data = { 720, 560, 240, TRUE, 1.0 };
gimp_ui_init (plug_in_binary);
g_object_get (config, "dialog-data", &bytes, NULL);
if (bytes != NULL && g_bytes_get_size (bytes) == sizeof (DialogData))
data = *((DialogData *) g_bytes_get_data (bytes, NULL));
g_bytes_unref (bytes);
gimp_get_data (GIMP_HELP_BROWSER_DIALOG_DATA, &data);
gimp_ui_init (plug_in_binary);
window = g_object_new (GIMP_TYPE_HELP_BROWSER_DIALOG,
"application", app,
@ -418,6 +425,8 @@ gimp_help_browser_dialog_new (const gchar *plug_in_binary,
"default-width", data.width,
"default-height", data.height,
NULL);
window->config = config;
gtk_paned_set_position (GTK_PANED (window->paned), data.paned_position);
if (data.show_index)
gtk_widget_show (window->sidebar);
@ -1001,7 +1010,8 @@ dialog_unmap (GtkWidget *window,
gpointer user_data)
{
GimpHelpBrowserDialog *self = GIMP_HELP_BROWSER_DIALOG (user_data);
DialogData data;
GBytes *bytes;
DialogData data = { 720, 560, 240, TRUE, 1.0 };
gtk_window_get_size (GTK_WINDOW (window), &data.width, &data.height);
@ -1011,7 +1021,9 @@ dialog_unmap (GtkWidget *window,
data.zoom = (self->webview ?
webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW (self->webview)) : 1.0);
gimp_set_data (GIMP_HELP_BROWSER_DIALOG_DATA, &data, sizeof (data));
bytes = g_bytes_new (&data, sizeof (DialogData));
g_object_set (self->config, "dialog-data", bytes, NULL);
g_bytes_unref (bytes);
}
static void

View File

@ -28,11 +28,11 @@
#define GIMP_TYPE_HELP_BROWSER_DIALOG (gimp_help_browser_dialog_get_type ())
G_DECLARE_FINAL_TYPE (GimpHelpBrowserDialog, gimp_help_browser_dialog,
GIMP, HELP_BROWSER_DIALOG,
GtkApplicationWindow)
GIMP, HELP_BROWSER_DIALOG, GtkApplicationWindow)
GimpHelpBrowserDialog * gimp_help_browser_dialog_new (const char *plug_in_binary,
GApplication *app);
GApplication *app,
GimpProcedureConfig *config);
void gimp_help_browser_dialog_load (GimpHelpBrowserDialog *self,
const char *uri);

View File

@ -62,6 +62,7 @@ struct _GimpHelpBrowser
{
GimpPlugIn parent_instance;
GimpProcedureConfig *config;
GtkApplication *app;
GimpHelpBrowserDialog *window;
};
@ -119,6 +120,11 @@ help_browser_create_procedure (GimpPlugIn *plug_in,
"Domain URIs",
"Domain URIs",
G_PARAM_READWRITE);
GIMP_PROC_AUX_ARG_BYTES (procedure, "dialog-data",
"Dialog data",
"Remembering dialog's basic features; this is never meant to be a public argument",
GIMP_PARAM_READWRITE);
}
return procedure;
@ -131,7 +137,7 @@ on_app_activate (GApplication *gapp,
GimpHelpBrowser *browser = GIMP_HELP_BROWSER (user_data);
GtkApplication *app = GTK_APPLICATION (gapp);
browser->window = gimp_help_browser_dialog_new (PLUG_IN_BINARY, gapp);
browser->window = gimp_help_browser_dialog_new (PLUG_IN_BINARY, gapp, browser->config);
gtk_application_set_accels_for_action (app, "win.back", (const char*[]) { "<alt>Left", NULL });
gtk_application_set_accels_for_action (app, "win.forward", (const char*[]) { "<alt>Right", NULL });
@ -156,6 +162,7 @@ help_browser_run (GimpProcedure *procedure,
gchar **domain_names = NULL;
gchar **domain_uris = NULL;
browser->config = config;
g_object_get (config,
"domain-names", &domain_names,
"domain-uris", &domain_uris,