[gimp] app: clean up GimpPrefsBox and the prefs dialog a bit
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: clean up GimpPrefsBox and the prefs dialog a bit
- Date: Wed, 9 May 2018 07:42:33 +0000 (UTC)
commit 384b116c156726c14c4ec21936092eb905a9243a
Author: Michael Natterer <mitch gimp org>
Date: Wed May 9 01:44:42 2018 +0200
app: clean up GimpPrefsBox and the prefs dialog a bit
Better API for getting properties of the current page, add missing
help IDs, fix the icon of the resolution calibrate dialog, ...
app/dialogs/preferences-dialog.c | 25 ++---
app/dialogs/resolution-calibrate-dialog.c | 12 +-
app/dialogs/resolution-calibrate-dialog.h | 4 +-
app/widgets/gimphelp-ids.h | 23 ++--
app/widgets/gimpprefsbox.c | 161 ++++++++++++++++++++---------
app/widgets/gimpprefsbox.h | 44 +++++----
6 files changed, 165 insertions(+), 104 deletions(-)
---
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 7178f90..ab8fb88 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -554,16 +554,16 @@ static void
prefs_resolution_calibrate_callback (GtkWidget *widget,
GtkWidget *entry)
{
- GtkWidget *dialog;
- GtkWidget *prefs_box;
- GtkWidget *image;
+ GtkWidget *dialog;
+ GtkWidget *prefs_box;
+ const gchar *icon_name;
dialog = gtk_widget_get_toplevel (entry);
prefs_box = g_object_get_data (G_OBJECT (dialog), "prefs-box");
- image = gimp_prefs_box_get_image (GIMP_PREFS_BOX (prefs_box));
+ icon_name = gimp_prefs_box_get_current_icon_name (GIMP_PREFS_BOX (prefs_box));
- resolution_calibrate_dialog (entry, gtk_image_get_pixbuf (GTK_IMAGE (image)));
+ resolution_calibrate_dialog (entry, icon_name);
}
static void
@@ -1023,16 +1023,11 @@ prefs_help_func (const gchar *help_id,
gpointer help_data)
{
GtkWidget *prefs_box;
- GtkWidget *notebook;
- GtkWidget *page;
- gint page_num;
prefs_box = g_object_get_data (G_OBJECT (help_data), "prefs-box");
- notebook = gimp_prefs_box_get_notebook (GIMP_PREFS_BOX (prefs_box));
- page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
- page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), page_num);
- help_id = g_object_get_data (G_OBJECT (page), "gimp-help-id");
+ help_id = gimp_prefs_box_get_current_help_id (GIMP_PREFS_BOX (prefs_box));
+
gimp_standard_help_func (help_id, NULL);
}
@@ -1457,7 +1452,7 @@ prefs_dialog_new (Gimp *gimp,
"gimp-prefs-import-export",
_("Image Import & Export"),
_("Image Import & Export"),
- GIMP_HELP_PREFS_DIALOG,
+ GIMP_HELP_PREFS_IMPORT_EXPORT,
NULL,
&top_iter);
@@ -1539,7 +1534,7 @@ prefs_dialog_new (Gimp *gimp,
"gimp-prefs-playground",
_("Experimental Playground"),
_("Playground"),
- GIMP_HELP_PREFS_DIALOG,
+ GIMP_HELP_PREFS_PLAYGROUND,
NULL,
&top_iter);
@@ -2943,7 +2938,7 @@ prefs_dialog_new (Gimp *gimp,
"gimp-prefs-image-windows-snapping",
_("Image Window Snapping Behavior"),
_("Snapping"),
- GIMP_HELP_PREFS_IMAGE_WINDOW_APPEARANCE,
+ GIMP_HELP_PREFS_IMAGE_WINDOW_SNAPPING,
&top_iter,
&child_iter);
diff --git a/app/dialogs/resolution-calibrate-dialog.c b/app/dialogs/resolution-calibrate-dialog.c
index 561da40..dcf7055 100644
--- a/app/dialogs/resolution-calibrate-dialog.c
+++ b/app/dialogs/resolution-calibrate-dialog.c
@@ -39,15 +39,15 @@ static gint ruler_height = 1;
/**
* resolution_calibrate_dialog:
* @resolution_entry: a #GimpSizeEntry to connect the dialog to
- * @pixbuf: an optional #GdkPixbuf for the upper left corner
+ * @icon_name: an optional icon-name for the upper left corner
*
* Displays a dialog that allows the user to interactively determine
* her monitor resolution. This dialog runs it's own GTK main loop and
* is connected to a #GimpSizeEntry handling the resolution to be set.
**/
void
-resolution_calibrate_dialog (GtkWidget *resolution_entry,
- GdkPixbuf *pixbuf)
+resolution_calibrate_dialog (GtkWidget *resolution_entry,
+ const gchar *icon_name)
{
GtkWidget *dialog;
GtkWidget *table;
@@ -61,7 +61,6 @@ resolution_calibrate_dialog (GtkWidget *resolution_entry,
g_return_if_fail (GIMP_IS_SIZE_ENTRY (resolution_entry));
g_return_if_fail (gtk_widget_get_realized (resolution_entry));
- g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
/* this dialog can only exist once */
if (calibrate_entry)
@@ -97,9 +96,10 @@ resolution_calibrate_dialog (GtkWidget *resolution_entry,
table, TRUE, TRUE, 0);
gtk_widget_show (table);
- if (pixbuf)
+ if (icon_name)
{
- GtkWidget *image = gtk_image_new_from_pixbuf (pixbuf);
+ GtkWidget *image = gtk_image_new_from_icon_name (icon_name,
+ GTK_ICON_SIZE_DIALOG);
gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 1,
GTK_SHRINK, GTK_SHRINK, 4, 4);
diff --git a/app/dialogs/resolution-calibrate-dialog.h b/app/dialogs/resolution-calibrate-dialog.h
index 4ac496c..21fd5af 100644
--- a/app/dialogs/resolution-calibrate-dialog.h
+++ b/app/dialogs/resolution-calibrate-dialog.h
@@ -19,8 +19,8 @@
#define __RESOLUTION_CALIBRATE_DIALOG_H__
-void resolution_calibrate_dialog (GtkWidget *resolution_entry,
- GdkPixbuf *pixbuf);
+void resolution_calibrate_dialog (GtkWidget *resolution_entry,
+ const gchar *icon_name);
#endif /* __RESOLUTION_CALIBRATE_DIALOG_H__ */
diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h
index 7f221bc..2c3971d 100644
--- a/app/widgets/gimphelp-ids.h
+++ b/app/widgets/gimphelp-ids.h
@@ -611,27 +611,28 @@
#define GIMP_HELP_ERRORS_SELECT_ALL "gimp-errors-select-all"
#define GIMP_HELP_PREFS_DIALOG "gimp-prefs-dialog"
-#define GIMP_HELP_PREFS_NEW_IMAGE "gimp-prefs-new-image"
+#define GIMP_HELP_PREFS_SYSTEM_RESOURCES "gimp-prefs-system-resources"
#define GIMP_HELP_PREFS_DEBUGGING "gimp-prefs-debugging"
+#define GIMP_HELP_PREFS_COLOR_MANAGEMENT "gimp-prefs-color-management"
+#define GIMP_HELP_PREFS_IMPORT_EXPORT "gimp-prefs-import-export"
+#define GIMP_HELP_PREFS_PLAYGROUND "gimp-prefs-playground"
+#define GIMP_HELP_PREFS_TOOL_OPTIONS "gimp-prefs-tool-options"
+#define GIMP_HELP_PREFS_NEW_IMAGE "gimp-prefs-new-image"
#define GIMP_HELP_PREFS_DEFAULT_GRID "gimp-prefs-default-grid"
#define GIMP_HELP_PREFS_INTERFACE "gimp-prefs-interface"
-#define GIMP_HELP_PREFS_HELP "gimp-prefs-help"
#define GIMP_HELP_PREFS_THEME "gimp-prefs-theme"
#define GIMP_HELP_PREFS_ICON_THEME "gimp-prefs-icon-theme"
-#define GIMP_HELP_PREFS_TOOL_OPTIONS "gimp-prefs-tool-options"
#define GIMP_HELP_PREFS_TOOLBOX "gimp-prefs-toolbox"
#define GIMP_HELP_PREFS_DIALOG_DEFAULTS "gimp-prefs-dialog-defaults"
-#define GIMP_HELP_PREFS_INPUT_DEVICES "gimp-prefs-input-devices"
-#define GIMP_HELP_PREFS_INPUT_CONTROLLERS "gimp-prefs-input-controllers"
+#define GIMP_HELP_PREFS_HELP "gimp-prefs-help"
+#define GIMP_HELP_PREFS_DISPLAY "gimp-prefs-display"
+#define GIMP_HELP_PREFS_WINDOW_MANAGEMENT "gimp-prefs-window-management"
#define GIMP_HELP_PREFS_IMAGE_WINDOW "gimp-prefs-image-window"
#define GIMP_HELP_PREFS_IMAGE_WINDOW_APPEARANCE "gimp-prefs-image-window-appearance"
#define GIMP_HELP_PREFS_IMAGE_WINDOW_TITLE "gimp-prefs-image-window-title"
-#define GIMP_HELP_PREFS_DISPLAY "gimp-prefs-display"
-#define GIMP_HELP_PREFS_MONITOR "gimp-prefs-monitor"
-#define GIMP_HELP_PREFS_COLOR_MANAGEMENT "gimp-prefs-color-management"
-#define GIMP_HELP_PREFS_WINDOW_MANAGEMENT "gimp-prefs-window-management"
-#define GIMP_HELP_PREFS_SESSION "gimp-prefs-session"
-#define GIMP_HELP_PREFS_SYSTEM_RESOURCES "gimp-prefs-system-resources"
+#define GIMP_HELP_PREFS_IMAGE_WINDOW_SNAPPING "gimp-prefs-image-window-snapping"
+#define GIMP_HELP_PREFS_INPUT_DEVICES "gimp-prefs-input-devices"
+#define GIMP_HELP_PREFS_INPUT_CONTROLLERS "gimp-prefs-input-controllers"
#define GIMP_HELP_PREFS_FOLDERS "gimp-prefs-folders"
#define GIMP_HELP_PREFS_FOLDERS_BRUSHES "gimp-prefs-folders-brushes"
#define GIMP_HELP_PREFS_FOLDERS_DYNAMICS "gimp-prefs-folders-dynamics"
diff --git a/app/widgets/gimpprefsbox.c b/app/widgets/gimpprefsbox.c
index 8327d8d..77f82d7 100644
--- a/app/widgets/gimpprefsbox.c
+++ b/app/widgets/gimpprefsbox.c
@@ -38,13 +38,13 @@ enum
COLUMN_TREE_ICON_NAME,
COLUMN_TREE_ICON_SIZE,
COLUMN_TREE_LABEL,
- COLUMN_NOTEBOOK_ICON_NAME,
- COLUMN_NOTEBOOK_ICON_SIZE,
- COLUMN_NOTEBOOK_LABEL,
+ COLUMN_PAGE_ICON_NAME,
+ COLUMN_PAGE_ICON_SIZE,
+ COLUMN_PAGE_TITLE,
+ COLUMN_PAGE_HELP_ID,
COLUMN_PAGE_INDEX
};
-typedef struct _GimpPrefsBoxPrivate GimpPrefsBoxPrivate;
struct _GimpPrefsBoxPrivate
{
@@ -55,16 +55,18 @@ struct _GimpPrefsBoxPrivate
GtkWidget *image;
gint tree_icon_size;
- gint notebook_icon_size;
+ gint page_icon_size;
gint page_index;
+ gchar *page_icon_name;
+ gchar *page_help_id;
};
-#define GET_PRIVATE(item) G_TYPE_INSTANCE_GET_PRIVATE (item, \
- GIMP_TYPE_PREFS_BOX, \
- GimpPrefsBoxPrivate)
+#define GET_PRIVATE(obj) (((GimpPrefsBox *) (obj))->priv)
+static void gimp_prefs_box_finalize (GObject *object);
+
static void gimp_prefs_box_tree_select_callback (GtkTreeSelection *sel,
GimpPrefsBox *box);
static void gimp_prefs_box_notebook_page_callback (GtkNotebook *notebook,
@@ -81,13 +83,17 @@ G_DEFINE_TYPE (GimpPrefsBox, gimp_prefs_box, GTK_TYPE_BOX)
static void
gimp_prefs_box_class_init (GimpPrefsBoxClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gimp_prefs_box_finalize;
+
g_type_class_add_private (klass, sizeof (GimpPrefsBoxPrivate));
}
static void
gimp_prefs_box_init (GimpPrefsBox *box)
{
- GimpPrefsBoxPrivate *private = GET_PRIVATE (box);
+ GimpPrefsBoxPrivate *private;
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
GtkTreeSelection *sel;
@@ -96,8 +102,14 @@ gimp_prefs_box_init (GimpPrefsBox *box)
GtkWidget *ebox;
GtkWidget *vbox;
- private->tree_icon_size = GTK_ICON_SIZE_BUTTON;
- private->notebook_icon_size = GTK_ICON_SIZE_DIALOG;
+ box->priv = G_TYPE_INSTANCE_GET_PRIVATE (box,
+ GIMP_TYPE_PREFS_BOX,
+ GimpPrefsBoxPrivate);
+
+ private = box->priv;
+
+ private->tree_icon_size = GTK_ICON_SIZE_BUTTON;
+ private->page_icon_size = GTK_ICON_SIZE_DIALOG;
gtk_orientable_set_orientation (GTK_ORIENTABLE (box),
GTK_ORIENTATION_HORIZONTAL);
@@ -114,13 +126,14 @@ gimp_prefs_box_init (GimpPrefsBox *box)
gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
- private->store = gtk_tree_store_new (7,
+ private->store = gtk_tree_store_new (8,
G_TYPE_STRING,
G_TYPE_INT,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_INT,
G_TYPE_STRING,
+ G_TYPE_STRING,
G_TYPE_INT);
private->tree_view =
gtk_tree_view_new_with_model (GTK_TREE_MODEL (private->store));
@@ -195,41 +208,52 @@ gimp_prefs_box_init (GimpPrefsBox *box)
}
static void
+gimp_prefs_box_finalize (GObject *object)
+{
+ GimpPrefsBoxPrivate *private = GET_PRIVATE (object);
+
+ g_clear_pointer (&private->page_icon_name, g_free);
+ g_clear_pointer (&private->page_help_id, g_free);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
gimp_prefs_box_tree_select_callback (GtkTreeSelection *sel,
GimpPrefsBox *box)
{
GimpPrefsBoxPrivate *private = GET_PRIVATE (box);
GtkTreeModel *model;
GtkTreeIter iter;
- gchar *notebook_text;
- gchar *notebook_icon_name;
- gint notebook_icon_size;
- gint notebook_index;
+ gchar *page_title;
+ gchar *page_icon_name;
+ gint page_icon_size;
+ gint page_index;
if (! gtk_tree_selection_get_selected (sel, &model, &iter))
return;
gtk_tree_model_get (model, &iter,
- COLUMN_NOTEBOOK_ICON_NAME, ¬ebook_icon_name,
- COLUMN_NOTEBOOK_ICON_SIZE, ¬ebook_icon_size,
- COLUMN_NOTEBOOK_LABEL, ¬ebook_text,
- COLUMN_PAGE_INDEX, ¬ebook_index,
+ COLUMN_PAGE_ICON_NAME, &page_icon_name,
+ COLUMN_PAGE_ICON_SIZE, &page_icon_size,
+ COLUMN_PAGE_TITLE, &page_title,
+ COLUMN_PAGE_INDEX, &page_index,
-1);
- gtk_label_set_text (GTK_LABEL (private->label), notebook_text);
- g_free (notebook_text);
+ gtk_label_set_text (GTK_LABEL (private->label), page_title);
+ g_free (page_title);
gtk_image_set_from_icon_name (GTK_IMAGE (private->image),
- notebook_icon_name,
- notebook_icon_size);
- g_free (notebook_icon_name);
+ page_icon_name,
+ page_icon_size);
+ g_free (page_icon_name);
g_signal_handlers_block_by_func (private->notebook,
gimp_prefs_box_notebook_page_callback,
sel);
gtk_notebook_set_current_page (GTK_NOTEBOOK (private->notebook),
- notebook_index);
+ page_index);
g_signal_handlers_unblock_by_func (private->notebook,
gimp_prefs_box_notebook_page_callback,
@@ -310,7 +334,7 @@ gimp_prefs_box_new (void)
GtkWidget *
gimp_prefs_box_add_page (GimpPrefsBox *box,
const gchar *icon_name,
- const gchar *notebook_label,
+ const gchar *page_title,
const gchar *tree_label,
const gchar *help_id,
GtkTreeIter *parent,
@@ -349,18 +373,71 @@ gimp_prefs_box_add_page (GimpPrefsBox *box,
gtk_tree_store_append (private->store, iter, parent);
gtk_tree_store_set (private->store, iter,
- COLUMN_TREE_ICON_NAME, icon_name,
- COLUMN_TREE_ICON_SIZE, private->tree_icon_size,
- COLUMN_TREE_LABEL, tree_label,
- COLUMN_NOTEBOOK_ICON_NAME, icon_name,
- COLUMN_NOTEBOOK_ICON_SIZE, private->notebook_icon_size,
- COLUMN_NOTEBOOK_LABEL , notebook_label,
- COLUMN_PAGE_INDEX, private->page_index++,
+ COLUMN_TREE_ICON_NAME, icon_name,
+ COLUMN_TREE_ICON_SIZE, private->tree_icon_size,
+ COLUMN_TREE_LABEL, tree_label,
+ COLUMN_PAGE_ICON_NAME, icon_name,
+ COLUMN_PAGE_ICON_SIZE, private->page_icon_size,
+ COLUMN_PAGE_TITLE , page_title,
+ COLUMN_PAGE_HELP_ID, help_id,
+ COLUMN_PAGE_INDEX, private->page_index++,
-1);
return vbox;
}
+const gchar *
+gimp_prefs_box_get_current_icon_name (GimpPrefsBox *box)
+{
+ GimpPrefsBoxPrivate *private = GET_PRIVATE (box);
+ GtkTreeSelection *sel;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ g_return_val_if_fail (GIMP_IS_PREFS_BOX (box), NULL);
+
+ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (private->tree_view));
+
+ if (gtk_tree_selection_get_selected (sel, &model, &iter))
+ {
+ g_clear_pointer (&private->page_icon_name, g_free);
+
+ gtk_tree_model_get (model, &iter,
+ COLUMN_PAGE_ICON_NAME, &private->page_icon_name,
+ -1);
+
+ return private->page_icon_name;
+ }
+
+ return NULL;
+}
+
+const gchar *
+gimp_prefs_box_get_current_help_id (GimpPrefsBox *box)
+{
+ GimpPrefsBoxPrivate *private = GET_PRIVATE (box);
+ GtkTreeSelection *sel;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ g_return_val_if_fail (GIMP_IS_PREFS_BOX (box), NULL);
+
+ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (private->tree_view));
+
+ if (gtk_tree_selection_get_selected (sel, &model, &iter))
+ {
+ g_clear_pointer (&private->page_help_id, g_free);
+
+ gtk_tree_model_get (model, &iter,
+ COLUMN_PAGE_HELP_ID, &private->page_help_id,
+ -1);
+
+ return private->page_help_id;
+ }
+
+ return NULL;
+}
+
void
gimp_prefs_box_set_page_scrollable (GimpPrefsBox *box,
GtkWidget *page,
@@ -429,19 +506,3 @@ gimp_prefs_box_get_tree_view (GimpPrefsBox *box)
return GET_PRIVATE (box)->tree_view;
}
-
-GtkWidget *
-gimp_prefs_box_get_notebook (GimpPrefsBox *box)
-{
- g_return_val_if_fail (GIMP_IS_PREFS_BOX (box), NULL);
-
- return GET_PRIVATE (box)->notebook;
-}
-
-GtkWidget *
-gimp_prefs_box_get_image (GimpPrefsBox *box)
-{
- g_return_val_if_fail (GIMP_IS_PREFS_BOX (box), NULL);
-
- return GET_PRIVATE (box)->image;
-}
diff --git a/app/widgets/gimpprefsbox.h b/app/widgets/gimpprefsbox.h
index b6e1ebb..144ea7e 100644
--- a/app/widgets/gimpprefsbox.h
+++ b/app/widgets/gimpprefsbox.h
@@ -30,11 +30,14 @@
#define GIMP_PREFS_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PREFS_BOX,
GimpPrefsBoxClass))
-typedef struct _GimpPrefsBoxClass GimpPrefsBoxClass;
+typedef struct _GimpPrefsBoxPrivate GimpPrefsBoxPrivate;
+typedef struct _GimpPrefsBoxClass GimpPrefsBoxClass;
struct _GimpPrefsBox
{
- GtkBox parent_instance;
+ GtkBox parent_instance;
+
+ GimpPrefsBoxPrivate *priv;
};
struct _GimpPrefsBoxClass
@@ -43,28 +46,29 @@ struct _GimpPrefsBoxClass
};
-GType gimp_prefs_box_get_type (void) G_GNUC_CONST;
+GType gimp_prefs_box_get_type (void) G_GNUC_CONST;
+
+GtkWidget * gimp_prefs_box_new (void);
-GtkWidget * gimp_prefs_box_new (void);
+GtkWidget * gimp_prefs_box_add_page (GimpPrefsBox *box,
+ const gchar *icon_name,
+ const gchar *notebook_label,
+ const gchar *tree_label,
+ const gchar *help_id,
+ GtkTreeIter *parent,
+ GtkTreeIter *iter);
-GtkWidget * gimp_prefs_box_add_page (GimpPrefsBox *box,
- const gchar *icon_name,
- const gchar *notebook_label,
- const gchar *tree_label,
- const gchar *help_id,
- GtkTreeIter *parent,
- GtkTreeIter *iter);
+const gchar * gimp_prefs_box_get_current_icon_name (GimpPrefsBox *box);
+const gchar * gimp_prefs_box_get_current_help_id (GimpPrefsBox *box);
-void gimp_prefs_box_set_page_scrollable (GimpPrefsBox *box,
- GtkWidget *page,
- gboolean scrollable);
-GtkWidget * gimp_prefs_box_set_page_resettable (GimpPrefsBox *box,
- GtkWidget *page,
- const gchar *label);
+void gimp_prefs_box_set_page_scrollable (GimpPrefsBox *box,
+ GtkWidget *page,
+ gboolean scrollable);
+GtkWidget * gimp_prefs_box_set_page_resettable (GimpPrefsBox *box,
+ GtkWidget *page,
+ const gchar *label);
-GtkWidget * gimp_prefs_box_get_tree_view (GimpPrefsBox *box);
-GtkWidget * gimp_prefs_box_get_notebook (GimpPrefsBox *box);
-GtkWidget * gimp_prefs_box_get_image (GimpPrefsBox *box);
+GtkWidget * gimp_prefs_box_get_tree_view (GimpPrefsBox *box);
#endif /* __GIMP_PREFS_BOX_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]