Commit 440a1bae authored by Michael Natterer's avatar Michael Natterer 😴

app: one more round of general dialog cleanup

- consistent coding style
- hide public structs
- add callbacks to move logic out of app/dialogs/
parent f47c012a
......@@ -1393,6 +1393,8 @@ image_scale_callback (GtkWidget *dialog,
if (width > 0 && height > 0)
{
gtk_widget_destroy (dialog);
if (width == gimp_image_get_width (image) &&
height == gimp_image_get_height (image) &&
xresolution == xres &&
......
......@@ -74,44 +74,51 @@
/* local function prototypes */
static void vectors_new_callback (GtkWidget *dialog,
GimpImage *image,
GimpVectors *vectors,
GimpContext *context,
const gchar *vectors_name,
gboolean vectors_visible,
gboolean vectors_linked,
gboolean vectors_lock_content,
gboolean vectors_lock_position,
gpointer user_data);
static void vectors_edit_attributes_callback (GtkWidget *dialog,
GimpImage *image,
GimpVectors *vectors,
GimpContext *context,
const gchar *vectors_name,
gboolean vectors_visible,
gboolean vectors_linked,
gboolean vectors_lock_content,
gboolean vectors_lock_position,
gpointer user_data);
static void vectors_fill_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpFillOptions *options,
gpointer user_data);
static void vectors_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer user_data);
static void vectors_import_response (GtkWidget *widget,
gint response_id,
VectorsImportDialog *dialog);
static void vectors_export_response (GtkWidget *widget,
gint response_id,
VectorsExportDialog *dialog);
static void vectors_new_callback (GtkWidget *dialog,
GimpImage *image,
GimpVectors *vectors,
GimpContext *context,
const gchar *vectors_name,
gboolean vectors_visible,
gboolean vectors_linked,
gboolean vectors_lock_content,
gboolean vectors_lock_position,
gpointer user_data);
static void vectors_edit_attributes_callback (GtkWidget *dialog,
GimpImage *image,
GimpVectors *vectors,
GimpContext *context,
const gchar *vectors_name,
gboolean vectors_visible,
gboolean vectors_linked,
gboolean vectors_lock_content,
gboolean vectors_lock_position,
gpointer user_data);
static void vectors_fill_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpFillOptions *options,
gpointer user_data);
static void vectors_stroke_callback (GtkWidget *dialog,
GimpItem *item,
GimpDrawable *drawable,
GimpContext *context,
GimpStrokeOptions *options,
gpointer user_data);
static void vectors_import_callback (GtkWidget *dialog,
GimpImage *image,
GFile *file,
GFile *import_folder,
gboolean merge_vectors,
gboolean scale_vectors,
gpointer user_data);
static void vectors_export_callback (GtkWidget *dialog,
GimpImage *image,
GFile *file,
GFile *export_folder,
gboolean active_only,
gpointer user_data);
/* public functions */
......@@ -437,7 +444,6 @@ vectors_fill_cmd_callback (GtkAction *action,
return;
}
#define FILL_DIALOG_KEY "gimp-vectors-fill-dialog"
dialog = dialogs_get_dialog (G_OBJECT (drawable), FILL_DIALOG_KEY);
......@@ -646,74 +652,75 @@ void
vectors_export_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *image;
GimpVectors *vectors;
GtkWidget *widget;
GimpDialogConfig *config;
VectorsExportDialog *dialog;
GimpImage *image;
GimpVectors *vectors;
GtkWidget *widget;
GtkWidget *dialog;
return_if_no_vectors (image, vectors, data);
return_if_no_widget (widget, data);
config = GIMP_DIALOG_CONFIG (image->gimp->config);
#define EXPORT_DIALOG_KEY "gimp-vectors-export-dialog"
dialog = vectors_export_dialog_new (image, widget,
config->vectors_export_active_only);
dialog = dialogs_get_dialog (G_OBJECT (image), EXPORT_DIALOG_KEY);
if (config->vectors_export_path)
if (! dialog)
{
GFile *folder = gimp_file_new_for_config_path (config->vectors_export_path,
NULL);
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
GFile *folder = NULL;
if (config->vectors_export_path)
folder = gimp_file_new_for_config_path (config->vectors_export_path,
NULL);
dialog = vectors_export_dialog_new (image, widget,
folder,
config->vectors_export_active_only,
vectors_export_callback,
NULL);
if (folder)
{
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog->dialog),
folder, NULL);
g_object_unref (folder);
}
}
g_object_unref (folder);
g_signal_connect (dialog->dialog, "response",
G_CALLBACK (vectors_export_response),
dialog);
dialogs_attach_dialog (G_OBJECT (image), EXPORT_DIALOG_KEY, dialog);
}
gtk_widget_show (dialog->dialog);
gtk_window_present (GTK_WINDOW (dialog));
}
void
vectors_import_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *image;
GtkWidget *widget;
GimpDialogConfig *config;
VectorsImportDialog *dialog;
GimpImage *image;
GtkWidget *widget;
GtkWidget *dialog;
return_if_no_image (image, data);
return_if_no_widget (widget, data);
config = GIMP_DIALOG_CONFIG (image->gimp->config);
#define IMPORT_DIALOG_KEY "gimp-vectors-import-dialog"
dialog = vectors_import_dialog_new (image, widget,
config->vectors_import_merge,
config->vectors_import_scale);
dialog = dialogs_get_dialog (G_OBJECT (image), IMPORT_DIALOG_KEY);
if (config->vectors_import_path)
if (! dialog)
{
GFile *folder = gimp_file_new_for_config_path (config->vectors_import_path,
NULL);
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
GFile *folder = NULL;
if (folder)
{
gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog->dialog),
folder, NULL);
g_object_unref (folder);
}
}
if (config->vectors_import_path)
folder = gimp_file_new_for_config_path (config->vectors_import_path,
NULL);
g_signal_connect (dialog->dialog, "response",
G_CALLBACK (vectors_import_response),
dialog);
dialog = vectors_import_dialog_new (image, widget,
folder,
config->vectors_import_merge,
config->vectors_import_scale,
vectors_import_callback,
NULL);
dialogs_attach_dialog (G_OBJECT (image), IMPORT_DIALOG_KEY, dialog);
}
gtk_widget_show (dialog->dialog);
gtk_window_present (GTK_WINDOW (dialog));
}
void
......@@ -975,110 +982,85 @@ vectors_stroke_callback (GtkWidget *dialog,
}
static void
vectors_import_response (GtkWidget *widget,
gint response_id,
VectorsImportDialog *dialog)
vectors_import_callback (GtkWidget *dialog,
GimpImage *image,
GFile *file,
GFile *import_folder,
gboolean merge_vectors,
gboolean scale_vectors,
gpointer user_data)
{
if (response_id == GTK_RESPONSE_OK)
{
GimpDialogConfig *config;
GtkFileChooser *chooser = GTK_FILE_CHOOSER (widget);
GFile *file;
gchar *folder = NULL;
GError *error = NULL;
config = GIMP_DIALOG_CONFIG (dialog->image->gimp->config);
file = gtk_file_chooser_get_current_folder_file (chooser);
if (file)
{
folder = gimp_file_get_config_path (file, NULL);
g_object_unref (file);
}
g_object_set (config,
"path-import-path", folder,
"path-import-merge", dialog->merge_vectors,
"path-import-scale", dialog->scale_vectors,
NULL);
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
gchar *path = NULL;
GError *error = NULL;
if (folder)
g_free (folder);
if (import_folder)
path = gimp_file_get_config_path (import_folder, NULL);
file = gtk_file_chooser_get_file (chooser);
g_object_set (config,
"path-import-path", path,
"path-import-merge", merge_vectors,
"path-import-scale", scale_vectors,
NULL);
if (gimp_vectors_import_file (dialog->image, file,
config->vectors_import_merge,
config->vectors_import_scale,
GIMP_IMAGE_ACTIVE_PARENT, -1,
NULL, &error))
{
gimp_image_flush (dialog->image);
}
else
{
gimp_message (dialog->image->gimp, G_OBJECT (widget),
GIMP_MESSAGE_ERROR,
"%s", error->message);
g_error_free (error);
return;
}
if (path)
g_free (path);
g_object_unref (file);
if (gimp_vectors_import_file (image, file,
config->vectors_import_merge,
config->vectors_import_scale,
GIMP_IMAGE_ACTIVE_PARENT, -1,
NULL, &error))
{
gimp_image_flush (image);
}
else
{
gimp_message (image->gimp, G_OBJECT (dialog),
GIMP_MESSAGE_ERROR,
"%s", error->message);
g_error_free (error);
return;
}
gtk_widget_destroy (widget);
gtk_widget_destroy (dialog);
}
static void
vectors_export_response (GtkWidget *widget,
gint response_id,
VectorsExportDialog *dialog)
vectors_export_callback (GtkWidget *dialog,
GimpImage *image,
GFile *file,
GFile *export_folder,
gboolean active_only,
gpointer user_data)
{
if (response_id == GTK_RESPONSE_OK)
{
GimpDialogConfig *config;
GtkFileChooser *chooser = GTK_FILE_CHOOSER (widget);
GimpVectors *vectors = NULL;
GFile *file;
gchar *folder = NULL;
GError *error = NULL;
config = GIMP_DIALOG_CONFIG (dialog->image->gimp->config);
file = gtk_file_chooser_get_current_folder_file (chooser);
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
GimpVectors *vectors = NULL;
gchar *path = NULL;
GError *error = NULL;
if (file)
{
folder = gimp_file_get_config_path (file, NULL);
g_object_unref (file);
}
if (export_folder)
path = gimp_file_get_config_path (export_folder, NULL);
g_object_set (config,
"path-export-path", folder,
"path-export-active-only", dialog->active_only,
NULL);
if (folder)
g_free (folder);
file = gtk_file_chooser_get_file (chooser);
g_object_set (config,
"path-export-path", path,
"path-export-active-only", active_only,
NULL);
if (config->vectors_export_active_only)
vectors = gimp_image_get_active_vectors (dialog->image);
if (path)
g_free (path);
if (! gimp_vectors_export_file (dialog->image, vectors, file, &error))
{
gimp_message (dialog->image->gimp, G_OBJECT (widget),
GIMP_MESSAGE_ERROR,
"%s", error->message);
g_error_free (error);
return;
}
if (config->vectors_export_active_only)
vectors = gimp_image_get_active_vectors (image);
g_object_unref (file);
if (! gimp_vectors_export_file (image, vectors, file, &error))
{
gimp_message (image->gimp, G_OBJECT (dialog),
GIMP_MESSAGE_ERROR,
"%s", error->message);
g_clear_error (&error);
return;
}
gtk_widget_destroy (widget);
gtk_widget_destroy (dialog);
}
......@@ -68,13 +68,13 @@ typedef struct
} ProfileDialog;
static void color_profile_dialog_free (ProfileDialog *private);
static GtkWidget * color_profile_combo_box_new (ProfileDialog *private);
static void color_profile_dialog_response (GtkWidget *dialog,
gint response_id,
ProfileDialog *private);
static void color_profile_dest_changed (GtkWidget *combo,
ProfileDialog *private);
static void color_profile_dialog_free (ProfileDialog *private);
/* public functions */
......@@ -319,6 +319,12 @@ color_profile_dialog_new (ColorProfileDialogType dialog_type,
/* private functions */
static void
color_profile_dialog_free (ProfileDialog *private)
{
g_slice_free (ProfileDialog, private);
}
static GtkWidget *
color_profile_combo_box_new (ProfileDialog *private)
{
......@@ -482,9 +488,3 @@ color_profile_dest_changed (GtkWidget *combo,
g_object_unref (dest_profile);
}
}
static void
color_profile_dialog_free (ProfileDialog *private)
{
g_slice_free (ProfileDialog, private);
}
......@@ -42,7 +42,9 @@
#include "gimp-intl.h"
typedef struct
typedef struct _IndexedDialog IndexedDialog;
struct _IndexedDialog
{
GimpImage *image;
GimpConvertPaletteType palette_type;
......@@ -58,9 +60,10 @@ typedef struct
GtkWidget *dialog;
GimpContext *context;
GimpContainer *container;
} IndexedDialog;
};
static void convert_dialog_free (IndexedDialog *private);
static void convert_dialog_response (GtkWidget *widget,
gint response_id,
IndexedDialog *private);
......@@ -70,7 +73,6 @@ static gboolean convert_dialog_palette_filter (GimpObject *object,
static void convert_dialog_palette_changed (GimpContext *context,
GimpPalette *palette,
IndexedDialog *private);
static void convert_dialog_free (IndexedDialog *private);
/* public functions */
......@@ -295,6 +297,18 @@ convert_indexed_dialog_new (GimpImage *image,
/* private functions */
static void
convert_dialog_free (IndexedDialog *private)
{
if (private->container)
g_object_unref (private->container);
if (private->context)
g_object_unref (private->context);
g_slice_free (IndexedDialog, private);
}
static void
convert_dialog_response (GtkWidget *dialog,
gint response_id,
......@@ -406,15 +420,3 @@ convert_dialog_palette_changed (GimpContext *context,
private->custom_palette = palette;
}
}
static void
convert_dialog_free (IndexedDialog *private)
{
if (private->container)
g_object_unref (private->container);
if (private->context)
g_object_unref (private->context);
g_slice_free (IndexedDialog, private);
}
......@@ -39,7 +39,9 @@
#include "gimp-intl.h"
typedef struct
typedef struct _ConvertDialog ConvertDialog;
struct _ConvertDialog
{
GimpImage *image;
GimpComponentType component_type;
......@@ -50,13 +52,15 @@ typedef struct
GeglDitherMethod channel_dither_method;
GimpConvertPrecisionCallback callback;
gpointer user_data;
} ConvertDialog;
};
/* local function prototypes */
static void convert_precision_dialog_free (ConvertDialog *private);
static void convert_precision_dialog_response (GtkWidget *widget,
gint response_id,
ConvertDialog *private);
static void convert_precision_dialog_free (ConvertDialog *private);
/* public functions */
......@@ -278,6 +282,12 @@ convert_precision_dialog_new (GimpImage *image,
/* private functions */
static void
convert_precision_dialog_free (ConvertDialog *private)
{
g_slice_free (ConvertDialog, private);
}
static void
convert_precision_dialog_response (GtkWidget *dialog,
gint response_id,
......@@ -301,9 +311,3 @@ convert_precision_dialog_response (GtkWidget *dialog,
gtk_widget_destroy (dialog);
}
}
static void
convert_precision_dialog_free (ConvertDialog *private)
{
g_slice_free (ConvertDialog, private);
}
......@@ -53,7 +53,7 @@ struct _DataDeleteDialog
static void data_delete_dialog_response (GtkWidget *dialog,
gint response_id,
DataDeleteDialog *delete_data);
DataDeleteDialog *private);
/* public functions */
......@@ -64,7 +64,7 @@ data_delete_dialog_new (GimpDataFactory *factory,
GimpContext *context,
GtkWidget *parent)
{
DataDeleteDialog *delete_data;
DataDeleteDialog *private;
GtkWidget *dialog;
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
......@@ -72,12 +72,12 @@ data_delete_dialog_new (GimpDataFactory *factory,
g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
delete_data = g_slice_new0 (DataDeleteDialog);
private = g_slice_new0 (DataDeleteDialog);
delete_data->factory = factory;
delete_data->data = data;
delete_data->context = context;
delete_data->parent = parent;
private->factory = factory;
private->data = data;
private->context = context;
private->parent = parent;
dialog = gimp_message_dialog_new (_("Delete Object"), "edit-delete",
gtk_widget_get_toplevel (parent), 0,
......@@ -99,7 +99,7 @@ data_delete_dialog_new (GimpDataFactory *factory,
g_signal_connect (dialog, "response",
G_CALLBACK (data_delete_dialog_response),
delete_data);
private);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Delete '%s'?"),
......@@ -118,23 +118,23 @@ data_delete_dialog_new (GimpDataFactory *factory,
static void
data_delete_dialog_response (GtkWidget *dialog,
gint response_id,
DataDeleteDialog *delete_data)
DataDeleteDialog *private)
{
gtk_widget_destroy (dialog);
if (response_id == GTK_RESPONSE_OK)
{
GimpDataFactory *factory = delete_data->factory;
GimpData *data = delete_data->data;
GimpDataFactory *factory = private->factory;
GimpData *data = private->data;
GimpContainer *container;
GimpObject *new_active = NULL;
GError *error = NULL;
container = gimp_data_factory_get_container (factory);
if (delete_data->context &&
if (private->context &&
GIMP_OBJECT (data) ==
gimp_context_get_by_type (delete_data->context,
gimp_context_get_by_type (private->context,
gimp_container_get_children_type (container)))
{
new_active = gimp_container_get_neighbor_of (container,
......@@ -144,16 +144,16 @@ data_delete_dialog_response (GtkWidget *dialog,
if (! gimp_data_factory_data_delete (factory, data, TRUE, &error))
{
gimp_message (gimp_data_factory_get_gimp (factory),
G_OBJECT (delete_data->parent), GIMP_MESSAGE_ERROR,
G_OBJECT (private->parent), GIMP_MESSAGE_ERROR,
"%s", error->message);
g_clear_error (&error);
}
if (new_active)
gimp_context_set_by_type (delete_data->context,
gimp_context_set_by_type (private->context,
gimp_container_get_children_type (container),
new_active);
}
g_slice_free (DataDeleteDialog, delete_data);
g_slice_free (DataDeleteDialog, private);
}
......@@ -54,12 +54,13 @@ typedef struct
} FadeDialog;
/* local function prototypes */
static void fade_dialog_free (FadeDialog *private);
static void fade_dialog_response (GtkWidget *dialog,
gint response_id,
FadeDialog *private);
static void fade_dialog_context_changed (FadeDialog *private);
static void fade_dialog_free (FadeDialog *private);
/* public functions */
......@@ -88,8 +89,8 @@ fade_dialog_new (GimpImage *image,
if (! (undo && undo->applied_buffer))
return NULL;
item = GIMP_ITEM_UNDO (undo)->item;
drawable = GIMP_DRAWABLE (item);
item = GIMP_ITEM_UNDO (undo)->item;
drawable = GIMP_DRAWABLE (item);
private = g_slice_new0 (FadeDialog);
......@@ -108,7 +109,6 @@ fade_dialog_new (GimpImage *image,
title = g_strdup_printf (_("Fade %s"), gimp_object_get_name (undo));
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (drawable),
private->context,
title, "gimp-edit-fade",
......@@ -124,12 +124,13 @@ fade_dialog_new (GimpImage *image,
g_free (title);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
g_object_weak_ref (G_OBJECT (dialog),
(GWeakNotify) fade_dialog_free, private);
......@@ -174,6 +175,12 @@ fade_dialog_new (GimpImage *image,
/* private functions */
static void
fade_dialog_free (FadeDialog *private)
{
g_slice_free (FadeDialog, private);
}
static void
fade_dialog_response (GtkWidget *dialog,
gint response_id,
......@@ -206,9 +213,3 @@ fade_dialog_context_changed (FadeDialog *private)
gimp_image_flush (private->image);
}
}
static void
fade_dialog_free (FadeDialog *private)
{
g_slice_free (FadeDialog, private);
}
......@@ -42,7 +42,9 @@
#define RESPONSE_RESET 1
typedef struct
typedef struct _FillDialog FillDialog;
struct _FillDialog
{