/*! \brief Delete Attribute dialog * * This function throws up the "Delete foo, are you sure?" dialog * box. It offers two buttons: "yes" and "cancel". */ void x_dialog_delattrib() { GtkWidget *dialog; gint mincol, maxcol; GtkSheet *sheet; gint cur_page; /* First verify that exactly one column is selected. */ cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); sheet = GTK_SHEET(sheets[cur_page]); if (sheet == NULL) { return; } mincol = x_gtksheet_get_min_col(sheet); maxcol = x_gtksheet_get_max_col(sheet); if ( (mincol != maxcol) || (mincol == -1) || (maxcol == -1) ) { /* Improper selection -- maybe throw up error box? */ return; } /* Create the dialog */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, _("Are you sure you want to delete this attribute?")); gtk_window_set_title(GTK_WINDOW(dialog), _("Delete attribute")); switch(gtk_dialog_run(GTK_DIALOG(dialog))) { case GTK_RESPONSE_YES: /* call the fcn to actually delete the attrib column. */ s_toplevel_delete_attrib_col(); /* this fcn figures out * which col to delete. */ break; default: break; } gtk_widget_destroy(dialog); }
/*! \brief Delete an attribute column * * This function gets called when the user has selected a single attrib * column, selected the edit->delete attrib item from the pull-down * menu, and then said "yes" to the confirm dialog. */ void s_toplevel_delete_attrib_col() { gint cur_page; /* current page in notbook */ gint mincol, maxcol; GtkSheet *sheet; gchar *attrib_name; /* Repeat previous checks */ cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); sheet = GTK_SHEET(sheets[cur_page]); if (sheet == NULL) { return; } mincol = x_gtksheet_get_min_col(sheet); maxcol = x_gtksheet_get_max_col(sheet); if ( (mincol != maxcol) || (mincol == -1) || (maxcol == -1) ) { return; } #ifdef DEBUG printf("In s_toplevel_delete_attrib_col, checks were OK, now do real work\n"); #endif /* Rebuild the gattrib-specific data structures */ switch (cur_page) { case 0: /* component attribute */ /* Eventually, I want to just resize the table after deleting the * attrib. However, that is difficult. Therefore, I will just * destroy the old table and recreate it for now. */ s_table_destroy(sheet_head->component_table, sheet_head->comp_count, sheet_head->comp_attrib_count); /* Get name (label) of the col to delete from the gtk sheet */ attrib_name = g_strdup( gtk_sheet_column_button_get_label(sheet, mincol) ); if (attrib_name != NULL) { #ifdef DEBUG printf("In s_toplevel_delete_attrib_col, attrib to delete = %s\n", attrib_name); #endif } else { fprintf(stderr, "In s_toplevel_delete_attrib_col, can't get attrib name\n"); return; } #ifdef DEBUG printf("In s_toplevel_delete_attrib_col, before deleting comp attrib.\n"); printf(" comp_attrib_count = %d\n", sheet_head->comp_attrib_count); #endif s_string_list_delete_item(&(sheet_head->master_comp_attrib_list_head), &(sheet_head->comp_attrib_count), attrib_name); s_string_list_sort_master_comp_attrib_list(); /* this renumbers list also */ g_free(attrib_name); #ifdef DEBUG printf("In s_toplevel_delete_attrib_col, just updated comp_attrib string list.\n"); printf(" new comp_attrib_count = %d\n", sheet_head->comp_attrib_count); #endif /* Now create new table with new attrib count*/ sheet_head->component_table = s_table_new(sheet_head->comp_count, sheet_head->comp_attrib_count); #ifdef DEBUG printf("In s_toplevel_delete_attrib_col, just updated SHEET_DATA info.\n"); #endif break; case 1: /* net attribute */ /* insert into net attribute list */ break; case 2: /* pin attribute */ /* insert into pin attribute list */ break; } /* switch */ /* Delete col on gtksheet */ #ifdef DEBUG printf("In s_toplevel_delete_attrib_col, about to delete col in gtksheet.\n"); #endif gtk_sheet_delete_columns (sheet, mincol, 1); #ifdef DEBUG printf("In s_toplevel_delete_attrib_col, done deleting col in gtksheet.\n"); #endif sheet_head->CHANGED = TRUE; /* Set changed flag so user is prompted when exiting */ return; }