static void mcview_hook (void *v) { mcview_t *view = (mcview_t *) v; WPanel *panel; /* If the user is busy typing, wait until he finishes to update the screen */ if (!is_idle ()) { if (!hook_present (idle_hook, mcview_hook)) add_hook (&idle_hook, mcview_hook, v); return; } delete_hook (&idle_hook, mcview_hook); if (get_current_type () == view_listing) panel = current_panel; else if (get_other_type () == view_listing) panel = other_panel; else return; mcview_done (view); mcview_init (view); mcview_load (view, 0, panel->dir.list[panel->selected].fname, 0, 0, 0); mcview_display (view); }
static void exec_extension_view (void *target, char *cmd, const vfs_path_t * filename_vpath, int start_line) { int def_hex_mode = mcview_default_hex_mode, changed_hex_mode = 0; int def_nroff_flag = mcview_default_nroff_flag, changed_nroff_flag = 0; mcview_altered_hex_mode = 0; mcview_altered_nroff_flag = 0; if (def_hex_mode != mcview_default_hex_mode) changed_hex_mode = 1; if (def_nroff_flag != mcview_default_nroff_flag) changed_nroff_flag = 1; if (target == NULL) mcview_viewer (cmd, filename_vpath, start_line); else mcview_load ((mcview_t *) target, cmd, vfs_path_as_str (filename_vpath), start_line); if (changed_hex_mode && !mcview_altered_hex_mode) mcview_default_hex_mode = def_hex_mode; if (changed_nroff_flag && !mcview_altered_nroff_flag) mcview_default_nroff_flag = def_nroff_flag; dialog_switch_process_pending (); }
gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_line) { gboolean succeeded; mcview_t *lc_mcview; WDialog *view_dlg; /* Create dialog and widgets, put them on the dialog */ view_dlg = dlg_create (FALSE, 0, 0, LINES, COLS, NULL, mcview_dialog_callback, NULL, "[Internal File Viewer]", NULL, DLG_WANT_TAB); lc_mcview = mcview_new (0, 0, LINES - 1, COLS, FALSE); add_widget (view_dlg, lc_mcview); add_widget (view_dlg, buttonbar_new (TRUE)); view_dlg->get_title = mcview_get_title; succeeded = mcview_load (lc_mcview, command, vfs_path_as_str (file_vpath), start_line); if (succeeded) dlg_run (view_dlg); else view_dlg->state = DLG_CLOSED; if (view_dlg->state == DLG_CLOSED) dlg_destroy (view_dlg); return succeeded; }
void mcview_toggle_magic_mode (mcview_t * view) { char *filename, *command; dir_list *dir; int *dir_idx; mcview_altered_magic_flag = 1; view->magic_mode = !view->magic_mode; /* reinit view */ filename = g_strdup (vfs_path_as_str (view->filename_vpath)); command = g_strdup (view->command); dir = view->dir; dir_idx = view->dir_idx; view->dir = NULL; view->dir_idx = NULL; mcview_done (view); mcview_init (view); mcview_load (view, command, filename, 0); view->dir = dir; view->dir_idx = dir_idx; g_free (filename); g_free (command); view->dpy_bbar_dirty = TRUE; view->dirty++; }
gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_line, off_t search_start, off_t search_end) { gboolean succeeded; WView *lc_mcview; WDialog *view_dlg; /* Create dialog and widgets, put them on the dialog */ view_dlg = dlg_create (FALSE, 0, 0, 1, 1, WPOS_FULLSCREEN, FALSE, NULL, mcview_dialog_callback, NULL, "[Internal File Viewer]", NULL); widget_want_tab (WIDGET (view_dlg), TRUE); lc_mcview = mcview_new (0, 0, LINES - 1, COLS, FALSE); add_widget (view_dlg, lc_mcview); add_widget (view_dlg, buttonbar_new (TRUE)); view_dlg->get_title = mcview_get_title; succeeded = mcview_load (lc_mcview, command, vfs_path_as_str (file_vpath), start_line, search_start, search_end); if (succeeded) dlg_run (view_dlg); else dlg_stop (view_dlg); if (widget_get_state (WIDGET (view_dlg), WST_CLOSED)) dlg_destroy (view_dlg); return succeeded; }
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); }