Code

list_window: check for unchanged value in set_length()
[ncmpc.git] / src / screen_text.c
index 13bc58d6bc80018bcfab6e1dd36f5f733669d67c..b7d66838fa6a6de260a10894857c59628c499f27 100644 (file)
@@ -1,24 +1,24 @@
-/*
- * (c) 2004-2008 The Music Player Daemon Project
- * http://www.musicpd.org/
- *
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- *
+
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
 
 #include "screen_text.h"
-#include "screen_utils.h"
+#include "screen_find.h"
 #include "charset.h"
 
 #include <assert.h>
@@ -33,6 +33,7 @@ screen_text_clear(struct screen_text *text)
                g_free(g_ptr_array_index(text->lines, i));
 
        g_ptr_array_set_size(text->lines, 0);
+       list_window_set_length(text->lw, 0);
 }
 
 void
@@ -74,18 +75,18 @@ screen_text_set(struct screen_text *text, const GString *str)
 
        if (*p != 0)
                g_ptr_array_add(text->lines, g_strdup(p));
+
+       list_window_set_length(text->lw, text->lines->len);
 }
 
 const char *
-screen_text_list_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
-                         void *data)
+screen_text_list_callback(unsigned idx, void *data)
 {
        const struct screen_text *text = data;
        static char buffer[256];
        char *value;
 
-       if (idx >= text->lines->len)
-               return NULL;
+       assert(idx < text->lines->len);
 
        value = utf8_to_locale(g_ptr_array_index(text->lines, idx));
        g_strlcpy(buffer, value, sizeof(buffer));
@@ -98,17 +99,15 @@ bool
 screen_text_cmd(struct screen_text *text,
                G_GNUC_UNUSED struct mpdclient *c, command_t cmd)
 {
-       if (list_window_scroll_cmd(text->lw, text->lines->len, cmd)) {
+       if (list_window_scroll_cmd(text->lw, cmd)) {
                screen_text_repaint(text);
                return true;
        }
 
-       text->lw->selected = text->lw->start + text->lw->rows;
-       if (screen_find(text->lw, text->lines->len,
-                       cmd, screen_text_list_callback, text)) {
+       list_window_set_cursor(text->lw, text->lw->start);
+       if (screen_find(text->lw, cmd, screen_text_list_callback, text)) {
                /* center the row */
-               list_window_center(text->lw, text->lines->len,
-                                  text->lw->selected);
+               list_window_center(text->lw, text->lw->selected);
                screen_text_repaint(text);
                return true;
        }