etags: get rid of limitation of window width.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-03-06 14:23:47 +03:00
parent 451e1585a7
commit 9c7437bf48
4 changed files with 29 additions and 22 deletions

View File

@ -3591,7 +3591,7 @@ edit_load_back_cmd (WEdit * edit)
void void
edit_get_match_keyword_cmd (WEdit * edit) edit_get_match_keyword_cmd (WEdit * edit)
{ {
gsize word_len = 0, max_len = 0; gsize word_len = 0;
gsize i; gsize i;
off_t word_start = 0; off_t word_start = 0;
GString *match_expr; GString *match_expr;
@ -3633,12 +3633,9 @@ edit_get_match_keyword_cmd (WEdit * edit)
} }
g_free (path); g_free (path);
max_len = MAX_WIDTH_DEF_DIALOG;
word_len = 0;
if (def_hash != NULL) if (def_hash != NULL)
{ {
editcmd_dialog_select_definition_show (edit, match_expr->str, max_len, word_len, def_hash); editcmd_dialog_select_definition_show (edit, match_expr->str, def_hash);
g_ptr_array_free (def_hash, TRUE); g_ptr_array_free (def_hash, TRUE);
} }

View File

@ -64,6 +64,9 @@ edit_search_options_t edit_search_options = {
/*** file scope variables ************************************************************************/ /*** file scope variables ************************************************************************/
static int def_max_width;
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/ /*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -92,12 +95,15 @@ editcmd_dialog_select_definition_add (gpointer data, gpointer user_data)
etags_hash_t *def_hash = (etags_hash_t *) data; etags_hash_t *def_hash = (etags_hash_t *) data;
WListbox *def_list = (WListbox *) user_data; WListbox *def_list = (WListbox *) user_data;
char *label_def; char *label_def;
int def_width;
label_def = label_def =
g_strdup_printf ("%s -> %s:%ld", def_hash->short_define, def_hash->filename, g_strdup_printf ("%s -> %s:%ld", def_hash->short_define, def_hash->filename,
def_hash->line); def_hash->line);
listbox_add_item (def_list, LISTBOX_APPEND_AT_END, 0, label_def, def_hash, FALSE); listbox_add_item (def_list, LISTBOX_APPEND_AT_END, 0, label_def, def_hash, FALSE);
def_width = str_term_width1 (label_def);
g_free (label_def); g_free (label_def);
def_max_width = MAX (def_max_width, def_width);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -427,9 +433,9 @@ editcmd_dialog_completion_show (const WEdit * edit, GQueue * compl, int max_widt
/* let the user select where function definition */ /* let the user select where function definition */
void void
editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_len, int word_len, editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, GPtrArray * def_hash)
GPtrArray * def_hash)
{ {
const Widget *we = CONST_WIDGET (edit);
int start_x, start_y, offset; int start_x, start_y, offset;
char *curr = NULL; char *curr = NULL;
WDialog *def_dlg; WDialog *def_dlg;
@ -437,24 +443,21 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
int def_dlg_h; /* dialog height */ int def_dlg_h; /* dialog height */
int def_dlg_w; /* dialog width */ int def_dlg_w; /* dialog width */
(void) word_len;
/* calculate the dialog metrics */ /* calculate the dialog metrics */
def_dlg_h = def_hash->len + 2; def_dlg_h = def_hash->len + 2;
def_dlg_w = max_len + 4; def_dlg_w = COLS - 2; /* will be clarified later */
start_x = edit->curs_col + edit->start_col - (def_dlg_w / 2) + start_x = we->x + edit->curs_col + edit->start_col + EDIT_TEXT_HORIZONTAL_OFFSET +
EDIT_TEXT_HORIZONTAL_OFFSET + (edit->fullscreen ? 0 : 1) + option_line_state_width; (edit->fullscreen ? 0 : 1) + option_line_state_width;
start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + (edit->fullscreen ? 0 : 1) + 1; start_y = we->y + edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + (edit->fullscreen ? 0 : 1) + 1;
if (start_x < 0) if (start_x < 0)
start_x = 0; start_x = 0;
if (def_dlg_w > COLS) if (start_x < we->x + 1)
def_dlg_w = COLS; start_x = we->x + 1 + option_line_state_width;
if (def_dlg_h > LINES - 2) if (def_dlg_h > LINES - 2)
def_dlg_h = LINES - 2; def_dlg_h = LINES - 2;
offset = start_x + def_dlg_w - COLS;
if (offset > 0)
start_x -= offset;
offset = start_y + def_dlg_h - LINES; offset = start_y + def_dlg_h - LINES;
if (offset > 0) if (offset > 0)
start_y -= (offset + 1); start_y -= (offset + 1);
@ -462,11 +465,20 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
def_dlg = dlg_create (TRUE, start_y, start_x, def_dlg_h, def_dlg_w, WPOS_KEEP_DEFAULT, TRUE, def_dlg = dlg_create (TRUE, start_y, start_x, def_dlg_h, def_dlg_w, WPOS_KEEP_DEFAULT, TRUE,
dialog_colors, NULL, NULL, "[Definitions]", match_expr); dialog_colors, NULL, NULL, "[Definitions]", match_expr);
def_list = listbox_new (1, 1, def_dlg_h - 2, def_dlg_w - 2, FALSE, NULL); def_list = listbox_new (1, 1, def_dlg_h - 2, def_dlg_w - 2, FALSE, NULL);
group_add_widget (GROUP (def_dlg), def_list); group_add_widget_autopos (GROUP (def_dlg), def_list, WPOS_KEEP_ALL, NULL);
/* fill the listbox with the completions */ /* fill the listbox with the completions and get the maximim width */
def_max_width = 0;
g_ptr_array_foreach (def_hash, editcmd_dialog_select_definition_add, def_list); g_ptr_array_foreach (def_hash, editcmd_dialog_select_definition_add, def_list);
/* adjust dialog width */
def_dlg_w = def_max_width + 4;
offset = start_x + def_dlg_w - COLS;
if (offset > 0)
start_x -= offset;
widget_set_size (WIDGET (def_dlg), start_y, start_x, def_dlg_h, def_dlg_w);
/* pop up the dialog and apply the chosen completion */ /* pop up the dialog and apply the chosen completion */
if (dlg_run (def_dlg) == B_ENTER) if (dlg_run (def_dlg) == B_ENTER)
{ {

View File

@ -27,7 +27,7 @@ int editcmd_dialog_raw_key_query (const char *heading, const char *query, gboole
char *editcmd_dialog_completion_show (const WEdit * edit, GQueue * compl, int max_width); char *editcmd_dialog_completion_show (const WEdit * edit, GQueue * compl, int max_width);
void editcmd_dialog_select_definition_show (WEdit *, char *, int, int, GPtrArray *); void editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, GPtrArray * def_hash);
int editcmd_dialog_replace_prompt_show (WEdit *, char *, char *, int, int); int editcmd_dialog_replace_prompt_show (WEdit *, char *, char *, int, int);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

View File

@ -3,8 +3,6 @@
/*** typedefs(not structures) and defined constants **********************************************/ /*** typedefs(not structures) and defined constants **********************************************/
#define MAX_WIDTH_DEF_DIALOG 60 /* max width def dialog */
/*** enums ***************************************************************************************/ /*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/ /*** structures declarations (and typedefs of structures)*****************************************/