1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Implemented /form help

This commit is contained in:
James Booth 2014-09-16 20:52:38 +01:00
parent 728f1f014b
commit 0d9a145d45
4 changed files with 63 additions and 13 deletions

View File

@ -317,15 +317,16 @@ static struct cmd_t command_defs[] =
{ "/form",
cmd_form, parse_args, 1, 3, NULL,
{ "/form show|submit|cancel|set|add|remove [tag value]", "Form manipulation.",
{ "/form show|submit|cancel|set|add|remove [tag value]",
"---------------------------------------------------",
{ "/form show|submit|cancel|set|add|remove|help [tag] [value]", "Form manipulation.",
{ "/form show|submit|cancel|set|add|remove|help [tag] [value]",
"----------------------------------------------------------",
"set tag value - Set tagged form field to value.",
"add tag value - Add value to tagged form field.",
"remove tag value - Remove value from tagged form field.",
"show - Show the current form.",
"submit - Submit the current form.",
"cancel - Cancel changes to the current form.",
"help [tag] - Display help for form, or a specific field.",
NULL } } },
{ "/rooms",
@ -1233,6 +1234,7 @@ cmd_init(void)
autocomplete_add(form_ac, "set");
autocomplete_add(form_ac, "add");
autocomplete_add(form_ac, "remove");
autocomplete_add(form_ac, "help");
cmd_history_init();
}

View File

@ -634,12 +634,9 @@ cmd_help(gchar **args, struct cmd_help_t help)
}
cons_show("");
if (help_text != NULL) {
int i;
for (i = 0; help_text[i] != NULL; i++) {
cons_show(help_text[i]);
}
ProfWin *console = wins_get_console();
ui_show_lines(console, help_text);
} else {
cons_show("No such command.");
}
@ -1806,6 +1803,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
if ((g_strcmp0(args[0], "submit") != 0) &&
(g_strcmp0(args[0], "cancel") != 0) &&
(g_strcmp0(args[0], "show") != 0) &&
(g_strcmp0(args[0], "help") != 0) &&
(g_strcmp0(args[0], "set") != 0) &&
(g_strcmp0(args[0], "add") != 0) &&
(g_strcmp0(args[0], "remove") != 0)) {
@ -1824,6 +1822,27 @@ cmd_form(gchar **args, struct cmd_help_t help)
return TRUE;
}
if (g_strcmp0(args[0], "help") == 0) {
char *tag = args[1];
if (tag != NULL) {
ui_show_form_field_help(current, current->form, tag);
} else {
ui_show_form_help(current, current->form);
const gchar **help_text = NULL;
Command *command = g_hash_table_lookup(commands, "/form");
if (command != NULL) {
help_text = command->help.long_help;
}
ui_show_lines(current, help_text);
}
ui_current_print_line("");
g_strfreev(split_recipient);
return TRUE;
}
if (g_strcmp0(args[0], "submit") == 0) {
iq_submit_room_config(room, current->form);

View File

@ -2025,11 +2025,7 @@ _ui_show_form(ProfWin *window, const char * const room, DataForm *form)
}
win_save_print(window, '-', NULL, 0, 0, "", "");
if (form->instructions != NULL) {
win_save_vprint(window, '-', NULL, 0, 0, "", "Instructions:");
win_save_print(window, '-', NULL, 0, 0, "", form->instructions);
win_save_print(window, '-', NULL, 0, 0, "", "");
}
ui_show_form_help(window, form);
GSList *fields = form->fields;
GSList *curr_field = fields;
@ -2084,6 +2080,33 @@ _ui_handle_room_config_submit_result(void)
cons_show("GOT ROOM CONFIG SUBMIT RESULT!!!!");
}
static void
_ui_show_form_field_help(ProfWin *window, DataForm *form, char *tag)
{
win_save_println(window, "HELP FIELD");
}
static void
_ui_show_form_help(ProfWin *window, DataForm *form)
{
if (form->instructions != NULL) {
win_save_vprint(window, '-', NULL, 0, 0, "", "Instructions:");
win_save_print(window, '-', NULL, 0, 0, "", form->instructions);
win_save_print(window, '-', NULL, 0, 0, "", "");
}
}
static void
_ui_show_lines(ProfWin *window, const gchar** lines)
{
if (lines != NULL) {
int i;
for (i = 0; lines[i] != NULL; i++) {
win_save_print(window, '-', NULL, 0, 0, "", lines[i]);
}
}
}
static void
_win_handle_switch(const wint_t * const ch)
{
@ -2326,4 +2349,7 @@ ui_init_module(void)
ui_win_has_unsaved_form = _ui_win_has_unsaved_form;
ui_show_form = _ui_show_form;
ui_show_form_field = _ui_show_form_field;
ui_show_form_help = _ui_show_form_help;
ui_show_form_field_help = _ui_show_form_field_help;
ui_show_lines = _ui_show_lines;
}

View File

@ -164,6 +164,9 @@ void (*ui_handle_room_configuration)(const char * const room, DataForm *form);
void (*ui_handle_room_config_submit_result)(void);
void (*ui_show_form)(ProfWin *window, const char * const room, DataForm *form);
void (*ui_show_form_field)(ProfWin *window, DataForm *form, char *tag);
void (*ui_show_form_help)(ProfWin *window, DataForm *form);
void (*ui_show_form_field_help)(ProfWin *window, DataForm *form, char *tag);
void (*ui_show_lines)(ProfWin *window, const gchar** lines);
// contact status functions
void (*ui_status_room)(const char * const contact);