示例#1
0
文件: running.c 项目: cfillion/vifm
/* Goes one directory up from current location.  Returns zero unless it won't
 * make sense to continue going up (like on error or reaching root). */
static int
cd_to_parent_dir(FileView *view)
{
	char dir_name[strlen(view->curr_dir) + 1];
	int ret;

	/* Return to original directory from custom view. */
	if(flist_custom_active(view))
	{
		navigate_to(view, view->custom.orig_dir);
		return 0;
	}

	/* Do nothing in root. */
	if(is_root_dir(view->curr_dir))
	{
		return 1;
	}

	dir_name[0] = '\0';
	extract_last_path_component(view->curr_dir, dir_name);

	ret = change_directory(view, "../");
	if(ret == -1)
	{
		return 1;
	}

	if(ret == 0)
	{
		load_dir_list(view, 0);
		flist_set_pos(view, find_file_pos_in_list(view, dir_name));
	}
	return 0;
}
示例#2
0
文件: running.c 项目: cfillion/vifm
/* Resolve link target and either navigate inside directory link points to or
 * navigate to directory where target is located pointing cursor on
 * it (the follow_dirs flag controls behaviour). */
static void
follow_link(FileView *view, int follow_dirs)
{
	char *dir, *file;
	char full_path[PATH_MAX];
	char linkto[PATH_MAX + NAME_MAX];
	dir_entry_t *const entry = &curr_view->dir_entry[curr_view->list_pos];

	get_full_path_of(entry, sizeof(full_path), full_path);

	if(get_link_target_abs(full_path, entry->origin, linkto, sizeof(linkto)) != 0)
	{
		show_error_msg("Error", "Can't read link.");
		return;
	}

	if(!path_exists(linkto, DEREF))
	{
		show_error_msg("Broken Link",
				"Can't access link destination.  It might be broken.");
		return;
	}

	chosp(linkto);

	if(is_dir(linkto) && !follow_dirs)
	{
		dir = strdup(entry->name);
		file = NULL;
	}
	else
	{
		dir = strdup(linkto);
		remove_last_path_component(dir);

		file = get_last_path_component(linkto);
	}

	if(dir[0] != '\0')
	{
		navigate_to(view, dir);
	}

	if(file != NULL)
	{
		const int pos = find_file_pos_in_list(view, file);
		if(pos >= 0)
		{
			flist_set_pos(view, pos);
		}
	}

	free(dir);
}
示例#3
0
void
goto_selected_directory(FileView *view, const char path[])
{
	if(!cfg.auto_ch_pos)
	{
		flist_hist_clear(view);
		curr_stats.ch_pos = 0;
	}
	navigate_to(view, path);
	if(!cfg.auto_ch_pos)
	{
		curr_stats.ch_pos = 1;
	}
}
示例#4
0
文件: menus.c 项目: lyuts/vifm
void
goto_selected_directory(FileView *view, menu_info *m)
{
	if(!cfg.auto_ch_pos)
	{
		clean_positions_in_history(curr_view);
		curr_stats.ch_pos = 0;
	}
	navigate_to(view, m->items[m->pos]);
	if(!cfg.auto_ch_pos)
	{
		curr_stats.ch_pos = 1;
	}
}
示例#5
0
	void menu::navigate(int down, int right, bool force) {
		auto &item = current_at(current);

		bool playBeep = false;

		bool newForce = force;
		if(!force && right && item.control && item.control->navigate(right)) {
			item.fn(item.control->get());
			render(current, true);
			playBeep = true;
		} else {
			newForce = force;
		}

		if(newForce) {
			while(right > 0) {
				auto &i = current_at(current);
				if(!i.children.empty()) {
					stack.emplace_back(current);
					current = 0;
					--right;
					playBeep = true;
				} else {
					activate();
				}
			}
			while(right < 0) {
				if(stack.empty()) {
					if(force) {
						engine->transition = "back";
						return;
					}
				} else {
					current = (int)stack.back();
					stack.pop_back();
					++right;
					playBeep = true;
				}
			}
			render_all();
		}
		if(down != 0) {
			navigate_to(current + down);
		}

		if(playBeep) {
			beep();
		}
	}
示例#6
0
文件: bookmarks.c 项目: lyuts/vifm
int
goto_bookmark(FileView *view, char mark)
{
	switch(mark)
	{
		case '\'':
			navigate_to(view, view->last_dir);
			return 0;
		case '\x03': /* Ctrl-C. */
		case '\x1b': /* Escape. */
			move_to_list_pos(view, view->list_pos);
			return 0;

		default:
			return navigate_to_bookmark(view, mark);
	}
}
示例#7
0
	void menu::on_cursor(int y) {
		auto size = current_size();

		auto scale = glm::min(actual_height() / Decimal(size), actual_scale());
		auto spacing = uiTextHeight * scale;

		auto height = engine->get<renderer::base>().lock()->getheight();
		auto origin = height - y;

		/* origin = 50 + spacing * (size - i - 1);
		 * spacing * (size - i - 1) = origin - 50
		 * size - i - 1 = (origin - 50) / spacing
		 * i = size - (origin - 50) / spacing - 1
		 */
		auto i = int(glm::floor(size - (origin - 50) / spacing));
		if(i >= 0 && i < int(size)) { navigate_to(i); }
	}
示例#8
0
文件: running.c 项目: cfillion/vifm
void
open_dir(FileView *view)
{
	char full_path[PATH_MAX];
	const char *filename;

	filename = get_current_file_name(view);

	if(is_parent_dir(filename))
	{
		cd_updir(view, 1);
		return;
	}

	get_current_full_path(view, sizeof(full_path), full_path);

	if(cd_is_possible(full_path))
	{
		navigate_to(view, full_path);
	}
}
示例#9
0
文件: fuse.c 项目: jubalh/vifm
void
fuse_try_mount(FileView *view, const char program[])
{
	/* TODO: refactor this function fuse_try_mount() */

	fuse_mount_t *runner;
	char file_full_path[PATH_MAX];
	char mount_point[PATH_MAX];

	if(!path_exists(cfg.fuse_home, DEREF))
	{
		if(make_path(cfg.fuse_home, S_IRWXU) != 0)
		{
			show_error_msg("Unable to create FUSE mount home directory",
					cfg.fuse_home);
			return;
		}
	}

	get_current_full_path(view, sizeof(file_full_path), file_full_path);

	/* Check if already mounted. */
	runner = get_mount_by_source(file_full_path);

	if(runner != NULL)
	{
		strcpy(mount_point, runner->mount_point);
	}
	else
	{
		char param[PATH_MAX];
		param[0] = '\0';

		/* New file to be mounted. */
		if(starts_with(program, "FUSE_MOUNT2"))
		{
			FILE *f;
			if((f = os_fopen(file_full_path, "r")) == NULL)
			{
				show_error_msg("SSH mount failed", "Can't open file for reading");
				curr_stats.save_msg = 1;
				return;
			}

			if(fgets(param, sizeof(param), f) == NULL)
			{
				show_error_msg("SSH mount failed", "Can't read file content");
				curr_stats.save_msg = 1;
				fclose(f);
				return;
			}
			fclose(f);

			chomp(param);
			if(param[0] == '\0')
			{
				show_error_msg("SSH mount failed", "File is empty");
				curr_stats.save_msg = 1;
				return;
			}

		}
		if(fuse_mount(view, file_full_path, param, program, mount_point) != 0)
		{
			return;
		}
	}

	navigate_to(view, mount_point);
}