summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Maggi <paolo@src.gnome.org>2002-02-07 18:34:52 +0000
committerPaolo Maggi <paolo@src.gnome.org>2002-02-07 18:34:52 +0000
commit414c230269705c0e578ffa4a11d4f4bc2fb13ab4 (patch)
tree51d0ba663f515f64e89a235ccacc25af4afaa02d
parent22f4d57c3e600443167ddbfc2b31c50bc90c6da8 (diff)
downloadgedit-414c230269705c0e578ffa4a11d4f4bc2fb13ab4.tar.gz
New taglist plugin
-rw-r--r--ChangeLog5
-rw-r--r--configure.in1
-rw-r--r--gedit/ChangeLog5
-rw-r--r--gedit/gedit-document.c29
-rw-r--r--gedit/gedit-document.h3
-rw-r--r--plugins/ChangeLog13
-rw-r--r--plugins/Makefile.am2
-rw-r--r--plugins/docinfo/docinfo.c2
-rw-r--r--plugins/taglist/Makefile.am30
-rw-r--r--plugins/taglist/gedit-taglist-plugin-parser.c351
-rw-r--r--plugins/taglist/gedit-taglist-plugin-parser.h41
-rw-r--r--plugins/taglist/gedit-taglist-plugin-window.c435
-rw-r--r--plugins/taglist/gedit-taglist-plugin-window.h37
-rw-r--r--plugins/taglist/gedit-taglist-plugin.c152
-rw-r--r--plugins/taglist/gedit-taglist-plugin.h62
-rw-r--r--plugins/taglist/taglist.xml52
-rw-r--r--src/ChangeLog5
-rw-r--r--src/gedit-document.c29
-rw-r--r--src/gedit-document.h3
19 files changed, 1254 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 53a76d68e..b6542008f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-02-07 Paolo Maggi <maggi@athena.polito.it>
+
+ * configure.in: bump version to 1.110.2
+ (AC_OUTPUT): added plugins/taglist/Makefile
+
2002-02-05 Paolo Maggi <maggi@athena.polito.it>
* configure.in: turn on additional checks for
diff --git a/configure.in b/configure.in
index 3b21d2b35..3096711b8 100644
--- a/configure.in
+++ b/configure.in
@@ -150,6 +150,7 @@ plugins/Makefile
plugins/docinfo/Makefile
plugins/sample/Makefile
plugins/cvschangelog/Makefile
+plugins/taglist/Makefile
plugins/time/Makefile
plugins/shell_output/Makefile
])
diff --git a/gedit/ChangeLog b/gedit/ChangeLog
index be3a85346..9e7d35417 100644
--- a/gedit/ChangeLog
+++ b/gedit/ChangeLog
@@ -1,3 +1,8 @@
+2002-02-07 Paolo Maggi <maggi@athena.polito.it>
+
+ * gedit-document.[ch] (gedit_document_get_cursor)
+ (gedit_document_set_cursor): new functions
+
2002-02-06 Paolo Maggi <maggi@athena.polito.it>
* gedit_mdi.c (gedit_mdi_update_ui_according_to_preferences):
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 11014a50f..e6af7ffb1 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -1535,3 +1535,32 @@ gedit_document_get_line_at_offset (const GeditDocument *doc, guint offset)
return gtk_text_iter_get_line (&iter);
}
+gint gedit_document_get_cursor (GeditDocument *doc)
+{
+ GtkTextIter iter;
+
+ gedit_debug (DEBUG_DOCUMENT, "");
+
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), 0);
+
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc),
+ &iter,
+ gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc),
+ "insert"));
+
+ return gtk_text_iter_get_offset (&iter);
+}
+
+void
+gedit_document_set_cursor (GeditDocument *doc, gint cursor)
+{
+ GtkTextIter iter;
+
+ gedit_debug (DEBUG_DOCUMENT, "");
+
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ /* Place the cursor at the requested position */
+ gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, cursor);
+ gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
+}
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index 175e1f9c8..df32b34ac 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -125,6 +125,9 @@ void gedit_document_insert_text_at_cursor (GeditDocument *doc,
const gchar *text,
gint len);
+gint gedit_document_get_cursor (GeditDocument *doc);
+void gedit_document_set_cursor (GeditDocument *doc, gint cursor);
+
void gedit_document_delete_text (GeditDocument *doc,
gint start, gint end);
diff --git a/plugins/ChangeLog b/plugins/ChangeLog
index 8a42dbd2e..00a438a9e 100644
--- a/plugins/ChangeLog
+++ b/plugins/ChangeLog
@@ -1,3 +1,16 @@
+2002-02-07 Paolo Maggi <maggi@athena.polito.it>
+
+ * Makefile.am (SUBDIRS): added taglist
+
+ * taglist/gedit-taglist-plugin.c:
+ * taglist/gedit-taglist-plugin.h:
+ * taglist/gedit-taglist-plugin-parser.c:
+ * taglist/gedit-taglist-plugin-parser.h:
+ * taglist/gedit-taglist-plugin-window.c:
+ * taglist/gedit-taglist-plugin-window.h:
+ * taglist/Makefile.am:
+ * taglist/taglist.xml: new files
+
2002-02-06 Paolo Maggi <maggi@athena.polito.it>
* cvschangelog/cvschangelog.c (update_ui): fix mem leak
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 59f6a2ac1..9e907dbbc 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,3 +1,3 @@
-SUBDIRS = docinfo sample cvschangelog time shell_output
+SUBDIRS = docinfo sample cvschangelog taglist time shell_output
EXTRA_DIST = ChangeLog
diff --git a/plugins/docinfo/docinfo.c b/plugins/docinfo/docinfo.c
index fe6c0c707..bfe7d7de8 100644
--- a/plugins/docinfo/docinfo.c
+++ b/plugins/docinfo/docinfo.c
@@ -121,8 +121,6 @@ get_dialog ()
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
window);
- gtk_widget_grab_focus (dialog->dialog);
-
if (!GTK_WIDGET_VISIBLE (dialog->dialog))
gtk_widget_show (dialog->dialog);
diff --git a/plugins/taglist/Makefile.am b/plugins/taglist/Makefile.am
new file mode 100644
index 000000000..5c157404a
--- /dev/null
+++ b/plugins/taglist/Makefile.am
@@ -0,0 +1,30 @@
+# Tag list plugin
+plugindir = $(libdir)/gedit2/plugins
+
+taglistdir = $(datadir)/gedit2/taglist
+taglist_DATA = taglist.xml
+
+INCLUDES = \
+ -I$(top_srcdir)/src \
+ $(GEDIT_CFLAGS) \
+ -DGNOME_ICONDIR=\""$(datadir)/pixmaps"\" \
+ -DGEDIT_GLADEDIR=\""$(datadir)/gedit2/glade/"\" \
+ -DGEDIT_TAGLIST=\""$(taglistdir)/taglist.xml"\" \
+ -DG_DISABLE_DEPRECATED \
+ -DGDK_DISABLE_DEPRECATED \
+ -DGTK_DISABLE_DEPRECATED \
+ -DGDK_PIXBUF_DISABLE_DEPRECATED \
+ -DGNOME_DISABLE_DEPRECATED
+
+plugin_LTLIBRARIES = libtaglist.la
+
+libtaglist_la_SOURCES = \
+ gedit-taglist-plugin-parser.c \
+ gedit-taglist-plugin-parser.h \
+ gedit-taglist-plugin-window.c \
+ gedit-taglist-plugin-window.h \
+ gedit-taglist-plugin.c \
+ gedit-taglist-plugin.h
+
+
+EXTRA_DIST = $(taglist_DATA)
diff --git a/plugins/taglist/gedit-taglist-plugin-parser.c b/plugins/taglist/gedit-taglist-plugin-parser.c
new file mode 100644
index 000000000..b42402d26
--- /dev/null
+++ b/plugins/taglist/gedit-taglist-plugin-parser.c
@@ -0,0 +1,351 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-taglist-plugin-parser.c
+ * This file is part of the gedit taglist plugin
+ *
+ * Copyright (C) 2002 Paolo Maggi
+ *
+ * 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.
+ */
+
+/*
+ * Modified by the gedit Team, 2002. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ */
+
+#include <libxml/parser.h>
+#include <glib.h>
+
+#include <gedit-debug.h>
+
+#include "gedit-taglist-plugin-parser.h"
+
+
+TagList *taglist = NULL;
+
+static gboolean parse_tag (Tag *tag, xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur);
+static gboolean parse_tag_group (TagGroup *tg, const gchar *fn,
+ xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur);
+static TagList *parse_taglist_file (const gchar* filename);
+
+static void free_tag (Tag *tag);
+static void free_tag_group (TagGroup *tag_group);
+
+static gboolean
+parse_tag (Tag *tag, xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur)
+{
+ gedit_debug (DEBUG_PLUGINS, " Tag name: %s", tag->name);
+
+ /* We don't care what the top level element name is */
+ cur = cur->xmlChildrenNode;
+
+ while (cur != NULL)
+ {
+ if ((!xmlStrcmp (cur->name, (const xmlChar *)"Begin")) &&
+ (cur->ns == ns))
+ {
+ tag->begin = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
+
+ gedit_debug (DEBUG_PLUGINS, " - Begin: %s", tag->begin);
+ }
+
+ if ((!xmlStrcmp (cur->name, (const xmlChar *)"End")) &&
+ (cur->ns == ns))
+ {
+ tag->end = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
+
+ gedit_debug (DEBUG_PLUGINS, " - End: %s", tag->end);
+ }
+
+ cur = cur->next;
+ }
+
+ if ((tag->begin == NULL) && (tag->end = NULL))
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean
+parse_tag_group (TagGroup *tg, const gchar* fn, xmlDocPtr doc,
+ xmlNsPtr ns, xmlNodePtr cur)
+{
+ gedit_debug (DEBUG_PLUGINS, "Parse TagGroup: %s", tg->name);
+
+ /* We don't care what the top level element name is */
+ cur = cur->xmlChildrenNode;
+
+ while (cur != NULL)
+ {
+ if ((xmlStrcmp (cur->name, (const xmlChar *) "Tag")) || (cur->ns != ns))
+ {
+ g_warning ("The tag list file '%s' is of the wrong type, "
+ "was '%s', 'Tag' expected.", fn, cur->name);
+
+ return FALSE;
+ }
+ else
+ {
+ Tag *tag;
+
+ tag = g_new0 (Tag, 1);
+
+ /* Get Tag name */
+ tag->name = xmlGetProp (cur, (const xmlChar *) "name");
+
+ if (tag->name == NULL)
+ {
+ /* Error: No name */
+ g_warning ("The tag list file '%s' is of the wrong type, "
+ "Tag without name.", fn);
+
+ g_free (tag);
+
+ return FALSE;
+ }
+ else
+ {
+ /* Parse Tag */
+ if (parse_tag (tag, doc, ns, cur))
+ {
+ /* Append Tag to TagGroup */
+ tg->tags = g_list_append (tg->tags, tag);
+ }
+ else
+ {
+ /* Error parsing Tag */
+ g_warning ("The tag list file '%s' is of the wrong type, "
+ "error parsing Tag '%s' in TagGroup '%s'.",
+ fn, tag->name, tg->name);
+
+ free_tag (tag);
+
+ return FALSE;
+ }
+ }
+ }
+
+ cur = cur->next;
+ }
+
+ return TRUE;
+}
+
+
+static TagList *
+parse_taglist_file (const gchar* filename)
+{
+ xmlDocPtr doc;
+
+ xmlNsPtr ns;
+ xmlNodePtr cur;
+
+ gedit_debug (DEBUG_PLUGINS, "Parse file: %s", filename);
+
+ /*
+ * build an XML tree from a the file;
+ */
+ doc = xmlParseFile (filename);
+ if (doc == NULL)
+ return taglist;
+
+ /*
+ * Check the document is of the right kind
+ */
+
+ cur = xmlDocGetRootElement (doc);
+
+ if (cur == NULL)
+ {
+ g_warning ("The tag list file '%s' is empty.", filename);
+ xmlFreeDoc(doc);
+ return taglist;
+ }
+
+ ns = xmlSearchNsByHref (doc, cur,
+ (const xmlChar *) "http://gedit.sourceforge.net/some-location");
+
+ if (ns == NULL)
+ {
+ g_warning ("The tag list file '%s' is of the wrong type, "
+ "gedit namespace not found.", filename);
+ xmlFreeDoc (doc);
+
+ return taglist;
+ }
+
+ if (xmlStrcmp(cur->name, (const xmlChar *) "TagList"))
+ {
+ g_warning ("The tag list file '%s' is of the wrong type, "
+ "root node != TagList.", filename);
+ xmlFreeDoc (doc);
+
+ return taglist;
+ }
+
+ /*
+ * If needed, allocate taglist
+ */
+
+ if (taglist == NULL)
+ taglist = g_new0 (TagList, 1);
+
+ /*
+ * Walk the tree.
+ *
+ * First level we expect a list TagGroup
+ */
+ cur = cur->xmlChildrenNode;
+
+ while (cur != NULL)
+ {
+ if ((xmlStrcmp (cur->name, (const xmlChar *) "TagGroup")) || (cur->ns != ns))
+ {
+ g_warning ("The tag list file '%s' is of the wrong type, "
+ "was '%s', 'TagGroup' expected.", filename, cur->name);
+ xmlFreeDoc (doc);
+
+ return taglist;
+ }
+ else
+ {
+ TagGroup *tag_group;
+
+ tag_group = g_new0 (TagGroup, 1);
+
+ /* Get TagGroup name */
+ tag_group->name = xmlGetProp (cur, (const xmlChar *) "name");
+
+ if (tag_group->name == NULL)
+ {
+ /* Error: No name */
+ g_warning ("The tag list file '%s' is of the wrong type, "
+ "TagGroup without name.", filename);
+
+ g_free (tag_group);
+ }
+ else
+ {
+ /* Name found */
+
+ /* Parse tag group */
+ if (parse_tag_group (tag_group, filename, doc, ns, cur))
+ {
+ /* Append TagGroup to TagList */
+ taglist->tag_groups =
+ g_list_append (taglist->tag_groups, tag_group);
+ }
+ else
+ {
+ /* Error parsing TagGroup */
+ g_warning ("The tag list file '%s' is of the wrong type, "
+ "error parsing TagGroup '%s'.",
+ filename, tag_group->name);
+
+ free_tag_group (tag_group);
+ }
+ }
+ }
+
+ cur = cur->next;
+ }
+
+ xmlFreeDoc (doc);
+
+ gedit_debug (DEBUG_PLUGINS, "END");
+
+ return taglist;
+}
+
+
+static void
+free_tag (Tag *tag)
+{
+ gedit_debug (DEBUG_PLUGINS, "Tag: %s", tag->name);
+
+ g_return_if_fail (tag != NULL);
+
+ free (tag->name);
+
+ if (tag->begin != NULL)
+ free (tag->begin);
+
+ if (tag->end != NULL)
+ free (tag->end);
+
+ g_free (tag);
+}
+
+static void
+free_tag_group (TagGroup *tag_group)
+{
+ gedit_debug (DEBUG_PLUGINS, "Tag group: %s", tag_group->name);
+
+ g_return_if_fail (tag_group != NULL);
+
+ free (tag_group->name);
+
+ while (tag_group->tags)
+ {
+ free_tag ((Tag *)tag_group->tags->data);
+
+ tag_group->tags = g_list_next (tag_group->tags);
+ }
+
+ g_list_free (tag_group->tags);
+
+ g_free (tag_group);
+
+ gedit_debug (DEBUG_PLUGINS, "END");
+}
+
+void
+free_taglist (void)
+{
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ if (taglist == NULL)
+ return;
+
+ while (taglist->tag_groups)
+ {
+ free_tag_group ((TagGroup *)taglist->tag_groups->data);
+
+ taglist->tag_groups = g_list_next (taglist->tag_groups);
+ }
+
+ g_list_free (taglist->tag_groups);
+
+ g_free (taglist);
+
+ taglist = NULL;
+
+ gedit_debug (DEBUG_PLUGINS, "END");
+}
+
+
+TagList* create_taglist (void)
+{
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ g_return_val_if_fail (taglist == NULL, taglist);
+
+ xmlKeepBlanksDefault (0);
+
+ /* FIXME: search user's taglists */
+ return parse_taglist_file (GEDIT_TAGLIST);
+}
diff --git a/plugins/taglist/gedit-taglist-plugin-parser.h b/plugins/taglist/gedit-taglist-plugin-parser.h
new file mode 100644
index 000000000..6d92b2843
--- /dev/null
+++ b/plugins/taglist/gedit-taglist-plugin-parser.h
@@ -0,0 +1,41 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-taglist-plugin-parser.c
+ * This file is part of the gedit taglist plugin
+ *
+ * Copyright (C) 2002 Paolo Maggi
+ *
+ * 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.
+ */
+
+/*
+ * Modified by the gedit Team, 2002. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ */
+
+#ifndef __GEDIT_TAGLIST_PLUGIN_PARSER_H__
+#define __GEDIT_TAGLIST_PLUGIN_PARSER_H__
+
+#include "gedit-taglist-plugin.h"
+
+TagList* create_taglist (void);
+
+void free_taglist (void);
+
+
+#endif /* __GEDIT_TAGLIST_PLUGIN_PARSER_H_ */
+
diff --git a/plugins/taglist/gedit-taglist-plugin-window.c b/plugins/taglist/gedit-taglist-plugin-window.c
new file mode 100644
index 000000000..8223507f8
--- /dev/null
+++ b/plugins/taglist/gedit-taglist-plugin-window.c
@@ -0,0 +1,435 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-taglist-plugin-window.c
+ * This file is part of the gedit taglist plugin
+ *
+ * Copyright (C) 2002 Paolo Maggi
+ *
+ * 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.
+ */
+
+/*
+ * Modified by the gedit Team, 2002. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ */
+
+
+#include <gtk/gtk.h>
+#include <libgnome/gnome-i18n.h>
+#include <gdk/gdkkeysyms.h>
+
+#include <string.h>
+
+#include "gedit-taglist-plugin.h"
+#include "gedit-taglist-plugin-window.h"
+
+#include <gedit-debug.h>
+#include <gedit2.h>
+#include <gedit-document.h>
+
+enum
+{
+ COLUMN_TAG_NAME,
+ COLUMN_TAG_INDEX_IN_GROUP,
+ NUM_COLUMNS
+};
+
+typedef struct _TagListWindow TagListWindow;
+
+struct _TagListWindow
+{
+ GtkWindow *window;
+
+ GtkWidget *tag_groups_combo;
+ GtkWidget *tags_list;
+
+ TagGroup *selected_tag_group;
+};
+
+static TagListWindow *tag_list_window = NULL;
+
+static void window_destroyed (GtkObject *obj, void **window_pointer);
+static void populate_tag_groups_combo (void);
+static void selected_group_changed (GtkEntry *entry, TagListWindow *w);
+static TagGroup *find_tag_group (const gchar *name);
+static void populate_tags_list (void);
+static GtkTreeModel *create_model (void);
+static void tag_list_row_activated_cb (GtkTreeView *tag_list, GtkTreePath *path,
+ GtkTreeViewColumn *column, gpointer data);
+static gboolean tag_list_key_press_event_cb (GtkTreeView *tag_list, GdkEventKey *event);
+static void insert_tag (Tag *tag, gboolean focus_to_document);
+static gboolean tag_list_window_key_press_event_cb (GtkTreeView *tag_list, GdkEventKey *event);
+
+static void
+window_destroyed (GtkObject *obj, void **window_pointer)
+{
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ if (window_pointer != NULL)
+ {
+ g_free (*window_pointer);
+ *window_pointer = NULL;
+ }
+}
+
+void taglist_window_show ()
+{
+ GtkWidget *vbox;
+ GtkWidget *sw;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *cell;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ if (tag_list_window != NULL)
+ {
+ gtk_window_set_transient_for (tag_list_window->window,
+ GTK_WINDOW (gedit_get_active_window ()));
+
+ gtk_window_present (tag_list_window->window);
+ gtk_widget_grab_focus (tag_list_window->tags_list);
+
+ return;
+ }
+
+ tag_list_window = g_new0 (TagListWindow, 1);
+
+ tag_list_window->window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
+ gtk_window_set_title (GTK_WINDOW (tag_list_window->window),
+ _("Tag list plugin"));
+
+ /* Connect destroy signal */
+
+ g_signal_connect (G_OBJECT (tag_list_window->window), "destroy",
+ G_CALLBACK (window_destroyed), &tag_list_window);
+
+ /* Build the window content */
+ vbox = gtk_vbox_new (FALSE, 4);
+
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
+
+ gtk_container_add (GTK_CONTAINER (tag_list_window->window), vbox);
+
+ tag_list_window->tag_groups_combo = gtk_combo_new ();
+
+ gtk_tooltips_set_tip (gtk_tooltips_new (),
+ GTK_COMBO (tag_list_window->tag_groups_combo)->entry,
+ _("Select the group of tab you want to use."),
+ NULL);
+
+ gtk_editable_set_editable (GTK_EDITABLE (
+ GTK_COMBO (tag_list_window->tag_groups_combo)->entry),
+ FALSE);
+
+ gtk_box_pack_start (GTK_BOX (vbox), tag_list_window->tag_groups_combo, FALSE, TRUE, 0);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
+
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+ gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
+
+ /* Create tree view */
+ tag_list_window->tags_list = gtk_tree_view_new ();
+ gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tag_list_window->tags_list), TRUE);
+
+ gtk_tooltips_set_tip (gtk_tooltips_new (),
+ tag_list_window->tags_list,
+ _("Double-click on a tag to insert it in the current document."),
+ NULL);
+
+ g_signal_connect_after (G_OBJECT (tag_list_window->tags_list), "row_activated",
+ G_CALLBACK (tag_list_row_activated_cb), NULL);
+
+ g_signal_connect_after (G_OBJECT (tag_list_window->tags_list), "key_press_event",
+ G_CALLBACK (tag_list_key_press_event_cb), NULL);
+
+ /* Add the tags column */
+ cell = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("Tags"), cell,
+ "text", COLUMN_TAG_NAME, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (tag_list_window->tags_list), column);
+
+ gtk_tree_view_set_search_column (GTK_TREE_VIEW (tag_list_window->tags_list),
+ COLUMN_TAG_NAME);
+
+ gtk_container_add (GTK_CONTAINER (sw), tag_list_window->tags_list);
+
+ gtk_window_set_default_size (GTK_WINDOW (tag_list_window->window), 250, 450);
+
+ g_signal_connect (G_OBJECT (GTK_COMBO (tag_list_window->tag_groups_combo)->entry),
+ "changed",
+ G_CALLBACK (selected_group_changed),
+ tag_list_window);
+
+ g_signal_connect (G_OBJECT (tag_list_window->window), "key_press_event",
+ G_CALLBACK (tag_list_window_key_press_event_cb), NULL);
+
+ /* Populate combo box */
+ populate_tag_groups_combo ();
+
+ gtk_window_set_transient_for (tag_list_window->window,
+ GTK_WINDOW (gedit_get_active_window ()));
+
+ gtk_widget_show_all (GTK_WIDGET (tag_list_window->window));
+ gtk_widget_grab_focus (tag_list_window->tags_list);
+
+}
+
+static void
+populate_tag_groups_combo (void)
+{
+ GList *list;
+ GList *cbitems = NULL;
+ GtkCombo *combo;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ combo = GTK_COMBO (tag_list_window->tag_groups_combo);
+
+ g_return_if_fail (taglist != NULL);
+ g_return_if_fail (combo != NULL);
+
+ list = taglist->tag_groups;
+
+ /* Build cbitems */
+ while (list)
+ {
+ cbitems = g_list_append (cbitems, ((TagGroup*)list->data)->name);
+
+ list = g_list_next (list);
+ }
+
+ gtk_combo_set_popdown_strings (combo, cbitems);
+
+ /* Free cbitems */
+ g_list_free (cbitems);
+
+ return;
+}
+
+static void
+selected_group_changed (GtkEntry *entry, TagListWindow *w)
+{
+ const gchar* group_name;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ group_name = gtk_entry_get_text (entry);
+
+ if ((group_name == NULL) || (strlen (group_name) <= 0))
+ return;
+
+ if ((w->selected_tag_group == NULL) ||
+ (strcmp (group_name, w->selected_tag_group->name) != 0))
+ {
+ w->selected_tag_group = find_tag_group (group_name);
+ g_return_if_fail (w->selected_tag_group != NULL);
+
+ gedit_debug (DEBUG_PLUGINS, "New selected group: %s",
+ w->selected_tag_group->name);
+
+ populate_tags_list ();
+ }
+}
+
+
+static TagGroup *
+find_tag_group (const gchar *name)
+{
+ GList *list;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ g_return_val_if_fail (taglist != NULL, NULL);
+
+ list = taglist->tag_groups;
+
+ while (list)
+ {
+ if (strcmp (name, ((TagGroup*)list->data)->name) == 0)
+ return (TagGroup*)list->data;
+
+ list = g_list_next (list);
+ }
+
+ return NULL;
+}
+
+static void
+populate_tags_list (void)
+{
+ GtkTreeModel* model;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ g_return_if_fail (taglist != NULL);
+
+ model = create_model ();
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (tag_list_window->tags_list),
+ model);
+}
+
+static GtkTreeModel*
+create_model (void)
+{
+ gint i = 0;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GList *list;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ /* create list store */
+ store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
+
+ /* add data to the list store */
+ list = tag_list_window->selected_tag_group->tags;
+
+ while (list != NULL)
+ {
+ const gchar* tag_name;
+
+ tag_name = ((Tag*)list->data)->name;
+
+ gedit_debug (DEBUG_PLUGINS, "%d : %s", i, tag_name);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COLUMN_TAG_NAME, tag_name,
+ COLUMN_TAG_INDEX_IN_GROUP, i,
+ -1);
+ ++i;
+
+ list = g_list_next (list);
+ }
+
+ return GTK_TREE_MODEL (store);
+}
+
+static void
+tag_list_row_activated_cb (GtkTreeView *tag_list, GtkTreePath *path,
+ GtkTreeViewColumn *column, gpointer data)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ gint index;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (tag_list_window->tags_list));
+ g_return_if_fail (model != NULL);
+
+ gtk_tree_model_get_iter (model, &iter, path);
+ g_return_if_fail (&iter != NULL);
+
+ gtk_tree_model_get (model, &iter, COLUMN_TAG_INDEX_IN_GROUP, &index, -1);
+
+ gedit_debug (DEBUG_PLUGINS, "Index: %d", index);
+
+ insert_tag ((Tag*)g_list_nth_data (tag_list_window->selected_tag_group->tags, index),
+ TRUE);
+}
+
+static gboolean
+tag_list_key_press_event_cb (GtkTreeView *tag_list, GdkEventKey *event)
+{
+ if (event->keyval == GDK_Return)
+ {
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ gint index;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (tag_list_window->tags_list));
+ g_return_val_if_fail (model != NULL, FALSE);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tag_list_window->tags_list));
+ g_return_val_if_fail (selection != NULL, FALSE);
+
+ if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+ {
+ gtk_tree_model_get (model, &iter, COLUMN_TAG_INDEX_IN_GROUP, &index, -1);
+
+ gedit_debug (DEBUG_PLUGINS, "Index: %d", index);
+
+ insert_tag ((Tag*)g_list_nth_data (tag_list_window->selected_tag_group->tags, index),
+ event->state & GDK_CONTROL_MASK);
+ }
+ }
+
+ return FALSE;
+}
+
+static void
+insert_tag (Tag *tag, gboolean focus_to_document)
+{
+ GeditView *view;
+ GeditDocument *doc;
+ gint cursor;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ view = gedit_get_active_view ();
+ if (view == NULL)
+ return;
+
+ gtk_window_set_transient_for (tag_list_window->window,
+ GTK_WINDOW (gedit_get_active_window ()));
+
+ doc = gedit_view_get_document (view);
+ g_return_if_fail (doc != NULL);
+
+ gedit_document_begin_user_action (doc);
+
+ if (tag->begin != NULL)
+ gedit_document_insert_text_at_cursor (doc, tag->begin, -1);
+
+ cursor = gedit_document_get_cursor (doc);
+
+ if (tag->end != NULL)
+ gedit_document_insert_text_at_cursor (doc, tag->end, -1);
+
+ gedit_document_set_cursor (doc, cursor);
+
+ gedit_document_end_user_action (doc);
+
+ if (focus_to_document)
+ {
+ gtk_window_present (GTK_WINDOW (gedit_get_active_window ()));
+ gtk_widget_grab_focus (GTK_WIDGET (view));
+ }
+}
+
+static gboolean
+tag_list_window_key_press_event_cb (GtkTreeView *tag_list, GdkEventKey *event)
+{
+ if (event->keyval == GDK_Escape)
+ {
+ gtk_widget_destroy (GTK_WIDGET (tag_list_window->window));
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
diff --git a/plugins/taglist/gedit-taglist-plugin-window.h b/plugins/taglist/gedit-taglist-plugin-window.h
new file mode 100644
index 000000000..d70d371d5
--- /dev/null
+++ b/plugins/taglist/gedit-taglist-plugin-window.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-taglist-plugin-window.h
+ * This file is part of the gedit taglist plugin
+ *
+ * Copyright (C) 2002 Paolo Maggi
+ *
+ * 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.
+ */
+
+/*
+ * Modified by the gedit Team, 2002. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ */
+
+#ifndef __GEDIT_TAGLIST_PLUGIN_WINDOW_H__
+#define __GEDIT_TAGLIST_PLUGIN_WINDOW_H__
+
+void taglist_window_show (void);
+
+#endif /* __GEDIT_TAGLIST_PLUGIN_WINDOW_H__ */
+
+
diff --git a/plugins/taglist/gedit-taglist-plugin.c b/plugins/taglist/gedit-taglist-plugin.c
new file mode 100644
index 000000000..264bfebe0
--- /dev/null
+++ b/plugins/taglist/gedit-taglist-plugin.c
@@ -0,0 +1,152 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-taglist-plugin.c
+ * This file is part of the gedit taglist plugin
+ *
+ * Copyright (C) 2002 Paolo Maggi
+ *
+ * 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.
+ */
+
+/*
+ * Modified by the gedit Team, 2002. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ */
+
+#include <libgnome/gnome-i18n.h>
+
+#include <gedit-menus.h>
+#include <gedit-plugin.h>
+#include <gedit-debug.h>
+
+#include "gedit-taglist-plugin.h"
+#include "gedit-taglist-plugin-window.h"
+#include "gedit-taglist-plugin-parser.h"
+
+#define MENU_ITEM_LABEL N_("_Show tag list")
+#define MENU_ITEM_PATH "/menu/Tools/ToolsOps/"
+#define MENU_ITEM_NAME "TagList"
+#define MENU_ITEM_TIP N_("Show the tag list window.")
+
+G_MODULE_EXPORT GeditPluginState update_ui (GeditPlugin *plugin, BonoboWindow *window);
+G_MODULE_EXPORT GeditPluginState destroy (GeditPlugin *pd);
+G_MODULE_EXPORT GeditPluginState activate (GeditPlugin *pd);
+G_MODULE_EXPORT GeditPluginState deactivate (GeditPlugin *pd);
+G_MODULE_EXPORT GeditPluginState init (GeditPlugin *pd);
+
+
+static void
+tag_list_cb (BonoboUIComponent *uic, gpointer user_data, const gchar* verbname)
+{
+ taglist_window_show ();
+}
+
+G_MODULE_EXPORT GeditPluginState
+update_ui (GeditPlugin *plugin, BonoboWindow *window)
+{
+ BonoboUIComponent *uic;
+ GeditDocument *doc;
+
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ g_return_val_if_fail (window != NULL, PLUGIN_ERROR);
+
+ uic = gedit_get_ui_component_from_window (window);
+
+ doc = gedit_get_active_document ();
+
+ if ((doc == NULL) || (gedit_document_is_readonly (doc)))
+ gedit_menus_set_verb_sensitive (uic, "/commands/" MENU_ITEM_NAME, FALSE);
+ else
+ gedit_menus_set_verb_sensitive (uic, "/commands/" MENU_ITEM_NAME, TRUE);
+
+ return PLUGIN_OK;
+}
+
+G_MODULE_EXPORT GeditPluginState
+destroy (GeditPlugin *plugin)
+{
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ free_taglist ();
+
+ return PLUGIN_OK;
+}
+
+G_MODULE_EXPORT GeditPluginState
+activate (GeditPlugin *pd)
+{
+ GList *top_windows;
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ if (create_taglist () == NULL)
+ return PLUGIN_ERROR;
+
+ top_windows = gedit_get_top_windows ();
+ g_return_val_if_fail (top_windows != NULL, PLUGIN_ERROR);
+
+ while (top_windows)
+ {
+ BonoboUIComponent *ui_component;
+
+ gedit_menus_add_menu_item (BONOBO_WINDOW (top_windows->data),
+ MENU_ITEM_PATH, MENU_ITEM_NAME,
+ MENU_ITEM_LABEL, MENU_ITEM_TIP, NULL,
+ tag_list_cb);
+
+ ui_component = gedit_get_ui_component_from_window (
+ BONOBO_WINDOW (top_windows->data));
+
+ bonobo_ui_component_set_prop (
+ ui_component, "/commands/" MENU_ITEM_NAME, "accel", "*Shift*F8", NULL);
+
+ pd->update_ui (pd, BONOBO_WINDOW (top_windows->data));
+
+ top_windows = g_list_next (top_windows);
+ }
+
+ return PLUGIN_OK;
+}
+
+G_MODULE_EXPORT GeditPluginState
+deactivate (GeditPlugin *pd)
+{
+ gedit_menus_remove_menu_item_all (MENU_ITEM_PATH, MENU_ITEM_NAME);
+
+ free_taglist ();
+
+ return PLUGIN_OK;
+}
+
+G_MODULE_EXPORT GeditPluginState
+init (GeditPlugin *pd)
+{
+ /* initialize */
+ gedit_debug (DEBUG_PLUGINS, "");
+
+ pd->name = _("Tag list");
+ pd->desc = _("The tag list plugin provides a method to easily insert into a document "
+ "commonly used tabs/strings without having to type them.");
+ pd->author = "Paolo Maggi <maggi@athena.polito.it>";
+ pd->copyright = _("Copyright (C) 2002 - Paolo Maggi");
+
+ pd->private_data = NULL;
+
+ return PLUGIN_OK;
+}
+
+
diff --git a/plugins/taglist/gedit-taglist-plugin.h b/plugins/taglist/gedit-taglist-plugin.h
new file mode 100644
index 000000000..df4a176f4
--- /dev/null
+++ b/plugins/taglist/gedit-taglist-plugin.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * gedit-taglist-plugin.h
+ * This file is part of the gedit taglist plugin
+ *
+ * Copyright (C) 2002 Paolo Maggi
+ *
+ * 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.
+ */
+
+/*
+ * Modified by the gedit Team, 2002. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ */
+
+#ifndef __GEDIT_TAGLIST_PLUGIN_H__
+#define __GEDIT_TAGLIST_PLUGIN_H__
+
+#include <libxml/tree.h>
+#include <glib/glist.h>
+
+typedef struct _TagList TagList;
+typedef struct _TagGroup TagGroup;
+typedef struct _Tag Tag;
+
+struct _TagList
+{
+ GList *tag_groups;
+};
+
+struct _TagGroup
+{
+ xmlChar *name;
+
+ GList *tags;
+};
+
+struct _Tag
+{
+ xmlChar *name;
+ xmlChar *begin;
+ xmlChar *end;
+};
+
+extern TagList *taglist;
+
+#endif /*__GEDIT_TAGLIST_PLUGIN_H_ */
+
diff --git a/plugins/taglist/taglist.xml b/plugins/taglist/taglist.xml
new file mode 100644
index 000000000..af5c141b3
--- /dev/null
+++ b/plugins/taglist/taglist.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<gedit:TagList xmlns:gedit="http://gedit.sourceforge.net/some-location">
+
+ <gedit:TagGroup name="HTML - Tags">
+
+ <gedit:Tag name="Abbreviated form">
+ <gedit:Begin>&lt;ABBR&gt;</gedit:Begin>
+ <gedit:End>&lt;/ABBR&gt;</gedit:End>
+ </gedit:Tag>
+
+ <gedit:Tag name="Abbreviation">
+ <gedit:Begin>ABBR=</gedit:Begin>
+ </gedit:Tag>
+
+ <gedit:Tag name="Above">
+ <gedit:Begin>&lt;ABOVE&gt;</gedit:Begin>
+ </gedit:Tag>
+
+ <gedit:Tag name="Accessibility Key Character">
+ <gedit:Begin>ACCESSKEY=</gedit:Begin>
+ </gedit:Tag>
+
+ <gedit:Tag name="Acronym">
+ <gedit:Begin>&lt;ACRONYM&gt;</gedit:Begin>
+ <gedit:End>&lt;/ACRONYM&gt;</gedit:End>
+ </gedit:Tag>
+
+ </gedit:TagGroup>
+
+ <gedit:TagGroup name="Perl - Tags">
+
+ <gedit:Tag name="abs(...)">
+ <gedit:Begin>abs(</gedit:Begin>
+ <gedit:End>) </gedit:End>
+ </gedit:Tag>
+
+ <gedit:Tag name="accept(...)">
+ <gedit:Begin>accept(</gedit:Begin>
+ <gedit:End>) </gedit:End>
+ </gedit:Tag>
+
+ <gedit:Tag name="alarm(...)">
+ <gedit:Begin>alarm(</gedit:Begin>
+ <gedit:End>) </gedit:End>
+ </gedit:Tag>
+
+ </gedit:TagGroup>
+
+</gedit:TagList>
+
+
+
diff --git a/src/ChangeLog b/src/ChangeLog
index be3a85346..9e7d35417 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2002-02-07 Paolo Maggi <maggi@athena.polito.it>
+
+ * gedit-document.[ch] (gedit_document_get_cursor)
+ (gedit_document_set_cursor): new functions
+
2002-02-06 Paolo Maggi <maggi@athena.polito.it>
* gedit_mdi.c (gedit_mdi_update_ui_according_to_preferences):
diff --git a/src/gedit-document.c b/src/gedit-document.c
index 11014a50f..e6af7ffb1 100644
--- a/src/gedit-document.c
+++ b/src/gedit-document.c
@@ -1535,3 +1535,32 @@ gedit_document_get_line_at_offset (const GeditDocument *doc, guint offset)
return gtk_text_iter_get_line (&iter);
}
+gint gedit_document_get_cursor (GeditDocument *doc)
+{
+ GtkTextIter iter;
+
+ gedit_debug (DEBUG_DOCUMENT, "");
+
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), 0);
+
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc),
+ &iter,
+ gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc),
+ "insert"));
+
+ return gtk_text_iter_get_offset (&iter);
+}
+
+void
+gedit_document_set_cursor (GeditDocument *doc, gint cursor)
+{
+ GtkTextIter iter;
+
+ gedit_debug (DEBUG_DOCUMENT, "");
+
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ /* Place the cursor at the requested position */
+ gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, cursor);
+ gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
+}
diff --git a/src/gedit-document.h b/src/gedit-document.h
index 175e1f9c8..df32b34ac 100644
--- a/src/gedit-document.h
+++ b/src/gedit-document.h
@@ -125,6 +125,9 @@ void gedit_document_insert_text_at_cursor (GeditDocument *doc,
const gchar *text,
gint len);
+gint gedit_document_get_cursor (GeditDocument *doc);
+void gedit_document_set_cursor (GeditDocument *doc, gint cursor);
+
void gedit_document_delete_text (GeditDocument *doc,
gint start, gint end);