Code

list_window: added top, middle, and bottom commands
[ncmpc.git] / src / list_window.c
index 4cd9a8f6009c241d2ee56700b4f4fbd24b8aeef0..bf0f45aa18dd2019e6a634bf805859d31188570b 100644 (file)
@@ -24,6 +24,8 @@
 #include "match.h"
 #include "command.h"
 #include "colors.h"
+#include "screen.h"
+#include "i18n.h"
 
 #include <assert.h>
 #include <stdlib.h>
@@ -150,6 +152,30 @@ list_window_previous(struct list_window *lw, unsigned length)
                list_window_set_selected(lw, length-1);
 }
 
+static void
+list_window_top(struct list_window *lw)
+{
+       list_window_set_selected(lw, lw->start);
+}
+
+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);
+       else
+               list_window_set_selected(lw, length / 2);
+}
+
+static void
+list_window_bottom(struct list_window *lw, unsigned length)
+{
+       if (length >= lw->rows)
+               list_window_set_selected(lw, lw->start + lw->rows - 1);
+       else
+               list_window_set_selected(lw, length - 1);
+}
+
 static void
 list_window_first(struct list_window *lw)
 {
@@ -184,7 +210,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_set_selected(lw, lw->selected - lw->rows + 1);
        else
                list_window_first(lw);
 }
@@ -367,6 +393,15 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd)
        case CMD_LIST_NEXT:
                list_window_next(lw, rows);
                break;
+       case CMD_LIST_TOP:
+               list_window_top(lw);
+               break;
+       case CMD_LIST_MIDDLE:
+               list_window_middle(lw,rows);
+               break;
+       case CMD_LIST_BOTTOM:
+               list_window_bottom(lw,rows);
+               break;
        case CMD_LIST_FIRST:
                list_window_first(lw);
                break;
@@ -382,11 +417,13 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd)
        case CMD_LIST_VISUAL_SELECT:
                if(lw->visual_selection)
                {
+                       screen_status_printf(_("Visual selection disabled"));
                        lw->visual_selection = false;
                        list_window_set_selected(lw, lw->selected);
                }
                else
                {
+                       screen_status_printf(_("Visual selection enabled"));
                        lw->visual_base = lw->selected;
                        lw->visual_selection = true;
                }