static void edit_insert_indent (WEdit * edit, long indent) { if (!option_fill_tabs_with_spaces) while (indent >= TAB_SIZE) { edit_insert (edit, '\t'); indent -= TAB_SIZE; } while (indent-- > 0) edit_insert (edit, ' '); }
/* let the user select its preferred completion */ void editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len, struct selection *compl, int num_compl) { int start_x, start_y, offset, i; char *curr = NULL; Dlg_head *compl_dlg; WListbox *compl_list; int compl_dlg_h; /* completion dialog height */ int compl_dlg_w; /* completion dialog width */ /* calculate the dialog metrics */ compl_dlg_h = num_compl + 2; compl_dlg_w = max_len + 4; start_x = edit->curs_col + edit->start_col - (compl_dlg_w / 2) + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1; if (start_x < 0) start_x = 0; if (compl_dlg_w > COLS) compl_dlg_w = COLS; if (compl_dlg_h > LINES - 2) compl_dlg_h = LINES - 2; offset = start_x + compl_dlg_w - COLS; if (offset > 0) start_x -= offset; offset = start_y + compl_dlg_h - LINES; if (offset > 0) start_y -= (offset + 1); /* create the dialog */ compl_dlg = create_dlg (start_y, start_x, compl_dlg_h, compl_dlg_w, dialog_colors, NULL, "[Completion]", NULL, DLG_COMPACT); /* create the listbox */ compl_list = listbox_new (1, 1, compl_dlg_h - 2, compl_dlg_w - 2, NULL); /* add the dialog */ add_widget (compl_dlg, compl_list); /* fill the listbox with the completions */ for (i = num_compl - 1; i >= 0; i--) /* reverse order */ listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL); /* pop up the dialog and apply the choosen completion */ if (run_dlg (compl_dlg) == B_ENTER) { listbox_get_current (compl_list, &curr, NULL); if (curr) { #ifdef HAVE_CHARSET GString *temp, *temp2; temp = g_string_new(""); for (curr += word_len; *curr; curr++) g_string_append_c(temp, *curr); temp2 = str_convert_to_input (temp->str); if (temp2 && temp2->len){ g_string_free(temp, TRUE); temp = temp2; } else g_string_free(temp2, TRUE); for (curr = temp->str; *curr; curr++) edit_insert (edit, *curr); g_string_free(temp, TRUE); #else for (curr += word_len; *curr; curr++) edit_insert (edit, *curr); #endif } } /* destroy dialog before return */ destroy_dlg (compl_dlg); }