/*! \brief delete a page and it's contents * \par Function Description * Deletes a single page <B>page</B> from <B>toplevel</B>'s list of pages. * * See #s_page_delete_list() to delete all pages of a <B>toplevel</B> * * If the current page of toplevel is given as parameter <B>page</B>, * the function sets the field <B>page_current</B> of the TOPLEVEL * struct to NULL. */ void s_page_delete (TOPLEVEL *toplevel, PAGE *page) { PAGE *tmp; gchar *backup_filename; gchar *real_filename; /* We need to temporarily make the page being deleted current because * various functions called below (some indirectly) assume they are * deleting objects from the current page. * * These functions are known to include: * s_delete_object () */ /* save page_current and switch to page */ if (page == toplevel->page_current) { tmp = NULL; } else { tmp = toplevel->page_current; s_page_goto (toplevel, page); } /* Get the real filename and file permissions */ real_filename = follow_symlinks (page->page_filename, NULL); if (real_filename == NULL) { s_log_message (_("s_page_delete: Can't get the real filename of %s."), page->page_filename); } else { backup_filename = f_get_autosave_filename (real_filename); /* Delete the backup file */ if ( (g_file_test (backup_filename, G_FILE_TEST_EXISTS)) && (!g_file_test(backup_filename, G_FILE_TEST_IS_DIR)) ) { if (unlink(backup_filename) != 0) { s_log_message(_("s_page_delete: Unable to delete backup file %s."), backup_filename); } } g_free (backup_filename); } g_free(real_filename); /* Free the selection object */ g_object_unref( page->selection_list ); /* then delete objects of page */ s_page_delete_objects (toplevel, page); /* Free the objects in the place list. */ s_delete_object_glist (toplevel, page->place_list); page->place_list = NULL; #if DEBUG printf("Freeing page: %s\n", page->page_filename); s_tile_print(toplevel); #endif s_tile_free_all (page); s_stretch_destroy_all (page->stretch_list); /* free current page undo structs */ s_undo_free_all (toplevel, page); /* ouch, deal with parents going away and the children still around */ page->up = -2; g_free (page->page_filename); geda_list_remove( toplevel->pages, page ); #if DEBUG s_tile_print (toplevel); #endif g_free (page); /* restore page_current */ if (tmp != NULL) { s_page_goto (toplevel, tmp); } else { /* page was page_current */ toplevel->page_current = NULL; /* page_current must be updated by calling function */ } }
/*! \brief delete a page and it's contents * \par Function Description * Deletes a single page <B>page</B> from <B>toplevel</B>'s list of pages. * * See #s_page_delete_list() to delete all pages of a <B>toplevel</B> * * If the current page of toplevel is given as parameter <B>page</B>, * the function sets the field <B>page_current</B> of the TOPLEVEL * struct to NULL. */ void s_page_delete (TOPLEVEL *toplevel, PAGE *page) { PAGE *tmp; gchar *backup_filename; gchar *real_filename; /* We need to temporarily make the page being deleted current because * various functions called below (some indirectly) assume they are * deleting objects from the current page. * * These functions are known to include: * s_delete_object () */ /* save page_current and switch to page */ if (page == toplevel->page_current) { tmp = NULL; } else { tmp = toplevel->page_current; s_page_goto (toplevel, page); } /* Get the real filename and file permissions */ real_filename = follow_symlinks (page->page_filename, NULL); if (real_filename == NULL) { s_log_message (_("s_page_delete: Can't get the real filename of %s."), page->page_filename); } else { backup_filename = f_get_autosave_filename (real_filename); /* Delete the backup file */ if ( (g_file_test (backup_filename, G_FILE_TEST_EXISTS)) && (!g_file_test(backup_filename, G_FILE_TEST_IS_DIR)) ) { if (unlink(backup_filename) != 0) { s_log_message(_("s_page_delete: Unable to delete backup file %s."), backup_filename); } } g_free (backup_filename); } g_free(real_filename); /* Free the selection object */ g_object_unref( page->selection_list ); /* then delete objects of page */ s_page_delete_objects (toplevel, page); /* Free the objects in the place list. */ s_delete_object_glist (toplevel, page->place_list); page->place_list = NULL; /* This removes all objects from the list of connectible objects * of the given \a page. */ if (g_list_length (page->connectible_list) != 0) { fprintf (stderr, "OOPS! page->connectible_list had something in it when it was freed!\n"); fprintf (stderr, "Length: %d\n", g_list_length (page->connectible_list)); } g_list_free (page->connectible_list); page->connectible_list = NULL; /* free current page undo structs */ s_undo_free_all (toplevel, page); /* ouch, deal with parents going away and the children still around */ page->up = -2; g_free (page->page_filename); geda_list_remove( toplevel->pages, page ); s_weakref_notify (page, page->weak_refs); g_free (page); /* restore page_current */ if (tmp != NULL) { s_page_goto (toplevel, tmp); } else { /* page was page_current */ s_toplevel_set_page_current (toplevel, NULL); /* page_current must be updated by calling function */ } }