Пример #1
0
/* leaves properties change dialog */
static void
leave_attr_mode(void)
{
	vle_mode_set(NORMAL_MODE, VMT_PRIMARY);
	curr_stats.use_input_bar = 1;

	clean_selected_files(view);
	load_dir_list(view, 1);
	move_to_list_pos(view, view->list_pos);

	update_all_windows();
}
Пример #2
0
static void
leave_attr_mode(void)
{
	*mode = NORMAL_MODE;
	curs_set(FALSE);
	curr_stats.use_input_bar = 1;

	clean_selected_files(view);
	load_dir_list(view, 1);
	move_to_list_pos(view, view->list_pos);

	update_all_windows();
}
Пример #3
0
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
void
enter_visual_mode(VisualSubmodes sub_mode)
{
	const int ub = check_mark_directory(curr_view, '<');
	const int lb = check_mark_directory(curr_view, '>');

	if(sub_mode == VS_RESTORE && (ub < 0 || lb < 0))
	{
		return;
	}

	view = curr_view;
	start_pos = view->list_pos;
	vle_mode_set(VISUAL_MODE, VMT_PRIMARY);

	switch(sub_mode)
	{
		case VS_NORMAL:
			amend_type = AT_NONE;
			clean_selected_files(view);
			backup_selection_flags(view);
			select_first_one();
			break;
		case VS_RESTORE:
			amend_type = AT_NONE;
			clean_selected_files(view);
			backup_selection_flags(view);
			restore_previous_selection();
			break;
		case VS_AMEND:
			amend_type = AT_APPEND;
			backup_selection_flags(view);
			select_first_one();
			break;
	}

	redraw_view(view);
}
Пример #5
0
static void
leave_change_mode(int clean_selection)
{
	*mode = NORMAL_MODE;

	if(clean_selection)
	{
		clean_selected_files(view);
		load_saving_pos(view, 1);
		move_to_list_pos(view, view->list_pos);
	}

	update_all_windows();
}
Пример #6
0
static void
leave_menu_mode(void)
{
	reset_popup_menu(menu);

	clean_selected_files(view);
	redraw_view(view);

	*mode = NORMAL_MODE;
	if(was_redraw)
		update_screen(UT_FULL);
	else
		update_all_windows();
}
Пример #7
0
/* Leaves menu mode, possibly resetting selection.  Does nothing if current mode
 * isn't menu mode. */
static void
leave_menu_mode(int reset_selection)
{
	/* Some menu implementation could have switched mode from one of handlers. */
	if(!vle_mode_is(MENU_MODE))
	{
		return;
	}

	reset_popup_menu(menu);

	if(reset_selection)
	{
		clean_selected_files(view);
		redraw_view(view);
	}

	vle_mode_set(NORMAL_MODE, VMT_PRIMARY);

	update_ui_on_leaving();
}
Пример #8
0
/* Callback that is called when menu item is selected.  Should return non-zero
 * to stay in menu mode. */
int
execute_filetype_cb(FileView *view, menu_info *m)
{
	if(view->dir_entry[view->list_pos].type == FT_DIR && m->pos == 0)
	{
		open_dir(view);
	}
	else
	{
		const char *prog_str = strchr(m->data[m->pos], '|') + 1;
		if(prog_str[0] != '\0')
		{
			int background = m->extra_data & 1;
			run_using_prog(view, prog_str, 0, background);
		}
	}

	clean_selected_files(view);
	redraw_view(view);
	return 0;
}
Пример #9
0
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);
		move_to_list_pos(view, view->list_pos);
		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++;
	}

	*mode = ATTR_MODE;
	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();
}
Пример #10
0
static void
run_file(FileView *view, int dont_execute)
{
	/* TODO: refactor this function run_file() */

	char *typed_fname;
	const char *multi_prog_cmd;
	int undef;
	int same;
	dir_entry_t *entry;
	int no_multi_run;

	if(!view->dir_entry[view->list_pos].selected)
	{
		clean_selected_files(view);
	}

	typed_fname = get_typed_entry_fpath(get_current_entry(view));
	multi_prog_cmd = ft_get_program(typed_fname);
	free(typed_fname);

	no_multi_run = !is_multi_run_compat(view, multi_prog_cmd);
	undef = 0;
	same = 1;

	entry = NULL;
	while(iter_selected_entries(view, &entry))
	{
		char *typed_fname;
		const char *entry_prog_cmd;

		if(!path_exists_at(entry->origin, entry->name, DEREF))
		{
			show_error_msgf("Broken Link", "Destination of \"%s\" link doesn't exist",
					entry->name);
			return;
		}

		typed_fname = get_typed_entry_fpath(entry);
		entry_prog_cmd = ft_get_program(typed_fname);
		free(typed_fname);

		if(entry_prog_cmd == NULL)
		{
			++undef;
			continue;
		}

		no_multi_run += !is_multi_run_compat(view, entry_prog_cmd);
		if(multi_prog_cmd == NULL)
		{
			multi_prog_cmd = entry_prog_cmd;
		}
		else if(strcmp(entry_prog_cmd, multi_prog_cmd) != 0)
		{
			same = 0;
		}
	}

	if(!same && undef == 0 && no_multi_run)
	{
		show_error_msg("Run error", "Handlers of selected files are incompatible.");
		return;
	}
	if(undef > 0)
	{
		multi_prog_cmd = NULL;
	}

	/* Check for a filetype */
	/* vi is set as the default for any extension without a program */
	if(multi_prog_cmd == NULL)
	{
		run_with_defaults(view);
		return;
	}

	if(no_multi_run)
	{
		run_using_prog(view, multi_prog_cmd, dont_execute, 0);
	}
	else
	{
		run_selection_separately(view, dont_execute);
	}
}
Пример #11
0
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;
    }
}
Пример #12
0
static void
input_line_changed(void)
{
	static wchar_t *previous;

	if(!cfg.inc_search || !input_stat.search_mode)
		return;

	if(prev_mode != MENU_MODE)
	{
		curr_view->top_line = input_stat.old_top;
		curr_view->list_pos = input_stat.old_pos;
	}
	else
	{
		load_menu_pos();
	}

	if(input_stat.line == NULL || input_stat.line[0] == L'\0')
	{
		if(cfg.hl_search)
		{
			clean_selected_files(curr_view);
			draw_dir_list(curr_view, curr_view->top_line);
			move_to_list_pos(curr_view, curr_view->list_pos);
		}
		free(previous);
		previous = NULL;
	}
	else if(previous == NULL || wcscmp(previous, input_stat.line) != 0)
	{
		char *p;

		free(previous);
		previous = my_wcsdup(input_stat.line);

		p = to_multibyte(input_stat.line);

		if(sub_mode == SEARCH_FORWARD_SUBMODE)
			exec_command(p, curr_view, GET_FSEARCH_PATTERN);
		else if(sub_mode == SEARCH_BACKWARD_SUBMODE)
			exec_command(p, curr_view, GET_BSEARCH_PATTERN);
		else if(sub_mode == MENU_SEARCH_FORWARD_SUBMODE ||
				sub_mode == MENU_SEARCH_BACKWARD_SUBMODE)
			search_menu_list(p, sub_mode_ptr);
		else if(sub_mode == VSEARCH_FORWARD_SUBMODE)
			exec_command(p, curr_view, GET_VFSEARCH_PATTERN);
		else if(sub_mode == VSEARCH_BACKWARD_SUBMODE)
			exec_command(p, curr_view, GET_VBSEARCH_PATTERN);

		free(p);
	}

	if(prev_mode != MENU_MODE)
	{
		draw_dir_list(curr_view, curr_view->top_line);
		move_to_list_pos(curr_view, curr_view->list_pos);
	}
	else
	{
		menu_redraw();
	}
}
Пример #13
0
/* Callback-like function, which is called every time input line is changed. */
static void
input_line_changed(void)
{
	static wchar_t *previous;

	if(!cfg.inc_search || (!input_stat.search_mode && sub_mode != FILTER_SUBMODE))
		return;

	set_view_port();

	if(input_stat.line == NULL || input_stat.line[0] == L'\0')
	{
		if(cfg.hl_search)
		{
			/* clear selection */
			if(prev_mode != MENU_MODE)
			{
				clean_selected_files(curr_view);
			}
			else
			{
				search_menu_list("", sub_mode_ptr);
			}
		}
		free(previous);
		previous = NULL;

		if(sub_mode == FILTER_SUBMODE)
		{
			set_local_filter("");
		}
	}
	else if(previous == NULL || wcscmp(previous, input_stat.line) != 0)
	{
		char *mbinput;

		free(previous);
		previous = my_wcsdup(input_stat.line);

		mbinput = to_multibyte(input_stat.line);

		switch(sub_mode)
		{
			case SEARCH_FORWARD_SUBMODE:
				exec_command(mbinput, curr_view, GET_FSEARCH_PATTERN);
				break;
			case SEARCH_BACKWARD_SUBMODE:
				exec_command(mbinput, curr_view, GET_BSEARCH_PATTERN);
				break;
			case VSEARCH_FORWARD_SUBMODE:
				exec_command(mbinput, curr_view, GET_VFSEARCH_PATTERN);
				break;
			case VSEARCH_BACKWARD_SUBMODE:
				exec_command(mbinput, curr_view, GET_VBSEARCH_PATTERN);
				break;
			case MENU_SEARCH_FORWARD_SUBMODE:
			case MENU_SEARCH_BACKWARD_SUBMODE:
				search_menu_list(mbinput, sub_mode_ptr);
				break;
			case FILTER_SUBMODE:
				set_local_filter(mbinput);
				break;

			default:
				assert("Unexpected filter type.");
				break;
		}

		free(mbinput);
	}

	if(prev_mode != MENU_MODE && prev_mode != VISUAL_MODE)
	{
		redraw_current_view();
	}
	else if(prev_mode != VISUAL_MODE)
	{
		menu_redraw();
	}
}