Commit 414c2302 authored by Paolo Maggi's avatar Paolo Maggi

New taglist plugin

parent 22f4d57c
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
......
......@@ -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
])
......
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):
......
......@@ -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);
}
......@@ -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);
......
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
......
SUBDIRS = docinfo sample cvschangelog time shell_output
SUBDIRS = docinfo sample cvschangelog taglist time shell_output
EXTRA_DIST = ChangeLog
......@@ -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);
......
# 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)
/* -*- 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);
}
/* -*- 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_ */
/* -*- 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"