From dc119eb9b2881c0f3cf92a0c77fe71411a6a1a13 Mon Sep 17 00:00:00 2001 From: "C. Davis" Date: Sat, 11 Aug 2012 23:22:06 -0700 Subject: [PATCH] regedit: Cut off the front of the path when screen width is too small. Reviewed-by: Andreas Schneider Reviewed-by: Michael Adam --- source3/utils/regedit.c | 16 +++++++++++++--- source3/utils/regedit_treeview.c | 15 ++++++++++----- source3/utils/regedit_treeview.h | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/source3/utils/regedit.c b/source3/utils/regedit.c index 51528a8d117..efea07b89c7 100644 --- a/source3/utils/regedit.c +++ b/source3/utils/regedit.c @@ -42,12 +42,14 @@ #define INFO_WIDTH (LINES) #define PATH_START_Y 0 #define PATH_START_X 6 -#define PATH_MAX_Y (COLS-1) +#define PATH_MAX_Y (COLS - 1) +#define PATH_WIDTH (COLS - 6) #define PATH_WIDTH_MAX 1024 struct regedit { WINDOW *main_window; WINDOW *path_label; + size_t path_len; struct value_list *vl; struct tree_view *keys; bool tree_input; @@ -57,13 +59,21 @@ static struct regedit *regedit_main = NULL; static void show_path(struct regedit *regedit) { - prefresh(regedit->path_label, 0, 0, PATH_START_Y, PATH_START_X, + int start_pad = 0; + int start_win = PATH_START_X; + + if (PATH_START_X + regedit->path_len > COLS) { + start_pad = 3 + PATH_START_X + regedit->path_len - COLS; + mvprintw(PATH_START_Y, start_win, "..."); + start_win += 3; + } + prefresh(regedit->path_label, 0, start_pad, PATH_START_Y, start_win, PATH_START_Y, PATH_MAX_Y); } static void print_path(struct regedit *regedit, struct tree_node *node) { - tree_node_print_path(regedit->path_label, node); + regedit->path_len = tree_node_print_path(regedit->path_label, node); } /* load all available hives */ diff --git a/source3/utils/regedit_treeview.c b/source3/utils/regedit_treeview.c index d19866e684c..f0c3bd81f82 100644 --- a/source3/utils/regedit_treeview.c +++ b/source3/utils/regedit_treeview.c @@ -371,23 +371,28 @@ void tree_view_resize(struct tree_view *view, int nlines, int ncols, post_menu(view->menu); } -static void print_path_recursive(WINDOW *label, struct tree_node *node) +static void print_path_recursive(WINDOW *label, struct tree_node *node, size_t *len) { if (node->parent) - print_path_recursive(label, node->parent); + print_path_recursive(label, node->parent, len); wprintw(label, "%s/", node->name); + *len += 1 + strlen(node->name); } /* print the path of node to label */ -void tree_node_print_path(WINDOW *label, struct tree_node *node) +size_t tree_node_print_path(WINDOW *label, struct tree_node *node) { + size_t len = 1; + if (node == NULL) - return; + return 0; werase(label); wprintw(label, "/"); if (node->parent) - print_path_recursive(label, node->parent); + print_path_recursive(label, node->parent, &len); + + return len; } diff --git a/source3/utils/regedit_treeview.h b/source3/utils/regedit_treeview.h index 3008372452c..39314418c6b 100644 --- a/source3/utils/regedit_treeview.h +++ b/source3/utils/regedit_treeview.h @@ -57,7 +57,7 @@ struct tree_node *tree_node_first(struct tree_node *list); struct tree_node *tree_node_last(struct tree_node *list); void tree_node_append_last(struct tree_node *list, struct tree_node *node); void tree_node_free_recursive(struct tree_node *list); -void tree_node_print_path(WINDOW *label, struct tree_node *node); +size_t tree_node_print_path(WINDOW *label, struct tree_node *node); struct tree_view *tree_view_new(TALLOC_CTX *ctx, struct tree_node *root, int nlines, int ncols, int begin_y, int begin_x); -- 2.11.4.GIT