/** -*- erwin-c -*- erwin - really simple html editor Copyright (C) 2002 Adrian Reber 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 File: recent.c Description: recent files functions Changes: 16 Jul 2002: created */ /* $Id: recent.c,v 1.9 2004/12/27 16:20:08 adrian Exp $ */ #ifndef lint static const char vcid[] = "$Id: recent.c,v 1.9 2004/12/27 16:20:08 adrian Exp $"; #endif /* lint */ #include #include #include #include "erwinfunctions.h" extern int _debug_; #ifdef ENABLE_DEBUG_OUTPUT #define _DEBUG_ if(_debug_) #else #define _DEBUG_ if(0) #endif GList *recent = NULL; void add_to_recent(gchar * file) { gint i; for (i = 0; i < g_list_length(recent); i++) { if (!strcmp(file, g_list_nth_data(recent, i))) return; } while (g_list_length(recent) >= globals.number_of_recent) recent = g_list_remove(recent, (g_list_last(recent))->data); recent = g_list_prepend(recent, file); } void dump_recent() { gint i; for (i = 0; i < g_list_length(recent); i++) { fprintf(stderr, "%s:dump:%s\n", PACKAGE, (char *) g_list_nth_data(recent, i)); } } gchar *get_recent(gint pos) { return (char *) g_list_nth_data(recent, pos); } void callback(GtkMenuItem * menuitem, gpointer user_data) { int *bla = (int *) user_data; _open_file_ok(get_recent(*bla)); } void update_recent(GtkWidget * recent_menu) { static GtkWidget *menu = NULL; static GList *menuitems = NULL; int i = 0; struct item_id { GtkWidget *menuitem; int call; }; struct item_id *bla = NULL; if (recent_menu && !menu) { menu = recent_menu; } if (!menu) return; while (g_list_length(menuitems) > 0) { if (menuitems->data) { bla = (struct item_id *) (g_list_last(menuitems))->data; if (bla->menuitem) gtk_widget_destroy(bla->menuitem); } menuitems = g_list_remove(menuitems, bla); free(bla); } for (i = 0; i < globals.number_of_recent; i++) { if (get_recent(i)) { bla = (struct item_id *) malloc(sizeof(struct item_id)); memset(bla, 0, sizeof(struct item_id)); bla->menuitem = gtk_menu_item_new_with_label(g_basename((const gchar *) get_recent(i))); gtk_menu_shell_append(GTK_MENU_SHELL(menu), bla->menuitem); bla->call = i; g_signal_connect(G_OBJECT(bla->menuitem), "activate", G_CALLBACK(callback), &bla->call); gtk_widget_show(bla->menuitem); menuitems = g_list_append(menuitems, bla); } } }