⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tab.c

📁 一个很有名的浏览器
💻 C
字号:
/* Tab-style (those containing real documents) windows infrastructure. *//* $Id: tab.c,v 1.80.4.2 2005/04/06 09:11:19 jonas Exp $ */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "elinks.h"#include "bfu/dialog.h"#include "config/options.h"#include "dialogs/menu.h"#include "document/document.h"#include "document/view.h"#include "intl/gettext/libintl.h"#include "lowlevel/select.h"#include "protocol/uri.h"#include "sched/session.h"#include "terminal/screen.h"#include "terminal/tab.h"#include "terminal/terminal.h"#include "terminal/window.h"#include "util/error.h"#include "util/memory.h"#include "util/lists.h"#include "viewer/text/link.h"#include "viewer/text/view.h"struct window *init_tab(struct terminal *term, void *data, window_handler handler){	struct window *win = mem_calloc(1, sizeof(*win));	if (!win) return NULL;	win->handler = handler;	win->term = term;	win->data = data;	win->type = WINDOW_TAB;	win->resize = 1;	add_to_list(term->windows, win);	return win;}/* Number of tabs at the terminal (in term->windows) */inline intnumber_of_tabs(struct terminal *term){	int result = 0;	struct window *win;	foreach_tab (win, term->windows)		result++;	return result;}/* Number of tab */intget_tab_number(struct window *window){	struct terminal *term = window->term;	struct window *win;	int current = 0;	int num = 0;	foreachback_tab (win, term->windows) {		if (win == window) {			num = current;			break;		}		current++;	}	return num;}/* Get tab of an according index */struct window *get_tab_by_number(struct terminal *term, int num){	struct window *win = NULL;	foreachback_tab (win, term->windows) {		if (!num) break;		num--;	}	return win;}/* Returns number of the tab at @xpos, or -1 if none. */intget_tab_number_by_xpos(struct terminal *term, int xpos){	int num = 0;	struct window *win = NULL;	foreachback_tab (win, term->windows) {		if (xpos >= win->xpos		    && xpos < win->xpos + win->width)			return num;		num++;	}	return -1;}/* if @tabs > 0, then it is taken as the result of a recent * call to number_of_tabs() so it just uses this value. */voidswitch_to_tab(struct terminal *term, int tab, int tabs){	if (tabs < 0) tabs = number_of_tabs(term);	if (tabs > 1) {		if (tab >= tabs) {			if (get_opt_bool("ui.tabs.wraparound"))				tab = 0;			else				tab = tabs - 1;		}		if (tab < 0) {			if (get_opt_bool("ui.tabs.wraparound"))				tab = tabs - 1;			else				tab = 0;		}	} else tab = 0;	if (tab != term->current_tab) {		term->current_tab = tab;		set_screen_dirty(term->screen, 0, term->height);		redraw_terminal(term);	}}voidswitch_current_tab(struct session *ses, int direction){	struct terminal *term = ses->tab->term;	int num_tabs = number_of_tabs(term);	if (num_tabs < 2)		return;	if (ses->kbdprefix.repeat_count) {		direction *= ses->kbdprefix.repeat_count;		ses->kbdprefix.repeat_count = 0;	}	switch_to_tab(term, term->current_tab + direction, num_tabs);}static voidreally_close_tab(struct session *ses){	struct terminal *term = ses->tab->term;	int num_tabs = number_of_tabs(term);	struct window *current_tab = get_current_tab(term);	if (ses->tab == current_tab)		switch_to_tab(term, term->current_tab - 1, num_tabs - 1);	delete_window(ses->tab);}voidclose_tab(struct terminal *term, struct session *ses){	int num_tabs = number_of_tabs(term);	if (num_tabs < 2) {		query_exit(ses);		return;	}	if (!get_opt_bool("ui.tabs.confirm_close")) {		really_close_tab(ses);		return;	}	msg_box(term, NULL, 0,		N_("Close tab"), ALIGN_CENTER,		N_("Do you really want to close the current tab?"),		ses, 2,		N_("~Yes"), (void (*)(void *)) really_close_tab, B_ENTER,		N_("~No"), NULL, B_ESC);}static voidreally_close_tabs(struct session *ses){	struct terminal *term = ses->tab->term;	struct window *current = get_current_tab(term);	struct window *tab;	foreach_tab (tab, term->windows) {		if (tab == current) continue;		tab = tab->prev;		delete_window(tab->next);	}	term->current_tab = 0;	redraw_terminal(term);}voidclose_all_tabs_but_current(struct session *ses){	assert(ses);	if_assert_failed return;	if (!get_opt_bool("ui.tabs.confirm_close")) {		really_close_tabs(ses);		return;	}	msg_box(ses->tab->term, NULL, 0,		N_("Close tab"), ALIGN_CENTER,		N_("Do you really want to close all except the current tab?"),		ses, 2,		N_("~Yes"), (void (*)(void *)) really_close_tabs, B_ENTER,		N_("~No"), NULL, B_ESC);}voidopen_uri_in_new_tab(struct session *ses, struct uri *uri, int in_background,                    int based){	assert(ses);	/* @based means whether the current @ses location will be preloaded	 * in the tab. */	init_session(based ? ses : NULL, ses->tab->term, uri, in_background);}voidopen_current_link_in_new_tab(struct session *ses, int in_background){	struct document_view *doc_view = current_frame(ses);	struct uri *uri = NULL;	struct link *link;	if (doc_view) assert(doc_view->vs && doc_view->document);	if_assert_failed return;	link = get_current_link(doc_view);	if (link) uri = get_link_uri(ses, doc_view, link);	open_uri_in_new_tab(ses, uri, in_background, 1);	if (uri) done_uri(uri);}voidmove_current_tab(struct session *ses, int direction){	struct terminal *term = ses->tab->term;	int tabs = number_of_tabs(term);	struct window *current_tab = get_current_tab(term);	struct window *tab;	int new_pos;	assert(ses && direction);	if (ses->kbdprefix.repeat_count) {		direction *= ses->kbdprefix.repeat_count;		ses->kbdprefix.repeat_count = 0;	}	new_pos = term->current_tab + direction;	while (new_pos < 1 || new_pos > tabs)		new_pos += new_pos < 1 ? tabs : -tabs;	assert(0 < new_pos && new_pos <= tabs);	if (new_pos == term->current_tab) return;	tab = get_tab_by_number(term, new_pos);	del_from_list(current_tab);	if (new_pos < term->current_tab) {		add_at_pos(tab, current_tab);	} else {		add_to_list_end(*tab, current_tab);	}	switch_to_tab(term, new_pos, tabs);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -