Skip to content

Commit

Permalink
Add -n option to win-add-{l,p,Q,q} to prevent selecting the next item (
Browse files Browse the repository at this point in the history
…cmus#1017)

* Add -n option to win-add-{l,p,Q,q} to prevent selecting the next item (cmus#1016)

* Rename 'no_next' -> 'advance'
  • Loading branch information
pgaskin authored Dec 13, 2020
1 parent 00bd124 commit ad7ff7e
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 33 deletions.
20 changes: 16 additions & 4 deletions Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -685,30 +685,42 @@ win-activate (*enter*)
view 6 activate the selected filters. In settings view (7) change
binding or variable.

win-add-l (*a*)
win-add-l [-n] (*a*)
Add the currently marked or selected track(s) (views 3-4), or the
currently selected file or directory (view 5) to the library.

Analogous to *:add -l*

win-add-p (*y*)
-n
Don't move the selection to the next item.

win-add-p [-n] (*y*)
Add the currently marked or selected track(s) (views 1-2, 4), or the
currently selected file or directory (view 5) to the marked playlist.

Analogous to *:add -p*

win-add-Q (*E*)
-n
Don't move the selection to the next item.

win-add-Q [-n] (*E*)
Prepend the currently marked or selected track(s) (views 1-3), or the
currently selected file or directory (view 5) to the play queue.

Analogous to *:add -Q*

win-add-q (*e*)
-n
Don't move the selection to the next item.

win-add-q [-n] (*e*)
Add the currently marked or selected track(s) (views 1-3), or the
currently selected file or directory (view 5) to the play queue.

Analogous to *:add -q*

-n
Don't move the selection to the next item.

win-bottom (*G*, *end*)
Goto bottom of the current window.

Expand Down
2 changes: 1 addition & 1 deletion cmus.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef int (*track_info_cb)(void *data, struct track_info *ti);
typedef int (*for_each_ti_cb)(track_info_cb cb, void *data, void *opaque);

/* lib_for_each_sel, pl_for_each_sel, play_queue_for_each_sel */
typedef int (*for_each_sel_ti_cb)(track_info_cb cb, void *data, int reverse);
typedef int (*for_each_sel_ti_cb)(track_info_cb cb, void *data, int reverse, int advance);

/* lib_add_track, pl_add_track, play_queue_append, play_queue_prepend */
typedef void (*add_ti_cb)(struct track_info *, void *opaque);
Expand Down
55 changes: 36 additions & 19 deletions command_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1454,14 +1454,14 @@ static void cmd_search_b_start(char *arg)
enter_search_backward_mode();
}

static int sorted_for_each_sel(track_info_cb cb, void *data, int reverse)
static int sorted_for_each_sel(track_info_cb cb, void *data, int reverse, int advance)
{
return editable_for_each_sel(&lib_editable, cb, data, reverse);
return editable_for_each_sel(&lib_editable, cb, data, reverse, advance);
}

static int pq_for_each_sel(track_info_cb cb, void *data, int reverse)
static int pq_for_each_sel(track_info_cb cb, void *data, int reverse, int advance)
{
return editable_for_each_sel(&pq_editable, cb, data, reverse);
return editable_for_each_sel(&pq_editable, cb, data, reverse, advance);
}

static for_each_sel_ti_cb view_for_each_sel[4] = {
Expand All @@ -1485,7 +1485,7 @@ static int wrapper_cb(void *data, struct track_info *ti)
return 0;
}

static void add_from_browser(add_ti_cb add, int job_type)
static void add_from_browser(add_ti_cb add, int job_type, int advance)
{
char *sel = get_browser_add_file();

Expand All @@ -1496,7 +1496,8 @@ static void add_from_browser(add_ti_cb add, int job_type)
ft = cmus_detect_ft(sel, &ret);
if (ft != FILE_TYPE_INVALID) {
cmus_add(add, ret, ft, job_type, 0, NULL);
window_down(browser_win, 1);
if (advance)
window_down(browser_win, 1);
}
free(ret);
free(sel);
Expand All @@ -1505,29 +1506,37 @@ static void add_from_browser(add_ti_cb add, int job_type)

static void cmd_win_add_l(char *arg)
{
int flag = parse_flags((const char **)&arg, "n");
if (flag == -1)
return;

if (cur_view == TREE_VIEW || cur_view == SORTED_VIEW)
return;

if (cur_view <= QUEUE_VIEW) {
struct wrapper_cb_data add = { lib_add_track };
view_for_each_sel[cur_view](wrapper_cb, &add, 0);
view_for_each_sel[cur_view](wrapper_cb, &add, 0, flag != 'n');
} else if (cur_view == BROWSER_VIEW) {
add_from_browser(lib_add_track, JOB_TYPE_LIB);
add_from_browser(lib_add_track, JOB_TYPE_LIB, flag != 'n');
}
}

static void cmd_win_add_p(char *arg)
{
int flag = parse_flags((const char **)&arg, "n");
if (flag == -1)
return;

if (cur_view == PLAYLIST_VIEW && pl_visible_is_marked())
return;

if (cur_view <= QUEUE_VIEW) {
struct wrapper_cb_data add = { pl_add_track_to_marked_pl2 };
view_for_each_sel[cur_view](wrapper_cb, &add, 0);
view_for_each_sel[cur_view](wrapper_cb, &add, 0, flag != 'n');
} else if (cur_view == BROWSER_VIEW) {
char *sel = get_browser_add_file();
if (sel) {
if (pl_add_file_to_marked_pl(sel))
if (pl_add_file_to_marked_pl(sel) && flag != 'n')
window_down(browser_win, 1);
free(sel);
}
Expand All @@ -1536,27 +1545,35 @@ static void cmd_win_add_p(char *arg)

static void cmd_win_add_Q(char *arg)
{
int flag = parse_flags((const char **)&arg, "n");
if (flag == -1)
return;

if (cur_view == QUEUE_VIEW)
return;

if (cur_view <= QUEUE_VIEW) {
struct wrapper_cb_data add = { play_queue_prepend };
view_for_each_sel[cur_view](wrapper_cb, &add, 1);
view_for_each_sel[cur_view](wrapper_cb, &add, 1, flag != 'n');
} else if (cur_view == BROWSER_VIEW) {
add_from_browser(play_queue_prepend, JOB_TYPE_QUEUE);
add_from_browser(play_queue_prepend, JOB_TYPE_QUEUE, flag != 'n');
}
}

static void cmd_win_add_q(char *arg)
{
int flag = parse_flags((const char **)&arg, "n");
if (flag == -1)
return;

if (cur_view == QUEUE_VIEW)
return;

if (cur_view <= QUEUE_VIEW) {
struct wrapper_cb_data add = { play_queue_append };
view_for_each_sel[cur_view](wrapper_cb, &add, 0);
view_for_each_sel[cur_view](wrapper_cb, &add, 0, flag != 'n');
} else if (cur_view == BROWSER_VIEW) {
add_from_browser(play_queue_append, JOB_TYPE_QUEUE);
add_from_browser(play_queue_append, JOB_TYPE_QUEUE, flag != 'n');
}
}

Expand Down Expand Up @@ -1787,7 +1804,7 @@ static void cmd_win_update_cache(char *arg)
if (cur_view != TREE_VIEW && cur_view != SORTED_VIEW)
return;

view_for_each_sel[cur_view](add_ti, &sel, 0);
view_for_each_sel[cur_view](add_ti, &sel, 0, 1);
if (sel.tis_nr == 0)
return;
sel.tis[sel.tis_nr] = NULL;
Expand Down Expand Up @@ -2615,10 +2632,10 @@ struct command commands[] = {
{ "vol", cmd_vol, 1, 2, NULL, 0, 0 },
{ "w", cmd_save, 0, 1, expand_load_save, 0, CMD_UNSAFE },
{ "win-activate", cmd_win_activate, 0, 0, NULL, 0, 0 },
{ "win-add-l", cmd_win_add_l, 0, 0, NULL, 0, 0 },
{ "win-add-p", cmd_win_add_p, 0, 0, NULL, 0, 0 },
{ "win-add-Q", cmd_win_add_Q, 0, 0, NULL, 0, 0 },
{ "win-add-q", cmd_win_add_q, 0, 0, NULL, 0, 0 },
{ "win-add-l", cmd_win_add_l, 0, 1, NULL, 0, 0 },
{ "win-add-p", cmd_win_add_p, 0, 1, NULL, 0, 0 },
{ "win-add-Q", cmd_win_add_Q, 0, 1, NULL, 0, 0 },
{ "win-add-q", cmd_win_add_q, 0, 1, NULL, 0, 0 },
{ "win-bottom", cmd_win_bottom, 0, 0, NULL, 0, 0 },
{ "win-down", cmd_win_down, 0, 1, NULL, 0, 0 },
{ "win-half-page-down", cmd_win_hf_pg_down, 0, 0, NULL, 0, 0 },
Expand Down
4 changes: 2 additions & 2 deletions editable.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,12 @@ int _editable_for_each_sel(struct editable *e, track_info_cb cb, void *data,
}

int editable_for_each_sel(struct editable *e, track_info_cb cb, void *data,
int reverse)
int reverse, int advance)
{
int rc;

rc = _editable_for_each_sel(e, cb, data, reverse);
if (e->nr_marked == 0 && editable_owns_shared(e))
if (advance && e->nr_marked == 0 && editable_owns_shared(e))
window_down(e->shared->win, 1);
return rc;
}
Expand Down
2 changes: 1 addition & 1 deletion editable.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void editable_invert_marks(struct editable *e);
int _editable_for_each_sel(struct editable *e, track_info_cb cb, void *data,
int reverse);
int editable_for_each_sel(struct editable *e, track_info_cb cb, void *data,
int reverse);
int reverse, int advance);
int editable_for_each(struct editable *e, track_info_cb cb, void *data,
int reverse);
void editable_update_track(struct editable *e, struct track_info *old, struct track_info *new);
Expand Down
2 changes: 1 addition & 1 deletion lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void tree_sel_update(int changed);
void tree_sel_current(int auto_expand_albums);
void tree_sel_first(void);
void tree_sel_track(struct tree_track *t, int auto_expand_albums );
int tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse);
int tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse, int advance);
int _tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse);

struct track_info *sorted_activate_selected(void);
Expand Down
4 changes: 2 additions & 2 deletions pl.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,10 @@ int _pl_for_each_sel(track_info_cb cb, void *data, int reverse)
return editable_for_each(&pl_visible->editable, cb, data, reverse);
}

int pl_for_each_sel(track_info_cb cb, void *data, int reverse)
int pl_for_each_sel(track_info_cb cb, void *data, int reverse, int advance)
{
if (pl_cursor_in_track_window)
return editable_for_each_sel(&pl_visible->editable, cb, data, reverse);
return editable_for_each_sel(&pl_visible->editable, cb, data, reverse, advance);
else
return editable_for_each(&pl_visible->editable, cb, data, reverse);
}
Expand Down
2 changes: 1 addition & 1 deletion pl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct track_info *pl_play_selected_row(void);
void pl_select_playing_track(void);
void pl_reshuffle(void);
int _pl_for_each_sel(track_info_cb cb, void *data, int reverse);
int pl_for_each_sel(track_info_cb cb, void *data, int reverse);
int pl_for_each_sel(track_info_cb cb, void *data, int reverse, int advance);
void pl_reload_visible(void);
struct window *pl_cursor_win(void);
void pl_set_nr_rows(int h);
Expand Down
5 changes: 3 additions & 2 deletions tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,10 +1358,11 @@ int _tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data,
return rc;
}

int tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse)
int tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse, int advance)
{
int rc = _tree_for_each_sel(cb, data, reverse);

window_down(lib_cur_win, 1);
if (advance)
window_down(lib_cur_win, 1);
return rc;
}

0 comments on commit ad7ff7e

Please sign in to comment.