Browse Source

Dynamic view. Thanks to aa.atnet.

Serj Kalichev 11 years ago
parent
commit
80d2d0ea50

+ 3 - 3
clish/command.h

@@ -53,7 +53,7 @@ const char *clish_command__get_escape_chars(const clish_command_t * instance);
 const char *clish_command__get_regex_chars(const clish_command_t * instance);
 const clish_param_t *clish_command__get_args(const clish_command_t * instance);
 clish_action_t *clish_command__get_action(const clish_command_t *instance);
-clish_view_t *clish_command__get_view(const clish_command_t * instance);
+char *clish_command__get_viewname(const clish_command_t * instance);
 char *clish_command__get_viewid(const clish_command_t *instance);
 unsigned int clish_command__get_param_count(const clish_command_t * instance);
 const clish_param_t *clish_command__get_param(const clish_command_t * instance,
@@ -65,8 +65,8 @@ void clish_command__set_regex_chars(clish_command_t * instance,
 	const char *escape_chars);
 void clish_command__set_args(clish_command_t * instance, clish_param_t * args);
 void clish_command__set_detail(clish_command_t * instance, const char *detail);
-void clish_command__set_view(clish_command_t * instance, clish_view_t * view);
-void clish_command__force_view(clish_command_t * instance, clish_view_t * view);
+void clish_command__set_viewname(clish_command_t * instance, const char *viewname);
+void clish_command__force_viewname(clish_command_t * instance, const char *viewname);
 void clish_command__set_viewid(clish_command_t * instance, const char *viewid);
 void clish_command__force_viewid(clish_command_t * instance, const char *viewid);
 void clish_command__set_pview(clish_command_t * instance, clish_view_t * view);

+ 8 - 8
clish/command/command.c

@@ -32,7 +32,7 @@ clish_command_init(clish_command_t *this, const char *name, const char *text)
 	this->alias_view = NULL;
 	this->paramv = clish_paramv_new();
 	this->viewid = NULL;
-	this->view = NULL;
+	this->viewname = NULL;
 	this->action = clish_action_new();
 	this->config = clish_config_new();
 	this->detail = NULL;
@@ -250,22 +250,22 @@ clish_config_t *clish_command__get_config(const clish_command_t *this)
 }
 
 /*--------------------------------------------------------- */
-void clish_command__set_view(clish_command_t * this, clish_view_t * view)
+void clish_command__set_viewname(clish_command_t * this, const char *viewname)
 {
-	assert(NULL == this->view);
-	clish_command__force_view(this, view);
+	assert(NULL == this->viewname);
+	clish_command__force_viewname(this, viewname);
 }
 
 /*--------------------------------------------------------- */
-void clish_command__force_view(clish_command_t * this, clish_view_t * view)
+void clish_command__force_viewname(clish_command_t * this, const char *viewname)
 {
-	this->view = view;
+	this->viewname = lub_string_dup(viewname);
 }
 
 /*--------------------------------------------------------- */
-clish_view_t *clish_command__get_view(const clish_command_t * this)
+char *clish_command__get_viewname(const clish_command_t * this)
 {
-	return this->view;
+	return this->viewname;
 }
 
 /*--------------------------------------------------------- */

+ 1 - 1
clish/command/private.h

@@ -14,7 +14,7 @@ struct clish_command_s {
 	clish_paramv_t *paramv;
 	clish_action_t *action;
 	clish_config_t *config;
-	clish_view_t *view;
+	char *viewname;
 	char *viewid;
 	char *detail;
 	char *escape_chars;

+ 11 - 7
clish/shell/shell_execute.c

@@ -166,13 +166,17 @@ int clish_shell_execute(clish_context_t *context, char **out)
 
 	/* Move into the new view */
 	if (!result) {
-		clish_view_t *view = clish_command__get_view(cmd);
-		/* Save the PWD */
-		if (view) {
-			char *line = clish_shell__get_line(context);
-			clish_shell__set_pwd(this, line, view,
-				clish_command__get_viewid(cmd), context);
-			lub_string_free(line);
+		const char *viewname = clish_shell_expand(clish_command__get_viewname(cmd), SHELL_VAR_NONE, context);
+		if (viewname) {
+			/* Search for the view */
+			clish_view_t *view = clish_shell_find_create_view(this, viewname, NULL);
+			/* Save the PWD */
+			if (view) {
+				char *line = clish_shell__get_line(context);
+				clish_shell__set_pwd(this, line, view,
+					clish_command__get_viewid(cmd), context);
+				lub_string_free(line);
+			}
 		}
 	}
 

+ 1 - 3
clish/shell/shell_startup.c

@@ -47,9 +47,7 @@ void clish_shell__set_startup_view(clish_shell_t * this, const char * viewname)
 
 	assert(this);
 	assert(this->startup);
-	/* Search for the view */
-	view = clish_shell_find_create_view(this, viewname, NULL);
-	clish_command__force_view(this->startup, view);
+	clish_command__force_viewname(this->startup, viewname);
 }
 
 /*----------------------------------------------------------- */

+ 2 - 7
clish/shell/shell_xml.c

@@ -508,11 +508,8 @@ process_command(clish_shell_t * shell, clish_xmlnode_t * element, void *parent)
 
 	/* define the view which this command changes to */
 	if (view) {
-		clish_view_t *next = clish_shell_find_create_view(shell, view,
-			NULL);
-
 		/* reference the next view */
-		clish_command__set_view(cmd, next);
+		clish_command__set_viewname(cmd, view);
 	}
 
 	/* define the view id which this command changes to */
@@ -599,10 +596,8 @@ process_startup(clish_shell_t * shell, clish_xmlnode_t * element, void *parent)
 	cmd = clish_view_new_command(v, "startup", NULL);
 	clish_command__set_lock(cmd, BOOL_FALSE);
 
-	/* define the view which this command changes to */
-	clish_view_t *next = clish_shell_find_create_view(shell, view, NULL);
 	/* reference the next view */
-	clish_command__set_view(cmd, next);
+	clish_command__set_viewname(cmd, view);
 
 	/* define the view id which this command changes to */
 	if (viewid)

+ 1 - 1
clish/view/view.c

@@ -198,7 +198,7 @@ clish_command_t *clish_view_resolve_command(clish_view_t *this,
 			(!clish_action__get_builtin(action)) &&
 			(CLISH_CONFIG_NONE == clish_config__get_op(config)) &&
 			(!clish_command__get_param_count(result)) &&
-			(!clish_command__get_view(result))) {
+			(!clish_command__get_viewname(result))) {
 			/* if this doesn't do anything we've
 			 * not resolved a command
 			 */