Example #1
0
int
show_file_menu(FileView *view, int background)
{
	static menu_info m;

	int i;
	int max_len;

	char *const typed_name = get_typed_current_fpath(view);
	assoc_records_t ft = ft_get_all_programs(typed_name);
	assoc_records_t magic = get_magic_handlers(typed_name);
	free(typed_name);

	init_menu_info(&m, strdup("Filetype associated commands"),
			strdup("No programs set for this filetype"));

	m.execute_handler = &execute_filetype_cb;
	m.key_handler = &filetypes_khandler;
	m.extra_data = (background ? 1 : 0);

	max_len = MAX(max_desc_len(&ft), max_desc_len(&magic));

	for(i = 0; i < ft.count; i++)
	{
		(void)add_to_string_array(&m.data, m.len, 1,
				form_filetype_data_entry(ft.list[i]));
		m.len = add_to_string_array(&m.items, m.len, 1,
				form_filetype_menu_entry(ft.list[i], max_len));
	}

	ft_assoc_records_free(&ft);

#ifdef ENABLE_DESKTOP_FILES
	(void)add_to_string_array(&m.data, m.len, 1,
			form_filetype_data_entry(NONE_PSEUDO_PROG));
	m.len = add_to_string_array(&m.items, m.len, 1, "");
#endif

	for(i = 0; i < magic.count; i++)
	{
		(void)add_to_string_array(&m.data, m.len, 1,
				form_filetype_data_entry(magic.list[i]));
		m.len = add_to_string_array(&m.items, m.len, 1,
				form_filetype_menu_entry(magic.list[i], max_len));
	}

	return display_menu(&m, view);
}
Example #2
0
/* Fills the menu with commands from association records. */
static void
fill_menu_from_records(menu_info *m, const assoc_records_t *records)
{
	int i;
	const int max_len = max_desc_len(records);

	for(i = 0; i < records->count; ++i)
	{
		m->len = add_to_string_array(&m->items, m->len, 1,
				form_filetype_menu_entry(records->list[i], max_len));
	}
}