[powerdebug,13/17] add a select callback on a clock from the search result

Message ID 1308610705-23281-13-git-send-email-daniel.lezcano@linaro.org
State Accepted
Headers show

Commit Message

Daniel Lezcano June 20, 2011, 10:58 p.m.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 clocks.c  |   28 +++++++++++++++++++++-------
 display.c |   11 ++++++++---
 display.h |    1 +
 3 files changed, 30 insertions(+), 10 deletions(-)

Patch

diff --git a/clocks.c b/clocks.c
index 2ae2f5a..6943b70 100644
--- a/clocks.c
+++ b/clocks.c
@@ -243,6 +243,10 @@  static int _clock_print_info_cb(struct tree *t, void *data)
 	int *line = data;
 	char *buffer;
 
+        /* we skip the root node of the tree */
+	if (!t->parent)
+		return 0;
+
 	buffer = clock_line(t);
 	if (!buffer)
 		return -1;
@@ -258,10 +262,6 @@  static int _clock_print_info_cb(struct tree *t, void *data)
 
 static int clock_print_info_cb(struct tree *t, void *data)
 {
-        /* we skip the root node of the tree */
-	if (!t->parent)
-		return 0;
-
         /* show the clock when *all* its parent is expanded */
 	if (tree_for_each_parent(t->parent, is_collapsed, NULL))
 		return 0;
@@ -300,7 +300,7 @@  static int clock_print_info(struct tree *tree)
 	return ret;
 }
 
-static int clock_toggle_expanded(void)
+static int clock_select(void)
 {
 	struct tree *t = display_get_row_data(CLOCK);
 	struct clock_info *clk = t->private;
@@ -323,7 +323,7 @@  static int clock_display(void)
 	return clock_print_info(clock_tree);
 }
 
-int clock_find(const char *name)
+static int clock_find(const char *name)
 {
 	struct tree **ptree = NULL;
 	int i, nr, line = 0, ret = 0;
@@ -350,6 +350,19 @@  int clock_find(const char *name)
 	return ret;
 }
 
+static int clock_selectf(void)
+{
+	struct tree *t = display_get_row_data(CLOCK);
+	int line = 0;
+
+	display_reset_cursor(CLOCK);
+
+	if (tree_for_each_parent(t, _clock_print_info_cb, &line))
+		return -1;
+
+	return display_refresh_pad(CLOCK);
+}
+
 /*
  * Read the clock information and fill the tree with the information
  * found in the files. Then dump to stdout a formatted result.
@@ -379,8 +392,9 @@  int clock_dump(char *clk)
 
 static struct display_ops clock_ops = {
 	.display = clock_display,
-	.select  = clock_toggle_expanded,
+	.select  = clock_select,
 	.find    = clock_find,
+	.selectf = clock_selectf,
 };
 
 /*
diff --git a/display.c b/display.c
index 1dc11dd..38596b0 100644
--- a/display.c
+++ b/display.c
@@ -447,9 +447,14 @@  static int display_find_keystroke(int fd, void *data)
 			string[strlen(string) - 1] = '\0';
 		break;
 
-	case KEY_ENTER:
-		/* next patch */
-		break;
+	case '\r':
+		if (!windata[current_win].ops || !windata[current_win].ops->selectf)
+			return 0;
+
+		if (windata[current_win].ops->selectf())
+			return -1;
+
+		return 0;
 
 	default:
 
diff --git a/display.h b/display.h
index fe084cb..7fa5361 100644
--- a/display.h
+++ b/display.h
@@ -19,6 +19,7 @@  struct display_ops {
 	int (*display)(void);
 	int (*select)(void);
 	int (*find)(const char *);
+	int (*selectf)(void);
 };
 
 extern int display_print_line(int window, int line, char *str,