Remove extra debug message
[geda-gaf.git] / gschem / src / o_delete.c
blobfd0a39a66c6e6ff2cac4fa225bb0573cf3107563
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2019 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <config.h>
22 #include <stdio.h>
24 #include "gschem.h"
26 /*! \brief Delete an object.
27 * \par Function Description
28 * This function erases the object \a object before deleting it. It
29 * deals with connection and object connected to it.
31 * \param [in] w_current The GschemToplevel object.
32 * \param [in] object The object to delete.
34 void o_delete (GschemToplevel *w_current, OBJECT *object)
36 TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
38 g_return_if_fail (object != NULL);
40 o_selection_remove (toplevel, toplevel->page_current->selection_list, object);
41 s_page_remove (toplevel, toplevel->page_current, object);
42 g_run_hook_object (w_current, "%remove-objects-hook", object);
43 s_delete_object (toplevel, object);
46 /*! \brief Delete objects from the selection.
47 * \par Function Description
48 * This function deletes the objects selected on the current page of
49 * toplevel \a w_current.
51 * \param [in] w_current The GschemToplevel object.
53 void o_delete_selected (GschemToplevel *w_current, gchar *undo_desc)
55 TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
56 SELECTION *selection = toplevel->page_current->selection_list;
57 GList *to_remove;
58 GList *iter;
59 OBJECT *obj;
60 unsigned int locked_num = 0;
62 g_return_if_fail (o_select_selected (w_current));
64 to_remove = g_list_copy (geda_list_get_glist (selection));
66 for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) {
67 obj = (OBJECT *) iter->data;
68 if (obj->selectable == FALSE)
69 locked_num++;
72 if (locked_num > 0) {
73 GList *non_locked = NULL;
74 gint resp;
75 GtkWidget *dialog = gtk_message_dialog_new (NULL,
76 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
77 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
78 ngettext ("Delete locked object?", "Delete %u locked objects?",
79 locked_num), locked_num);
80 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
81 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
82 GTK_STOCK_YES, GTK_RESPONSE_YES,
83 GTK_STOCK_NO, GTK_RESPONSE_NO, NULL);
84 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO);
86 resp = gtk_dialog_run (GTK_DIALOG (dialog));
87 gtk_widget_destroy (dialog);
89 switch (resp) {
90 case GTK_RESPONSE_YES: /* Remove all */
91 break;
92 case GTK_RESPONSE_NO: /* Remove non locked */
93 for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) {
94 obj = (OBJECT *) iter->data;
95 if (obj->selectable == TRUE)
96 non_locked = g_list_append (non_locked, iter->data);
98 g_list_free (to_remove);
99 to_remove = non_locked;
100 break;
101 default: /* Cancel */
102 g_list_free (to_remove);
103 return;
107 for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) {
108 obj = (OBJECT *) iter->data;
109 o_selection_remove (toplevel, selection, obj);
110 s_page_remove (toplevel, toplevel->page_current, obj);
113 g_run_hook_object_list (w_current, "%remove-objects-hook", to_remove);
115 if (w_current->inside_action && w_current->event_state == MOVEMODE) {
116 /* In MOVEMODE selection is equal to the place list and we
117 * have to remove the place list as well. o_move_cancel will
118 * do it for us. */
119 o_move_cancel (w_current);
120 /* Now change the current mode to SELECT since we have nothing
121 * to move any more. */
122 i_set_state (w_current, SELECT);
125 for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) {
126 obj = (OBJECT *) iter->data;
127 s_delete_object (toplevel, obj);
130 g_list_free (to_remove);
132 gschem_toplevel_page_content_changed (w_current, toplevel->page_current);
133 o_undo_savestate_old (w_current, UNDO_ALL, undo_desc);
134 i_update_menus (w_current);