From 61b1bbfadfb80ad2162370d438e10bdd18c2e991 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 9 Oct 2009 22:13:53 +0200 Subject: [PATCH] list_window: splitted function list_window_set_selected() list_window_set_selected() becomes list_window_move_cursor(). list_window_set_cursor() is the new public function, which sets the cursor and disables range selection. --- src/list_window.c | 50 ++++++++++++++++++++++++++------------------- src/list_window.h | 14 ++++++++++++- src/screen_artist.c | 8 ++++---- src/screen_file.c | 4 ++-- src/screen_play.c | 8 ++++---- 5 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/list_window.c b/src/list_window.c index 3faf437..e11e75a 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -128,7 +128,16 @@ list_window_center(struct list_window *lw, unsigned rows, unsigned n) } void -list_window_set_selected(struct list_window *lw, unsigned n) +list_window_set_cursor(struct list_window *lw, unsigned i) +{ + lw->range_selection = false; + lw->selected = i; + lw->selected_start = i; + lw->selected_end = i; +} + +void +list_window_move_cursor(struct list_window *lw, unsigned n) { lw->selected = n; if(lw->range_selection) @@ -155,39 +164,39 @@ static void list_window_next(struct list_window *lw, unsigned length) { if (lw->selected + 1 < length) - list_window_set_selected(lw, lw->selected + 1); + list_window_move_cursor(lw, lw->selected + 1); else if (options.list_wrap) - list_window_set_selected(lw, 0); + list_window_move_cursor(lw, 0); } static void list_window_previous(struct list_window *lw, unsigned length) { if (lw->selected > 0) - list_window_set_selected(lw, lw->selected - 1); + list_window_move_cursor(lw, lw->selected - 1); else if (options.list_wrap) - list_window_set_selected(lw, length-1); + list_window_move_cursor(lw, length-1); } static void list_window_top(struct list_window *lw) { if (lw->start == 0) - list_window_set_selected(lw, lw->start); + list_window_move_cursor(lw, lw->start); else if ((unsigned) options.scroll_offset * 2 >= lw->rows) - list_window_set_selected(lw, lw->start + lw->rows / 2); + list_window_move_cursor(lw, lw->start + lw->rows / 2); else - list_window_set_selected(lw, lw->start + options.scroll_offset); + list_window_move_cursor(lw, lw->start + options.scroll_offset); } static void list_window_middle(struct list_window *lw, unsigned length) { if (length >= lw->rows) - list_window_set_selected(lw, lw->start + lw->rows / 2); + list_window_move_cursor(lw, lw->start + lw->rows / 2); else - list_window_set_selected(lw, length / 2); + list_window_move_cursor(lw, length / 2); } static void @@ -195,29 +204,29 @@ list_window_bottom(struct list_window *lw, unsigned length) { if (length >= lw->rows) if ((unsigned) options.scroll_offset * 2 >= lw->rows) - list_window_set_selected(lw, lw->start + lw->rows / 2); + list_window_move_cursor(lw, lw->start + lw->rows / 2); else if (lw->start + lw->rows == length) - list_window_set_selected(lw, length - 1); + list_window_move_cursor(lw, length - 1); else - list_window_set_selected(lw, lw->start + lw->rows - 1 - options.scroll_offset); + list_window_move_cursor(lw, lw->start + lw->rows - 1 - options.scroll_offset); else - list_window_set_selected(lw, length - 1); + list_window_move_cursor(lw, length - 1); } static void list_window_first(struct list_window *lw) { - list_window_set_selected(lw, 0); + list_window_move_cursor(lw, 0); } static void list_window_last(struct list_window *lw, unsigned length) { if (length > 0) - list_window_set_selected(lw, length - 1); + list_window_move_cursor(lw, length - 1); else - list_window_set_selected(lw, 0); + list_window_move_cursor(lw, 0); } static void @@ -226,7 +235,7 @@ list_window_next_page(struct list_window *lw, unsigned length) if (lw->rows < 2) return; if (lw->selected + lw->rows < length) - list_window_set_selected(lw, lw->selected + lw->rows - 1); + list_window_move_cursor(lw, lw->selected + lw->rows - 1); else list_window_last(lw, length); } @@ -237,7 +246,7 @@ list_window_previous_page(struct list_window *lw) if (lw->rows < 2) return; if (lw->selected > lw->rows - 1) - list_window_set_selected(lw, lw->selected - lw->rows + 1); + list_window_move_cursor(lw, lw->selected - lw->rows + 1); else list_window_first(lw); } @@ -558,8 +567,7 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd) if(lw->range_selection) { screen_status_printf(_("Range selection disabled")); - lw->range_selection = false; - list_window_set_selected(lw, lw->selected); + list_window_set_cursor(lw, lw->selected); } else { diff --git a/src/list_window.h b/src/list_window.h index 68abd4d..7c6a2a7 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -91,9 +91,21 @@ void list_window_center(struct list_window *lw, unsigned rows, unsigned n); /* select functions */ -void list_window_set_selected(struct list_window *lw, unsigned n); void list_window_check_selected(struct list_window *lw, unsigned length); +/** + * Sets the position of the cursor. Disables range selection. + */ +void +list_window_set_cursor(struct list_window *lw, unsigned i); + +/** + * Moves the cursor. Modifies the range if range selection is + * enabled. + */ +void +list_window_move_cursor(struct list_window *lw, unsigned n); + /* find a string in a list window */ bool list_window_find(struct list_window *lw, diff --git a/src/screen_artist.c b/src/screen_artist.c index 996a0b7..3ffc533 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -494,7 +494,7 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd) g_free(old); if (idx >= 0) { - list_window_set_selected(browser.lw, idx); + list_window_set_cursor(browser.lw, idx); list_window_center(browser.lw, artist_list->len, idx); } @@ -528,7 +528,7 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd) if (idx >= 0) { ++idx; - list_window_set_selected(browser.lw, idx); + list_window_set_cursor(browser.lw, idx); list_window_center(browser.lw, album_list->len, idx); } @@ -557,7 +557,7 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd) g_free(old); if (idx >= 0) { - list_window_set_selected(browser.lw, idx); + list_window_set_cursor(browser.lw, idx); list_window_center(browser.lw, artist_list->len, idx); } @@ -576,7 +576,7 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd) if (idx >= 0) { ++idx; - list_window_set_selected(browser.lw, idx); + list_window_set_cursor(browser.lw, idx); list_window_center(browser.lw, album_list->len, idx); } diff --git a/src/screen_file.c b/src/screen_file.c index b087068..5a37c0c 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -126,7 +126,7 @@ change_to_parent(struct mpdclient *c) if (success && idx >= 0) { /* set the cursor on the previous working directory */ - list_window_set_selected(browser.lw, idx); + list_window_set_cursor(browser.lw, idx); list_window_center(browser.lw, filelist_length(browser.filelist), idx); } @@ -454,7 +454,7 @@ screen_file_goto_song(struct mpdclient *c, const struct mpd_song *song) if (i < 0) i = 0; - list_window_set_selected(browser.lw, i); + list_window_set_cursor(browser.lw, i); /* finally, switch to the file screen */ screen_switch(&screen_browse, c); diff --git a/src/screen_play.c b/src/screen_play.c index 256ea36..dd3fccd 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -212,14 +212,14 @@ center_playing_item(struct mpdclient *c, bool center_cursor) if (length < lw->rows) { if (center_cursor) - list_window_set_selected(lw, idx); + list_window_set_cursor(lw, idx); return; } list_window_center(lw, length, idx); if (center_cursor) { - list_window_set_selected(lw, idx); + list_window_set_cursor(lw, idx); return; } @@ -666,8 +666,8 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd) playlist_repaint(); return false; case CMD_SELECT_PLAYING: - list_window_set_selected(lw, playlist_get_index(&c->playlist, - c->song)); + list_window_set_cursor(lw, playlist_get_index(&c->playlist, + c->song)); playlist_save_selection(); playlist_repaint(); return true; -- 2.30.2