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 *popup_menu_model;
GMenuModel *copy_popup_menu_model; GMenuModel *copy_popup_menu_model;
GimpProcedureConfig *config;
}; };
G_DEFINE_TYPE (GimpHelpBrowserDialog, gimp_help_browser_dialog, GTK_TYPE_APPLICATION_WINDOW) G_DEFINE_TYPE (GimpHelpBrowserDialog, gimp_help_browser_dialog, GTK_TYPE_APPLICATION_WINDOW)
@ -402,22 +404,29 @@ gimp_help_browser_dialog_finalize (GObject *object)
/* Public functions. */ /* Public functions. */
GimpHelpBrowserDialog * GimpHelpBrowserDialog *
gimp_help_browser_dialog_new (const gchar *plug_in_binary, gimp_help_browser_dialog_new (const gchar *plug_in_binary,
GApplication *app) GApplication *app,
GimpProcedureConfig *config)
{ {
GimpHelpBrowserDialog *window; GimpHelpBrowserDialog *window;
DialogData data = { 720, 560, 240, TRUE, 1.0 }; GBytes *bytes = NULL;
DialogData data = { 720, 560, 240, TRUE, 1.0 };
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_ui_init (plug_in_binary); gimp_ui_init (plug_in_binary);
gimp_get_data (GIMP_HELP_BROWSER_DIALOG_DATA, &data);
window = g_object_new (GIMP_TYPE_HELP_BROWSER_DIALOG, window = g_object_new (GIMP_TYPE_HELP_BROWSER_DIALOG,
"application", app, "application", app,
"role", plug_in_binary, "role", plug_in_binary,
"default-width", data.width, "default-width", data.width,
"default-height", data.height, "default-height", data.height,
NULL); NULL);
window->config = config;
gtk_paned_set_position (GTK_PANED (window->paned), data.paned_position); gtk_paned_set_position (GTK_PANED (window->paned), data.paned_position);
if (data.show_index) if (data.show_index)
gtk_widget_show (window->sidebar); gtk_widget_show (window->sidebar);
@ -1001,7 +1010,8 @@ dialog_unmap (GtkWidget *window,
gpointer user_data) gpointer user_data)
{ {
GimpHelpBrowserDialog *self = GIMP_HELP_BROWSER_DIALOG (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); gtk_window_get_size (GTK_WINDOW (window), &data.width, &data.height);
@ -1011,7 +1021,9 @@ dialog_unmap (GtkWidget *window,
data.zoom = (self->webview ? data.zoom = (self->webview ?
webkit_web_view_get_zoom_level (WEBKIT_WEB_VIEW (self->webview)) : 1.0); 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 static void

View File

@ -28,11 +28,11 @@
#define GIMP_TYPE_HELP_BROWSER_DIALOG (gimp_help_browser_dialog_get_type ()) #define GIMP_TYPE_HELP_BROWSER_DIALOG (gimp_help_browser_dialog_get_type ())
G_DECLARE_FINAL_TYPE (GimpHelpBrowserDialog, gimp_help_browser_dialog, G_DECLARE_FINAL_TYPE (GimpHelpBrowserDialog, gimp_help_browser_dialog,
GIMP, HELP_BROWSER_DIALOG, GIMP, HELP_BROWSER_DIALOG, GtkApplicationWindow)
GtkApplicationWindow)
GimpHelpBrowserDialog * gimp_help_browser_dialog_new (const char *plug_in_binary, 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, void gimp_help_browser_dialog_load (GimpHelpBrowserDialog *self,
const char *uri); const char *uri);

View File

@ -62,6 +62,7 @@ struct _GimpHelpBrowser
{ {
GimpPlugIn parent_instance; GimpPlugIn parent_instance;
GimpProcedureConfig *config;
GtkApplication *app; GtkApplication *app;
GimpHelpBrowserDialog *window; GimpHelpBrowserDialog *window;
}; };
@ -119,6 +120,11 @@ help_browser_create_procedure (GimpPlugIn *plug_in,
"Domain URIs", "Domain URIs",
"Domain URIs", "Domain URIs",
G_PARAM_READWRITE); 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; return procedure;
@ -131,7 +137,7 @@ on_app_activate (GApplication *gapp,
GimpHelpBrowser *browser = GIMP_HELP_BROWSER (user_data); GimpHelpBrowser *browser = GIMP_HELP_BROWSER (user_data);
GtkApplication *app = GTK_APPLICATION (gapp); 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.back", (const char*[]) { "<alt>Left", NULL });
gtk_application_set_accels_for_action (app, "win.forward", (const char*[]) { "<alt>Right", 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_names = NULL;
gchar **domain_uris = NULL; gchar **domain_uris = NULL;
browser->config = config;
g_object_get (config, g_object_get (config,
"domain-names", &domain_names, "domain-names", &domain_names,
"domain-uris", &domain_uris, "domain-uris", &domain_uris,