Commit 718ca7c7 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/widgets/Makefile.am app/widgets/widgets-types.h new widget derived

2007-06-27  Sven Neumann  <sven@gimp.org>

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpimagecommenteditor.[ch]: new widget derived from
	GimpImageParasiteView. Basically the code that used to live in
	image-properties-dialog.c.

	* app/dialogs/image-properties-dialog.c: use the comment editor.

svn path=/trunk/; revision=22846
parent 02b3fcea
2007-06-27 Sven Neumann <sven@gimp.org>
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpimagecommenteditor.[ch]: new widget derived from
GimpImageParasiteView. Basically the code that used to live in
image-properties-dialog.c.
* app/dialogs/image-properties-dialog.c: use the comment editor.
2007-06-27 Sven Neumann <sven@gimp.org>
* app/dialogs/image-properties-dialog.c: allow to edit the comment.
......@@ -25,7 +25,6 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "dialogs-types.h"
......@@ -34,6 +33,7 @@
#include "core/gimpimage.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpimagecommenteditor.h"
#include "widgets/gimpimagepropview.h"
#include "widgets/gimpimageprofileview.h"
#include "widgets/gimpviewabledialog.h"
......@@ -43,15 +43,6 @@
#include "gimp-intl.h"
static GtkWidget * image_comment_view_new (GimpImage *image);
static void image_comment_view_update (GimpImageParasiteView *view,
GtkTextBuffer *buffer);
static void image_comment_buffer_changed (GtkTextBuffer *buffer,
GimpImageParasiteView *view);
/* public functions */
GtkWidget *
image_properties_dialog_new (GimpImage *image,
GimpContext *context,
......@@ -78,8 +69,6 @@ image_properties_dialog_new (GimpImage *image,
NULL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy),
NULL);
......@@ -100,7 +89,7 @@ image_properties_dialog_new (GimpImage *image,
view, gtk_label_new (_("Color Profile")));
gtk_widget_show (view);
view = image_comment_view_new (image);
view = gimp_image_comment_editor_new (image);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
view, gtk_label_new (_("Comment")));
gtk_widget_show (view);
......@@ -109,126 +98,3 @@ image_properties_dialog_new (GimpImage *image,
return dialog;
}
static GtkWidget *
image_comment_view_new (GimpImage *image)
{
GtkWidget *view;
GtkWidget *scrolled_window;
GtkWidget *text_view;
GtkTextBuffer *buffer;
view = gimp_image_parasite_view_new (image, "gimp-comment");
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 2);
gtk_container_add (GTK_CONTAINER (view), scrolled_window);
gtk_widget_show (scrolled_window);
text_view = gtk_text_view_new ();
gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), TRUE);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (text_view), 6);
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text_view), 6);
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (text_view), 6);
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
gtk_widget_show (text_view);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
g_signal_connect (view, "update",
G_CALLBACK (image_comment_view_update),
buffer);
g_signal_connect (buffer, "changed",
G_CALLBACK (image_comment_buffer_changed),
view);
image_comment_view_update (GIMP_IMAGE_PARASITE_VIEW (view), buffer);
return view;
}
static void
image_comment_view_update (GimpImageParasiteView *view,
GtkTextBuffer *buffer)
{
GimpImage *image = gimp_image_parasite_view_get_image (view);
const GimpParasite *parasite;
g_signal_handlers_block_by_func (buffer,
image_comment_buffer_changed, image);
parasite = gimp_image_parasite_view_get_parasite (view);
if (parasite)
{
gchar *text = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
if (! g_utf8_validate (text, -1, NULL))
{
gchar *tmp = gimp_any_to_utf8 (text, -1, NULL);
g_free (text);
text = tmp;
}
gtk_text_buffer_set_text (buffer, text, -1);
g_free (text);
}
else
{
gtk_text_buffer_set_text (buffer, "", 0);
}
g_signal_handlers_unblock_by_func (buffer,
image_comment_buffer_changed, image);
}
static void
image_comment_buffer_changed (GtkTextBuffer *buffer,
GimpImageParasiteView *view)
{
GimpImage *image = gimp_image_parasite_view_get_image (view);
gchar *text;
gint len;
GtkTextIter start;
GtkTextIter end;
g_signal_handlers_block_by_func (view,
image_comment_view_update, buffer);
gtk_text_buffer_get_bounds (buffer, &start, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
len = text ? strlen (text) : 0;
if (len > 0)
{
GimpParasite *parasite;
parasite = gimp_parasite_new ("gimp-comment",
GIMP_PARASITE_PERSISTENT,
len + 1, text);
gimp_image_parasite_attach (image, parasite);
gimp_parasite_free (parasite);
}
else
{
gimp_image_parasite_detach (image, "gimp-comment");
}
g_free (text);
g_signal_handlers_unblock_by_func (view,
image_comment_view_update, buffer);
}
......@@ -169,6 +169,8 @@ libappwidgets_a_sources = \
gimphistogramview.h \
gimpimagedock.c \
gimpimagedock.h \
gimpimagecommenteditor.c \
gimpimagecommenteditor.h \
gimpimageeditor.c \
gimpimageeditor.h \
gimpimageparasiteview.c \
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpImageCommentEditor
* Copyright (C) 2007 Sven Neumann <sven@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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "core/gimpimage.h"
#include "gimpimagecommenteditor.h"
#define GIMP_IMAGE_COMMENT_PARASITE "gimp-comment"
static void gimp_image_comment_editor_update (GimpImageParasiteView *view);
static void gimp_image_comment_editor_buffer_changed (GtkTextBuffer *buffer,
GimpImageCommentEditor *editor);
G_DEFINE_TYPE (GimpImageCommentEditor,
gimp_image_comment_editor, GIMP_TYPE_IMAGE_PARASITE_VIEW)
static void
gimp_image_comment_editor_class_init (GimpImageCommentEditorClass *klass)
{
GimpImageParasiteViewClass *view_class;
view_class = GIMP_IMAGE_PARASITE_VIEW_CLASS (klass);
view_class->update = gimp_image_comment_editor_update;
}
static void
gimp_image_comment_editor_init (GimpImageCommentEditor *editor)
{
GtkWidget *scrolled_window;
GtkWidget *text_view;
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 2);
gtk_container_add (GTK_CONTAINER (editor), scrolled_window);
gtk_widget_show (scrolled_window);
text_view = gtk_text_view_new ();
gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), TRUE);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (text_view), 6);
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text_view), 6);
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (text_view), 6);
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
gtk_widget_show (text_view);
editor->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
g_signal_connect (editor->buffer, "changed",
G_CALLBACK (gimp_image_comment_editor_buffer_changed),
editor);
}
/* public functions */
GtkWidget *
gimp_image_comment_editor_new (GimpImage *image)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
return g_object_new (GIMP_TYPE_IMAGE_COMMENT_EDITOR,
"image", image,
"parasite", GIMP_IMAGE_COMMENT_PARASITE,
NULL);
}
/* private functions */
static void
gimp_image_comment_editor_update (GimpImageParasiteView *view)
{
GimpImageCommentEditor *editor = GIMP_IMAGE_COMMENT_EDITOR (view);
const GimpParasite *parasite;
if (editor->recursing)
return;
g_signal_handlers_block_by_func (editor->buffer,
gimp_image_comment_editor_buffer_changed,
editor);
parasite = gimp_image_parasite_view_get_parasite (view);
if (parasite)
{
gchar *text = g_strndup (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
if (! g_utf8_validate (text, -1, NULL))
{
gchar *tmp = gimp_any_to_utf8 (text, -1, NULL);
g_free (text);
text = tmp;
}
gtk_text_buffer_set_text (editor->buffer, text, -1);
g_free (text);
}
else
{
gtk_text_buffer_set_text (editor->buffer, "", 0);
}
g_signal_handlers_unblock_by_func (editor->buffer,
gimp_image_comment_editor_buffer_changed,
editor);
}
static void
gimp_image_comment_editor_buffer_changed (GtkTextBuffer *buffer,
GimpImageCommentEditor *editor)
{
GimpImage *image;
gchar *text;
gint len;
GtkTextIter start;
GtkTextIter end;
image =
gimp_image_parasite_view_get_image (GIMP_IMAGE_PARASITE_VIEW (editor));
gtk_text_buffer_get_bounds (buffer, &start, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
len = text ? strlen (text) : 0;
editor->recursing = TRUE;
if (len > 0)
{
GimpParasite *parasite;
parasite = gimp_parasite_new (GIMP_IMAGE_COMMENT_PARASITE,
GIMP_PARASITE_PERSISTENT,
len + 1, text);
gimp_image_parasite_attach (image, parasite);
gimp_parasite_free (parasite);
}
else
{
gimp_image_parasite_detach (image, GIMP_IMAGE_COMMENT_PARASITE);
}
editor->recursing = FALSE;
g_free (text);
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpImageCommentEditor
* Copyright (C) 2007 Sven Neumann <sven@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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_IMAGE_COMMENT_EDITOR_H__
#define __GIMP_IMAGE_COMMENT_EDITOR_H__
#include "gimpimageparasiteview.h"
#define GIMP_TYPE_IMAGE_COMMENT_EDITOR (gimp_image_comment_editor_get_type ())
#define GIMP_IMAGE_COMMENT_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_IMAGE_COMMENT_EDITOR, GimpImageCommentEditor))
#define GIMP_IMAGE_COMMENT_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_IMAGE_COMMENT_EDITOR, GimpImageCommentEditorClass))
#define GIMP_IS_IMAGE_COMMENT_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_IMAGE_COMMENT_EDITOR))
#define GIMP_IS_IMAGE_COMMENT_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_IMAGE_COMMENT_EDITOR))
#define GIMP_IMAGE_COMMENT_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_IMAGE_COMMENT_EDITOR, GimpImageCommentEditorClass))
typedef struct _GimpImageCommentEditorClass GimpImageCommentEditorClass;
struct _GimpImageCommentEditor
{
GimpImageParasiteView parent_instance;
GtkTextBuffer *buffer;
gboolean recursing;
};
struct _GimpImageCommentEditorClass
{
GimpImageParasiteViewClass parent_class;
};
GType gimp_image_comment_editor_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_image_comment_editor_new (GimpImage *image);
#endif /* __GIMP_IMAGE_COMMENT_EDITOR_H__ */
......@@ -164,6 +164,7 @@ typedef struct _GimpFileProcView GimpFileProcView;
typedef struct _GimpGridEditor GimpGridEditor;
typedef struct _GimpHistogramBox GimpHistogramBox;
typedef struct _GimpHistogramView GimpHistogramView;
typedef struct _GimpImageCommentEditor GimpImageCommentEditor;
typedef struct _GimpImageParasiteView GimpImageParasiteView;
typedef struct _GimpImagePropView GimpImagePropView;
typedef struct _GimpImageProfileView GimpImageProfileView;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment