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

📄 bookmark.c

📁 this is the file used to browse web
💻 C
📖 第 1 页 / 共 2 页
字号:
	struct bookmark *bm = get_bookmark_by_id(id);		if (bm == NULL) {		return NULL;	}	return bm->url;}/* Gets the name of the requested bookmark. * * See bookmark_get_url() for further comments. */const unsigned char *bookmark_get_name(bookmark_id id) {	struct bookmark *bm = get_bookmark_by_id(id);		if (bm == NULL) {		return NULL;	}	return bm->title;}		/* Goes to the called bookmark */void bookmark_goto(bookmark_id id, struct session *ses) {	struct bookmark *bm;	bm = get_bookmark_by_id(id);		if (bm) 		goto_url(ses, bm->url);		}/* Shows the bookmark list */void bookmark_menu(struct terminal *term, void *ddd, struct session *ses){	struct bookmark *bm;	struct menu_item *mi;		if (!(mi = new_menu(3)))		return;			foreach(bm, bookmarks) {		add_to_menu(&mi, stracpy(bm->title), "", 0, MENU_FUNC menu_goto_bookmark, (void *)bm->url, 0);	}		do_menu(term, mi, ses);}/* Called to setup the bookmark dialog */void layout_bookmark_manager(struct dialog_data *dlg){	int max = 0, min = 0;	int w, rw;	int y = -1;	struct terminal *term;	term = dlg->win->term;		/* Find dimensions of dialog */	max_text_width(term, bookmark_dialog_msg[0], &max);	min_text_width(term, bookmark_dialog_msg[0], &min);	max_buttons_width(term, dlg->items + 2, 2, &max);	min_buttons_width(term, dlg->items + 2, 2, &min);		w = term->x * 9 / 10 - 2 * DIALOG_LB;	if (w > max) w = max;	if (w < min) w = min;		if (w > term->x - 2 * DIALOG_LB) 		w = term->x - 2 * DIALOG_LB;			if (w < 1) 		w = 1;			w = rw = 50 ;		y += 1;	/* Blankline between top and top of box */	dlg_format_box(NULL, term, &dlg->items[BM_BOX_IND], dlg->x + DIALOG_LB, &y, w, NULL, AL_LEFT);	y += 1;	/* Blankline between box and menu */	dlg_format_buttons(NULL, term, dlg->items, 5, 0, &y, w, &rw, AL_CENTER);	w = rw;	dlg->xw = w + 2 * DIALOG_LB;	dlg->yw = y + 2 * DIALOG_TB;	center_dlg(dlg);	draw_dlg(dlg);	y = dlg->y + DIALOG_TB;		y++;	dlg_format_box(term, term, &dlg->items[BM_BOX_IND], dlg->x + DIALOG_LB, &y, w, NULL, AL_LEFT);	y++;	dlg_format_buttons(term, term, &dlg->items[0], 5, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);}void launch_bm_add_doc_dialog(struct terminal *,struct dialog_data *, struct session *);/* Callback for the "add" button in the bookmark manager */int push_add_button(struct dialog_data *dlg, struct dialog_item_data *di) {	launch_bm_add_doc_dialog(dlg->win->term, dlg, (struct session *)dlg->dlg->udata);	return 0;}/* Called when the goto button is pushed */int push_goto_button(struct dialog_data *dlg, struct dialog_item_data *goto_btn) {	bookmark_id id;	struct dlg_data_item_data_box *box;		box = (struct dlg_data_item_data_box*)(dlg->dlg->items[BM_BOX_IND].data);		/* Follow the bookmark */	id = bookmark_dlg_box_id_get(box);	if (id != BAD_BOOKMARK_ID) 		bookmark_goto(id, (struct session*)goto_btn->item->udata);	/* FIXME There really should be some feedback to the user here */	/* Close the bookmark dialog */	delete_window(dlg->win);	return 0;}/* Called when an edit is complete. */void bookmark_edit_done(struct dialog *d) {	bookmark_id id = (bookmark_id)d->udata2;	struct dialog_data *parent;		bookmark_update(id, d->items[0].data, d->items[1].data);	parent = d->udata;	/* Tell the bookmark dialog to redraw */	if (parent) 		bookmark_dlg_list_update(&(((struct dlg_data_item_data_box*)parent->dlg->items[BM_BOX_IND].data)->items));}/* Called when the edit button is pushed */int push_edit_button(struct dialog_data *dlg, struct dialog_item_data *edit_btn) {	bookmark_id id;	struct dlg_data_item_data_box *box;		box = (struct dlg_data_item_data_box*)(dlg->dlg->items[BM_BOX_IND].data);		/* Follow the bookmark */	id = bookmark_dlg_box_id_get(box);	if (id != BAD_BOOKMARK_ID) {		const unsigned char *name = bookmark_get_name(id);		const unsigned char *url = bookmark_get_url(id);		bookmark_edit_dialog(dlg->win->term, TEXT(T_EDIT_BOOKMARK), name, url, (struct session*)edit_btn->item->udata, dlg, bookmark_edit_done, (void *)id);	}	/* FIXME There really should be some feedback to the user here */	return 0;}/* Used to carry extra info between the push_delete_button() and the really_del_bookmark_ */struct push_del_button_hop_struct {	struct dialog *dlg;	struct dlg_data_item_data_box *box;	bookmark_id id;};/* Called to _really_ delete a bookmark (a confirm in the delete dialog) */void really_del_bookmark(void *vhop) {	struct push_del_button_hop_struct *hop;	int last;	hop = (struct push_del_button_hop_struct *)vhop;		if (!delete_bookmark_by_id(hop->id)) 		return;	last = bookmark_dlg_list_update(&(hop->box->items));	/* In case we deleted the last bookmark */	if (hop->box->sel >= (last - 1))		hop->box->sel = last - 1;	/* Made in push_delete_button() */	/*mem_free(vhop);*/}/* Callback for the "delete" button in the bookmark manager */int push_delete_button(struct dialog_data *dlg, struct dialog_item_data *some_useless_delete_button) {	struct bookmark *bm;	struct push_del_button_hop_struct *hop;	struct terminal *term; 	struct dlg_data_item_data_box *box;	/* FIXME There's probably a nicer way to do this */	term = dlg->win->term;	box = (struct dlg_data_item_data_box*)(dlg->dlg->items[BM_BOX_IND].data);	bm = get_bookmark_by_id(bookmark_dlg_box_id_get(box));		if (bm == NULL) 		return 0;	/* Deleted in really_del_bookmark() */	hop = mem_alloc(sizeof(struct push_del_button_hop_struct));			hop->id = bm->id;	hop->dlg = dlg->dlg;	hop->box = box;    	msg_box(term, getml(hop, NULL), TEXT(T_DELETE_BOOKMARK), AL_CENTER | AL_EXTD_TEXT, TEXT(T_DELETE_BOOKMARK), " \"", bm->title, "\" (", TEXT(T_url), ": \"", bm->url, "\")?", NULL, hop, 2, TEXT(T_YES), really_del_bookmark, B_ENTER, TEXT(T_NO), NULL, B_ESC);	return 0;}/* Builds the "Bookmark manager" dialog */void menu_bookmark_manager(struct terminal *term, void *fcp, struct session *ses){	struct dialog *d;		/* Create the dialog */	d = mem_alloc(sizeof(struct dialog) + 7 * sizeof(struct dialog_item) + sizeof(struct bookmark) + 2 * MAX_STR_LEN);		memset(d, 0, sizeof(struct dialog) + 7 * sizeof(struct dialog_item) + sizeof(struct bookmark) + 2 * MAX_STR_LEN);		d->title = TEXT(T_BOOKMARK_MANAGER);	d->fn = layout_bookmark_manager;	d->handle_event = bookmark_dialog_event_handler;	d->abort = bookmark_dialog_abort_handler;/*	bookmark_build_dlg_list(d);*/	/* Where the currently displayed list goes */	d->udata = ses;	d->items[0].type = D_BUTTON;	d->items[0].gid = B_ENTER;	d->items[0].fn = push_goto_button;	d->items[0].udata = ses;	d->items[0].text = TEXT(T_GOTO);		d->items[1].type = D_BUTTON;	d->items[1].gid = B_ENTER;	d->items[1].fn = push_edit_button;	d->items[1].udata = ses;	d->items[1].text = TEXT(T_EDIT);		d->items[2].type = D_BUTTON;	d->items[2].gid = B_ENTER;	d->items[2].fn = push_delete_button;	d->items[2].text = TEXT(T_DELETE);		d->items[3].type = D_BUTTON;	d->items[3].gid = B_ENTER;	d->items[3].fn = push_add_button;	d->items[3].text = TEXT(T_ADD);		d->items[4].type = D_BUTTON;	d->items[4].gid = B_ESC;	d->items[4].fn = cancel_dialog;	d->items[4].text = TEXT(T_CLOSE);	d->items[5].type = D_BOX;	/* MP: D_BOX is nonsence. I tried to remove it, but didn't succeed */	d->items[5].gid = 12;	/*d->items[5].data = (void *)bookmark_dlg_box_build();*/	/* Where the currently displayed list goes */	bookmark_dlg_box_build((struct dlg_data_item_data_box**)(void *)&(d->items[5].data));	/* Where the currently displayed list goes */		d->items[6].type = D_END;	do_dialog(term, d, getml(d, NULL));}/****************************************************************************** Bookmark add dialog*****************************************************************************//* Adds the bookmark */void bookmark_add_add(struct dialog *d){	struct dialog_data *parent;		add_bookmark(d->items[0].data, d->items[1].data);	parent = d->udata;	/* Tell the bookmark dialog to redraw */	if (parent) 		bookmark_dlg_list_update(&(((struct dlg_data_item_data_box*)parent->dlg->items[BM_BOX_IND].data)->items));}void launch_bm_add_doc_dialog(struct terminal *term,struct dialog_data *parent,struct session *ses) {				bookmark_edit_dialog(term, TEXT(T_ADD_BOOKMARK), NULL, NULL, ses, parent, bookmark_add_add, NULL);}/* Called to launch an add dialog on the current link */void launch_bm_add_link_dialog(struct terminal *term,struct dialog_data *parent,struct session *ses) {	unsigned char url[MAX_STR_LEN];	/* FIXME: Logic error -- if there is no current link, 	 * get_current_link_url() will return NULL, which will cause 	 * bookmark_add_dialog() to try and use the current document's url. 	 * Instead, it should use "". 	 */ 	bookmark_edit_dialog(term, TEXT(T_ADD_BOOKMARK), NULL, get_current_link_url(ses, url, MAX_STR_LEN), ses, parent, bookmark_add_add, NULL);}unsigned char *bm_add_msg[] = {	TEXT(T_NNAME),	TEXT(T_URL),};/* Called to setup the add bookmark dialog */void layout_add_dialog(struct dialog_data *dlg){	int max = 0, min = 0;	int w, rw;	int y = -1;	struct terminal *term;	term = dlg->win->term;		max_text_width(term, bm_add_msg[0], &max);	min_text_width(term, bm_add_msg[0], &min);	max_text_width(term, bm_add_msg[1], &max);	min_text_width(term, bm_add_msg[1], &min);	max_buttons_width(term, dlg->items + 2, 2, &max);	min_buttons_width(term, dlg->items + 2, 2, &min);	w = term->x * 9 / 10 - 2 * DIALOG_LB;		if (w > max) w = max;	if (w < min) w = min;	if (w > term->x - 2 * DIALOG_LB) w = term->x - 2 * DIALOG_LB;	if (w < 1) w = 1;	w = rw = 50;		dlg_format_text(NULL, term, bm_add_msg[0], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);	y += 2;	dlg_format_text(NULL, term, bm_add_msg[1], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);	y += 2;	dlg_format_buttons(NULL, term, dlg->items + 2, 2, 0, &y, w, &rw, AL_CENTER);	w = rw;	dlg->xw = w + 2 * DIALOG_LB;	dlg->yw = y + 2 * DIALOG_TB;	center_dlg(dlg);	draw_dlg(dlg);	y = dlg->y + DIALOG_TB;	dlg_format_text(term, term, bm_add_msg[0], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);	dlg_format_field(NULL, term, &dlg->items[0], dlg->x + DIALOG_LB, &y, w, NULL, AL_LEFT);	y++;	dlg_format_text(term, term, bm_add_msg[1], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);	dlg_format_field(term, term, &dlg->items[1], dlg->x + DIALOG_LB, &y, w, NULL, AL_LEFT);	y++;	dlg_format_buttons(term, term, &dlg->items[2], 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);	}/* Edits a bookmark's fields.  * If parent is defined, then that points to a dialog that should be sent  * an update when the add is done. * * If either of src_name or src_url are NULL, try to obtain the name and url  * of the current document. If you want to create two null fields, pass in a  * pointer to a zero length string ("").*/void bookmark_edit_dialog(		struct terminal *term /* Terminal to write on. */, 		unsigned char *title /* Title of the dialog. */, 		const unsigned char *src_name /* Pointer to name to use. (can be null)*/, 		const unsigned char *src_url /* Url to use. (can be null) */, 		struct session *ses, 		struct dialog_data *parent /* The parent window launching this one. */,		void when_done(struct dialog *) /* Function to execute on 'ok'. */, 		void *done_data /* Spare data to pass to when_done. Stored in udata2 */) {	unsigned char *name, *url;	struct dialog *d;		/* Create the dialog */	d = mem_alloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item) + sizeof(struct extension) + 2 * MAX_STR_LEN);	memset(d, 0, sizeof(struct dialog) + 5 * sizeof(struct dialog_item) + sizeof(struct extension) + 2 * MAX_STR_LEN);	name = (unsigned char *)&d->items[5];	url = name + MAX_STR_LEN;	/* Get the name */	if (src_name == NULL) {		/* Unknown name. */		get_current_title(ses, name, MAX_STR_LEN);	} else {		/* Known name. */		safe_strncpy(name, src_name, MAX_STR_LEN);	}	/* Get the url */	if (src_url == NULL) {		/* Unknown . */		get_current_url(ses, url, MAX_STR_LEN);	} else {		/* Known url. */		safe_strncpy(url, src_url, MAX_STR_LEN);	}	d->title = title;	d->fn = layout_add_dialog;	d->refresh = (void (*)(void *))when_done;	d->refresh_data = d;	d->udata = parent;	d->udata2 = done_data;	d->items[0].type = D_FIELD;	d->items[0].dlen = MAX_STR_LEN;	d->items[0].data = name;	d->items[0].fn = check_nonempty;	d->items[1].type = D_FIELD;	d->items[1].dlen = MAX_STR_LEN;	d->items[1].data = url;	d->items[1].fn = check_nonempty;	d->items[2].type = D_BUTTON;	d->items[2].gid = B_ENTER;	d->items[2].fn = ok_dialog;	d->items[2].text = TEXT(T_OK);		d->items[3].type = D_BUTTON;	d->items[3].gid = B_ESC;	d->items[3].text = TEXT(T_CANCEL);	d->items[3].fn = cancel_dialog;		d->items[4].type = D_END;		do_dialog(term, d, getml(d, NULL));}

⌨️ 快捷键说明

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