Code

list_window: splitted function list_window_set_selected()
authorMax Kellermann <max@duempel.org>
Fri, 9 Oct 2009 20:13:53 +0000 (22:13 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 9 Oct 2009 20:13:53 +0000 (22:13 +0200)
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
src/list_window.h
src/screen_artist.c
src/screen_file.c
src/screen_play.c

index 3faf437f791a9b305d303c0139a28ec945a4ac5e..e11e75acf986c6d339c349e4d537ebd3dd0a1589 100644 (file)
@@ -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
                {
index 68abd4d0d75a18cb7513d86b60b8abf2342aa1bd..7c6a2a71868dc2cfb0a31f651cc14d34301069b3 100644 (file)
@@ -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,
index 996a0b7914d6ebea2889abbcc2e3f005b79d7669..3ffc533021eff02a428811574fe9741902340053 100644 (file)
@@ -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);
                        }
index b087068ea79f717b04093ded2555b3f4e2672f8f..5a37c0c6a1b84b51a2275926974d66550cd9bb08 100644 (file)
@@ -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);
index 256ea36d2b9e5f03b5d593586cf4637c88e511a9..dd3fccdc2492039864a2e392b8464af53cf3a81c 100644 (file)
@@ -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;