[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA-cvs: CVS update: gschem.c
User: ahvezda
Date: 07/06/09 11:14:08
Modified: . gschem.c gschem_dialog.c x_menus.c x_window.c
Log:
Applied a few patches from Ivan Stankovic
Revision Changes Path
1.44 eda/geda/gaf/gschem/src/gschem.c
(In the diff below, changes in quantity of whitespace are not shown.)
Index: gschem.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/gschem.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- gschem.c 9 Jun 2007 14:54:33 -0000 1.43
+++ gschem.c 9 Jun 2007 15:14:08 -0000 1.44
@@ -47,6 +47,34 @@
void stroke_init(void);
#endif
+typedef struct {
+ gschem_atexit_func func;
+ gpointer arg;
+} gschem_atexit_struct;
+
+static GList *exit_functions = NULL;
+
+/*! \brief Register a function to be called on program exit
+ *
+ * \par Function Description
+ * This function registers a function to be called on
+ * program exit. Multiple functions will be executed in
+ * the order they are registered.
+ *
+ * \param [in] func a pointer to the function to be registered
+ * \param [in] data an arbitrary argument provided to the function
+ * when it is called
+ */
+void gschem_atexit(gschem_atexit_func func, gpointer data)
+{
+ gschem_atexit_struct *p;
+
+ p = g_new(gschem_atexit_struct, 1);
+ p->func = func;
+ p->arg = data;
+ exit_functions = g_list_append(exit_functions, p);
+}
+
/*! \brief Cleanup gSchem on exit.
* \par Function Description
* This function cleans up all memory objects allocated during the
@@ -54,6 +82,19 @@
*/
void gschem_quit(void)
{
+ GList *list;
+ gschem_atexit_struct *p;
+
+ /* Call all registered functions in order */
+ list = exit_functions;
+ while(list != NULL) {
+ p = (gschem_atexit_struct *) list->data;
+ p->func(p->arg);
+ g_free(p);
+ list = g_list_next(list);
+ }
+ g_list_free(exit_functions);
+
s_clib_free();
s_slib_free();
s_menu_free();
@@ -212,6 +253,7 @@
/* Load recent files list. This must be done
* before calling x_window_setup(). */
recent_files_load();
+ gschem_atexit(recent_files_save, NULL);
/* At end, complete set up of window. */
colormap = gdk_colormap_get_system ();
1.2 eda/geda/gaf/gschem/src/gschem_dialog.c
(In the diff below, changes in quantity of whitespace are not shown.)
Index: gschem_dialog.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/gschem_dialog.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gschem_dialog.c 30 May 2007 00:10:23 -0000 1.1
+++ gschem_dialog.c 9 Jun 2007 15:14:08 -0000 1.2
@@ -51,8 +51,10 @@
*
* \par Function Description
* This is called at program exit to save all window geometry data into a file
+ *
+ * \param [in] user_data unused
*/
-static void save_geometry_to_file()
+static void save_geometry_to_file(gpointer user_data)
{
gchar *data, *file;
@@ -119,7 +121,7 @@
dialog_geometry = g_key_file_new();
/* Remember to save data on program exit */
- atexit(save_geometry_to_file);
+ gschem_atexit(save_geometry_to_file, NULL);
if (!g_file_test (file, G_FILE_TEST_EXISTS)) {
gchar *dir = g_build_filename (g_get_home_dir (), ".gEDA", NULL);
1.46 eda/geda/gaf/gschem/src/x_menus.c
(In the diff below, changes in quantity of whitespace are not shown.)
Index: x_menus.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/x_menus.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- x_menus.c 4 Jun 2007 16:15:38 -0000 1.45
+++ x_menus.c 9 Jun 2007 15:14:08 -0000 1.46
@@ -420,11 +420,69 @@
#define RECENT_FILES_STORE ".gEDA/gschem-recent-files"
+/*! \brief Make all toplevels reflect changes to the
+ * recent files list.
+ */
+static void update_recent_files_menus()
+{
+ TOPLEVEL *w;
+ GtkWidget *submenu, *recent_menu_item;
+
+ w = global_window_current;
+ while(w->prev)
+ w = w->prev;
+
+ while(w) {
+ if(w->wid == -1 || w->menubar == NULL) {
+ w = w->next;
+ continue;
+ }
+
+ recent_menu_item = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(
+ w->menubar), "File/Recent files");
+
+ submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(recent_menu_item));
+ gtk_widget_destroy(submenu);
+ x_menu_attach_recent_files_submenu(w);
+ w = w->next;
+ }
+}
+
+/*! \brief Remove all entries from the recent files
+ * list and update all toplevels.
+ */
+static void clear_recent_file_list(gpointer data)
+{
+ GList *p;
+
+ p = recent_files;
+ while(p) {
+ g_free(p->data);
+ p = g_list_next(p);
+ }
+ g_list_free(recent_files);
+ recent_files = NULL;
+
+ update_recent_files_menus();
+}
+
static void recent_file_clicked(gpointer filename)
{
+ FILE *fp;
PAGE *page;
TOPLEVEL *w;
+ /* Check if the file exists */
+ fp = fopen((char *) filename, "r");
+ if(fp == NULL) {
+ /* Remove this entry from all menus */
+ s_log_message(_("Couldn't open file %s\n"), (char *) filename);
+ recent_files = g_list_remove(recent_files, filename);
+ update_recent_files_menus();
+ return;
+ }
+ fclose(fp);
+
w = s_toplevel_new();
x_window_setup(w);
page = x_window_open_page(w, (char *)filename);
@@ -440,6 +498,7 @@
void x_menu_attach_recent_files_submenu(TOPLEVEL *w_current)
{
gulong id;
+ GtkWidget *tmp;
GtkWidget *recent_menu_item, *recent_submenu;
recent_menu_item = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(
@@ -457,18 +516,34 @@
/* remove 'q' from the menu item string; there has to be a better way to
* create a menu item without a hotkey being assigned to it automatically */
GtkWidget *label = gtk_bin_get_child(GTK_BIN(recent_menu_item));
- gtk_label_set_text(GTK_LABEL(label), "Recent files");
+ gtk_label_set_text(GTK_LABEL(label), _("Recent files"));
recent_submenu = gtk_menu_new();
GList *p = recent_files;
while(p) {
- GtkWidget *tmp = gtk_menu_item_new_with_label((gchar *)p->data);
+ tmp = gtk_menu_item_new_with_label((gchar *)p->data);
gtk_signal_connect_object(GTK_OBJECT(tmp), "activate",
GTK_SIGNAL_FUNC (recent_file_clicked),
p->data);
gtk_menu_append(GTK_MENU(recent_submenu), tmp);
p = g_list_next(p);
}
+
+ if(recent_files != NULL) {
+ /* Append the 'Clear' menu item to the submenu */
+ GtkWidget *alignment = gtk_alignment_new(0.5, 0, 0, 0);
+
+ tmp = gtk_menu_item_new();
+ gtk_container_add(GTK_CONTAINER(alignment), gtk_label_new(_("Clear")));
+ gtk_container_add(GTK_CONTAINER(tmp), alignment);
+
+ gtk_signal_connect_object(GTK_OBJECT(tmp), "activate",
+ GTK_SIGNAL_FUNC (clear_recent_file_list), NULL);
+
+ gtk_menu_append(GTK_MENU(recent_submenu), gtk_separator_menu_item_new());
+ gtk_menu_append(GTK_MENU(recent_submenu), tmp);
+ }
+
gtk_widget_show_all(recent_submenu);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent_menu_item), recent_submenu);
}
@@ -478,7 +553,6 @@
void recent_files_add(const char *filename)
{
gchar *basename;
- GtkWidget *recent_menu_item, *recent_submenu;
basename = g_path_get_basename(filename);
if(strstr(basename, "untitled_") == basename) {
@@ -498,30 +572,7 @@
filename = g_strdup(filename);
recent_files = g_list_prepend(recent_files, (gpointer)filename);
-
- /* walk through all toplevels and add the filename to the recent file submenu */
- TOPLEVEL *w = global_window_current;
- while(w->prev)
- w = w->prev;
-
- while(w) {
- if(w->menubar == NULL) {
- w = w->next;
- continue;
- }
-
- recent_menu_item = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(
- w->menubar), "File/Recent files");
- recent_submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(recent_menu_item));
-
- GtkWidget *s = gtk_menu_item_new_with_label(filename);
- gtk_widget_show(s);
- gtk_menu_shell_prepend(GTK_MENU_SHELL(recent_submenu), s);
- gtk_signal_connect_object(GTK_OBJECT(s), "activate",
- GTK_SIGNAL_FUNC (recent_file_clicked),
- (gpointer)filename);
- w = w->next;
- }
+ update_recent_files_menus();
}
/*! \brief Make RECENT_FILES_STORE contain an empty file list.
@@ -543,8 +594,10 @@
}
/*! \brief Save the list of recent files to RECENT_FILES_STORE.
+ *
+ * \param [in] user_data unused
*/
-void recent_files_save()
+void recent_files_save(gpointer user_data)
{
gchar **files = NULL;
int num = 0;
@@ -552,8 +605,10 @@
gchar *file = g_build_filename(g_get_home_dir(), RECENT_FILES_STORE, NULL);
GList *p = recent_files;
- if(p == NULL)
+ if(p == NULL) {
+ recent_files_create_empty();
return;
+ }
while(p) {
files = g_realloc(files, (num + 1) * sizeof(gchar *));
1.56 eda/geda/gaf/gschem/src/x_window.c
(In the diff below, changes in quantity of whitespace are not shown.)
Index: x_window.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/x_window.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -b -r1.55 -r1.56
--- x_window.c 28 May 2007 07:42:19 -0000 1.55
+++ x_window.c 9 Jun 2007 15:14:08 -0000 1.56
@@ -829,7 +829,6 @@
/* just closed last window, so quit */
if (last_window) {
- recent_files_save();
gschem_quit();
}
_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs