Merge branch '2212_tree_colors'

* 2212_tree_colors:
  Added title and separate line to the tree selection window.
  Minor changes of tree panel look'n'feel.
  Stop searching mode when tree becomes unfocused.
  Fixed length of current directory selecting line.
  Ticket #2212: fixed WTree widget colors.
This commit is contained in:
Andrew Borodin 2010-05-28 11:32:18 +04:00
commit 0ea12cdec6
2 changed files with 38 additions and 41 deletions

View File

@ -692,10 +692,12 @@ tree_box (const char *current_dir)
/* Create the components */
dlg = create_dlg (0, 0, LINES - 9, COLS - 20, dialog_colors,
tree_callback, "[Directory Tree]", NULL, DLG_CENTER | DLG_REVERSE);
tree_callback, "[Directory Tree]",
_("Directory tree"), DLG_CENTER | DLG_REVERSE);
mytree = tree_new (2, 2, dlg->lines - 6, dlg->cols - 5, FALSE);
add_widget (dlg, mytree);
add_widget (dlg, hline_new (dlg->lines - 4, 1, -1));
bar = buttonbar_new (TRUE);
add_widget (dlg, bar);
/* restore ButtonBar coordinates after add_widget() */

View File

@ -72,6 +72,7 @@
/* Use the color of the parent widget for the unselected entries */
#define TREE_NORMALC(h) (DLG_NORMALC (h))
#define TREE_CURRENTC(h) (DLG_FOCUSC (h))
/* Specifies the display mode: 1d or 2d */
static gboolean tree_navigation_flag = FALSE;
@ -199,23 +200,22 @@ tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols)
else
line = tree_lines + 1;
tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols);
widget_move (&tree->widget, line, 1);
if (tree->searching)
{
/* Show search string */
tty_setcolor (TREE_NORMALC (h));
tty_setcolor (DLG_FOCUSC (h));
tty_setcolor (INPUT_COLOR);
tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols);
widget_move (&tree->widget, line, 1);
tty_print_char (PATH_SEP);
tty_print_string (str_fit_to_term (tree->search_buffer, tree_cols - 2, J_LEFT_FIT));
tty_print_char (' ');
tty_setcolor (DLG_FOCUSC (h));
}
else
{
/* Show full name of selected directory */
tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h));
tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols);
widget_move (&tree->widget, line, 1);
tty_print_string (str_fit_to_term (tree->selected_ptr->name, tree_cols, J_LEFT_FIT));
}
}
@ -226,15 +226,13 @@ show_tree (WTree * tree)
Dlg_head *h = tree->widget.parent;
tree_entry *current;
int i, j, topsublevel;
int x, y;
int x = 0, y = 0;
int tree_lines, tree_cols;
/* Initialize */
x = y = 0;
tree_lines = tlines (tree);
tree_cols = tree->widget.cols;
tty_setcolor (TREE_NORMALC (h));
widget_move ((Widget *) tree, y, x);
if (tree->is_panel)
{
@ -290,33 +288,31 @@ show_tree (WTree * tree)
/* Loop for every line */
for (i = 0; i < tree_lines; i++)
{
tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h));
/* Move to the beginning of the line */
tty_draw_hline (tree->widget.y + y + i, tree->widget.x + x, ' ', tree_cols);
if (!current)
if (current == NULL)
continue;
if (tree->is_panel)
tty_setcolor (tree->active && current == tree->selected_ptr
? SELECTED_COLOR : NORMAL_COLOR);
else
tty_setcolor (current == tree->selected_ptr ? TREE_CURRENTC (h) : TREE_NORMALC (h));
tree->tree_shown[i] = current;
if (current->sublevel == topsublevel)
{
/* Top level directory */
if (tree->active && current == tree->selected_ptr)
{
if (!tty_use_colors () && !tree->is_panel)
tty_setcolor (MARKED_COLOR);
else
tty_setcolor (SELECTED_COLOR);
}
/* Show full name */
tty_print_string (str_fit_to_term (current->name, tree_cols - 6, J_LEFT_FIT));
tty_print_string (str_fit_to_term (current->name, tree_cols + (tree->is_panel ? 0 : 1), J_LEFT_FIT));
}
else
{
/* Sub level directory */
tty_set_alt_charset (TRUE);
/* Output branch parts */
for (j = 0; j < current->sublevel - topsublevel - 1; j++)
{
@ -338,30 +334,16 @@ show_tree (WTree * tree)
tty_print_char (ACS_HLINE);
tty_set_alt_charset (FALSE);
if (tree->active && current == tree->selected_ptr)
{
/* Selected directory -> change color */
if (!tty_use_colors () && !tree->is_panel)
tty_setcolor (MARKED_COLOR);
else
tty_setcolor (SELECTED_COLOR);
}
/* Show sub-name */
tty_print_char (' ');
tty_print_string (str_fit_to_term (current->subname,
tree_cols - 2 - 4 - 3 * j, J_LEFT_FIT));
tty_print_string (str_fit_to_term (current->subname, tree_cols - x - 3 * j, J_LEFT_FIT));
}
tty_print_char (' ');
/* Return to normal color */
tty_setcolor (TREE_NORMALC (h));
/* Calculate the next value for current */
current = current->next;
if (tree_navigation_flag)
{
while (current)
while (current != NULL)
{
if (current->sublevel < tree->selected_ptr->sublevel)
{
@ -371,7 +353,8 @@ show_tree (WTree * tree)
}
else if (current->sublevel == tree->selected_ptr->sublevel)
{
for (j = strlen (current->name) - 1; current->name[j] != PATH_SEP; j--);
for (j = strlen (current->name) - 1; current->name[j] != PATH_SEP; j--)
;
if (strncmp (current->name, tree->selected_ptr->name, j) == 0)
break;
}
@ -386,6 +369,7 @@ show_tree (WTree * tree)
}
}
}
tree_show_mini_info (tree, tree_lines, tree_cols);
}
@ -1053,9 +1037,19 @@ tree_frame (Dlg_head * h, WTree * tree)
widget_erase ((Widget *) tree);
if (tree->is_panel)
{
const char *title = _("Directory tree");
const int len = str_term_width1 (title);
draw_box (h, tree->widget.y, tree->widget.x, tree->widget.lines, tree->widget.cols, FALSE);
widget_move (&tree->widget, 0, (tree->widget.cols - len - 2)/2);
tty_printf (" %s ", title);
if (show_mini_info)
widget_move (&tree->widget, tlines (tree) + 1, 0);
tty_print_alt_char (ACS_LTEE, FALSE);
widget_move (&tree->widget, tlines (tree) + 1, tree->widget.cols - 1);
tty_print_alt_char (ACS_RTEE, FALSE);
tty_draw_hline (tree->widget.y + tlines (tree) + 1,
tree->widget.x + 1, ACS_HLINE, tree->widget.cols - 2);
}
@ -1103,6 +1097,7 @@ tree_callback (Widget * w, widget_msg_t msg, int parm)
case WIDGET_UNFOCUS:
tree->active = 0;
tree->searching = 0;
show_tree (tree);
return MSG_HANDLED;