summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Zwartepoorte <jeroen@xs4all.nl>2003-04-14 08:12:30 +0000
committerJeroen Zwartepoorte <jeroen@src.gnome.org>2003-04-14 08:12:30 +0000
commit229985647d97795699005aa64ebefba74a344360 (patch)
treea55624bbc83e63d466332ebc1f4c908868be87e7
parent3b1978f0354330b0dc395482fdaa1f2d0b17e9e1 (diff)
downloadgedit-229985647d97795699005aa64ebefba74a344360.tar.gz
Added new viewer control for nautilus with syntax highlighting thanks to
2003-04-14 Jeroen Zwartepoorte <jeroen@xs4all.nl> * Makefile.am: * configure.in: * data/GNOME_Gedit.server.in: * viewer/.cvsignore: * viewer/Makefile.am: * viewer/gedit-factory.c: (gedit_factory): * viewer/gedit-persist-stream.c: (impl_save), (impl_load), (impl_get_content_types), (gedit_persist_stream_new): * viewer/gedit-persist-stream.h: * viewer/gedit-viewer-ui.xml: * viewer/gedit-viewer.c: (copy_cb), (activate_cb), (gedit_viewer_new): * viewer/gedit-viewer.h: Added new viewer control for nautilus with syntax highlighting thanks to gtksourceview. Gedit now depends on gtksourceview (toward-gedit-integration branch). This viewer will eventually replace the standard text viewer in nautilus.
-rw-r--r--ChangeLog31
-rw-r--r--Makefile.am2
-rw-r--r--configure.in4
-rw-r--r--data/GNOME_Gedit.server.in49
-rw-r--r--gedit/ChangeLog13
-rw-r--r--gedit/Makefile.am4
-rw-r--r--viewer/.cvsignore5
-rw-r--r--viewer/Makefile.am34
-rw-r--r--viewer/gedit-factory.c54
-rw-r--r--viewer/gedit-persist-stream.c187
-rw-r--r--viewer/gedit-persist-stream.h36
-rw-r--r--viewer/gedit-viewer-ui.xml11
-rw-r--r--viewer/gedit-viewer.c140
-rw-r--r--viewer/gedit-viewer.h35
14 files changed, 579 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 41db60a1e..a11026936 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2003-04-14 Jeroen Zwartepoorte <jeroen@xs4all.nl>
+
+ * Makefile.am:
+ * configure.in:
+ * data/GNOME_Gedit.server.in:
+ * viewer/.cvsignore:
+ * viewer/Makefile.am:
+ * viewer/gedit-factory.c: (gedit_factory):
+ * viewer/gedit-persist-stream.c: (impl_save), (impl_load),
+ (impl_get_content_types), (gedit_persist_stream_new):
+ * viewer/gedit-persist-stream.h:
+ * viewer/gedit-viewer-ui.xml:
+ * viewer/gedit-viewer.c: (copy_cb), (activate_cb),
+ (gedit_viewer_new):
+ * viewer/gedit-viewer.h:
+
+ Added new viewer control for nautilus with syntax highlighting thanks
+ to gtksourceview. Gedit now depends on gtksourceview
+ (toward-gedit-integration branch). This viewer will eventually replace
+ the standard text viewer in nautilus.
+
2003-04-14 Mike Lei <mike.lei@sun.com>
* configure.in: Added Makefile support for de es fr it sv
@@ -747,7 +768,7 @@
* Makefile.am: removed unused code
-2002-02-14 Tõivo Leedjärv <leedjarv@interest.ee>
+2002-02-14 Tõivo Leedjärv <leedjarv@interest.ee>
* configure.in: Added et to ALL_LINGUAS.
@@ -962,7 +983,7 @@
* configure.in: bump version to 1.107.0
-2001-12-03 Carlos Perelló Marín <carlos@gnome-db.org>
+2001-12-03 Carlos Perelló Marín <carlos@gnome-db.org>
* configure.in: Reverted my change about GETTEXT_PACKAGE. We should
use the "standar" name (gedit-2.0 instead of gedit-2).
@@ -976,11 +997,11 @@
* configure.in: cleaned following the suggestions of the gnome2
porting foc. Now libgnomeprintui-2.0 is required
-2001-11-21 Carlos Perelló Marín <carlos@gnome-db.org>
+2001-11-21 Carlos Perelló Marín <carlos@gnome-db.org>
* configure.in: Changed GETTEXT_PACKAGE from gedit-2.0 to gedit-2
-2001-11-16 Carlos Perelló Marín <carlos@gnome-db.org>
+2001-11-16 Carlos Perelló Marín <carlos@gnome-db.org>
* Makefile.am, configure.in: Migrated from xml-i18n-tools to intltool
and added support to AM_GLIB_GNU_GETTEXT
@@ -990,6 +1011,6 @@
* Started the port to GNOME 2.0
-2001-11-16 Carlos Perelló Marín <carlos@gnome-db.org>
+2001-11-16 Carlos Perelló Marín <carlos@gnome-db.org>
* ChangeLog: rolled over to ChangeLog-20011116
diff --git a/Makefile.am b/Makefile.am
index 0baf0528c..0094db7b2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = gedit pixmaps po help data plugins
+SUBDIRS = gedit pixmaps po help data plugins viewer
EXTRA_DIST = BUGS \
ChangeLog \
diff --git a/configure.in b/configure.in
index d3c15630c..fdf2707c6 100644
--- a/configure.in
+++ b/configure.in
@@ -72,7 +72,8 @@ dnl Start of pkg-config checks
dnl
PKG_CHECK_MODULES(GEDIT, libgnomeui-2.0 >= 2.2.0 libglade-2.0 >= 2.0.0
libgnomeprintui-2.2 >= 2.2.0
- eel-2.0 >= 2.2.0)
+ eel-2.0 >= 2.2.0
+ gtksourceview-1.0 >= 0.1.0)
GEDIT_LIBS="${GEDIT_LIBS}"
AC_SUBST(GEDIT_LIBS)
AC_SUBST(GEDIT_CFLAGS)
@@ -206,6 +207,7 @@ plugins/spell/Makefile
plugins/docinfo/Makefile
plugins/sample/Makefile
plugins/time/Makefile
+viewer/Makefile
help/Makefile
help/C/Makefile
help/de/Makefile
diff --git a/data/GNOME_Gedit.server.in b/data/GNOME_Gedit.server.in
index deeaa682b..951e1178a 100644
--- a/data/GNOME_Gedit.server.in
+++ b/data/GNOME_Gedit.server.in
@@ -1,18 +1,41 @@
<oaf_info>
+ <oaf_server iid="OAFIID:GNOME_Gedit_Factory" type="exe" location="gedit">
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/ObjectFactory:1.0"/>
+ </oaf_attribute>
+ <oaf_attribute name="name" type="string" _value="gedit automation factory"/>
+ </oaf_server>
-<oaf_server iid="OAFIID:GNOME_Gedit_Factory" type="exe" location="gedit">
- <oaf_attribute name="repo_ids" type="stringv">
- <item value="IDL:GNOME/ObjectFactory:1.0"/>
- </oaf_attribute>
- <oaf_attribute name="name" type="string" _value="gedit automation factory"/>
-</oaf_server>
+ <oaf_server iid="OAFIID:GNOME_Gedit_Application" type="factory" location="OAFIID:GNOME_Gedit_Factory">
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:Bonobo/Unknown:1.0"/>
+ <item value="IDL:GNOME/Gedit/Application:1.0"/>
+ </oaf_attribute>
+ <oaf_attribute name="name" type="string" _value="gedit application"/>
+ </oaf_server>
-<oaf_server iid="OAFIID:GNOME_Gedit_Application" type="factory" location="OAFIID:GNOME_Gedit_Factory">
- <oaf_attribute name="repo_ids" type="stringv">
- <item value="IDL:Bonobo/Unknown:1.0"/>
- <item value="IDL:GNOME/Gedit/Application:1.0"/>
- </oaf_attribute>
- <oaf_attribute name="name" type="string" _value="gedit application"/>
-</oaf_server>
+ <oaf_server iid="OAFIID:GNOME_Gedit_ViewerFactory"
+ type="shlib" location="libgedit-control.so">
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:Bonobo/GenericFactory:1.0"/>
+ </oaf_attribute>
+ <oaf_attribute name="name" type="string" _value="Gedit viewer factory"/>
+ <oaf_attribute name="description" type="string" _value="Gedit viewer factory"/>
+ </oaf_server>
+ <oaf_server iid="OAFIID:GNOME_Gedit_Control" type="factory"
+ location="OAFIID:GNOME_Gedit_ViewerFactory">
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:Bonobo/Unknown:1.0" />
+ <item value="IDL:Bonobo/Control:1.0" />
+ <item value="IDL:Bonobo/PersistStream:1.0"/>
+ <item value="IDL:Bonobo/Persist:1.0"/>
+ </oaf_attribute>
+ <oaf_attribute name="bonobo:supported_mime_types" type="stringv">
+ <item value="text/*"/>
+ </oaf_attribute>
+ <oaf_attribute name="name" type="string" _value="Gedit View" />
+ <oaf_attribute name="description" type="string" _value="Gedit View." />
+ <oaf_attribute name="nautilus:view_as_name" type="string" _value="Source"/>
+ </oaf_server>
</oaf_info>
diff --git a/gedit/ChangeLog b/gedit/ChangeLog
index b3e465989..6dbe24437 100644
--- a/gedit/ChangeLog
+++ b/gedit/ChangeLog
@@ -1,3 +1,8 @@
+2003-04-14 Jeroen Zwartepoorte <jeroen@xs4all.nl>
+
+ * Makefile.am: Create libgedit.la instead of libgedit.a because
+ the viewer uses .la as well and linking with a .a file is not portable.
+
2003-04-09 Paolo Maggi <paolo.maggi@polito.it>
* Makefile.am: create a non-installed libgedit.a lib (it will be used
@@ -1216,7 +1221,7 @@
2002-05-27 James Willcox <jwillcox@cs.indiana.edu>
* gnome-recent-model.c (gnome_recent_model_delete_from_list):
- Fixed memory leak (Thanks to Gustavo Giráldez for the patch)
+ Fixed memory leak (Thanks to Gustavo Giráldez for the patch)
2002-05-23 Paolo Maggi <maggi@athena.polito.it>
@@ -1544,7 +1549,7 @@
2002-03-12 Kjartan Maraas <kmaraas@gnome.org>
- * gedit-utils.c: Fix some strings to be consistent wrt «.» and throw
+ * gedit-utils.c: Fix some strings to be consistent wrt «.» and throw
in some spaces where needed.
2002-03-07 Paolo Maggi <maggi@athena.polito.it>
@@ -2564,7 +2569,7 @@
* gedit2.c (gedit_load_file_list): now calls gedit_file_open_from_stdin (NULL)
-2001-11-16 Carlos Perelló Marín <carlos@gnome-db.org>
+2001-11-16 Carlos Perelló Marín <carlos@gnome-db.org>
* gedit2.c: Added support to AM_GLIB_GNU_GETTEXT
* gedit-recent.c, gedit-utils.c, gedit-document.c, gedit-file.c:
@@ -2574,6 +2579,6 @@
* Started the port to GNOME 2.0
-2001-11-16 Carlos Perelló Marín <carlos@gnome-db.org>
+2001-11-16 Carlos Perelló Marín <carlos@gnome-db.org>
* ChangeLog: rolled over to ChangeLog-20011116.
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index bfd7bb9d5..c7506fa83 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -21,7 +21,7 @@ INCLUDES = \
-DGDK_PIXBUF_DISABLE_DEPRECATED \
-DGNOME_DISABLE_DEPRECATED
-noinst_LIBRARIES = libgedit.a
+noinst_LTLIBRARIES = libgedit.la
gedit_LDFLAGS = -export-dynamic
@@ -111,7 +111,7 @@ gedit_SOURCES = \
$(APP_H_FILES) \
$(BUILT_SOURCES)
-libgedit_a_SOURCES = \
+libgedit_la_SOURCES = \
gedit-debug.c \
gedit-convert.c \
gedit-encodings.c \
diff --git a/viewer/.cvsignore b/viewer/.cvsignore
new file mode 100644
index 000000000..465f8c1eb
--- /dev/null
+++ b/viewer/.cvsignore
@@ -0,0 +1,5 @@
+.deps
+Makefile
+Makefile.in
+.libs
+core.*
diff --git a/viewer/Makefile.am b/viewer/Makefile.am
new file mode 100644
index 000000000..fbdb75710
--- /dev/null
+++ b/viewer/Makefile.am
@@ -0,0 +1,34 @@
+## Process this file with automake to produce Makefile.in
+
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -I$(top_srcdir)/gedit \
+ $(GEDIT_CFLAGS) \
+ -DDATADIR=\""$(datadir)"\" \
+ -DGNOME_ICONDIR=\""$(datadir)/pixmaps"\" \
+ -DGEDIT_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ -DGEDIT_UI_DIR=\""$(datadir)/gedit-2/ui/"\" \
+ -DGEDIT_PLUGINDIR=\""$(libdir)/gedit-2/plugins"\" \
+ -DGEDIT_GLADEDIR=\""$(datadir)/gedit-2/glade/"\" \
+ -DG_DISABLE_DEPRECATED \
+ -DGDK_DISABLE_DEPRECATED \
+ -DGTK_DISABLE_DEPRECATED \
+ -DGDK_PIXBUF_DISABLE_DEPRECATED \
+ -DGNOME_DISABLE_DEPRECATED
+
+lib_LTLIBRARIES = libgedit-control.la
+
+libgedit_control_la_SOURCES = \
+ gedit-factory.c \
+ gedit-viewer.c \
+ gedit-persist-stream.c
+
+libgedit_control_la_LIBADD = \
+ ../gedit/libgedit.la \
+ $(GEDIT_LIBS)
+
+uidir = $(datadir)/gnome-2.0/ui
+ui_DATA = gedit-viewer-ui.xml
+
+EXTRA_DIST = $(ui_DATA)
diff --git a/viewer/gedit-factory.c b/viewer/gedit-factory.c
new file mode 100644
index 000000000..f917c4a53
--- /dev/null
+++ b/viewer/gedit-factory.c
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-factory.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2003 Jeroen Zwartepoorte
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <libbonobo.h>
+#include <bonobo/bonobo-shlib-factory.h>
+#include <bonobo-activation/bonobo-activation.h>
+#include <libgnomevfs/gnome-vfs-init.h>
+#include "gedit-viewer.h"
+
+static BonoboObject *
+gedit_factory (BonoboGenericFactory *factory,
+ const char *component_id,
+ gpointer closure)
+{
+ BonoboControl *control = NULL;
+
+ if (!gnome_vfs_initialized ())
+ if (!gnome_vfs_init ())
+ return NULL;
+
+ if (!strcmp (component_id, "OAFIID:GNOME_Gedit_Control"))
+ control = gedit_viewer_new ();
+
+ return BONOBO_OBJECT (control);
+}
+
+BONOBO_ACTIVATION_SHLIB_FACTORY ("OAFIID:GNOME_Gedit_ViewerFactory",
+ N_("Gedit viewer factory"),
+ gedit_factory, NULL);
diff --git a/viewer/gedit-persist-stream.c b/viewer/gedit-persist-stream.c
new file mode 100644
index 000000000..287f7dc96
--- /dev/null
+++ b/viewer/gedit-persist-stream.c
@@ -0,0 +1,187 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-persist-stream.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2003 Jeroen Zwartepoorte
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <libbonobo.h>
+#include <gtksourceview.h>
+#include <gtksourcelanguagesmanager.h>
+#include "gedit-persist-stream.h"
+#include "gedit-convert.h"
+
+static int
+impl_save (BonoboPersistStream *ps,
+ const Bonobo_Stream stream,
+ Bonobo_Persist_ContentType type,
+ void *closure,
+ CORBA_Environment *ev)
+{
+ g_message (_("Save method not implemented for Gedit viewer"));
+
+ return 0;
+}
+
+static int
+impl_load (BonoboPersistStream *ps,
+ Bonobo_Stream stream,
+ Bonobo_Persist_ContentType type,
+ void *closure,
+ CORBA_Environment *ev)
+{
+ GtkSourceView *source_view = GTK_SOURCE_VIEW (closure);
+ GtkTextView *view = GTK_TEXT_VIEW (source_view);
+ GtkTextBuffer *buffer = view->buffer;
+ GtkTextIter start;
+ GtkTextIter end;
+ GtkSourceLanguagesManager *manager;
+ GtkSourceLanguage *language = NULL;
+ GString *text_buf;
+ guint read_size = 16 *1024;
+
+ gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (buffer));
+
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_buffer_delete (buffer, &start, &end);
+
+ manager = g_object_get_data (G_OBJECT (source_view), "languages-manager");
+ language = gtk_source_languages_manager_get_language_from_mime_type (manager,
+ type);
+ if (language) {
+ g_object_set (G_OBJECT (buffer), "highlight", TRUE, NULL);
+ gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (buffer), language);
+ }
+
+ text_buf = g_string_new ("");
+
+ /* Read the complete stream first. */
+ while (TRUE) {
+ Bonobo_Stream_iobuf *buf;
+
+ Bonobo_Stream_read (stream, read_size, &buf, ev);
+
+ if (ev->_major != CORBA_NO_EXCEPTION)
+ break;
+
+ if (buf->_length)
+ text_buf = g_string_append_len (text_buf, buf->_buffer, buf->_length);
+
+ if (buf->_length < read_size)
+ break;
+ }
+
+ if (text_buf->len > 0) {
+ gchar *converted_text;
+
+ if (g_utf8_validate (text_buf->str, text_buf->len, NULL)) {
+ converted_text = text_buf->str;
+ } else {
+ converted_text = gedit_convert_to_utf8 (text_buf->str,
+ text_buf->len,
+ NULL);
+ }
+
+ if (converted_text == NULL) {
+ g_warning (_("Invalid UTF-8 data"));
+ g_free (converted_text);
+ return FALSE;
+ }
+
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_buffer_insert (buffer,
+ &end,
+ converted_text,
+ text_buf->len);
+ }
+
+ g_string_free (text_buf, TRUE);
+
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_place_cursor (buffer, &start);
+ gtk_text_view_place_cursor_onscreen (view);
+ gtk_text_buffer_set_modified (buffer, FALSE);
+
+ gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (buffer));
+
+ return 0;
+}
+
+static Bonobo_Persist_ContentTypeList *
+impl_get_content_types (BonoboPersistStream *ps,
+ gpointer data,
+ CORBA_Environment *ev)
+{
+ /* FIXME: Can we suffice with "text/ *" here? */
+ return bonobo_persist_generate_content_types (32,
+ "text/plain",
+ "text/x-ada",
+ "text/x-c",
+ "text/x-c++",
+ "text/x-dtml",
+ "text/x-fortran",
+ "text/x-gtkrc",
+ "text/html",
+ "text/x-idl",
+ "text/x-java",
+ "text/x-js",
+ "text/x-lang",
+ "text/x-tex",
+ "text/x-makefile",
+ "text/x-ml",
+ "text/x-perl",
+ "text/x-php",
+ "text/x-po",
+ "text/x-pot",
+ "text/x-pox",
+ "text/x-python",
+ "text/x-scheme",
+ "text/x-sgml",
+ "text/xml",
+ "text/x-sh",
+ "text/x-csh",
+ "text/x-sql",
+ "text/x-tcl",
+ "text/x-wml",
+ "text/x-asm",
+ "text/x-x86",
+ "text/xml",
+ "text/x-z80");
+}
+
+BonoboPersistStream *
+gedit_persist_stream_new (GtkSourceView *view)
+{
+ BonoboPersistStream *stream;
+
+ stream = bonobo_persist_stream_new ((BonoboPersistStreamIOFn) impl_load,
+ (BonoboPersistStreamIOFn) impl_save,
+ (BonoboPersistStreamTypesFn) impl_get_content_types,
+ "GeditPersistStream",
+ view);
+
+ g_object_set_data (G_OBJECT (view), "PersistStream", stream);
+
+ return stream;
+}
diff --git a/viewer/gedit-persist-stream.h b/viewer/gedit-persist-stream.h
new file mode 100644
index 000000000..570077160
--- /dev/null
+++ b/viewer/gedit-persist-stream.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-persist-stream.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2003 Jeroen Zwartepoorte
+ *
+ * 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 __GEDIT_PERSIST_STREAM_H__
+#define __GEDIT_PERSIST_STREAM_H__
+
+#include <bonobo/bonobo-persist-stream.h>
+#include <gtksourceview.h>
+
+G_BEGIN_DECLS
+
+BonoboPersistStream *gedit_persist_stream_new (GtkSourceView *view);
+
+G_END_DECLS
+
+#endif /* __GEDIT_PERSIST_STREAM_H__ */
diff --git a/viewer/gedit-viewer-ui.xml b/viewer/gedit-viewer-ui.xml
new file mode 100644
index 000000000..901ae0fe8
--- /dev/null
+++ b/viewer/gedit-viewer-ui.xml
@@ -0,0 +1,11 @@
+<Root>
+<commands>
+ <cmd name="Copy Text"
+ accel="*Control*c" sensitive="1"/>
+</commands>
+<menu>
+ <submenu name="Edit">
+ <menuitem name="Copy" _label="_Copy Text" _tip="Copy the selected text to the clipboard" pixtype="stock" pixname="gtk-copy" verb="Copy Text"/>
+ </submenu>
+</menu>
+</Root>
diff --git a/viewer/gedit-viewer.c b/viewer/gedit-viewer.c
new file mode 100644
index 000000000..210266db4
--- /dev/null
+++ b/viewer/gedit-viewer.c
@@ -0,0 +1,140 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-viewer.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2003 Jeroen Zwartepoorte
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo/bonobo-ui-util.h>
+#include <gconf/gconf-client.h>
+#include <gtksourceview.h>
+#include <gtksourcelanguagesmanager.h>
+#include "gedit-persist-stream.h"
+#include "gedit-viewer.h"
+#include "gedit-prefs-manager.h"
+
+static void
+copy_cb (BonoboUIComponent *component,
+ gpointer callback_data,
+ const char *verb)
+{
+ GtkWidget *source_view;
+ GdkDisplay *display;
+
+ source_view = GTK_WIDGET (callback_data);
+
+ display = gtk_widget_get_display (source_view);
+
+ gtk_text_buffer_copy_clipboard (GTK_TEXT_VIEW (source_view)->buffer,
+ gtk_clipboard_get_for_display (display, GDK_NONE));
+}
+
+static void
+activate_cb (BonoboObject *control,
+ gboolean state,
+ gpointer callback_data)
+{
+ GtkWidget *source_view;
+ BonoboUIComponent *ui_component;
+ Bonobo_UIContainer ui_container;
+
+ BonoboUIVerb verbs[] = {
+ BONOBO_UI_VERB ("Copy Text", copy_cb),
+ BONOBO_UI_VERB_END
+ };
+
+ if (state) {
+ source_view = GTK_WIDGET (callback_data);
+
+ /* Get the UI component that's pre-made by the control. */
+ ui_component = bonobo_control_get_ui_component (BONOBO_CONTROL (control));
+
+ /* Connect the UI component to the control frame's UI container. */
+ ui_container = bonobo_control_get_remote_ui_container (BONOBO_CONTROL (control), NULL);
+ bonobo_ui_component_set_container (ui_component, ui_container, NULL);
+ bonobo_object_release_unref (ui_container, NULL);
+
+ /* Set up the UI from an XML file. */
+ bonobo_ui_util_set_ui (ui_component, DATADIR, "gedit-viewer-ui.xml",
+ "gedit-viewer", NULL);
+
+ bonobo_ui_component_add_verb_list_with_data (ui_component,
+ verbs,
+ source_view);
+ }
+}
+
+BonoboControl *
+gedit_viewer_new (void)
+{
+ GtkWidget *source_view, *scrolled;
+ GtkSourceLanguagesManager *lm;
+ GConfClient *conf_client;
+ char *monospace_font;
+ PangoFontDescription *monospace_font_desc;
+ BonoboControl *control;
+ BonoboPersistStream *persist_stream;
+
+ gedit_prefs_manager_init ();
+
+ source_view = gtk_source_view_new ();
+
+ lm = gtk_source_languages_manager_new ();
+ g_object_ref (lm);
+ g_object_set_data_full (G_OBJECT (source_view), "languages-manager",
+ lm, (GDestroyNotify) g_object_unref);
+
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (source_view), FALSE);
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (source_view), GTK_WRAP_NONE);
+ gtk_text_view_set_left_margin (GTK_TEXT_VIEW (source_view), 3);
+ gtk_text_view_set_right_margin (GTK_TEXT_VIEW (source_view), 3);
+
+ /* Pick up the monospace font from desktop preferences */
+ conf_client = gconf_client_get_default ();
+ monospace_font = gconf_client_get_string (conf_client, "/desktop/gnome/interface/monospace_font_name", NULL);
+ if (monospace_font) {
+ monospace_font_desc = pango_font_description_from_string (monospace_font);
+ gtk_widget_modify_font (source_view, monospace_font_desc);
+ pango_font_description_free (monospace_font_desc);
+ }
+ g_object_unref (conf_client);
+
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+
+ gtk_container_add (GTK_CONTAINER (scrolled), source_view);
+ gtk_widget_show_all (scrolled);
+
+ control = bonobo_control_new (scrolled);
+
+ persist_stream = gedit_persist_stream_new (GTK_SOURCE_VIEW (source_view));
+ bonobo_object_add_interface (BONOBO_OBJECT (control),
+ BONOBO_OBJECT (persist_stream));
+
+ g_signal_connect_object (control, "activate",
+ G_CALLBACK (activate_cb), source_view, 0);
+
+ return control;
+}
diff --git a/viewer/gedit-viewer.h b/viewer/gedit-viewer.h
new file mode 100644
index 000000000..a16cc0c5d
--- /dev/null
+++ b/viewer/gedit-viewer.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-persist-stream.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2003 Jeroen Zwartepoorte
+ *
+ * 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 __GEDIT_VIEWER_H__
+#define __GEDIT_VIEWER_H__
+
+#include <bonobo/bonobo-control.h>
+
+G_BEGIN_DECLS
+
+BonoboControl *gedit_viewer_new (void);
+
+G_END_DECLS
+
+#endif /* __GEDIT_VIEWER_H__ */