void tabs_move(view_t *view, int where_to) { int future = MAX(0, MIN(tabs_count(view) - 1, where_to)); const int current = tabs_current(view); const int from = (current <= future ? current + 1 : future); const int to = (current <= future ? current : future + 1); /* Second check is for the case when the value was already truncated by MIN() * above. */ if(current < future && where_to < tabs_count(view)) { --future; } if(cfg.pane_tabs) { pane_tab_t *const ptabs = get_pane_tabs(view)->tabs; const pane_tab_t ptab = ptabs[current]; memmove(ptabs + to, ptabs + from, sizeof(*ptabs)*abs(future - current)); ptabs[future] = ptab; get_pane_tabs(view)->current = future; } else { const global_tab_t gtab = gtabs[current]; memmove(gtabs + to, gtabs + from, sizeof(*gtabs)*abs(future - current)); gtabs[future] = gtab; current_tab = future; } }
void tabs_only(view_t *view) { if(cfg.pane_tabs) { pane_tabs_t *const ptabs = get_pane_tabs(curr_view); while(DA_SIZE(ptabs->tabs) != 1U) { pane_tab_t *const ptab = &ptabs->tabs[ptabs->current == 0 ? 1 : 0]; ptabs->current -= (ptabs->current == 0 ? 0 : 1); free_pane_tab(ptab); DA_REMOVE(ptabs->tabs, ptab); } } else { while(DA_SIZE(gtabs) != 1U) { global_tab_t *const gtab = >abs[current_tab == 0 ? 1 : 0]; current_tab -= (current_tab == 0 ? 0 : 1); free_global_tab(gtab); DA_REMOVE(gtabs, gtab); } } }
/* Switches to pane tab specified by its index if the index is valid. */ static void tabs_goto_pane(int idx) { pane_tabs_t *const ptabs = get_pane_tabs(curr_view); if(ptabs->current == idx) { return; } if(idx < 0 || idx >= (int)DA_SIZE(ptabs->tabs)) { return; } ptabs->tabs[ptabs->current].view = *curr_view; assign_preview(&ptabs->tabs[ptabs->current].preview, &curr_stats.preview); *curr_view = ptabs->tabs[idx].view; assign_preview(&curr_stats.preview, &ptabs->tabs[idx].preview); ptabs->current = idx; stats_set_quickview(curr_stats.preview.on); ui_view_schedule_redraw(curr_view); load_view_options(curr_view); (void)vifm_chdir(flist_get_dir(curr_view)); }
int tabs_count(const view_t *view) { if(cfg.pane_tabs) { pane_tabs_t *const ptabs = get_pane_tabs(view); return (int)DA_SIZE(ptabs->tabs); } return (int)DA_SIZE(gtabs); }
void tabs_next(int n) { if(cfg.pane_tabs) { pane_tabs_t *const ptabs = get_pane_tabs(curr_view); const int count = (int)DA_SIZE(ptabs->tabs); tabs_goto((ptabs->current + n)%count); } else { tabs_goto((current_tab + 1)%(int)DA_SIZE(gtabs)); } }
void tabs_rename(view_t *view, const char name[]) { if(cfg.pane_tabs) { pane_tabs_t *const ptabs = get_pane_tabs(view); update_string(&ptabs->tabs[ptabs->current].name, name);; } else { global_tab_t *const gtab = >abs[current_tab]; update_string(>ab->name, name); } }
void tabs_previous(int n) { if(cfg.pane_tabs) { pane_tabs_t *const ptabs = get_pane_tabs(curr_view); const int count = (int)DA_SIZE(ptabs->tabs); tabs_goto((ptabs->current + count - n)%count); } else { const int count = DA_SIZE(gtabs); tabs_goto((current_tab + count - n)%count); } }
/* Switches to pane tab specified by its index if the index is valid. */ static void tabs_goto_pane(int idx) { pane_tabs_t *const ptabs = get_pane_tabs(curr_view); if(ptabs->current == idx) { return; } //add by sim1 +++++++++++++++++++++++++++++++++++ if(idx < 0) { idx = ptabs->last; if (idx == ptabs->current) { return; } } //add by sim1 ----------------------------------- if(idx < 0 || idx >= (int)DA_SIZE(ptabs->tabs)) { return; } ptabs->tabs[ptabs->current].view = *curr_view; assign_preview(&ptabs->tabs[ptabs->current].preview, &curr_stats.preview); *curr_view = ptabs->tabs[idx].view; assign_preview(&curr_stats.preview, &ptabs->tabs[idx].preview); ptabs->last = ptabs->current; //add by sim1 ptabs->current = idx; stats_set_quickview(curr_stats.preview.on); ui_view_schedule_redraw(curr_view); load_view_options(curr_view); (void)vifm_chdir(flist_get_dir(curr_view)); //add by sim1 for test //ui_sb_msgf("tabs_goto_pane: curr=%d, last=%d, tabs=%d", ptabs->current, ptabs->last, (int)DA_SIZE(ptabs->tabs)); }
int tabs_get(view_t *view, int idx, tab_info_t *tab_info) { if(cfg.pane_tabs) { pane_tabs_t *const ptabs = get_pane_tabs(view); const int n = (int)DA_SIZE(ptabs->tabs); if(idx < 0 || idx >= n) { return 0; } tab_info->view = (idx == ptabs->current ? view : &ptabs->tabs[idx].view); tab_info->name = ptabs->tabs[idx].name; tab_info->last = (idx == n - 1); return 1; } return get_global_tab(view, idx, tab_info, 1); }
int tabs_new(const char name[], const char path[]) { if(cfg.pane_tabs) { pane_tabs_t *const ptabs = get_pane_tabs(curr_view); pane_tab_t *const ptab = tabs_new_pane(ptabs, curr_view, name, path); if(ptab == NULL) { return 1; } ptab->preview.on = curr_stats.preview.on; tabs_goto(ptab - ptabs->tabs); return 0; } return tabs_new_global(name, path); }
void tabs_close(void) { // XXX: FUSE filesystems aren't exited this way, but this might be OK because // usually we exit from them on explicit ".." by a user. if(cfg.pane_tabs) { pane_tabs_t *const ptabs = get_pane_tabs(curr_view); pane_tab_t *const ptab = &ptabs->tabs[ptabs->current]; const int n = (int)DA_SIZE(ptabs->tabs); if(n != 1) { tabs_goto(ptabs->current + (ptabs->current == n - 1 ? -1 : +1)); if(ptabs->current > ptab - ptabs->tabs) { --ptabs->current; } free_pane_tab(ptab); DA_REMOVE(ptabs->tabs, ptab); } //add by sim1 for test //ui_sb_msgf("tabs_close: curr=%d, last=%d, tabs=%d", ptabs->current, ptabs->last, (int)DA_SIZE(ptabs->tabs)); } else { global_tab_t *const gtab = >abs[current_tab]; const int n = (int)DA_SIZE(gtabs); if(n != 1) { tabs_goto(current_tab == n - 1 ? current_tab - 1 : current_tab + 1); if(current_tab > gtab - gtabs) { --current_tab; } free_global_tab(gtab); DA_REMOVE(gtabs, gtab); } } }
int tabs_get(view_t *view, int idx, tab_info_t *tab_info) { if(cfg.pane_tabs) { pane_tabs_t *const ptabs = get_pane_tabs(view); const int n = (int)DA_SIZE(ptabs->tabs); if(idx < 0 || idx >= n) { return 0; } tab_info->view = (idx == ptabs->current ? view : &ptabs->tabs[idx].view); tab_info->name = ptabs->tabs[idx].name; tab_info->last = (idx == n - 1); return 1; } else { global_tab_t *gtab; const int n = (int)DA_SIZE(gtabs); if(idx < 0 || idx >= n) { return 0; } gtab = >abs[idx]; tab_info->name = gtab->name; tab_info->last = (idx == n - 1); if(idx == current_tab) { tab_info->view = view; return 1; } tab_info->view = gtab->active_pane ? >ab->right.tabs[gtab->right.current].view : >ab->left.tabs[gtab->left.current].view; return 1; } }
int tabs_current(const view_t *view) { return (cfg.pane_tabs ? get_pane_tabs(view)->current : current_tab); }