mirror of
https://github.com/samba-team/samba.git
synced 2025-02-22 05:57:43 +03:00
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>
This commit is contained in:
parent
a728c391d7
commit
061d3e9a66
@ -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\"?",
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user