diff options
author | C. Davis <cd.rattan@gmail.com> | 2012-08-09 18:14:42 -0700 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2013-04-29 13:06:17 +0200 |
commit | 3344f5e3d568d607bdf354ed74dc473a612fbf9d (patch) | |
tree | ab1e6c241238e7089aa75d63c35dbb5eab6e5e8e /source3 | |
parent | 6ef5ee250c3b906d56413b213e1f18fe1ff3579f (diff) | |
download | samba-3344f5e3d568d607bdf354ed74dc473a612fbf9d.tar.gz samba-3344f5e3d568d607bdf354ed74dc473a612fbf9d.tar.xz samba-3344f5e3d568d607bdf354ed74dc473a612fbf9d.zip |
regedit: Delete and add keys.
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3')
-rw-r--r-- | source3/utils/regedit.c | 62 | ||||
-rw-r--r-- | source3/utils/regedit_treeview.c | 46 | ||||
-rw-r--r-- | source3/utils/regedit_treeview.h | 4 |
3 files changed, 99 insertions, 13 deletions
diff --git a/source3/utils/regedit.c b/source3/utils/regedit.c index 7db0cbfe17b..3f476e720be 100644 --- a/source3/utils/regedit.c +++ b/source3/utils/regedit.c @@ -137,18 +137,76 @@ static void handle_tree_input(struct regedit *regedit, int c) value_list_load(regedit->vl, node->key); } break; + case 'n': + case 'N': { + char *name; + + node = item_userptr(current_item(regedit->keys->menu)); + if (!node->parent) { + break; + } + dialog_input(regedit, &name, "New Key", regedit->main_window, + "Enter name of new key"); + if (name) { + WERROR rv; + struct registry_key *new_key; + struct tree_node *new_node; + struct tree_node *list = tree_node_first(node); + + rv = reg_key_add_name(regedit, node->parent->key, name, + NULL, NULL, &new_key); + if (W_ERROR_IS_OK(rv)) { + new_node = tree_node_new(node->parent, + node->parent, + name, new_key); + SMB_ASSERT(new_node); + tree_node_append_last(list, new_node); + tree_view_clear(regedit->keys); + tree_view_update(regedit->keys, list); + } else { + dialog_notice(regedit, DIA_ALERT, "New Key", + regedit->main_window, + "Failed to create key."); + } + talloc_free(name); + } + break; + } case 'd': case 'D': { int sel; node = item_userptr(current_item(regedit->keys->menu)); + if (!node->parent) { + break; + } sel = dialog_notice(regedit, DIA_CONFIRM, "Delete Key", regedit->main_window, "Really delete key \"%s\"?", node->name); - mvwprintw(regedit->main_window, 1, 0, "Sel: %d", sel); - /* TODO */ + if (sel == DIALOG_OK) { + WERROR rv; + struct tree_node *pop; + struct tree_node *parent = node->parent; + + rv = reg_key_del(node, parent->key, node->name); + if (W_ERROR_IS_OK(rv)) { + tree_view_clear(regedit->keys); + pop = tree_node_pop(&node); + tree_node_free_recursive(pop); + node = parent->child_head; + if (node == NULL) { + node = tree_node_first(parent); + } + tree_view_update(regedit->keys, node); + value_list_load(regedit->vl, node->key); + } else { + dialog_notice(regedit, DIA_ALERT, "Delete Key", + regedit->main_window, + "Failed to delete key."); + } + } break; } } diff --git a/source3/utils/regedit_treeview.c b/source3/utils/regedit_treeview.c index 1135ebc424b..fb6247faacf 100644 --- a/source3/utils/regedit_treeview.c +++ b/source3/utils/regedit_treeview.c @@ -59,6 +59,11 @@ void tree_node_append(struct tree_node *left, struct tree_node *right) right->previous = left; } +void tree_node_append_last(struct tree_node *list, struct tree_node *node) +{ + tree_node_append(tree_node_last(list), node); +} + struct tree_node *tree_node_pop(struct tree_node **plist) { struct tree_node *node; @@ -78,7 +83,9 @@ struct tree_node *tree_node_pop(struct tree_node **plist) if (node->next) { node->next->previous = node->previous; } - + if (node->parent && node->parent->child_head == node) { + node->parent->child_head = node->next; + } node->next = NULL; node->previous = NULL; @@ -99,6 +106,15 @@ struct tree_node *tree_node_first(struct tree_node *list) return list; } +struct tree_node *tree_node_last(struct tree_node *list) +{ + while (list && list->next) { + list = list->next; + } + + return list; +} + bool tree_node_has_children(struct tree_node *node) { const char *classname; @@ -210,6 +226,14 @@ static void tree_view_free_current_items(ITEM **items) talloc_free(items); } +void tree_view_clear(struct tree_view *view) +{ + unpost_menu(view->menu); + set_menu_items(view->menu, view->empty); + tree_view_free_current_items(view->current_items); + view->current_items = NULL; +} + WERROR tree_view_update(struct tree_view *view, struct tree_node *list) { ITEM **items; @@ -270,6 +294,9 @@ static int tree_view_free(struct tree_view *view) unpost_menu(view->menu); free_menu(view->menu); } + if (view->empty[0]) { + free_item(view->empty[0]); + } tree_view_free_current_items(view->current_items); tree_node_free_recursive(view->root); @@ -281,7 +308,7 @@ struct tree_view *tree_view_new(TALLOC_CTX *ctx, struct tree_node *root, int begin_y, int begin_x) { struct tree_view *view; - static const char *dummy = "1234"; + static const char *dummy = "(empty)"; view = talloc_zero(ctx, struct tree_view); if (view == NULL) { @@ -290,21 +317,18 @@ struct tree_view *tree_view_new(TALLOC_CTX *ctx, struct tree_node *root, talloc_set_destructor(view, tree_view_free); - view->current_items = talloc_zero_array(ctx, ITEM *, 2); - if (view->current_items == NULL) { + view->empty[0] = new_item(dummy, dummy); + if (view->empty[0] == NULL) { goto fail; } - - view->current_items[0] = new_item(dummy, dummy); - if (view->current_items[0] == NULL) { - goto fail; - } - view->window = orig; view->sub_window = derwin(orig, nlines, ncols, begin_y, begin_x); + if (view->sub_window == NULL) { + goto fail; + } view->root = root; - view->menu = new_menu(view->current_items); + view->menu = new_menu(view->empty); if (view->menu == NULL) { goto fail; } diff --git a/source3/utils/regedit_treeview.h b/source3/utils/regedit_treeview.h index 5be542514a1..52b64da5f80 100644 --- a/source3/utils/regedit_treeview.h +++ b/source3/utils/regedit_treeview.h @@ -45,6 +45,7 @@ struct tree_view { WINDOW *sub_window; MENU *menu; ITEM **current_items; + ITEM *empty[2]; }; struct tree_node *tree_node_new(TALLOC_CTX *ctx, struct tree_node *parent, @@ -52,12 +53,15 @@ struct tree_node *tree_node_new(TALLOC_CTX *ctx, struct tree_node *parent, void tree_node_append(struct tree_node *left, struct tree_node *right); struct tree_node *tree_node_pop(struct tree_node **plist); 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); struct tree_view *tree_view_new(TALLOC_CTX *ctx, struct tree_node *root, WINDOW *orig, int nlines, int ncols, int begin_y, int begin_x); void tree_view_show(struct tree_view *view); +void tree_view_clear(struct tree_view *view); WERROR tree_view_update(struct tree_view *view, struct tree_node *list); bool tree_node_has_children(struct tree_node *node); WERROR tree_node_load_children(struct tree_node *node); |