mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Dont allow unsaved form windows to be closed
This commit is contained in:
parent
529b4f175b
commit
c5b697dba7
@ -1,7 +1,5 @@
|
|||||||
Split out form management commands from /room to /form command
|
|
||||||
Autocompelte values for field types on set
|
|
||||||
Don't allow form windows to be closed without submitting/cancelling
|
|
||||||
Help command for form fields
|
Help command for form fields
|
||||||
Command to show current form
|
Command to show current form
|
||||||
Handle error on form submit
|
Handle error on form submit
|
||||||
Show field after setting/adding/removing
|
Show field after setting/adding/removing
|
||||||
|
Autocompelte values for set/add/remove
|
||||||
|
@ -2490,6 +2490,17 @@ cmd_close(gchar **args, struct cmd_help_t help)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check for unsaved form
|
||||||
|
if (ui_win_has_unsaved_form(index)) {
|
||||||
|
ProfWin *window = wins_get_current();
|
||||||
|
if (wins_is_current(window)) {
|
||||||
|
ui_current_print_line("You have unsaved changes, use /form submit or /form cancel");
|
||||||
|
} else {
|
||||||
|
cons_show("Cannot close form window with unsaved changes, use /form submit or /form cancel");
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// handle leaving rooms, or chat
|
// handle leaving rooms, or chat
|
||||||
if (conn_status == JABBER_CONNECTED) {
|
if (conn_status == JABBER_CONNECTED) {
|
||||||
ui_close_connected_win(index);
|
ui_close_connected_win(index);
|
||||||
|
@ -632,7 +632,7 @@ _ui_close_all_wins(void)
|
|||||||
|
|
||||||
while (curr != NULL) {
|
while (curr != NULL) {
|
||||||
int num = GPOINTER_TO_INT(curr->data);
|
int num = GPOINTER_TO_INT(curr->data);
|
||||||
if (num != 1) {
|
if ((num != 1) && (!ui_win_has_unsaved_form(num))) {
|
||||||
if (conn_status == JABBER_CONNECTED) {
|
if (conn_status == JABBER_CONNECTED) {
|
||||||
ui_close_connected_win(num);
|
ui_close_connected_win(num);
|
||||||
}
|
}
|
||||||
@ -659,7 +659,7 @@ _ui_close_read_wins(void)
|
|||||||
|
|
||||||
while (curr != NULL) {
|
while (curr != NULL) {
|
||||||
int num = GPOINTER_TO_INT(curr->data);
|
int num = GPOINTER_TO_INT(curr->data);
|
||||||
if ((num != 1) && (ui_win_unread(num) == 0)) {
|
if ((num != 1) && (ui_win_unread(num) == 0) && (!ui_win_has_unsaved_form(num))) {
|
||||||
if (conn_status == JABBER_CONNECTED) {
|
if (conn_status == JABBER_CONNECTED) {
|
||||||
ui_close_connected_win(num);
|
ui_close_connected_win(num);
|
||||||
}
|
}
|
||||||
@ -675,6 +675,20 @@ _ui_close_read_wins(void)
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_ui_win_has_unsaved_form(int num)
|
||||||
|
{
|
||||||
|
ProfWin *window = wins_get_by_num(num);
|
||||||
|
|
||||||
|
if (window->type != WIN_MUC_CONFIG) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (window->form == NULL) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return window->form->modified;
|
||||||
|
}
|
||||||
|
|
||||||
GString *
|
GString *
|
||||||
_get_recipient_string(ProfWin *window)
|
_get_recipient_string(ProfWin *window)
|
||||||
{
|
{
|
||||||
@ -2295,4 +2309,5 @@ ui_init_module(void)
|
|||||||
ui_room_destroyed = _ui_room_destroyed;
|
ui_room_destroyed = _ui_room_destroyed;
|
||||||
ui_handle_room_configuration = _ui_handle_room_configuration;
|
ui_handle_room_configuration = _ui_handle_room_configuration;
|
||||||
ui_handle_room_config_submit_result = _ui_handle_room_config_submit_result;
|
ui_handle_room_config_submit_result = _ui_handle_room_config_submit_result;
|
||||||
|
ui_win_has_unsaved_form = _ui_win_has_unsaved_form;
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,8 @@ void (*ui_create_xmlconsole_win)(void);
|
|||||||
gboolean (*ui_xmlconsole_exists)(void);
|
gboolean (*ui_xmlconsole_exists)(void);
|
||||||
void (*ui_open_xmlconsole_win)(void);
|
void (*ui_open_xmlconsole_win)(void);
|
||||||
|
|
||||||
|
gboolean (*ui_win_has_unsaved_form)(int num);
|
||||||
|
|
||||||
// console window actions
|
// console window actions
|
||||||
void (*cons_show)(const char * const msg, ...);
|
void (*cons_show)(const char * const msg, ...);
|
||||||
void (*cons_about)(void);
|
void (*cons_about)(void);
|
||||||
|
@ -192,6 +192,7 @@ form_create(xmpp_stanza_t * const form_stanza)
|
|||||||
form->var_to_tag = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
|
form->var_to_tag = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
|
||||||
form->tag_to_var = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
|
form->tag_to_var = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
|
||||||
form->tag_ac = autocomplete_new();
|
form->tag_ac = autocomplete_new();
|
||||||
|
form->modified = FALSE;
|
||||||
|
|
||||||
int tag_num = 1;
|
int tag_num = 1;
|
||||||
|
|
||||||
@ -430,10 +431,12 @@ _form_set_value(DataForm *form, const char * const tag, char *value)
|
|||||||
if (g_strcmp0(field->var, var) == 0) {
|
if (g_strcmp0(field->var, var) == 0) {
|
||||||
if (g_slist_length(field->values) == 0) {
|
if (g_slist_length(field->values) == 0) {
|
||||||
field->values = g_slist_append(field->values, strdup(value));
|
field->values = g_slist_append(field->values, strdup(value));
|
||||||
|
form->modified = TRUE;
|
||||||
return;
|
return;
|
||||||
} else if (g_slist_length(field->values) == 1) {
|
} else if (g_slist_length(field->values) == 1) {
|
||||||
free(field->values->data);
|
free(field->values->data);
|
||||||
field->values->data = strdup(value);
|
field->values->data = strdup(value);
|
||||||
|
form->modified = TRUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -452,6 +455,7 @@ _form_add_value(DataForm *form, const char * const tag, char *value)
|
|||||||
FormField *field = curr->data;
|
FormField *field = curr->data;
|
||||||
if (g_strcmp0(field->var, var) == 0) {
|
if (g_strcmp0(field->var, var) == 0) {
|
||||||
field->values = g_slist_append(field->values, strdup(value));
|
field->values = g_slist_append(field->values, strdup(value));
|
||||||
|
form->modified = TRUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
curr = g_slist_next(curr);
|
curr = g_slist_next(curr);
|
||||||
@ -477,6 +481,7 @@ _form_add_unique_value(DataForm *form, const char * const tag, char *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
field->values = g_slist_append(field->values, strdup(value));
|
field->values = g_slist_append(field->values, strdup(value));
|
||||||
|
form->modified = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
curr = g_slist_next(curr);
|
curr = g_slist_next(curr);
|
||||||
@ -500,6 +505,7 @@ _form_remove_value(DataForm *form, const char * const tag, char *value)
|
|||||||
free(found->data);
|
free(found->data);
|
||||||
found->data = NULL;
|
found->data = NULL;
|
||||||
field->values = g_slist_delete_link(field->values, found);
|
field->values = g_slist_delete_link(field->values, found);
|
||||||
|
form->modified = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -527,6 +533,7 @@ _form_remove_text_multi_value(DataForm *form, const char * const tag, int index)
|
|||||||
free(item->data);
|
free(item->data);
|
||||||
item->data = NULL;
|
item->data = NULL;
|
||||||
field->values = g_slist_delete_link(field->values, item);
|
field->values = g_slist_delete_link(field->values, item);
|
||||||
|
form->modified = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -125,6 +125,7 @@ typedef struct data_form_t {
|
|||||||
GHashTable *var_to_tag;
|
GHashTable *var_to_tag;
|
||||||
GHashTable *tag_to_var;
|
GHashTable *tag_to_var;
|
||||||
Autocomplete tag_ac;
|
Autocomplete tag_ac;
|
||||||
|
gboolean modified;
|
||||||
} DataForm;
|
} DataForm;
|
||||||
|
|
||||||
void jabber_init_module(void);
|
void jabber_init_module(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user