/* * Copyright (c) by Allin Cottrell * * 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 "gretl.h" #include "filelists.h" #ifdef G_OS_WIN32 # include "gretlwin32.h" #endif /* lists of recently opened files */ static char datalist[MAXRECENT][MAXSTR]; static char sessionlist[MAXRECENT][MAXSTR]; static char scriptlist[MAXRECENT][MAXSTR]; /* and pointers to same */ static char *datap[MAXRECENT]; static char *sessionp[MAXRECENT]; static char *scriptp[MAXRECENT]; static void real_add_files_to_menus (int ftype); void initialize_file_lists (void) { int i; /* initialize lists of recently opened files */ for (i=0; imessage); g_error_free (err); } g_free(key); g_slist_free(flist); } void save_file_lists (GConfClient *client) { printfilelist(FILE_LIST_DATA, client); printfilelist(FILE_LIST_SESSION, client); printfilelist(FILE_LIST_SCRIPT, client); } void read_file_lists (GConfClient *client) { GSList *flist = NULL; char key[MAXSTR]; int i, j; initialize_file_lists(); for (i=0; i<3; i++) { sprintf(key, "/apps/gretl/%s", file_sections[i]); flist = gconf_client_get_list(client, key, GCONF_VALUE_STRING, NULL); if (flist != NULL) { for (j=0; jdata); flist = flist->next; } g_slist_free(flist); flist = NULL; } } } #elif defined(G_OS_WIN32) static void printfilelist (int filetype) { char rpath[MAXLEN]; char **filep; int i; filep = get_file_list(filetype); if (filep == NULL) { return; } for (i=0; iifac, itempath); if (w != NULL) { gtk_item_factory_delete_item(mdata->ifac, itempath); } } } static char *cut_multiple_slashes (char *fname) { char *s = fname; #ifdef G_OS_WIN32 /* may be ok for a filename to start with a double backslash */ s++; #endif while (*s) { if (*s == SLASH) { if (*(s+1) == SLASH) { memmove(s, s + 1, strlen(s + 1) + 1); } else if (*(s+1) == '.' && *(s+2) == SLASH) { memmove(s, s + 2, strlen(s + 2) + 1); } } s++; } return fname; } static void add_files_to_menu (int ftype) { real_add_files_to_menus(ftype); } void mkfilelist (int filetype, char *fname_in) { char *tmp[MAXRECENT-1]; char **filep; char *fname; int i, match = -1; char trfname[MAXLEN]; cut_multiple_slashes(fname_in); strcpy(trfname, fname_in); my_filename_to_utf8(trfname); fname = trfname; filep = get_file_list(filetype); if (filep == NULL) { return; } /* see if this file is already on the list */ #ifdef G_OS_WIN32 for (i=0; iifac, msep[j]); if (w == NULL) { fileitem.path = g_strdup(msep[j]); fileitem.accelerator = NULL; fileitem.callback = NULL; fileitem.callback_action = 0; fileitem.item_type = itemtype; gtk_item_factory_create_item(mdata->ifac, &fileitem, NULL, 1); g_free(fileitem.path); } /* put the files under the menu separator */ for (i=0; iifac, &fileitem, NULL, 1); g_free(fileitem.path); w = gtk_item_factory_get_widget_by_action(mdata->ifac, i); if (w != NULL) { gretl_tooltips_add(w, filep[i]); } } else { break; } } } } void add_files_to_menus (void) { real_add_files_to_menus(3); }