libgimp: add GimpProcedureDialog, the new dialog class for plug-ins

It knows about the procedure and its config, and so far implements the
entire construction boilerplate and "Reset" on its own.
This commit is contained in:
Michael Natterer
2019-09-20 19:24:40 +02:00
parent df62d08798
commit bfb7f43dbc
7 changed files with 316 additions and 0 deletions

View File

@ -185,6 +185,7 @@ libgimpui_introspectable_headers = \
../libgimp/gimppaletteselectbutton.h \
../libgimp/gimppatternselectbutton.h \
../libgimp/gimpprocbrowserdialog.h \
../libgimp/gimpproceduredialog.h \
../libgimp/gimpprocview.h \
../libgimp/gimpprogressbar.h \
../libgimp/gimpselectbutton.h \
@ -205,6 +206,7 @@ libgimpui_introspectable = \
../libgimp/gimppaletteselectbutton.c \
../libgimp/gimppatternselectbutton.c \
../libgimp/gimpprocbrowserdialog.c \
../libgimp/gimpproceduredialog.c \
../libgimp/gimpprocview.c \
../libgimp/gimpprogressbar.c \
../libgimp/gimpselectbutton.c \

View File

@ -0,0 +1,228 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpproceduredialog.c
* Copyright (C) 2019 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gimp.h"
#include "gimpui.h"
#include "libgimp-intl.h"
enum
{
PROP_0,
PROP_PROCEDURE,
PROP_CONFIG,
N_PROPS
};
#define RESPONSE_RESET 1
struct _GimpProcedureDialogPrivate
{
GimpProcedure *procedure;
GimpProcedureConfig *config;
};
static void gimp_procedure_dialog_dispose (GObject *object);
static void gimp_procedure_dialog_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_procedure_dialog_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE_WITH_PRIVATE (GimpProcedureDialog, gimp_procedure_dialog,
GIMP_TYPE_DIALOG)
#define parent_class gimp_procedure_dialog_parent_class
static GParamSpec *props[N_PROPS] = { NULL, };
static void
gimp_procedure_dialog_class_init (GimpProcedureDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = gimp_procedure_dialog_dispose;
object_class->get_property = gimp_procedure_dialog_get_property;
object_class->set_property = gimp_procedure_dialog_set_property;
props[PROP_PROCEDURE] =
g_param_spec_object ("procedure", NULL, NULL,
GIMP_TYPE_PROCEDURE,
GIMP_PARAM_READWRITE);
props[PROP_CONFIG] =
g_param_spec_object ("config", NULL, NULL,
GIMP_TYPE_PROCEDURE_CONFIG,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT);
g_object_class_install_properties (object_class, N_PROPS, props);
}
static void
gimp_procedure_dialog_init (GimpProcedureDialog *dialog)
{
dialog->priv = gimp_procedure_dialog_get_instance_private (dialog);
}
static void
gimp_procedure_dialog_dispose (GObject *object)
{
GimpProcedureDialog *dialog = GIMP_PROCEDURE_DIALOG (object);
g_clear_object (&dialog->priv->procedure);
g_clear_object (&dialog->priv->config);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_procedure_dialog_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpProcedureDialog *dialog = GIMP_PROCEDURE_DIALOG (object);
switch (property_id)
{
case PROP_PROCEDURE:
dialog->priv->procedure = g_value_dup_object (value);
break;
case PROP_CONFIG:
dialog->priv->config = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_procedure_dialog_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpProcedureDialog *dialog = GIMP_PROCEDURE_DIALOG (object);
switch (property_id)
{
case PROP_PROCEDURE:
g_value_set_object (value, dialog->priv->procedure);
break;
case PROP_CONFIG:
g_value_set_object (value, dialog->priv->config);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
GtkWidget *
gimp_procedure_dialog_new (GimpProcedure *procedure,
GimpProcedureConfig *config,
const gchar *title)
{
GtkWidget *dialog;
gchar *role;
const gchar *help_id;
gboolean use_header_bar;
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL);
g_return_val_if_fail (GIMP_IS_PROCEDURE_CONFIG (config), NULL);
g_return_val_if_fail (title != NULL, NULL);
role = g_strdup_printf ("gimp-%s", gimp_procedure_get_name (procedure));
help_id = gimp_procedure_get_help_id (procedure);
g_object_get (gtk_settings_get_default (),
"gtk-dialogs-use-header", &use_header_bar,
NULL);
dialog = g_object_new (GIMP_TYPE_PROCEDURE_DIALOG,
"procedure", procedure,
"config", config,
"title", title,
"role", role,
"help-func", gimp_standard_help_func,
"help-id", help_id,
"use-header-bar", use_header_bar,
NULL);
g_free (role);
gimp_dialog_add_buttons (GIMP_DIALOG (dialog),
_("_Reset"), RESPONSE_RESET,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_OK"), GTK_RESPONSE_OK,
NULL);
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
RESPONSE_RESET,
GTK_RESPONSE_CANCEL,
-1);
gimp_window_set_transient (GTK_WINDOW (dialog));
return GTK_WIDGET (dialog);
}
gboolean
gimp_procedure_dialog_run (GimpProcedureDialog *dialog)
{
g_return_val_if_fail (GIMP_IS_PROCEDURE_DIALOG (dialog), FALSE);
while (TRUE)
{
gint response = gimp_dialog_run (GIMP_DIALOG (dialog));
if (response == RESPONSE_RESET)
{
gimp_config_reset (GIMP_CONFIG (dialog->priv->config));
}
else
{
return response == GTK_RESPONSE_OK;
}
}
}

View File

@ -0,0 +1,78 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpproceduredialog.h
* Copyright (C) 2019 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#if !defined (__GIMP_UI_H_INSIDE__) && !defined (GIMP_COMPILATION)
#error "Only <libgimp/gimpui.h> can be included directly."
#endif
#ifndef __GIMP_PROCEDURE_DIALOG_H__
#define __GIMP_PROCEDURE_DIALOG_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
#define GIMP_TYPE_PROCEDURE_DIALOG (gimp_procedure_dialog_get_type ())
#define GIMP_PROCEDURE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PROCEDURE_DIALOG, GimpProcedureDialog))
#define GIMP_PROCEDURE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PROCEDURE_DIALOG, GimpProcedureDialogClass))
#define GIMP_IS_PROCEDURE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PROCEDURE_DIALOG))
#define GIMP_IS_PROCEDURE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PROCEDURE_DIALOG))
#define GIMP_PROCEDURE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PROCEDURE_DIALOG, GimpProcedureDialogClass))
typedef struct _GimpProcedureDialogClass GimpProcedureDialogClass;
typedef struct _GimpProcedureDialogPrivate GimpProcedureDialogPrivate;
struct _GimpProcedureDialog
{
GimpDialog parent_instance;
GimpProcedureDialogPrivate *priv;
};
struct _GimpProcedureDialogClass
{
GimpDialogClass parent_class;
/* Padding for future expansion */
void (*_gimp_reserved1) (void);
void (*_gimp_reserved2) (void);
void (*_gimp_reserved3) (void);
void (*_gimp_reserved4) (void);
void (*_gimp_reserved5) (void);
void (*_gimp_reserved6) (void);
void (*_gimp_reserved7) (void);
void (*_gimp_reserved8) (void);
};
GType gimp_procedure_dialog_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_procedure_dialog_new (GimpProcedure *procedure,
GimpProcedureConfig *config,
const gchar *title);
gboolean gimp_procedure_dialog_run (GimpProcedureDialog *dialog);
G_END_DECLS
#endif /* __GIMP_PROCEDURE_DIALOG_H__ */

View File

@ -44,6 +44,9 @@ EXPORTS
gimp_proc_browser_dialog_get_type
gimp_proc_browser_dialog_new
gimp_proc_view_new
gimp_procedure_dialog_get_type
gimp_procedure_dialog_new
gimp_procedure_dialog_run
gimp_progress_bar_get_type
gimp_progress_bar_new
gimp_select_button_close_popup

View File

@ -39,6 +39,7 @@
#include <libgimp/gimppaletteselectbutton.h>
#include <libgimp/gimppatternselectbutton.h>
#include <libgimp/gimpprocbrowserdialog.h>
#include <libgimp/gimpproceduredialog.h>
#include <libgimp/gimpprocview.h>
#include <libgimp/gimpprogressbar.h>
#include <libgimp/gimpselectbutton.h>

View File

@ -28,6 +28,8 @@ G_BEGIN_DECLS
/* For information look into the html documentation */
typedef struct _GimpProcedureDialog GimpProcedureDialog;
typedef struct _GimpAspectPreview GimpAspectPreview;
typedef struct _GimpDrawablePreview GimpDrawablePreview;
typedef struct _GimpProcBrowserDialog GimpProcBrowserDialog;

View File

@ -231,6 +231,7 @@ libgimpui_sources_introspectable = [
'gimppaletteselectbutton.c',
'gimppatternselectbutton.c',
'gimpprocbrowserdialog.c',
'gimpproceduredialog.c',
'gimpprocview.c',
'gimpprogressbar.c',
'gimpselectbutton.c',
@ -256,6 +257,7 @@ libgimpui_headers_introspectable = [
'gimppaletteselectbutton.h',
'gimppatternselectbutton.h',
'gimpprocbrowserdialog.h',
'gimpproeduredialog.h',
'gimpprocview.h',
'gimpprogressbar.h',
'gimpselectbutton.h',