comparison finch/libgnt/gnttree.c @ 16249:f02e611bdb6b

Show the search string in the tree.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 18 Apr 2007 22:05:18 +0000
parents 4f6a6443a1e3
children 5187395d6b78
comparison
equal deleted inserted replaced
16247:3fccb0824005 16249:f02e611bdb6b
5 5
6 #include <string.h> 6 #include <string.h>
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #define SEARCH_TIMEOUT 4000 /* 4 secs */ 9 #define SEARCH_TIMEOUT 4000 /* 4 secs */
10 #define SEARCHING(tree) (tree->search && tree->search->len > 0)
10 11
11 enum 12 enum
12 { 13 {
13 SIG_SELECTION_CHANGED, 14 SIG_SELECTION_CHANGED,
14 SIG_SCROLLED, 15 SIG_SCROLLED,
501 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); 502 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
502 503
503 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol, 504 mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol,
504 (row ? ACS_DARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); 505 (row ? ACS_DARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
505 506
507 /* If there's a search-text, show it in the bottom of the tree */
508 if (tree->search && tree->search->len > 0) {
509 const char *str = gnt_util_onscreen_width_to_pointer(tree->search->str, scrcol - 1, NULL);
510 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D));
511 mvwaddnstr(widget->window, widget->priv.height - pos - 1, pos,
512 tree->search->str, str - tree->search->str);
513 }
514
506 gnt_widget_queue_update(widget); 515 gnt_widget_queue_update(widget);
507 } 516 }
508 517
509 static void 518 static void
510 gnt_tree_draw(GntWidget *widget) 519 gnt_tree_draw(GntWidget *widget)
574 static gboolean 583 static gboolean
575 action_move_parent(GntBindable *bind, GList *null) 584 action_move_parent(GntBindable *bind, GList *null)
576 { 585 {
577 GntTree *tree = GNT_TREE(bind); 586 GntTree *tree = GNT_TREE(bind);
578 GntTreeRow *row = tree->current; 587 GntTreeRow *row = tree->current;
579 if (row->parent) { 588 int dist;
580 int dist; 589
581 tree->current = row->parent; 590 if (!row->parent || SEARCHING(tree))
582 if ((dist = get_distance(tree->current, tree->top)) > 0) 591 return FALSE;
583 gnt_tree_scroll(tree, -dist); 592
584 else 593 tree->current = row->parent;
585 redraw_tree(tree); 594 if ((dist = get_distance(tree->current, tree->top)) > 0)
586 tree_selection_changed(tree, row, tree->current); 595 gnt_tree_scroll(tree, -dist);
587 } 596 else
597 redraw_tree(tree);
598 tree_selection_changed(tree, row, tree->current);
588 return TRUE; 599 return TRUE;
589 } 600 }
590 601
591 static gboolean 602 static gboolean
592 action_up(GntBindable *bind, GList *list) 603 action_up(GntBindable *bind, GList *list)
691 702
692 if (text[0] == '\r') { 703 if (text[0] == '\r') {
693 end_search(tree); 704 end_search(tree);
694 gnt_widget_activate(widget); 705 gnt_widget_activate(widget);
695 } else if (tree->search) { 706 } else if (tree->search) {
707 gboolean changed = TRUE;
696 if (isalnum(*text)) { 708 if (isalnum(*text)) {
697 tree->search = g_string_append_c(tree->search, *text); 709 tree->search = g_string_append_c(tree->search, *text);
710 } else if (g_utf8_collate(text, GNT_KEY_BACKSPACE) == 0) {
711 if (tree->search->len)
712 tree->search->str[--tree->search->len] = '\0';
713 } else
714 changed = FALSE;
715 if (changed) {
698 redraw_tree(tree); 716 redraw_tree(tree);
699 g_source_remove(tree->search_timeout); 717 g_source_remove(tree->search_timeout);
700 tree->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree); 718 tree->search_timeout = g_timeout_add(SEARCH_TIMEOUT, search_timeout, tree);
701 } 719 }
702 return TRUE; 720 return TRUE;