Browse Source

New function clish_view_remove_command

Allows removal of commands inserted using clish_view_insert_command.

Commands are being disowned from the view, so the client may delete them.
Ingo Albrecht 7 years ago
parent
commit
1e3141027f
2 changed files with 13 additions and 0 deletions
  1. 2 0
      clish/view.h
  2. 11 0
      clish/view/view.c

+ 2 - 0
clish/view.h

@@ -37,6 +37,8 @@ clish_command_t *clish_view_new_command(clish_view_t * instance,
 	const char *name, const char *text);
 bool_t clish_view_insert_command(clish_view_t * instance,
 	clish_command_t *cmd);
+bool_t clish_view_remove_command(clish_view_t * instance,
+	clish_command_t *cmd);
 clish_command_t *clish_view_find_command(clish_view_t * instance,
 	const char *name, bool_t inherit);
 const clish_command_t *clish_view_find_next_completion(clish_view_t * instance,

+ 11 - 0
clish/view/view.c

@@ -129,6 +129,17 @@ bool_t clish_view_insert_command(clish_view_t * this,
 	return BOOL_TRUE;
 }
 
+/*--------------------------------------------------------- */
+bool_t clish_view_remove_command(clish_view_t * this,
+	clish_command_t *cmd)
+{
+	void *found = lub_bintree_find(&this->tree, cmd);
+	/* remove the command from the tree */
+	lub_bintree_remove(&this->tree, cmd);
+	/* return true if found */
+	return found ? BOOL_TRUE : BOOL_FALSE;
+}
+
 /*--------------------------------------------------------- */
 /* This method identifies the command (if any) which provides
  * the longest match with the specified line of text.