Skip to content

Commit b4c5dca

Browse files
committed
menuselect: Various menuselect enhancements
* Add 'external' as a support level. * Add ability for module directories to add entries to the menu by adding members to the <module_prefix>/<module_prefix>.xml file. * Expand the description field to 3 lines in the ncurses implementation. * Allow the description field to wrap in the newt implementation. * Add description field to the gtk implementation. Change-Id: I7f9600a1984a42ce0696db574c1051bc9ad7c808
1 parent 616446f commit b4c5dca

7 files changed

+56
-33
lines changed

Makefile.moddir_rules

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ dist-clean::
164164
$(AWK) -f $(ASTTOPDIR)/build_tools/get_moduleinfo $^ >> $@
165165
echo "</member>" >> $@
166166

167-
.moduleinfo:: $(addsuffix .moduleinfo,$(addprefix .,$(sort $(ALL_C_MODS) $(ALL_CC_MODS))))
167+
.moduleinfo:: $(addsuffix .moduleinfo,$(addprefix .,$(sort $(ALL_C_MODS) $(ALL_CC_MODS)))) $(wildcard $(call tolower,$(MENUSELECT_CATEGORY)).xml)
168168
@echo "<category name=\"MENUSELECT_$(MENUSELECT_CATEGORY)\" displayname=\"$(MENUSELECT_DESCRIPTION)\" remove_on_change=\"$(SUBDIR)/modules.link\">" > $@
169169
@cat $^ >> $@
170170
@echo "</category>" >> $@

Makefile.rules

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
-include $(ASTTOPDIR)/makeopts
1919

20+
# Helpful functions
21+
# call with $(call function,...)
22+
tolower = $(shell echo $(1) | tr '[:upper:]' '[:lower:]')
23+
2024
.PHONY: dist-clean
2125

2226
# If 'make' decides to create intermediate files to satisfy a build requirement

menuselect/menuselect.c

+6
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ static enum support_level_values string_to_support_level(const char *support_lev
246246
return SUPPORT_DEPRECATED;
247247
}
248248

249+
if (!strcasecmp(support_level, "external")) {
250+
return SUPPORT_EXTERNAL;
251+
}
252+
249253
return SUPPORT_UNSPECIFIED;
250254
}
251255

@@ -259,6 +263,8 @@ static const char *support_level_to_string(enum support_level_values support_lev
259263
return "Extended";
260264
case SUPPORT_DEPRECATED:
261265
return "Deprecated";
266+
case SUPPORT_EXTERNAL:
267+
return "External";
262268
default:
263269
return "Unspecified";
264270
}

menuselect/menuselect.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ enum support_level_values {
105105
SUPPORT_EXTENDED = 1,
106106
SUPPORT_DEPRECATED = 2,
107107
SUPPORT_UNSPECIFIED = 3,
108-
SUPPORT_COUNT = 4, /* Keep this item at the end of the list. Tracks total number of support levels. */
108+
SUPPORT_EXTERNAL = 4,
109+
SUPPORT_COUNT = 5, /* Keep this item at the end of the list. Tracks total number of support levels. */
109110
};
110111

111112
AST_LIST_HEAD_NOLOCK(support_level_bucket, member);

menuselect/menuselect_curses.c

+32-29
Original file line numberDiff line numberDiff line change
@@ -194,46 +194,49 @@ static void display_mem_info(WINDOW *menu, struct member *mem, int start_y, int
194194
int start_x = (max_x / 2 - MEMBER_INFO_LEFT_ADJ);
195195
int maxlen = (max_x - start_x);
196196

197-
wmove(menu, end - start_y + 1, start_x);
197+
wmove(menu, end - start_y + 1, 0);
198198
wclrtoeol(menu);
199-
wmove(menu, end - start_y + 2, start_x);
199+
wmove(menu, end - start_y + 2, 0);
200200
wclrtoeol(menu);
201-
wmove(menu, end - start_y + 3, start_x);
201+
wmove(menu, end - start_y + 3, 0);
202202
wclrtoeol(menu);
203-
wmove(menu, end - start_y + 4, start_x);
203+
wmove(menu, end - start_y + 4, 0);
204204
wclrtoeol(menu);
205-
wmove(menu, end - start_y + 5, start_x);
205+
wmove(menu, end - start_y + 5, 0);
206206
wclrtoeol(menu);
207-
wmove(menu, end - start_y + 6, start_x);
207+
wmove(menu, end - start_y + 6, 0);
208+
wclrtoeol(menu);
209+
wmove(menu, end - start_y + 7, 0);
208210
wclrtoeol(menu);
209211

210212
if (mem->displayname) {
211-
int name_len = strlen(mem->displayname);
213+
char buf[maxlen + 1];
214+
char *displayname = strdupa(mem->displayname);
215+
char *word;
216+
int current_line = 1;
217+
int new_line = 1;
212218

219+
buf[0] = '\0';
213220
wmove(menu, end - start_y + 1, start_x);
214-
if (name_len > maxlen) {
215-
char *last_space;
216-
char *line_1 = strdup(mem->displayname);
217-
218-
if (line_1) {
219-
line_1[maxlen] = '\0';
220-
last_space = strrchr(line_1, ' ');
221-
if (last_space) {
222-
*last_space = '\0';
223-
}
224-
waddstr(menu, line_1);
225-
wmove(menu, end - start_y + 2, start_x);
226-
waddstr(menu, &mem->displayname[last_space - line_1]);
227-
free(line_1);
228-
} else {
229-
waddstr(menu, (char *) mem->displayname);
221+
222+
while ((word = strsep(&displayname, " "))) {
223+
if ((strlen(buf) + strlen(word) + 1) > maxlen) {
224+
waddstr(menu, buf);
225+
current_line++;
226+
wmove(menu, end - start_y + current_line, start_x);
227+
buf[0] = '\0';
228+
new_line = 1;
230229
}
231-
} else {
232-
waddstr(menu, (char *) mem->displayname);
230+
sprintf(buf, "%s%*.*s%s", buf, new_line ? 0 : 1, new_line ? 0 : 1, " ", word);
231+
new_line = 0;
232+
}
233+
if (strlen(buf)) {
234+
waddstr(menu, buf);
233235
}
234236
}
237+
235238
if (!AST_LIST_EMPTY(&mem->deps)) {
236-
wmove(menu, end - start_y + 3, start_x);
239+
wmove(menu, end - start_y + 4, start_x);
237240
strcpy(buf, "Depends on: ");
238241
AST_LIST_TRAVERSE(&mem->deps, dep, list) {
239242
strncat(buf, dep->displayname, sizeof(buf) - strlen(buf) - 1);
@@ -244,7 +247,7 @@ static void display_mem_info(WINDOW *menu, struct member *mem, int start_y, int
244247
waddstr(menu, buf);
245248
}
246249
if (!AST_LIST_EMPTY(&mem->uses)) {
247-
wmove(menu, end - start_y + 4, start_x);
250+
wmove(menu, end - start_y + 5, start_x);
248251
strcpy(buf, "Can use: ");
249252
AST_LIST_TRAVERSE(&mem->uses, use, list) {
250253
strncat(buf, use->displayname, sizeof(buf) - strlen(buf) - 1);
@@ -255,7 +258,7 @@ static void display_mem_info(WINDOW *menu, struct member *mem, int start_y, int
255258
waddstr(menu, buf);
256259
}
257260
if (!AST_LIST_EMPTY(&mem->conflicts)) {
258-
wmove(menu, end - start_y + 5, start_x);
261+
wmove(menu, end - start_y + 6, start_x);
259262
strcpy(buf, "Conflicts with: ");
260263
AST_LIST_TRAVERSE(&mem->conflicts, con, list) {
261264
strncat(buf, con->displayname, sizeof(buf) - strlen(buf) - 1);
@@ -268,7 +271,7 @@ static void display_mem_info(WINDOW *menu, struct member *mem, int start_y, int
268271

269272
if (!mem->is_separator) { /* Separators lack support levels */
270273
{ /* support level */
271-
wmove(menu, end - start_y + 6, start_x);
274+
wmove(menu, end - start_y + 7, start_x);
272275
snprintf(buf, sizeof(buf), "Support Level: %s", mem->support_level);
273276
if (mem->replacement && *mem->replacement) {
274277
char buf2[64];

menuselect/menuselect_gtk.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ enum {
1616
COLUMN_USES,
1717
/*! Conflicts */
1818
COLUMN_CNFS,
19+
/*! Description */
20+
COLUMN_DESC,
1921
/*! Number of columns, must be the last element in the enum */
2022
NUM_COLUMNS,
2123
};
@@ -254,7 +256,8 @@ int run_menu(void)
254256
G_TYPE_BOOLEAN, /* COLUMN_SELECTED */
255257
G_TYPE_STRING, /* COLUMN_DEPS */
256258
G_TYPE_STRING, /* COLUMN_USES */
257-
G_TYPE_STRING); /* COLUMN_CNFS */
259+
G_TYPE_STRING, /* COLUMN_CNFS */
260+
G_TYPE_STRING); /* COLUMN_DESC */
258261

259262
AST_LIST_TRAVERSE(&categories, cat, list) {
260263
GtkTreeIter iter, iter2;
@@ -307,6 +310,7 @@ int run_menu(void)
307310
COLUMN_DEPS, dep_buf,
308311
COLUMN_USES, use_buf,
309312
COLUMN_CNFS, cnf_buf,
313+
COLUMN_DESC, mem->displayname,
310314
-1);
311315
}
312316
}
@@ -344,6 +348,11 @@ int run_menu(void)
344348
renderer, "text", COLUMN_CNFS, NULL);
345349
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
346350

351+
renderer = gtk_cell_renderer_text_new();
352+
column = gtk_tree_view_column_new_with_attributes("Description",
353+
renderer, "text", COLUMN_DESC, NULL);
354+
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
355+
347356
g_signal_connect(tree, "row-activated", (GCallback) row_activated_handler, store);
348357

349358
gtk_container_add(GTK_CONTAINER(s_window), GTK_WIDGET(tree));

menuselect/menuselect_newt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ int run_menu(void)
326326
newtFormAddComponent(form, subOptions);
327327
newtComponentAddCallback(subOptions, category_menu_callback, NULL);
328328

329-
memberNameTextbox = newtTextbox(2, y - 13, x - 10, 1, 0);
329+
memberNameTextbox = newtTextbox(2, y - 13, x - 10, 2, NEWT_FLAG_WRAP);
330330
dependsLabel = newtLabel(2, y - 11, " Depends on:");
331331
usesLabel = newtLabel(2, y - 10, " Can use:");
332332
conflictsLabel = newtLabel(2, y - 9, "Conflicts with:");

0 commit comments

Comments
 (0)