Ticket #3530: viewer: highlight Find File's result.

Initial commit: (WLEntry): add free_data member to free or keep the data
on entry's removal.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Egmont Koblinger 2015-10-04 15:14:16 +03:00 committed by Yury V. Zaytsev
parent 2cee5e50c3
commit 7e622158a2
18 changed files with 54 additions and 41 deletions

View File

@ -250,7 +250,8 @@ dialog_switch_list (void)
else
title = g_strdup ("");
listbox_add_item (listbox->list, LISTBOX_APPEND_BEFORE, get_hotkey (i++), title, NULL);
listbox_add_item (listbox->list, LISTBOX_APPEND_BEFORE, get_hotkey (i++), title, NULL,
FALSE);
g_free (title);
}

View File

@ -1251,7 +1251,7 @@ complete_engine (WInput * in, int what_to_do)
query_list = listbox_new (1, 1, h - 2, w - 2, FALSE, NULL);
add_widget (query_dlg, query_list);
for (p = in->completions + 1; *p; p++)
listbox_add_item (query_list, LISTBOX_APPEND_AT_END, 0, *p, NULL);
listbox_add_item (query_list, LISTBOX_APPEND_AT_END, 0, *p, NULL, FALSE);
dlg_run (query_dlg);
q = NULL;
if (query_dlg->ret_value == B_ENTER)

View File

@ -7,8 +7,8 @@
/*** typedefs(not structures) and defined constants **********************************************/
#define LISTBOX_APPEND_TEXT(l,h,t,d) \
listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)
#define LISTBOX_APPEND_TEXT(l,h,t,d,f) \
listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d, f)
/*** enums ***************************************************************************************/

View File

@ -75,7 +75,10 @@ static void
listbox_entry_free (void *data)
{
WLEntry *e = data;
g_free (e->text);
if (e->free_data)
g_free (e->data);
g_free (e);
}
@ -770,7 +773,8 @@ listbox_remove_list (WListbox * l)
/* --------------------------------------------------------------------------------------------- */
char *
listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *text, void *data)
listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *text, void *data,
gboolean free_data)
{
WLEntry *entry;
@ -783,6 +787,7 @@ listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *te
entry = g_new (WLEntry, 1);
entry->text = g_strdup (text);
entry->data = data;
entry->free_data = free_data;
entry->hotkey = hotkey;
listbox_append_item (l, entry, pos);

View File

@ -40,6 +40,7 @@ typedef struct WLEntry
char *text; /* Text to display */
int hotkey;
void *data; /* Client information */
gboolean free_data; /* Whether to free the data on entry's removal */
} WLEntry;
typedef struct WListbox
@ -73,8 +74,8 @@ void listbox_remove_current (WListbox * l);
gboolean listbox_is_empty (const WListbox * l);
void listbox_set_list (WListbox * l, GList * list);
void listbox_remove_list (WListbox * l);
char *listbox_add_item (WListbox * l, listbox_append_t pos,
int hotkey, const char *text, void *data);
char *listbox_add_item (WListbox * l, listbox_append_t pos, int hotkey, const char *text,
void *data, gboolean free_data);
/*** inline functions ****************************************************************************/

View File

@ -74,15 +74,15 @@ exec_edit_syntax_dialog (const GPtrArray * names, const char *current_syntax)
syntaxlist = create_listbox_window (LIST_LINES, MAX_ENTRY_LEN,
_("Choose syntax highlighting"), NULL);
LISTBOX_APPEND_TEXT (syntaxlist, 'A', _("< Auto >"), NULL);
LISTBOX_APPEND_TEXT (syntaxlist, 'R', _("< Reload Current Syntax >"), NULL);
LISTBOX_APPEND_TEXT (syntaxlist, 'A', _("< Auto >"), NULL, FALSE);
LISTBOX_APPEND_TEXT (syntaxlist, 'R', _("< Reload Current Syntax >"), NULL, FALSE);
for (i = 0; i < names->len; i++)
{
const char *name;
name = g_ptr_array_index (names, i);
LISTBOX_APPEND_TEXT (syntaxlist, 0, name, NULL);
LISTBOX_APPEND_TEXT (syntaxlist, 0, name, NULL, FALSE);
if (current_syntax != NULL && strcmp (name, current_syntax) == 0)
listbox_select_entry (syntaxlist->list, i + N_DFLT_ENTRIES);
}

View File

@ -390,7 +390,8 @@ editcmd_dialog_completion_show (const WEdit * edit, int max_len, GString ** comp
/* 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]->str, NULL);
listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i]->str, NULL,
FALSE);
/* pop up the dialog and apply the chosen completion */
if (dlg_run (compl_dlg) == B_ENTER)
@ -461,7 +462,7 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
label_def =
g_strdup_printf ("%s -> %s:%ld", def_hash[i].short_define, def_hash[i].filename,
def_hash[i].line);
listbox_add_item (def_list, LISTBOX_APPEND_AT_END, 0, label_def, &def_hash[i]);
listbox_add_item (def_list, LISTBOX_APPEND_AT_END, 0, label_def, &def_hash[i], FALSE);
g_free (label_def);
}

View File

@ -342,7 +342,7 @@ edit_window_list (const WDialog * h)
vfs_path_as_str (e->filename_vpath));
listbox_add_item (listbox->list, LISTBOX_APPEND_AT_END, get_hotkey (i++),
str_term_trim (fname, WIDGET (listbox->list)->cols - 2), NULL);
str_term_trim (fname, WIDGET (listbox->list)->cols - 2), NULL, FALSE);
g_free (fname);
}

View File

@ -120,7 +120,7 @@ spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word
sug_list = listbox_new (5, 2, sug_dlg_h - 7, 24, FALSE, NULL);
for (i = 0; i < suggest->len; i++)
listbox_add_item (sug_list, LISTBOX_APPEND_AT_END, 0, g_array_index (suggest, char *, i),
NULL);
NULL, FALSE);
add_widget (sug_dlg, sug_list);
add_widget (sug_dlg, add_btn);
@ -170,7 +170,7 @@ spell_dialog_lang_list_show (GArray * languages)
_("Select language"), "[ASpell]");
for (i = 0; i < languages->len; i++)
LISTBOX_APPEND_TEXT (lang_list, 0, g_array_index (languages, char *, i), NULL);
LISTBOX_APPEND_TEXT (lang_list, 0, g_array_index (languages, char *, i), NULL, FALSE);
res = run_listbox (lang_list);
if (res >= 0)

View File

@ -343,13 +343,14 @@ do_enter_key (WDialog * h, int f_pos)
/* get new listboxes */
chl_list = listbox_new (1, 1, 11, 15, FALSE, NULL);
listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL);
listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL, FALSE);
if (is_owner)
{
/* get and put user names in the listbox */
setpwent ();
while ((chl_pass = getpwent ()) != NULL)
listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL);
listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL,
FALSE);
endpwent ();
fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid));
}
@ -358,7 +359,8 @@ do_enter_key (WDialog * h, int f_pos)
/* get and put group names in the listbox */
setgrent ();
while ((chl_grp = getgrent ()) != NULL)
listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL);
listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL,
FALSE);
endgrent ();
fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid));
}

View File

@ -205,7 +205,7 @@ sel_skin_button (WButton * button, int action)
skin_list = listbox_new (1, 1, 11, 22, FALSE, NULL);
skin_name = "default";
listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
(void *) skin_name);
(void *) skin_name, FALSE);
if (strcmp (skin_name, current_skin_name) == 0)
listbox_select_entry (skin_list, 0);
@ -216,7 +216,7 @@ sel_skin_button (WButton * button, int action)
if (strcmp (skin_name, "default") != 0)
{
listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
(void *) skin_name);
(void *) skin_name, FALSE);
if (strcmp (skin_name, current_skin_name) == 0)
listbox_select_entry (skin_list, pos);
pos++;
@ -467,7 +467,7 @@ jobs_fill_listbox (WListbox * list)
char *s;
s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl, FALSE);
g_free (s);
}
}

View File

@ -218,22 +218,22 @@ init_chown (void)
l_user = listbox_new (3, 4, GH - 2, GW - 2, FALSE, NULL);
add_widget (ch_dlg, l_user);
/* add field for unknown names (numbers) */
listbox_add_item (l_user, LISTBOX_APPEND_AT_END, 0, _("<Unknown user>"), NULL);
listbox_add_item (l_user, LISTBOX_APPEND_AT_END, 0, _("<Unknown user>"), NULL, FALSE);
/* get and put user names in the listbox */
setpwent ();
while ((l_pass = getpwent ()) != NULL)
listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL);
listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL, FALSE);
endpwent ();
add_widget (ch_dlg, groupbox_new (2, 4 + GW, GH, GW, _("Group name")));
l_group = listbox_new (3, 5 + GW, GH - 2, GW - 2, FALSE, NULL);
add_widget (ch_dlg, l_group);
/* add field for unknown names (numbers) */
listbox_add_item (l_group, LISTBOX_APPEND_AT_END, 0, _("<Unknown group>"), NULL);
listbox_add_item (l_group, LISTBOX_APPEND_AT_END, 0, _("<Unknown group>"), NULL, FALSE);
/* get and put group names in the listbox */
setgrent ();
while ((l_grp = getgrent ()) != NULL)
listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL);
listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL, FALSE);
endgrent ();
add_widget (ch_dlg, groupbox_new (2, 5 + GW * 2, GH, GW, _("File")));

View File

@ -332,7 +332,7 @@ find_save_options (void)
static inline char *
add_to_list (const char *text, void *data)
{
return listbox_add_item (find_list, LISTBOX_APPEND_AT_END, 0, text, data);
return listbox_add_item (find_list, LISTBOX_APPEND_AT_END, 0, text, data, FALSE);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -290,12 +290,12 @@ fill_listbox (WListbox * list)
g_string_truncate (buff, 0);
g_string_append (buff, "->");
g_string_append (buff, current->label);
listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, buff->str, current);
listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, buff->str, current, FALSE);
}
break;
case HL_TYPE_DOTDOT:
case HL_TYPE_ENTRY:
listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, current->label, current);
listbox_add_item (list, LISTBOX_APPEND_AT_END, 0, current->label, current, FALSE);
default:
break;
}
@ -328,7 +328,7 @@ unlink_entry (struct hotlist *entry)
static void
add_name_to_list (const char *path)
{
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, path, 0);
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, path, NULL, FALSE);
}
#endif /* !ENABLE_VFS */
@ -476,7 +476,8 @@ hotlist_button_callback (WButton * button, int action)
case B_REFRESH_VFS:
listbox_remove_list (l_hotlist);
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, mc_config_get_home_dir (), 0);
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, mc_config_get_home_dir (), NULL,
FALSE);
vfs_fill_names (add_name_to_list);
return 0;
#endif /* ENABLE_VFS */
@ -762,7 +763,8 @@ init_hotlist (hotlist_t list_type)
#ifdef ENABLE_VFS
if (list_type == LIST_VFSLIST)
{
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, mc_config_get_home_dir (), 0);
listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, mc_config_get_home_dir (), NULL,
FALSE);
vfs_fill_names (add_name_to_list);
}
else
@ -948,11 +950,11 @@ add2hotlist (char *label, char *directory, enum HotListType type, listbox_append
char *lbl;
lbl = g_strconcat ("->", new->label, (char *) NULL);
listbox_add_item (l_hotlist, pos, 0, lbl, new);
listbox_add_item (l_hotlist, pos, 0, lbl, new, FALSE);
g_free (lbl);
}
else
listbox_add_item (l_hotlist, pos, 0, new->label, new);
listbox_add_item (l_hotlist, pos, 0, new->label, new, FALSE);
listbox_select_entry (l_hotlist, l_hotlist->pos);
}

View File

@ -120,7 +120,8 @@ select_new_item (void)
mylistbox = create_listbox_window (20, 12, "Add listing format item", listmode_section);
for (i = 0; possible_items[i]; i++)
{
listbox_add_item (mylistbox->list, LISTBOX_APPEND_AT_END, 0, possible_items[i], NULL);
listbox_add_item (mylistbox->list, LISTBOX_APPEND_AT_END, 0, possible_items[i], NULL,
FALSE);
}
i = run_listbox (mylistbox);
@ -155,7 +156,7 @@ badd_cback (int action)
char *s = select_new_item ();
if (s)
{
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL);
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL, FALSE);
g_free (s);
}
return 0;
@ -250,7 +251,7 @@ init_listmode (char *oldlistformat)
while (s)
{
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL);
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL, FALSE);
s = strtok (NULL, ",");
}

View File

@ -179,7 +179,7 @@ init_panelize (void)
l_panelize = listbox_new (y, UX + 1, 10, panelize_cols - UX * 2 - 2, FALSE, NULL);
for (current = panelize; current != NULL; current = current->next)
listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current);
listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current, FALSE);
listbox_select_entry (l_panelize, listbox_search_text (l_panelize, _("Other command")));
add_widget (panelize_dlg, l_panelize);

View File

@ -1107,7 +1107,7 @@ user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_e
{
p = entries[i];
LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0],
extract_line (p, p + MAX_ENTRY_LEN), p);
extract_line (p, p + MAX_ENTRY_LEN), p, FALSE);
}
/* Select the default entry */
listbox_select_entry (listbox->list, selected);

View File

@ -86,20 +86,20 @@ select_charset (int center_y, int center_x, int current_charset, gboolean seldis
"[Codepages Translation]");
if (!seldisplay)
LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"), NULL);
LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"), NULL, FALSE);
/* insert all the items found */
for (i = 0; i < codepages->len; i++)
{
const char *name = ((codepage_desc *) g_ptr_array_index (codepages, i))->name;
g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i), name);
LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL);
LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL, FALSE);
}
if (seldisplay)
{
unsigned char hotkey = get_hotkey (codepages->len);
g_snprintf (buffer, sizeof (buffer), "%c %s", hotkey, _("Other 8 bit"));
LISTBOX_APPEND_TEXT (listbox, hotkey, buffer, NULL);
LISTBOX_APPEND_TEXT (listbox, hotkey, buffer, NULL, FALSE);
}
/* Select the default entry */