コード例 #1
0
ファイル: dir_stack.c プロジェクト: cosminadrianpopescu/vifm
int
swap_dirs(void)
{
	stack_entry_t item;

	if(stack_top == 0)
		return -1;

	item = stack[--stack_top];

	if(pushd() != 0)
	{
		free_entry(&item);
		return -1;
	}

	if(change_directory(&lwin, item.lpane_dir) >= 0)
		load_dir_list(&lwin, 0);

	if(change_directory(&rwin, item.rpane_dir) >= 0)
		load_dir_list(&rwin, 0);

	fview_cursor_redraw(curr_view);
	refresh_view_win(other_view);

	free_entry(&item);
	return 0;
}
コード例 #2
0
ファイル: marks.c プロジェクト: dennishamester/vifm
/* Navigates the view to given mark if it's valid.  Returns new value for
 * save_msg flag. */
static int
navigate_to_mark(FileView *view, char m)
{
	const mark_t *const mark = get_mark_by_name(m);

	if(is_mark_valid(mark))
	{
		navigate_to_file(view, mark->directory, mark->file);
		return 0;
	}

	if(!char_is_one_of(valid_marks, m))
	{
		status_bar_message("Invalid mark name");
	}
	else if(is_empty(mark))
	{
		status_bar_message("Mark is not set");
	}
	else
	{
		status_bar_message("Mark is invalid");
	}

	fview_cursor_redraw(view);
	return 1;
}
コード例 #3
0
ファイル: attr_dialog_nix.c プロジェクト: onovy/vifm
static void
leave_attr_mode(void)
{
	vle_mode_set(NORMAL_MODE, VMT_PRIMARY);
	curs_set(0);
	curr_stats.use_input_bar = 1;

	clean_selected_files(view);
	load_dir_list(view, 1);
	fview_cursor_redraw(view);

	update_all_windows();
}
コード例 #4
0
ファイル: search.c プロジェクト: lowtalker/vifm
/* Looks for a search match in specified direction navigates to it if match is
 * found.  Wraps search around specified wrap start position, when requested.
 * Returns non-zero if something was found, otherwise zero is returned. */
static int
find_and_goto_pattern(FileView *view, int wrap_start, int backward)
{
    if(!find_and_goto_match(view, view->list_pos, backward))
    {
        if(!cfg.wrap_scan || !find_and_goto_match(view, wrap_start, backward))
        {
            return 0;
        }
    }
    fview_cursor_redraw(view);
    return 1;
}
コード例 #5
0
ファイル: marks.c プロジェクト: dennishamester/vifm
int
goto_mark(FileView *view, char mark)
{
	switch(mark)
	{
		case '\'':
			navigate_back(view);
			return 0;
		case '\x03': /* Ctrl-C. */
		case '\x1b': /* Escape. */
			fview_cursor_redraw(view);
			return 0;

		default:
			return navigate_to_mark(view, mark);
	}
}
コード例 #6
0
int
goto_search_match(FileView *view, int backward)
{
	const int wrap_start = backward ? view->list_rows : -1;
	if(!find_and_goto_match(view, view->list_pos, backward))
	{
		if(!cfg.wrap_scan || !find_and_goto_match(view, wrap_start, backward))
		{
			return 0;
		}
	}

	/* Redraw the cursor which also might synchronize cursors of two views. */
	fview_cursor_redraw(view);
	/* Schedule redraw of the view to highlight search matches. */
	ui_view_schedule_redraw(view);

	return 1;
}
コード例 #7
0
ファイル: dir_stack.c プロジェクト: cosminadrianpopescu/vifm
int
popd(void)
{
	if(stack_top == 0)
		return -1;

	stack_top--;

	if(change_directory(&lwin, stack[stack_top].lpane_dir) >= 0)
		load_dir_list(&lwin, 0);

	if(change_directory(&rwin, stack[stack_top].rpane_dir) >= 0)
		load_dir_list(&rwin, 0);

	fview_cursor_redraw(curr_view);
	refresh_view_win(other_view);

	free_entry(&stack[stack_top]);

	return 0;
}
コード例 #8
0
ファイル: attr_dialog_nix.c プロジェクト: onovy/vifm
void
enter_attr_mode(FileView *active_view)
{
	int i;
	mode_t fmode;
	mode_t diff;
	uid_t uid = geteuid();

	if(curr_stats.load_stage < 2)
		return;

	view = active_view;
	memset(perms, 0, sizeof(perms));

	diff = 0;
	i = 0;
	while(i < view->list_rows && !view->dir_entry[i].selected)
		i++;
	file_is_dir = 0;
	if(i == view->list_rows)
	{
		i = view->list_pos;
		file_is_dir = is_dir(view->dir_entry[i].name);
	}
	fmode = view->dir_entry[i].mode;
	if(uid != 0 && view->dir_entry[i].uid != uid)
	{
		show_error_msgf("Access error", "You are not owner of %s",
				view->dir_entry[i].name);
		clean_selected_files(view);
		load_dir_list(view, 1);
		fview_cursor_redraw(view);
		return;
	}
	while(i < view->list_rows)
	{
		if(view->dir_entry[i].selected)
		{
			diff |= (view->dir_entry[i].mode ^ fmode);
			file_is_dir = file_is_dir || is_dir(view->dir_entry[i].name);

			if(uid != 0 && view->dir_entry[i].uid != uid)
			{
				show_error_msgf("Access error", "You are not owner of %s",
						view->dir_entry[i].name);
				return;
			}
		}

		i++;
	}

	vle_mode_set(ATTR_MODE, VMT_SECONDARY);
	clear_input_bar();
	curr_stats.use_input_bar = 0;

	perms[0] = !(diff & S_IRUSR) ? (int)(fmode & S_IRUSR) : -1;
	perms[1] = !(diff & S_IWUSR) ? (int)(fmode & S_IWUSR) : -1;
	perms[2] = !(diff & S_IXUSR) ? (int)(fmode & S_IXUSR) : -1;
	perms[3] = !(diff & S_ISUID) ? (int)(fmode & S_ISUID) : -1;
	perms[4] = !(diff & S_IRGRP) ? (int)(fmode & S_IRGRP) : -1;
	perms[5] = !(diff & S_IWGRP) ? (int)(fmode & S_IWGRP) : -1;
	perms[6] = !(diff & S_IXGRP) ? (int)(fmode & S_IXGRP) : -1;
	perms[7] = !(diff & S_ISGID) ? (int)(fmode & S_ISGID) : -1;
	perms[8] = !(diff & S_IROTH) ? (int)(fmode & S_IROTH) : -1;
	perms[9] = !(diff & S_IWOTH) ? (int)(fmode & S_IWOTH) : -1;
	perms[10] = !(diff & S_IXOTH) ? (int)(fmode & S_IXOTH) : -1;
	perms[11] = !(diff & S_ISVTX) ? (int)(fmode & S_ISVTX) : -1;
	adv_perms[0] = 0;
	adv_perms[1] = 0;
	adv_perms[2] = 0;
	memcpy(origin_perms, perms, sizeof(perms));

	top = 3;
	bottom = file_is_dir ? 18 : 16;
	curr = 3;
	permnum = 0;
	step = 1;
	while(perms[permnum] < 0 && curr <= bottom)
	{
		inc_curr();
		permnum++;
	}

	if(curr > bottom)
	{
		show_error_msg("Permissions change error",
				"Selected files have no common access state");
		leave_attr_mode();
		return;
	}

	col = 9;
	changed = 0;
	redraw_attr_dialog();
}
コード例 #9
0
ファイル: search.c プロジェクト: lowtalker/vifm
int
find_pattern(FileView *view, const char pattern[], int backward, int move,
             int *const found, int interactive)
{
    int cflags;
    int nmatches = 0;
    regex_t re;
    int err;
    FileView *other;

    if(move && cfg.hl_search)
    {
        clean_selected_files(view);
    }

    reset_search_results(view);

    if(pattern[0] == '\0')
    {
        *found = 1;
        return 0;
    }

    *found = 0;

    cflags = get_regexp_cflags(pattern);
    if((err = regcomp(&re, pattern, cflags)) == 0)
    {
        int i;
        for(i = 0; i < view->list_rows; ++i)
        {
            regmatch_t matches[1];
            dir_entry_t *const entry = &view->dir_entry[i];

            if(is_parent_dir(entry->name))
            {
                continue;
            }

            if(regexec(&re, entry->name, 1, matches, 0) != 0)
            {
                continue;
            }

            entry->search_match = nmatches + 1;
            entry->match_left = matches[0].rm_so;
            entry->match_right = matches[0].rm_eo;
            if(cfg.hl_search)
            {
                entry->selected = 1;
                ++view->selected_files;
            }
            ++nmatches;
        }
        regfree(&re);
    }
    else
    {
        if(interactive)
        {
            status_bar_errorf("Regexp error: %s", get_regexp_error(err, &re));
        }
        regfree(&re);
        return 1;
    }

    other = (view == &lwin) ? &rwin : &lwin;
    if(other->matches != 0 && strcmp(other->last_search, pattern) != 0)
    {
        other->last_search[0] = '\0';
        ui_view_reset_search_highlight(other);
    }
    view->matches = nmatches;
    copy_str(view->last_search, sizeof(view->last_search), pattern);

    /* Need to redraw the list so that the matching files are highlighted */
    draw_dir_list(view);

    view->matches = nmatches;
    if(nmatches > 0)
    {
        const int was_found = move ? goto_search_match(view, backward) : 1;
        *found = was_found;

        if(cfg.hl_search && !was_found)
        {
            /* Update the view.  It look might have changed, because of selection. */
            fview_cursor_redraw(view);
        }

        if(!cfg.hl_search)
        {
            if(interactive)
            {
                print_result(view, was_found, backward);
            }
            return 1;
        }
        return 0;
    }
    else
    {
        fview_cursor_redraw(view);
        if(interactive)
        {
            print_search_fail_msg(view, backward);
        }
        return 1;
    }
}