Exemplo n.º 1
0
static void handle_value_input(struct regedit *regedit, int c)
{
	struct value_item *vitem;
	bool binmode = false;

	switch (c) {
	case KEY_DOWN:
		menu_driver(regedit->vl->menu, REQ_DOWN_ITEM);
		break;
	case KEY_UP:
		menu_driver(regedit->vl->menu, REQ_UP_ITEM);
		break;
	case 'b':
	case 'B':
		binmode = true;
		/* Falthrough... */
	case '\n':
	case KEY_ENTER:
		vitem = item_userptr(current_item(regedit->vl->menu));
		if (vitem) {
			struct tree_node *node;
			node = item_userptr(current_item(regedit->keys->menu));
			dialog_edit_value(regedit, node->key, vitem->type,
					  vitem, binmode);
			value_list_load(regedit->vl, node->key);
		}
		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;
			node = item_userptr(current_item(regedit->keys->menu));
			dialog_edit_value(regedit, node->key, new_type, NULL,
					  false);
			value_list_load(regedit->vl, node->key);
		}
		break;
	}
	case 'd':
	case 'D':
		vitem = item_userptr(current_item(regedit->vl->menu));
		if (vitem) {
			int sel;

			sel = dialog_notice(regedit, DIA_CONFIRM,
					    "Delete Value",
					     "Really delete value \"%s\"?",
					     vitem->value_name);
			if (sel == DIALOG_OK) {
				ITEM *it = current_item(regedit->keys->menu);
				struct tree_node *node = item_userptr(it);
				reg_del_value(regedit, node->key,
					      vitem->value_name);
				value_list_load(regedit->vl, node->key);
			}
		}
		break;
	}

	value_list_show(regedit->vl);
}
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:
		value_list_driver(regedit->vl, ML_CURSOR_DOWN);
		break;
	case KEY_UP:
		value_list_driver(regedit->vl, ML_CURSOR_UP);
		break;
	case KEY_NPAGE:
		value_list_driver(regedit->vl, ML_CURSOR_PGDN);
		break;
	case KEY_PPAGE:
		value_list_driver(regedit->vl, ML_CURSOR_PGUP);
		break;
	case KEY_HOME:
		value_list_driver(regedit->vl, ML_CURSOR_HOME);
		break;
	case KEY_END:
		value_list_driver(regedit->vl, ML_CURSOR_END);
		break;
	case 'b':
	case 'B':
		binmode = true;
		/* Falthrough... */
	case '\n':
	case KEY_ENTER:
		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);
			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(regedit->registry_context,
						     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;

		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);
			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(regedit->registry_context,
						     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 'd':
	case 'D':
		vitem = value_list_get_current_item(regedit->vl);
		if (vitem) {
			sel = dialog_notice(regedit, DIA_CONFIRM,
					    "Delete Value",
					     "Really delete value \"%s\"?",
					     vitem->value_name);
			if (sel == DIALOG_OK) {
				struct tree_node *node;
				node = tree_view_get_current_node(regedit->keys);
				reg_del_value(regedit, node->key,
					      vitem->value_name);
				tree_node_reopen_key(regedit->registry_context,
						     node);
				value_list_load(regedit->vl, node->key);
			}
		}
		break;
	}

	value_list_show(regedit->vl);
}