Exemple #1
0
static VALUE rbncurs_c_menu_format(VALUE rb_menu, VALUE rows, VALUE cols)
{
  if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue ||
      rb_obj_is_instance_of(cols, rb_cArray) != Qtrue)
  {
    rb_raise(rb_eArgError, "rows and cols arguments must be empty Arrays");
    return Qnil;
  }
  else
  {
    MENU *menu = get_menu(rb_menu);
    int vals[2] = {0,0};
	
    menu_format(menu, &vals[0], &vals[1]);
    rb_ary_push(rows, INT2NUM(vals[0]));
    rb_ary_push(cols, INT2NUM(vals[1]));
    return Qnil;
  }
}
Exemple #2
0
static void cui_boot_editor_on_exit(struct cui *cui,
		struct pmenu_item *item,
		struct pb_boot_data *bd)
{
	struct pmenu *menu = cui->main;
	struct cui_opt_data *cod;
	int idx, top, rows, cols;
	static int user_idx = 0;

	/* Was the edit cancelled? */
	if (!bd) {
		cui_set_current(cui, &cui->main->scr);
		talloc_free(cui->boot_editor);
		cui->boot_editor = NULL;
		return;
	}

	/* Is this was a new item, we'll need to update the menu */
	if (!item) {
		int insert_pt;

		cod = talloc_zero(NULL, struct cui_opt_data);
		cod->name = talloc_asprintf(cod, _("User item %u"), ++user_idx);

		item = pmenu_item_create(menu, cod->name);
		if (!item) {
			talloc_free(cod);
			goto out;
		}

		item->on_edit = cui_item_edit;
		item->on_execute = cui_boot;
		item->data = cod;

		talloc_steal(item, cod);

		/* Detach the items array. */
		set_menu_items(menu->ncm, NULL);

		/* Insert new item at insert_pt. */
		insert_pt = pmenu_grow(menu, 1);
		pmenu_item_insert(menu, item, insert_pt);

		/* Re-attach the items array. */
		set_menu_items(menu->ncm, menu->items);

		/* If our index is above the current top row, align
		 * us to the new top. Otherwise, align us to the new
		 * bottom */
		menu_format(cui->main->ncm, &rows, &cols);
		top = top_row(cui->main->ncm);
		idx = item_index(item->nci);

		if (top >= idx)
			top = idx;
		else
			top = idx < rows ? 0 : idx - rows + 1;

		set_top_row(cui->main->ncm, top);
		set_current_item(item->pmenu->ncm, item->nci);

		nc_scr_post(&menu->scr);
	} else {