diff options
| author | Chris Davis <cd.rattan@gmail.com> | 2014-07-26 19:49:33 -0700 |
|---|---|---|
| committer | Michael Adam <obnox@samba.org> | 2014-10-01 14:32:09 +0200 |
| commit | 061d3e9a66f7f71cc6532fa6b0bcf47bf0fe3e35 (patch) | |
| tree | bb7f10d42ec7b650a6ac14e3da54f07a7c09af05 /source3 | |
| parent | a728c391d7d4f6474e37f7118ba6df14dc9da6fd (diff) | |
| download | samba-061d3e9a66f7f71cc6532fa6b0bcf47bf0fe3e35.tar.gz samba-061d3e9a66f7f71cc6532fa6b0bcf47bf0fe3e35.tar.xz samba-061d3e9a66f7f71cc6532fa6b0bcf47bf0fe3e35.zip | |
regedit: move cursor to edited value in list and report edit errors
Signed-off-by: Chris Davis <cd.rattan@gmail.com>
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 | 41 | ||||
| -rw-r--r-- | source3/utils/regedit_dialog.c | 26 | ||||
| -rw-r--r-- | source3/utils/regedit_dialog.h | 7 | ||||
| -rw-r--r-- | source3/utils/regedit_valuelist.c | 22 | ||||
| -rw-r--r-- | source3/utils/regedit_valuelist.h | 4 |
5 files changed, 77 insertions, 23 deletions
diff --git a/source3/utils/regedit.c b/source3/utils/regedit.c index 5b7885ca3e..cc3598b10b 100644 --- a/source3/utils/regedit.c +++ b/source3/utils/regedit.c @@ -406,6 +406,8 @@ static void handle_value_input(struct regedit *regedit, int c) { struct value_item *vitem; bool binmode = false; + WERROR err; + int sel; switch (c) { case KEY_DOWN: @@ -423,26 +425,45 @@ static void handle_value_input(struct regedit *regedit, int c) vitem = value_list_get_current_item(regedit->vl); if (vitem) { struct tree_node *node; + const char *name = NULL; node = tree_view_get_current_node(regedit->keys); - dialog_edit_value(regedit, node->key, vitem->type, - vitem, binmode); - tree_node_reopen_key(node); - value_list_load(regedit->vl, node->key); + sel = dialog_edit_value(regedit, node->key, vitem->type, + vitem, binmode, &err, &name); + if (!W_ERROR_IS_OK(err)) { + const char *msg = get_friendly_werror_msg(err); + dialog_notice(regedit, DIA_ALERT, "Error", + "Error editing value:\n%s", msg); + } else if (sel == DIALOG_OK) { + tree_node_reopen_key(node); + value_list_load(regedit->vl, node->key); + value_list_set_current_item_by_name(regedit->vl, + name); + talloc_free(discard_const(name)); + } } break; case 'n': case 'N': { int new_type; - int sel; sel = dialog_select_type(regedit, &new_type); if (sel == DIALOG_OK) { struct tree_node *node; + const char *name = NULL; node = tree_view_get_current_node(regedit->keys); - dialog_edit_value(regedit, node->key, new_type, NULL, - false); - tree_node_reopen_key(node); - value_list_load(regedit->vl, node->key); + sel = dialog_edit_value(regedit, node->key, new_type, + NULL, false, &err, &name); + if (!W_ERROR_IS_OK(err)) { + const char *msg = get_friendly_werror_msg(err); + dialog_notice(regedit, DIA_ALERT, "Error", + "Error creating value:\n%s", msg); + } else if (sel == DIALOG_OK) { + tree_node_reopen_key(node); + value_list_load(regedit->vl, node->key); + value_list_set_current_item_by_name(regedit->vl, + name); + talloc_free(discard_const(name)); + } } break; } @@ -450,8 +471,6 @@ static void handle_value_input(struct regedit *regedit, int c) case 'D': vitem = value_list_get_current_item(regedit->vl); if (vitem) { - int sel; - sel = dialog_notice(regedit, DIA_CONFIRM, "Delete Value", "Really delete value \"%s\"?", diff --git a/source3/utils/regedit_dialog.c b/source3/utils/regedit_dialog.c index 119219d4a3..3cef7a06d6 100644 --- a/source3/utils/regedit_dialog.c +++ b/source3/utils/regedit_dialog.c @@ -1871,11 +1871,11 @@ static bool edit_on_submit(struct dialog *dia, struct dialog_section *section, } -WERROR dialog_edit_value(TALLOC_CTX *ctx, struct registry_key *key, - uint32_t type, const struct value_item *vitem, - bool force_binary) +int dialog_edit_value(TALLOC_CTX *ctx, struct registry_key *key, + uint32_t type, const struct value_item *vitem, + bool force_binary, WERROR *err, + const char **name) { - WERROR err; enum dialog_action action; struct dialog *dia; struct dialog_section *section; @@ -1947,17 +1947,25 @@ WERROR dialog_edit_value(TALLOC_CTX *ctx, struct registry_key *key, dialog_create(dia); - err = fill_value_buffer(dia, &edit); - if (!W_ERROR_IS_OK(err)) { - return err; + *err = fill_value_buffer(dia, &edit); + if (!W_ERROR_IS_OK(*err)) { + return DIALOG_CANCEL; } dialog_show(dia); - dialog_modal_loop(dia, &err, &action); + dialog_modal_loop(dia, err, &action); + + if (action == DIALOG_OK && name) { + if (vitem) { + *name = talloc_strdup(ctx, vitem->value_name); + } else if ((section = dialog_find_section(dia, "name"))) { + *name = dialog_section_text_field_get(ctx, section); + } + } talloc_free(dia); - return WERR_OK; + return action; } int dialog_select_type(TALLOC_CTX *ctx, int *type) diff --git a/source3/utils/regedit_dialog.h b/source3/utils/regedit_dialog.h index 0018f9fc06..c0d89ff3ec 100644 --- a/source3/utils/regedit_dialog.h +++ b/source3/utils/regedit_dialog.h @@ -213,9 +213,10 @@ int dialog_input(TALLOC_CTX *ctx, const char **output, const char *title, struct registry_key; struct value_item; -WERROR dialog_edit_value(TALLOC_CTX *ctx, struct registry_key *key, - uint32_t type, const struct value_item *vitem, - bool force_binary); +int dialog_edit_value(TALLOC_CTX *ctx, struct registry_key *key, + uint32_t type, const struct value_item *vitem, + bool force_binary, WERROR *err, + const char **name); int dialog_select_type(TALLOC_CTX *ctx, int *type); diff --git a/source3/utils/regedit_valuelist.c b/source3/utils/regedit_valuelist.c index 9557c8ca6a..aa387a740a 100644 --- a/source3/utils/regedit_valuelist.c +++ b/source3/utils/regedit_valuelist.c @@ -392,6 +392,28 @@ struct value_item *value_list_get_current_item(struct value_list *vl) multilist_get_current_row(vl->list)); } +void value_list_set_current_item_by_name(struct value_list *vl, + const char *name) +{ + size_t i; + struct value_item *item = NULL; + + for (i = 0; i < vl->nvalues; ++i) { + if (strequal(vl->values[i].value_name, name)) { + item = &vl->values[i]; + break; + } + } + + multilist_set_current_row(vl->list, item); +} + +void value_list_set_current_item(struct value_list *vl, + const struct value_item *item) +{ + multilist_set_current_row(vl->list, item); +} + void value_list_driver(struct value_list *vl, int c) { multilist_driver(vl->list, c); diff --git a/source3/utils/regedit_valuelist.h b/source3/utils/regedit_valuelist.h index ea67075d14..b84b4ff4e4 100644 --- a/source3/utils/regedit_valuelist.h +++ b/source3/utils/regedit_valuelist.h @@ -52,6 +52,10 @@ WERROR value_list_load(struct value_list *vl, struct registry_key *key); void value_list_resize(struct value_list *vl, int nlines, int ncols, int begin_y, int begin_x); struct value_item *value_list_get_current_item(struct value_list *vl); +void value_list_set_current_item(struct value_list *vl, + const struct value_item *item); +void value_list_set_current_item_by_name(struct value_list *vl, + const char *name); void value_list_driver(struct value_list *vl, int c); #endif |
