void dlg_destroy (WDialog * h) { /* if some widgets have history, save all history at one moment here */ dlg_save_history (h); dlg_broadcast_msg (h, MSG_DESTROY); g_list_free_full (h->widgets, g_free); mc_event_group_del (h->event_group); g_free (h->event_group); g_free (h->title); g_free (h); do_refresh (); }
void destroy_dlg (Dlg_head * h) { /* if some widgets have history, save all history at one moment here */ dlg_save_history (h); dlg_broadcast_msg (h, WIDGET_DESTROY, FALSE); g_list_foreach (h->widgets, (GFunc) g_free, NULL); g_list_free (h->widgets); mc_event_group_del (h->event_group); g_free (h->event_group); g_free (h->title); g_free (h); do_refresh (); }
void set_display_type (int num, panel_view_mode_t type) { int x = 0, y = 0, cols = 0, lines = 0; unsigned int the_other = 0; /* Index to the other panel */ const char *file_name = NULL; /* For Quick view */ Widget *new_widget = NULL, *old_widget = NULL; panel_view_mode_t old_type = view_listing; WPanel *the_other_panel = NULL; if (num >= MAX_VIEWS) { fprintf (stderr, "Cannot allocate more that %d views\n", MAX_VIEWS); abort (); } /* Check that we will have a WPanel * at least */ if (type != view_listing) { the_other = num == 0 ? 1 : 0; if (panels[the_other].type != view_listing) return; } /* Get rid of it */ if (panels[num].widget != NULL) { Widget *w = panels[num].widget; WPanel *panel = PANEL (w); x = w->x; y = w->y; cols = w->cols; lines = w->lines; old_widget = w; old_type = panels[num].type; if (old_type == view_listing && panel->frame_size == frame_full && type != view_listing) { if (panels_layout.horizontal_split) { cols = COLS; x = 0; } else { cols = COLS - panels_layout.left_panel_size; if (num == 1) x = panels_layout.left_panel_size; } } } /* Restoring saved path from panels.ini for nonlist panel */ /* when it's first creation (for example view_info) */ if (old_widget == NULL && type != view_listing) { char *panel_dir; panel_dir = _vfs_get_cwd (); panels[num].last_saved_dir = g_strdup (panel_dir); g_free (panel_dir); } switch (type) { case view_nothing: case view_listing: new_widget = restore_into_right_dir_panel (num, old_widget); widget_set_size (new_widget, y, x, lines, cols); break; case view_info: new_widget = WIDGET (info_new (y, x, lines, cols)); break; case view_tree: new_widget = WIDGET (tree_new (y, x, lines, cols, TRUE)); break; case view_quick: new_widget = WIDGET (mcview_new (y, x, lines, cols, TRUE)); the_other_panel = PANEL (panels[the_other].widget); if (the_other_panel != NULL) file_name = the_other_panel->dir.list[the_other_panel->selected].fname; else file_name = ""; mcview_load ((struct mcview_struct *) new_widget, 0, file_name, 0, 0, 0); break; default: break; } if (type != view_listing) /* Must save dir, for restoring after change type to */ /* view_listing */ save_panel_dir (num); panels[num].type = type; panels[num].widget = new_widget; /* We use replace to keep the circular list of the dialog in the */ /* same state. Maybe we could just kill it and then replace it */ if ((midnight_dlg != NULL) && (old_widget != NULL)) { if (old_type == view_listing) { /* save and write directory history of panel * ... and other histories of midnight_dlg */ dlg_save_history (midnight_dlg); } widget_replace (old_widget, new_widget); } if (type == view_listing) { WPanel *panel = PANEL (new_widget); /* if existing panel changed type to view_listing, then load history */ if (old_widget != NULL) { ev_history_load_save_t event_data = { NULL, new_widget }; mc_event_raise (midnight_dlg->event_group, MCEVENT_HISTORY_LOAD, &event_data); } if (num == 0) left_panel = panel; else right_panel = panel; /* forced update format after set new sizes */ set_panel_formats (panel); } if (type == view_tree) the_tree = (WTree *) new_widget; /* Prevent current_panel's value from becoming invalid. * It's just a quick hack to prevent segfaults. Comment out and * try following: * - select left panel * - invoke menue left/tree * - as long as you stay in the left panel almost everything that uses * current_panel causes segfault, e.g. C-Enter, C-x c, ... */ if ((type != view_listing) && (current_panel == PANEL (old_widget))) current_panel = num == 0 ? right_panel : left_panel; g_free (old_widget); }