giftcurs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[giFTcurs-devel] [PATCH] Standard scrolling behavior for lists


From: Charles Levert
Subject: [giFTcurs-devel] [PATCH] Standard scrolling behavior for lists
Date: Fri, 31 Dec 2004 21:59:18 -0500
User-agent: Mutt/1.4.1i

Changes:

        * Content position (list selector) commands should only scroll
          when necessary.  Likewise, scroll commands should only modify
          the content position when necessary.  The ui_list_handler()
          function and the help text have been updated to reflect this;
          the scrolling behavior is now similar to that of GNU Emacs
          or Vim, including a 2-line overlap between screens.



[ Edited with ude,
    the unified-format diff-output ("unidiff") editor,
    version 0.1 of 2004-11-03.  ]
--- src/ui.h.orig-0.6.2 2003-11-16 11:15:36 -0500
+++ src/ui.h    2004-12-31 20:58:35 -0500
@@ -57,7 +57,7 @@
 #endif
 void ui_handler(int key);
 
-int ui_list_handler(list *foo, int key, int page_len);
+int ui_list_handler(list *foo, int key, int page_len, int h);
 
 void ui_draw(void);
 
--- src/ui.c.orig-0.6.2 2003-11-16 11:15:36 -0500
+++ src/ui.c    2004-12-31 21:28:23 -0500
@@ -313,40 +313,65 @@ void ui_draw(void)
        move(curs_y, curs_x);
 }
 
-/* This changes position in a list. */
-/* returns true if position changes */
+/* This changes position in a list, or scrolls, or both.  */
+/* Returns true if display or position change.  */
-int ui_list_handler(list *foo, int key, int page_len)
+int ui_list_handler(list *foo, int key, int page_len, int h)
 {
-       int old_sel = foo->sel;
+       int tmp;
+
+       if (!page_len)
+               page_len = h - 2;       /* Use default.  */
+       if (page_len < 1)
+               page_len = 1;
 
        switch (key) {
        case KEY_DOWN:
+               if (foo->sel >= foo->num - 1)
+                       return 0;
                foo->sel++;
                break;
        case KEY_UP:
+               if (foo->sel <= 0)
+                       return 0;
                foo->sel--;
                break;
        case KEY_NPAGE:
-               foo->sel += page_len;
-               break;
+               tmp = foo->num - foo->start - h;
+               if (tmp <= 0)
+                       return 0;
+               if (page_len >= tmp)
+                       page_len = tmp;
+               foo->start += page_len;
+               if (foo->sel < foo->start)
+                       foo->sel = foo->start;
+               return 1;
        case KEY_PPAGE:
-               foo->sel -= page_len;
-               break;
+               if (page_len >= foo->start)
+                       page_len = foo->start;
+               if (!page_len)
+                       return 0;
+               foo->start -= page_len;
+               tmp = foo->start + h;
+               if (foo->sel >= tmp)
+                       foo->sel = tmp - 1;
+               return 1;
        case KEY_HOME:
+               if (foo->sel <= 0)
+                       return 0;
                foo->sel = 0;
                break;
        case KEY_END:
-               foo->sel = foo->num - 1;
+               tmp = foo->num - 1;
+               if (foo->sel >= tmp)
+                       return 0;
+               foo->sel = tmp;
                break;
        default:
-               break;
+               return 0;
        }
-       if (foo->sel < 0)
-               foo->sel = 0;
-       if (foo->sel >= foo->num)
-               foo->sel = foo->num - 1;
+       list_check_values(foo, h);
 
-       return foo->sel != old_sel;
+       return 1;
 }
 
 void ui_cursor_move(gint x, gint y)
--- src/ui_help.c.orig-0.6.2    2003-09-15 17:51:40 -0400
+++ src/ui_help.c       2004-12-31 21:11:36 -0500
@@ -44,8 +44,8 @@
 const char helptext[] = N_("\
 Welcome to giFTcurs!\n\
 \n\
 Key list:\n\
-{%header:B}up{%prev}/{%header:B}down{%prev}        select item or scroll in a 
list\n\
+{%header:B}up{%prev}/{%header:B}down{%prev}        select item or traverse a 
list\n\
 {%header:B}PgUp{%prev}/{%header:B}PgDown{%prev}    scroll lists one screen at 
a time\n\
 {%header:B}tab{%prev}            move to the next input field\n\
 {%header:B}F1{%prev}             this help screen\n\
@@ -161,7 +161,7 @@ static int help_screen_handler(int key)
        int ret;
 
        help.sel = help.start;
-       ret = ui_list_handler(&help, key, max_y - 3 - show_buttonbar);
+       ret = ui_list_handler(&help, key, 0, max_y - 3 - show_buttonbar);
        help.start = help.sel;
        help_screen_update();
 
--- src/ui_main.c.orig-0.6.2    2003-11-22 07:21:15 -0500
+++ src/ui_main.c       2004-12-31 21:04:45 -0500
@@ -398,7 +398,7 @@
 
        case FIELD_SEARCH_TERM:
                if (!ui_input_handler(&search_input, key))
-                       if (ui_list_handler(&queries, key, 5)) {
+                       if (ui_list_handler(&queries, key, 5, 1)) {
                                q = list_selected(&queries);
 
                                ui_input_assign(&search_input, q->search_term);
@@ -418,8 +418,7 @@
                refresh();
                return 1;
        case FIELD_SEARCH_REALM:
-               if (ui_list_handler(&search_realm, key, 1)) {
+               if (ui_list_handler(&search_realm, key, 1, 1)) {
-                       list_check_values(&search_realm, 1);
                        ui_input_assign(&realm_input, 
list_selected(&search_realm));
                } else if (key == KEY_ENTER && search_input.str->len) {
                        active_field = FIELD_SEARCH_BUTTON;
@@ -483,7 +482,7 @@
 
                        incoming_search_item();
                        g_message(_("Sorting order changed to %s."), method);
-               } else if (ui_list_handler(tree_flat(q), key, RESULT_H)) {
+               } else if (ui_list_handler(tree_flat(q), key, 0, RESULT_H)) {
                        main_screen_update_results();
                } else if (key == 'j' || key == 'J' || key == 'k' || key == 
'K') {
                        if (key == 'j' || key == 'J')
--- src/ui_transfer.c.orig-0.6.2        2003-11-16 11:39:40 -0500
+++ src/ui_transfer.c   2004-12-31 21:00:31 -0500
@@ -349,7 +349,7 @@
                        g_message(_("Transfer sorting order changed to %s."), 
method);
                return 1;
        default:
-               if (ui_list_handler(tree_flat(active_tree), key, height - 2)) {
+               if (ui_list_handler(tree_flat(active_tree), key, 0, height - 
2)) {
                        update_func();
                        refresh();
                        return 1;
--- src/ui_console.c.orig-0.6.2 2003-11-04 18:40:44 -0500
+++ src/ui_console.c    2004-12-31 21:01:38 -0500
@@ -137,7 +137,7 @@
                break;
        default:
                messages.sel = messages.start;
-               ret = ui_list_handler(&messages, key, max_y - 3 - 
show_buttonbar);
+               ret = ui_list_handler(&messages, key, 0, max_y - 3 - 
show_buttonbar);
                messages.start = messages.sel;
                console_screen_update();
                break;
--- src/ui_settings.c.orig-0.6.2        2003-06-30 04:10:57 -0400
+++ src/ui_settings.c   2004-12-31 21:02:37 -0500
@@ -121,14 +121,14 @@
 
        switch (active_field) {
        case FIELD_COLOR_ITEM:
-               if (ui_list_handler(&items, key, LIST_H)) {
+               if (ui_list_handler(&items, key, 0, LIST_H)) {
                        settings_screen_update();
                        refresh();
                        return 1;
                }
                break;
        case FIELD_COLOR_FG:
-               if (ui_list_handler(&fgcolors, key, LIST_H)) {
+               if (ui_list_handler(&fgcolors, key, 0, LIST_H)) {
                        init_pair(items.sel + 1, fgcolors.sel, bgcolors.sel);
                        ui_draw();
                        refresh();
@@ -136,7 +136,7 @@
                }
                break;
        case FIELD_COLOR_BG:
-               if (ui_list_handler(&bgcolors, key, LIST_H)) {
+               if (ui_list_handler(&bgcolors, key, 0, LIST_H)) {
                        init_pair(items.sel + 1, fgcolors.sel, bgcolors.sel);
                        ui_draw();
                        refresh();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]