Commit c83df2ab authored by Jason Leach's avatar Jason Leach Committed by Jacob Leach

Replaced the use of gnome-history with custom routines to store history in

2000-04-25  Jason Leach  <leach@wam.umd.edu>

	    * recent.c: Replaced the use of gnome-history with custom
              routines to store history in ~/.gnome/gedit, much
              better.
parent 33a1921e
......@@ -8,7 +8,7 @@
** Jason **
[ ] New webpage
[ ] Hack around the problem with recently used files, maybe we should
[X] Hack around the problem with recently used files, maybe we should
do all the code for that and not use gnome-history
[X] Fix the bug reported in www.freshmeat.net, when a user compiles
with --disable-gnome
......@@ -55,14 +55,13 @@ Medium tasks
* Add more options to the Preferences
* Auto-save options (configurable timeout in prefs)
* Add plugin to allow posting a document to a newsgroup.
* Make the column indicator accurate (if possible)
( I think we will solve this after porting to TkText )
* Get some decent documentation
Big/hard tasks
* Port to TkText
* Better line counting (might be easier after porting to TkText)
* Better column counting (might be easier after porting to TkText)
* regex searching
* Syntax Highlighting (plugin?)
......
2000-04-25 Jason Leach <leach@wam.umd.edu>
* recent.c: Replaced the use of gnome-history with custom routines
to store history in ~/.gnome/gedit, much better.
2000-04-21 Alex Roberts <bse@error.fsnet.co.uk>
* file.c: Fixed various spelling mistakes.
......
......@@ -29,6 +29,7 @@
#include "file.h"
#include "menus.h"
#include "plugin.h"
#include "recent.h"
#ifdef HAVE_LIBGNORBA
......@@ -74,6 +75,7 @@ void
gedit_shutdown (void)
{
gedit_save_settings ();
history_write_config ();
gtk_main_quit ();
}
......
......@@ -105,7 +105,8 @@ GnomeUIInfo gedit_edit_menu[] =
GNOMEUIINFO_MENU_PASTE_ITEM (edit_paste_cb, NULL),
GNOMEUIINFO_MENU_SELECT_ALL_ITEM (edit_selall_cb, NULL),
/* Simplify the interface. Find in files should be a plugin
/*
Simplify the interface. Find in files should be a plugin
Find in all the files open is something that will be used
very very little times. We should have it as a plugin, tho
{
......@@ -114,7 +115,8 @@ GnomeUIInfo gedit_edit_menu[] =
N_("Find text in all open files"),
find_in_files_cb, NULL, NULL,
GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_SEARCH
},*/
},
*/
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_MENU_FIND_ITEM (search_cb, NULL),
......
......@@ -21,7 +21,6 @@
#include <config.h>
#include <gnome.h>
#include <libgnome/gnome-history.h>
#include "gedit.h"
#include "document.h"
......@@ -39,6 +38,128 @@ static void recent_cb (GtkWidget *w, gedit_data *data);
void recent_add (char *filename);
GList *history_list = NULL;
static GList *
history_get_list (void)
{
gchar *filename, *key;
gint max_entries, i;
gboolean do_set = FALSE;
if (history_list)
return history_list;
gnome_config_push_prefix ("/gedit/History/");
/* Get maximum number of history entries. Write default value to
* config file if no entry exists. */
max_entries = gnome_config_get_int_with_default ("MaxFiles=4", &do_set); if (do_set)
gnome_config_set_int ("MaxFiles", 4);
/* Read the history filenames from the config file */
for (i = 0; i < max_entries; i++)
{
key = g_strdup_printf ("File%d", i);
filename = gnome_config_get_string (key);
if (filename == NULL)
{
/* Ran out of filenames. */
g_free (key);
break;
}
history_list = g_list_append (history_list, filename);
g_free (key);
}
gnome_config_pop_prefix ();
return history_list;
}
/**
* history_update_list:
* @filename:
*
* This function updates the history list. The return value is a
* pointer to the filename that was removed, if the list was already full
* or NULL if no items were removed.
*
* Return value:
**/
gchar *
history_update_list (gchar *filename)
{
gchar *name, *old_name = NULL;
GList *l = NULL;
GList *new_list = NULL;
gint max_entries, count = 0;
gboolean do_set = FALSE;
gboolean found = FALSE;
g_return_val_if_fail (filename != NULL, NULL);
/* Get maximum list length from config */
gnome_config_push_prefix ("/gedit/History/");
max_entries = gnome_config_get_int_with_default ("MaxFiles=4", &do_set);
if (do_set)
gnome_config_set_int ("MaxFiles", max_entries);
gnome_config_pop_prefix ();
/* Check if this filename already exists in the list */
for (l = history_list; l && (count < max_entries); l = l->next)
{
if (!found && (!strcmp ((gchar *)l->data, filename)
|| (count == max_entries - 1)))
{
/* This is either the last item in the list, or a
* duplicate of the requested entry. */
old_name = (gchar *)l->data;
found = TRUE;
}
else /* Add this item to the new list */
new_list = g_list_append (new_list, l->data);
count++;
}
/* Insert the new filename to the new list and free up the old list */
name = g_strdup (filename);
new_list = g_list_prepend (new_list, name);
g_list_free (history_list);
history_list = new_list;
return old_name;
}
/* Write contents of the history list to the configuration file. */
void
history_write_config (void)
{
gchar *key;
GList *l;
gint max_entries, i = 0;
if (history_list == NULL)
return;
max_entries = gnome_config_get_int ("/gedit/History/MaxFiles=4");
gnome_config_clean_section ("/gedit/History");
gnome_config_push_prefix ("/gedit/History/");
gnome_config_set_int ("MaxFiles", max_entries);
for (l = history_list; l; l = l->next) {
key = g_strdup_printf ("File%d", i++);
gnome_config_set_string (key, (gchar *)l->data);
g_free (l->data);
g_free (key);
}
gnome_config_sync ();
gnome_config_pop_prefix ();
g_list_free (history_list);
history_list = NULL;
}
/* Update the graphical part of the recently-used menu */
static void
recent_update_menus (GnomeApp *app, GList *recent_files)
......@@ -51,14 +172,14 @@ recent_update_menus (GnomeApp *app, GList *recent_files)
g_return_if_fail (app != NULL);
if (settings->num_recent)
gnome_app_remove_menu_range (app, _("_File/"), 6, settings->num_recent + 1);
gnome_app_remove_menu_range (app, _("_File/"), 6, 5);
if (recent_files == NULL)
return;
/* insert a separator at the beginning */
menu = g_malloc0 (2 * sizeof (GnomeUIInfo));
path = g_new (gchar, strlen (_("_File")) + strlen ("<Separator>") + 3 );
path = g_new (gchar, strlen (_("_File")) + strlen ("<Separator>") + 2);
sprintf (path, "%s/%s", _("_File"), "<Separator>");
menu->type = GNOME_APP_UI_SEPARATOR;
......@@ -86,12 +207,10 @@ recent_update_menus (GnomeApp *app, GList *recent_files)
(menu + 1)->type = GNOME_APP_UI_ENDOFINFO;
gnome_app_insert_menus (GNOME_APP(app), path, menu);
g_free (g_list_nth_data (recent_files, i));
}
g_free (menu);
settings->num_recent = g_list_length (recent_files);
g_list_free (recent_files);
g_free (path);
}
......@@ -113,9 +232,8 @@ recent_cb (GtkWidget *widget, gedit_data *data)
else
{
g_print ("recent_cb(): file unable to open\n");
/* FIXME :
If an error was encountered the delete the entry
from the menu ... Chema */
/* FIXME: If an error was encountered the delete the
entry from the menu */
}
}
......@@ -131,64 +249,9 @@ void
recent_update (GnomeApp *app)
{
GList *filelist = NULL;
GList *gnome_recent_list;
GnomeHistoryEntry histentry;
char *filename;
int i, j;
int nrecentdocs = 0;
filelist = NULL;
gnome_recent_list = gnome_history_get_recently_used ();
filelist = history_get_list ();
if (g_list_length (gnome_recent_list) <= 0)
{
return;
}
for (i = g_list_length (gnome_recent_list) - 1; i >= 0; i--)
{
histentry = g_list_nth_data (gnome_recent_list, i);
if (strcmp ("gedit", histentry->creator) != 0)
break;
/* FIXME : if file_1 is in the 3rd line of the recent
files and I reopen it, it should be in the 1st line now.Chema*/
if (g_list_length (filelist) > 0)
{
for (j = g_list_length (filelist) - 1; j >= 0; j--)
{
if (strcmp (histentry->filename, g_list_nth_data (filelist, j)) == 0)
{
filelist = g_list_remove (filelist, g_list_nth_data (filelist, j));
nrecentdocs--;
}
}
}
filename = g_malloc0 (strlen (histentry->filename) + 1);
strcpy (filename, histentry->filename);
filelist = g_list_append (filelist, filename);
nrecentdocs++;
/* For recent-directories, not yet fully implemented...
end_path = strrchr (histentry->filename, '/');
if (end_path) {
for (i = 0; i < strlen (histentry->filename); i++)
if ((histentry->filename + i) == end_path)
break;
directory = g_malloc0 (i + 2);
strcat (directory, histentry->filename, i);
}*/
if (nrecentdocs == MAX_RECENT)
/* if (g_list_length (filelist) == MAX_RECENT) */
break;
}
gnome_history_free_recently_used_list (gnome_recent_list);
recent_update_menus (app, filelist);
}
......@@ -201,10 +264,12 @@ recent_update (GnomeApp *app)
void
recent_add (char *filename)
{
gchar *del_name;
g_return_if_fail (filename != NULL);
gnome_history_recently_used (filename, "text/plain",
"gedit", "gedit_document");
del_name = history_update_list (filename);
g_free (del_name);
}
......
......@@ -22,7 +22,9 @@
#ifndef __RECENT_H__
#define __RECENT_H__
extern void recent_add (char *filename);
extern void recent_update (GnomeApp *app);
void recent_add (char *filename);
void recent_update (GnomeApp *app);
void history_write_config (void);
#endif
2000-04-25 Jason Leach <leach@wam.umd.edu>
* recent.c: Replaced the use of gnome-history with custom routines
to store history in ~/.gnome/gedit, much better.
2000-04-21 Alex Roberts <bse@error.fsnet.co.uk>
* file.c: Fixed various spelling mistakes.
......
......@@ -29,6 +29,7 @@
#include "file.h"
#include "menus.h"
#include "plugin.h"
#include "recent.h"
#ifdef HAVE_LIBGNORBA
......@@ -74,6 +75,7 @@ void
gedit_shutdown (void)
{
gedit_save_settings ();
history_write_config ();
gtk_main_quit ();
}
......
......@@ -105,7 +105,8 @@ GnomeUIInfo gedit_edit_menu[] =
GNOMEUIINFO_MENU_PASTE_ITEM (edit_paste_cb, NULL),
GNOMEUIINFO_MENU_SELECT_ALL_ITEM (edit_selall_cb, NULL),
/* Simplify the interface. Find in files should be a plugin
/*
Simplify the interface. Find in files should be a plugin
Find in all the files open is something that will be used
very very little times. We should have it as a plugin, tho
{
......@@ -114,7 +115,8 @@ GnomeUIInfo gedit_edit_menu[] =
N_("Find text in all open files"),
find_in_files_cb, NULL, NULL,
GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_SEARCH
},*/
},
*/
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_MENU_FIND_ITEM (search_cb, NULL),
......
......@@ -21,7 +21,6 @@
#include <config.h>
#include <gnome.h>
#include <libgnome/gnome-history.h>
#include "gedit.h"
#include "document.h"
......@@ -39,6 +38,128 @@ static void recent_cb (GtkWidget *w, gedit_data *data);
void recent_add (char *filename);
GList *history_list = NULL;
static GList *
history_get_list (void)
{
gchar *filename, *key;
gint max_entries, i;
gboolean do_set = FALSE;
if (history_list)
return history_list;
gnome_config_push_prefix ("/gedit/History/");
/* Get maximum number of history entries. Write default value to
* config file if no entry exists. */
max_entries = gnome_config_get_int_with_default ("MaxFiles=4", &do_set); if (do_set)
gnome_config_set_int ("MaxFiles", 4);
/* Read the history filenames from the config file */
for (i = 0; i < max_entries; i++)
{
key = g_strdup_printf ("File%d", i);
filename = gnome_config_get_string (key);
if (filename == NULL)
{
/* Ran out of filenames. */
g_free (key);
break;
}
history_list = g_list_append (history_list, filename);
g_free (key);
}
gnome_config_pop_prefix ();
return history_list;
}
/**
* history_update_list:
* @filename:
*
* This function updates the history list. The return value is a
* pointer to the filename that was removed, if the list was already full
* or NULL if no items were removed.
*
* Return value:
**/
gchar *
history_update_list (gchar *filename)
{
gchar *name, *old_name = NULL;
GList *l = NULL;
GList *new_list = NULL;
gint max_entries, count = 0;
gboolean do_set = FALSE;
gboolean found = FALSE;
g_return_val_if_fail (filename != NULL, NULL);
/* Get maximum list length from config */
gnome_config_push_prefix ("/gedit/History/");
max_entries = gnome_config_get_int_with_default ("MaxFiles=4", &do_set);
if (do_set)
gnome_config_set_int ("MaxFiles", max_entries);
gnome_config_pop_prefix ();
/* Check if this filename already exists in the list */
for (l = history_list; l && (count < max_entries); l = l->next)
{
if (!found && (!strcmp ((gchar *)l->data, filename)
|| (count == max_entries - 1)))
{
/* This is either the last item in the list, or a
* duplicate of the requested entry. */
old_name = (gchar *)l->data;
found = TRUE;
}
else /* Add this item to the new list */
new_list = g_list_append (new_list, l->data);
count++;
}
/* Insert the new filename to the new list and free up the old list */
name = g_strdup (filename);
new_list = g_list_prepend (new_list, name);
g_list_free (history_list);
history_list = new_list;
return old_name;
}
/* Write contents of the history list to the configuration file. */
void
history_write_config (void)
{
gchar *key;
GList *l;
gint max_entries, i = 0;
if (history_list == NULL)
return;
max_entries = gnome_config_get_int ("/gedit/History/MaxFiles=4");
gnome_config_clean_section ("/gedit/History");
gnome_config_push_prefix ("/gedit/History/");
gnome_config_set_int ("MaxFiles", max_entries);
for (l = history_list; l; l = l->next) {
key = g_strdup_printf ("File%d", i++);
gnome_config_set_string (key, (gchar *)l->data);
g_free (l->data);
g_free (key);
}
gnome_config_sync ();
gnome_config_pop_prefix ();
g_list_free (history_list);
history_list = NULL;
}
/* Update the graphical part of the recently-used menu */
static void
recent_update_menus (GnomeApp *app, GList *recent_files)
......@@ -51,14 +172,14 @@ recent_update_menus (GnomeApp *app, GList *recent_files)
g_return_if_fail (app != NULL);
if (settings->num_recent)
gnome_app_remove_menu_range (app, _("_File/"), 6, settings->num_recent + 1);
gnome_app_remove_menu_range (app, _("_File/"), 6, 5);
if (recent_files == NULL)
return;
/* insert a separator at the beginning */
menu = g_malloc0 (2 * sizeof (GnomeUIInfo));
path = g_new (gchar, strlen (_("_File")) + strlen ("<Separator>") + 3 );
path = g_new (gchar, strlen (_("_File")) + strlen ("<Separator>") + 2);
sprintf (path, "%s/%s", _("_File"), "<Separator>");
menu->type = GNOME_APP_UI_SEPARATOR;
......@@ -86,12 +207,10 @@ recent_update_menus (GnomeApp *app, GList *recent_files)
(menu + 1)->type = GNOME_APP_UI_ENDOFINFO;
gnome_app_insert_menus (GNOME_APP(app), path, menu);
g_free (g_list_nth_data (recent_files, i));
}
g_free (menu);
settings->num_recent = g_list_length (recent_files);
g_list_free (recent_files);
g_free (path);
}
......@@ -113,9 +232,8 @@ recent_cb (GtkWidget *widget, gedit_data *data)
else
{
g_print ("recent_cb(): file unable to open\n");
/* FIXME :
If an error was encountered the delete the entry
from the menu ... Chema */
/* FIXME: If an error was encountered the delete the
entry from the menu */
}
}
......@@ -131,64 +249,9 @@ void
recent_update (GnomeApp *app)
{
GList *filelist = NULL;
GList *gnome_recent_list;
GnomeHistoryEntry histentry;
char *filename;
int i, j;
int nrecentdocs = 0;
filelist = NULL;
gnome_recent_list = gnome_history_get_recently_used ();
filelist = history_get_list ();
if (g_list_length (gnome_recent_list) <= 0)
{
return;
}
for (i = g_list_length (gnome_recent_list) - 1; i >= 0; i--)
{
histentry = g_list_nth_data (gnome_recent_list, i);
if (strcmp ("gedit", histentry->creator) != 0)
break;
/* FIXME : if file_1 is in the 3rd line of the recent
files and I reopen it, it should be in the 1st line now.Chema*/
if (g_list_length (filelist) > 0)
{
for (j = g_list_length (filelist) - 1; j >= 0; j--)
{
if (strcmp (histentry->filename, g_list_nth_data (filelist, j)) == 0)
{
filelist = g_list_remove (filelist, g_list_nth_data (filelist, j));
nrecentdocs--;
}
}
}
filename = g_malloc0 (strlen (histentry->filename) + 1);
strcpy (filename, histentry->filename);
filelist = g_list_append (filelist, filename);
nrecentdocs++;
/* For recent-directories, not yet fully implemented...
end_path = strrchr (histentry->filename, '/');
if (end_path) {
for (i = 0; i < strlen (histentry->filename); i++)
if ((histentry->filename + i) == end_path)
break;
directory = g_malloc0 (i + 2);
strcat (directory, histentry->filename, i);
}*/
if (nrecentdocs == MAX_RECENT)
/* if (g_list_length (filelist) == MAX_RECENT) */
break;
}
gnome_history_free_recently_used_list (gnome_recent_list);
recent_update_menus (app, filelist);
}
......@@ -201,10 +264,12 @@ recent_update (GnomeApp *app)
void
recent_add (char *filename)
{
gchar *del_name;
g_return_if_fail (filename != NULL);
gnome_history_recently_used (filename, "text/plain",
"gedit", "gedit_document");
del_name = history_update_list (filename);
g_free (del_name);
}
......
......@@ -22,7 +22,9 @@
#ifndef __RECENT_H__
#define __RECENT_H__
extern void recent_add (char *filename);
extern void recent_update (GnomeApp *app);
void recent_add (char *filename);
void recent_update (GnomeApp *app);
void history_write_config (void);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment