Пример #1
0
KHandlerResponse
filelist_khandler(FileView *view, menu_data_t *m, const wchar_t keys[])
{
	if(wcscmp(keys, L"gf") == 0)
	{
		(void)goto_selected_file(m, curr_view, m->items[m->pos], 0);
		return KHR_CLOSE_MENU;
	}
	else if(wcscmp(keys, L"e") == 0)
	{
		(void)goto_selected_file(m, curr_view, m->items[m->pos], 1);
		return KHR_REFRESH_WINDOW;
	}
	else if(wcscmp(keys, L"c") == 0)
	{
		/* Insert just file name. */
		int line_num;
		const char *const rel_base = get_relative_path_base(m, view);
		char *const path = parse_file_spec(m->items[m->pos], &line_num, rel_base);
		if(path == NULL)
		{
			show_error_msg("Command insertion", "No valid filename found");
			return KHR_REFRESH_WINDOW;
		}
		menu_morph_into_cmdline(CLS_COMMAND, path, 1);
		free(path);
		return KHR_MORPHED_MENU;
	}

	return KHR_UNHANDLED;
}
Пример #2
0
int
goto_selected_file(menu_data_t *m, FileView *view, const char spec[],
		int try_open)
{
	char *path_buf;
	int line_num;

	path_buf = parse_file_spec(spec, &line_num, get_relative_path_base(m, view));
	if(path_buf == NULL)
	{
		show_error_msg("Memory Error", "Unable to allocate enough memory");
		return 1;
	}

	if(!path_exists(path_buf, NODEREF))
	{
		show_error_msgf("Missing file", "File \"%s\" doesn't exist", path_buf);
		free(path_buf);
		return 1;
	}

	if(try_open)
	{
		open_selected_file(path_buf, line_num);
	}
	else
	{
		navigate_to_selected_file(view, path_buf);
	}

	free(path_buf);
	return 0;
}
Пример #3
0
TEST(win_relative_path_with_linenum, IF(windows))
{
	int line_num;
	char *const path = parse_file_spec("repos\\repo:9876:", &line_num, ".");

	assert_string_equal("./repos/repo", path);
	assert_int_equal(9876, line_num);

	free(path);
}
Пример #4
0
TEST(win_absolute_path_with_linenum, IF(windows))
{
	int line_num;
	char *const path = parse_file_spec("c:/home/user:1234:", &line_num, ".");

	assert_string_equal("c:/home/user", path);
	assert_int_equal(1234, line_num);

	free(path);
}
Пример #5
0
TEST(win_absolute_path_without_linenum, IF(windows))
{
	int line_num;
	char *const path = parse_file_spec(test_data, &line_num, ".");

	assert_string_equal(test_data, path);
	assert_int_equal(DEFAULT_LINENUM, line_num);

	free(path);
}
Пример #6
0
TEST(trailing_forward_slash_of_path_is_preserved, IF(windows))
{
	int line_num;
	char *path;

	strcat(test_data, "\\");

	path = parse_file_spec(test_data, &line_num, ".");

	chosp(test_data);
	strcat(test_data, "/");

	assert_string_equal(test_data, path);
	assert_int_equal(DEFAULT_LINENUM, line_num);

	free(path);

	chosp(test_data);
}
Пример #7
0
int
menu_to_custom_view(menu_state_t *m, FileView *view, int very)
{
	int i;
	char *current = NULL;
	const char *const rel_base = get_relative_path_base(m->d, view);

	flist_custom_start(view, m->d->title);

	for(i = 0; i < m->d->len; ++i)
	{
		char *path;
		int line_num;

		/* Skip empty lines. */
		if(skip_whitespace(m->d->items[i])[0] == '\0')
		{
			continue;
		}

		path = parse_file_spec(m->d->items[i], &line_num, rel_base);
		if(path == NULL)
		{
			continue;
		}

		flist_custom_add(view, path);

		/* Use either exact position or the next path. */
		if(i == m->d->pos || (current == NULL && i > m->d->pos))
		{
			current = path;
			continue;
		}

		free(path);
	}

	/* If current line and none of the lines below didn't contain valid path, try
	 * to use file above cursor position. */
	if(current == NULL && view->custom.entry_count != 0)
	{
		char full_path[PATH_MAX];
		get_full_path_of(&view->custom.entries[view->custom.entry_count - 1],
				sizeof(full_path), full_path);

		current = strdup(full_path);
	}

	if(flist_custom_finish(view, very ? CV_VERY : CV_REGULAR, 0) != 0)
	{
		free(current);
		return 1;
	}

	if(current != NULL)
	{
		flist_goto_by_path(view, current);
		free(current);
	}

	return 0;
}