From 09f5cadf1a2052f07f31611dc4ba986b3db0ec27 Mon Sep 17 00:00:00 2001 From: MarcoPolo-PasTonMolo Date: Thu, 7 Oct 2021 15:53:12 +0300 Subject: Add /correct-editor command --- src/command/cmd_ac.c | 18 +++++++- src/command/cmd_defs.c | 19 ++++++++ src/command/cmd_funcs.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + 4 files changed, 153 insertions(+), 1 deletion(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 9db42841..88b2b2f7 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1795,6 +1795,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ g_hash_table_insert(ac_funcs, "/avatar", _avatar_autocomplete); g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete); g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete); + g_hash_table_insert(ac_funcs, "/correct-editor", _correct_autocomplete); g_hash_table_insert(ac_funcs, "/software", _software_autocomplete); g_hash_table_insert(ac_funcs, "/url", _url_autocomplete); g_hash_table_insert(ac_funcs, "/executable", _executable_autocomplete); @@ -4054,7 +4055,22 @@ _correct_autocomplete(ProfWin* window, const char* const input, gboolean previou return NULL; } - GString* result_str = g_string_new("/correct "); + // Get command + int len = strlen(input); + char command[len + 2]; + int i = 0; + while (i < len) { + if (input[i] == ' ') { + break; + } else { + command[i] = input[i]; + } + i++; + } + command[i] = ' '; + command[i + 1] = '\0'; + + GString* result_str = g_string_new(command); g_string_append(result_str, last_message); char* result = result_str->str; g_string_free(result_str, FALSE); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 1b8c3112..47ab34ad 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2622,6 +2622,25 @@ static struct cmd_t command_defs[] = { CMD_NOEXAMPLES }, + { "/correct-editor", + parse_args_as_one, 1, 1, NULL, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_correct_editor) + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/correct-editor ") + CMD_DESC( + "Spawn external editor to correct and resend the last message (XEP-0308). " + "Use tab completion to get the last sent message. " + "For more information on how to configure corrections, see: /help correction. " + "Use /executable to set your favourite editor.") + CMD_ARGS( + { "message", "The corrected message." }) + CMD_NOEXAMPLES + }, + { "/silence", parse_args, 1, 1, &cons_silence_setting, CMD_NOSUBFUNCS diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 67c59802..7e767659 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9527,6 +9527,122 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args) return TRUE; } +gboolean +cmd_correct_editor(ProfWin* window, const char* const command, gchar** args) +{ + jabber_conn_status_t conn_status = connection_get_status(); + if (conn_status != JABBER_CONNECTED) { + cons_show("You are currently not connected."); + return TRUE; + } else if (!prefs_get_boolean(PREF_CORRECTION_ALLOW)) { + win_println(window, THEME_DEFAULT, "!", "Corrections not enabled. See /help correction."); + return TRUE; + } else if (window->type == WIN_CHAT) { + ProfChatWin* chatwin = (ProfChatWin*)window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + + if (chatwin->last_msg_id == NULL || chatwin->last_message == NULL) { + win_println(window, THEME_DEFAULT, "!", "No last message to correct."); + return TRUE; + } + } else if (window->type == WIN_MUC) { + ProfMucWin* mucwin = (ProfMucWin*)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + + if (mucwin->last_msg_id == NULL || mucwin->last_message == NULL) { + win_println(window, THEME_DEFAULT, "!", "No last message to correct."); + return TRUE; + } + } else { + win_println(window, THEME_DEFAULT, "!", "Command /correct-editor only valid in regular chat windows."); + return TRUE; + } + + // create editor dir if not present + char *jid = connection_get_barejid(); + gchar *path = files_get_account_data_path(DIR_EDITOR, jid); + if (g_mkdir_with_parents(path, S_IRWXU) != 0) { + cons_show_error("Failed to create directory at '%s' with error '%s'", path, strerror(errno)); + free(jid); + g_free(path); + return TRUE; + } + // build temp file name. Example: /home/user/.local/share/profanity/editor/jid/compose.md + char* filename = g_strdup_printf("%s/compose.md", path); + free(jid); + g_free(path); + + GError* creation_error = NULL; + GFile* file = g_file_new_for_path(filename); + GFileOutputStream* fos = g_file_create(file, G_FILE_CREATE_PRIVATE, NULL, &creation_error); + int fd_output_file = open(g_file_get_path(file), O_WRONLY); + + const size_t COUNT = 8192; + gchar* message = g_strjoinv(" ", args); + write(fd_output_file, message, strlen(message)); + + free(message); + free(filename); + + if (creation_error) { + cons_show_error("Editor: could not create temp file"); + return TRUE; + } + g_object_unref(fos); + + char* editor = prefs_get_string(PREF_COMPOSE_EDITOR); + + // Fork / exec + pid_t pid = fork(); + if (pid == 0) { + int x = execlp(editor, editor, g_file_get_path(file), (char*)NULL); + if (x == -1) { + cons_show_error("Editor:Failed to exec %s", editor); + } + _exit(EXIT_FAILURE); + } else { + if (pid == -1) { + return TRUE; + } + int status = 0; + waitpid(pid, &status, 0); + int fd_input_file = open(g_file_get_path(file), O_RDONLY); + char buf[COUNT]; + ssize_t size_read = read(fd_input_file, buf, COUNT); + if (size_read > 0 && size_read <= COUNT) { + buf[size_read - 1] = '\0'; + GString* text = g_string_new(buf); + + if (window->type == WIN_CHAT) { + ProfChatWin* chatwin = (ProfChatWin*)window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + + cl_ev_send_msg_correct(chatwin, text->str, FALSE, TRUE); + } else if (window->type == WIN_MUC) { + ProfMucWin* mucwin = (ProfMucWin*)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + + cl_ev_send_muc_msg_corrected(mucwin, text->str, FALSE, TRUE); + } + + g_string_free(text, TRUE); + } + close(fd_input_file); + + GError* deletion_error = NULL; + g_file_delete(file, NULL, &deletion_error); + if (deletion_error) { + cons_show("Editor: error during file deletion"); + return TRUE; + } + g_object_unref(file); + ui_resize(); + rl_point = rl_end; + rl_forced_update_display(); + } + return TRUE; +} + gboolean cmd_silence(ProfWin* window, const char* const command, gchar** args) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 54cc6e78..cf6ec5bf 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -246,6 +246,7 @@ gboolean cmd_executable_urlsave(ProfWin* window, const char* const command, gcha gboolean cmd_executable_editor(ProfWin* window, const char* const command, gchar** args); gboolean cmd_mam(ProfWin* window, const char* const command, gchar** args); gboolean cmd_editor(ProfWin* window, const char* const command, gchar** args); +gboolean cmd_correct_editor(ProfWin* window, const char* const command, gchar** args); gboolean cmd_silence(ProfWin* window, const char* const command, gchar** args); #endif -- cgit 1.4.1-2-gfad0 From cd16264d2bfb8ffb7afd9bd42a39e06c019f5915 Mon Sep 17 00:00:00 2001 From: MarcoPolo-PasTonMolo Date: Sun, 17 Oct 2021 20:31:36 +0300 Subject: Export common code to helper functions --- src/command/cmd_funcs.c | 194 ++++++++++++++++++------------------------------ 1 file changed, 72 insertions(+), 122 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 7e767659..c0537087 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9101,52 +9101,64 @@ cmd_correction(ProfWin* window, const char* const command, gchar** args) } gboolean -cmd_correct(ProfWin* window, const char* const command, gchar** args) +_can_correct(ProfWin* window) { jabber_conn_status_t conn_status = connection_get_status(); if (conn_status != JABBER_CONNECTED) { cons_show("You are currently not connected."); - return TRUE; - } - - if (!prefs_get_boolean(PREF_CORRECTION_ALLOW)) { + return FALSE; + } else if (!prefs_get_boolean(PREF_CORRECTION_ALLOW)) { win_println(window, THEME_DEFAULT, "!", "Corrections not enabled. See /help correction."); - return TRUE; - } - - if (window->type == WIN_CHAT) { + return FALSE; + } else if (window->type == WIN_CHAT) { ProfChatWin* chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); if (chatwin->last_msg_id == NULL || chatwin->last_message == NULL) { win_println(window, THEME_DEFAULT, "!", "No last message to correct."); - return TRUE; + return FALSE; } + } else if (window->type == WIN_MUC) { + ProfMucWin* mucwin = (ProfMucWin*)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + + if (mucwin->last_msg_id == NULL || mucwin->last_message == NULL) { + win_println(window, THEME_DEFAULT, "!", "No last message to correct."); + return FALSE; + } + } else { + win_println(window, THEME_DEFAULT, "!", "Command /correct-editor only valid in regular chat windows."); + return FALSE; + } + + return TRUE; +} + +gboolean +cmd_correct(ProfWin* window, const char* const command, gchar** args) +{ + if (!_can_correct(window)) { + return TRUE; + } + + if (window->type == WIN_CHAT) { + ProfChatWin* chatwin = (ProfChatWin*)window; // send message again, with replace flag gchar* message = g_strjoinv(" ", args); cl_ev_send_msg_correct(chatwin, message, FALSE, TRUE); free(message); - return TRUE; } else if (window->type == WIN_MUC) { ProfMucWin* mucwin = (ProfMucWin*)window; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - - if (mucwin->last_msg_id == NULL || mucwin->last_message == NULL) { - win_println(window, THEME_DEFAULT, "!", "No last message to correct."); - return TRUE; - } // send message again, with replace flag gchar* message = g_strjoinv(" ", args); cl_ev_send_muc_msg_corrected(mucwin, message, FALSE, TRUE); free(message); - return TRUE; } - win_println(window, THEME_DEFAULT, "!", "Command /correct only valid in regular chat windows."); return TRUE; } @@ -9449,16 +9461,10 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args) return TRUE; } +// Returns true if any error occured gboolean -cmd_editor(ProfWin* window, const char* const command, gchar** args) +_get_message_from_editor(gchar* message, gchar** returned_message) { - jabber_conn_status_t conn_status = connection_get_status(); - - if (conn_status != JABBER_CONNECTED) { - cons_show("You are currently not connected."); - return TRUE; - } - // create editor dir if not present char* jid = connection_get_barejid(); gchar* path = files_get_account_data_path(DIR_EDITOR, jid); @@ -9477,6 +9483,12 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args) GFile* file = g_file_new_for_path(filename); GFileOutputStream* fos = g_file_create(file, G_FILE_CREATE_PRIVATE, NULL, &creation_error); + if (message != NULL && strlen(message) > 0) { + int fd_output_file = open(g_file_get_path(file), O_WRONLY); + write(fd_output_file, message, strlen(message)); + close(fd_output_file); + } + free(filename); if (creation_error) { @@ -9508,7 +9520,7 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args) if (size_read > 0 && size_read <= COUNT) { buf[size_read - 1] = '\0'; GString* text = g_string_new(buf); - rl_insert_text(text->str); + *returned_message = g_strdup(text->str); g_string_free(text, TRUE); } close(fd_input_file); @@ -9520,126 +9532,64 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args) return TRUE; } g_object_unref(file); - ui_resize(); - rl_point = rl_end; - rl_forced_update_display(); } - return TRUE; + + return FALSE; } gboolean -cmd_correct_editor(ProfWin* window, const char* const command, gchar** args) +cmd_editor(ProfWin* window, const char* const command, gchar** args) { jabber_conn_status_t conn_status = connection_get_status(); + if (conn_status != JABBER_CONNECTED) { cons_show("You are currently not connected."); return TRUE; - } else if (!prefs_get_boolean(PREF_CORRECTION_ALLOW)) { - win_println(window, THEME_DEFAULT, "!", "Corrections not enabled. See /help correction."); - return TRUE; - } else if (window->type == WIN_CHAT) { - ProfChatWin* chatwin = (ProfChatWin*)window; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + } - if (chatwin->last_msg_id == NULL || chatwin->last_message == NULL) { - win_println(window, THEME_DEFAULT, "!", "No last message to correct."); - return TRUE; - } - } else if (window->type == WIN_MUC) { - ProfMucWin* mucwin = (ProfMucWin*)window; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + gchar* message = NULL; - if (mucwin->last_msg_id == NULL || mucwin->last_message == NULL) { - win_println(window, THEME_DEFAULT, "!", "No last message to correct."); - return TRUE; - } - } else { - win_println(window, THEME_DEFAULT, "!", "Command /correct-editor only valid in regular chat windows."); + if (_get_message_from_editor(NULL, &message)) { return TRUE; } - // create editor dir if not present - char *jid = connection_get_barejid(); - gchar *path = files_get_account_data_path(DIR_EDITOR, jid); - if (g_mkdir_with_parents(path, S_IRWXU) != 0) { - cons_show_error("Failed to create directory at '%s' with error '%s'", path, strerror(errno)); - free(jid); - g_free(path); - return TRUE; - } - // build temp file name. Example: /home/user/.local/share/profanity/editor/jid/compose.md - char* filename = g_strdup_printf("%s/compose.md", path); - free(jid); - g_free(path); + rl_insert_text(message); + ui_resize(); + rl_point = rl_end; + rl_forced_update_display(); + g_free(message); - GError* creation_error = NULL; - GFile* file = g_file_new_for_path(filename); - GFileOutputStream* fos = g_file_create(file, G_FILE_CREATE_PRIVATE, NULL, &creation_error); - int fd_output_file = open(g_file_get_path(file), O_WRONLY); + return TRUE; +} - const size_t COUNT = 8192; - gchar* message = g_strjoinv(" ", args); - write(fd_output_file, message, strlen(message)); +gboolean +cmd_correct_editor(ProfWin* window, const char* const command, gchar** args) +{ + if (!_can_correct(window)) { + return TRUE; + } - free(message); - free(filename); + gchar* initial_message = g_strjoinv(" ", args); - if (creation_error) { - cons_show_error("Editor: could not create temp file"); + gchar* message = NULL; + if (_get_message_from_editor(initial_message, &message)) { return TRUE; } - g_object_unref(fos); - - char* editor = prefs_get_string(PREF_COMPOSE_EDITOR); - // Fork / exec - pid_t pid = fork(); - if (pid == 0) { - int x = execlp(editor, editor, g_file_get_path(file), (char*)NULL); - if (x == -1) { - cons_show_error("Editor:Failed to exec %s", editor); - } - _exit(EXIT_FAILURE); - } else { - if (pid == -1) { - return TRUE; - } - int status = 0; - waitpid(pid, &status, 0); - int fd_input_file = open(g_file_get_path(file), O_RDONLY); - char buf[COUNT]; - ssize_t size_read = read(fd_input_file, buf, COUNT); - if (size_read > 0 && size_read <= COUNT) { - buf[size_read - 1] = '\0'; - GString* text = g_string_new(buf); + free(initial_message); - if (window->type == WIN_CHAT) { - ProfChatWin* chatwin = (ProfChatWin*)window; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + if (window->type == WIN_CHAT) { + ProfChatWin* chatwin = (ProfChatWin*)window; - cl_ev_send_msg_correct(chatwin, text->str, FALSE, TRUE); - } else if (window->type == WIN_MUC) { - ProfMucWin* mucwin = (ProfMucWin*)window; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + cl_ev_send_msg_correct(chatwin, message, FALSE, TRUE); + } else if (window->type == WIN_MUC) { + ProfMucWin* mucwin = (ProfMucWin*)window; - cl_ev_send_muc_msg_corrected(mucwin, text->str, FALSE, TRUE); - } + cl_ev_send_muc_msg_corrected(mucwin, message, FALSE, TRUE); + } - g_string_free(text, TRUE); - } - close(fd_input_file); + g_free(message); - GError* deletion_error = NULL; - g_file_delete(file, NULL, &deletion_error); - if (deletion_error) { - cons_show("Editor: error during file deletion"); - return TRUE; - } - g_object_unref(file); - ui_resize(); - rl_point = rl_end; - rl_forced_update_display(); - } return TRUE; } -- cgit 1.4.1-2-gfad0 From 6b0f15a1c90116a01463a8c9e26c32f4112810e7 Mon Sep 17 00:00:00 2001 From: MarcoPolo-PasTonMolo Date: Thu, 21 Oct 2021 17:01:54 +0300 Subject: Remove autocomplete for /correct-editor We decided that it was better to remove autocomplete for this command, since adding it only introduced problems and the command can still function perfectly without autocomplete. --- src/command/cmd_ac.c | 34 ++++++++++++---------------------- src/command/cmd_ac.h | 1 + src/command/cmd_defs.c | 8 +++----- src/command/cmd_funcs.c | 6 ++---- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 88b2b2f7..a0d57a18 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1795,7 +1795,6 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ g_hash_table_insert(ac_funcs, "/avatar", _avatar_autocomplete); g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete); g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete); - g_hash_table_insert(ac_funcs, "/correct-editor", _correct_autocomplete); g_hash_table_insert(ac_funcs, "/software", _software_autocomplete); g_hash_table_insert(ac_funcs, "/url", _url_autocomplete); g_hash_table_insert(ac_funcs, "/executable", _executable_autocomplete); @@ -4031,6 +4030,17 @@ _correction_autocomplete(ProfWin* window, const char* const input, gboolean prev static char* _correct_autocomplete(ProfWin* window, const char* const input, gboolean previous) +{ + GString* result_str = g_string_new("/correct "); + g_string_append(result_str, _get_last_message(window)); + char* result = result_str->str; + g_string_free(result_str, FALSE); + + return result; +} + +char* +_get_last_message(ProfWin* window) { char* last_message = NULL; switch (window->type) { @@ -4055,27 +4065,7 @@ _correct_autocomplete(ProfWin* window, const char* const input, gboolean previou return NULL; } - // Get command - int len = strlen(input); - char command[len + 2]; - int i = 0; - while (i < len) { - if (input[i] == ' ') { - break; - } else { - command[i] = input[i]; - } - i++; - } - command[i] = ' '; - command[i + 1] = '\0'; - - GString* result_str = g_string_new(command); - g_string_append(result_str, last_message); - char* result = result_str->str; - g_string_free(result_str, FALSE); - - return result; + return last_message; } static char* diff --git a/src/command/cmd_ac.h b/src/command/cmd_ac.h index ef715310..c0485916 100644 --- a/src/command/cmd_ac.h +++ b/src/command/cmd_ac.h @@ -59,5 +59,6 @@ void cmd_ac_add_form_fields(DataForm* form); void cmd_ac_remove_form_fields(DataForm* form); char* cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean previous); +char* _get_last_message(ProfWin* window); #endif diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 47ab34ad..85631a34 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2623,21 +2623,19 @@ static struct cmd_t command_defs[] = { }, { "/correct-editor", - parse_args_as_one, 1, 1, NULL, + parse_args, 0, 0, NULL, CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_correct_editor) CMD_TAGS( CMD_TAG_CHAT, CMD_TAG_GROUPCHAT) CMD_SYN( - "/correct-editor ") + "/correct-editor") CMD_DESC( "Spawn external editor to correct and resend the last message (XEP-0308). " - "Use tab completion to get the last sent message. " "For more information on how to configure corrections, see: /help correction. " "Use /executable to set your favourite editor.") - CMD_ARGS( - { "message", "The corrected message." }) + CMD_NOARGS CMD_NOEXAMPLES }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index c0537087..55a05be2 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9461,7 +9461,7 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args) return TRUE; } -// Returns true if any error occured +// Returns true if an error occured gboolean _get_message_from_editor(gchar* message, gchar** returned_message) { @@ -9569,15 +9569,13 @@ cmd_correct_editor(ProfWin* window, const char* const command, gchar** args) return TRUE; } - gchar* initial_message = g_strjoinv(" ", args); + gchar* initial_message = _get_last_message(window); gchar* message = NULL; if (_get_message_from_editor(initial_message, &message)) { return TRUE; } - free(initial_message); - if (window->type == WIN_CHAT) { ProfChatWin* chatwin = (ProfChatWin*)window; -- cgit 1.4.1-2-gfad0 From da3a6d87437ce14215acbb5f1740cb81066df39d Mon Sep 17 00:00:00 2001 From: MarcoPolo-PasTonMolo Date: Fri, 22 Oct 2021 10:24:51 +0300 Subject: Move declaration and definition of win_get_last_sent_message to the correct place --- src/command/cmd_ac.c | 32 ++------------------------------ src/command/cmd_ac.h | 1 - src/command/cmd_funcs.c | 2 +- src/ui/ui.h | 1 + src/ui/window.c | 29 +++++++++++++++++++++++++++++ 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index a0d57a18..ee0f717e 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -49,6 +49,7 @@ #include "command/cmd_funcs.h" #include "tools/parser.h" #include "plugins/plugins.h" +#include "ui/ui.h" #include "ui/win_types.h" #include "ui/window_list.h" #include "xmpp/muc.h" @@ -4032,42 +4033,13 @@ static char* _correct_autocomplete(ProfWin* window, const char* const input, gboolean previous) { GString* result_str = g_string_new("/correct "); - g_string_append(result_str, _get_last_message(window)); + g_string_append(result_str, win_get_last_sent_message(window)); char* result = result_str->str; g_string_free(result_str, FALSE); return result; } -char* -_get_last_message(ProfWin* window) -{ - char* last_message = NULL; - switch (window->type) { - case WIN_CHAT: - { - ProfChatWin* chatwin = (ProfChatWin*)window; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - last_message = chatwin->last_message; - break; - } - case WIN_MUC: - { - ProfMucWin* mucwin = (ProfMucWin*)window; - assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - last_message = mucwin->last_message; - } - default: - break; - } - - if (last_message == NULL) { - return NULL; - } - - return last_message; -} - static char* _software_autocomplete(ProfWin* window, const char* const input, gboolean previous) { diff --git a/src/command/cmd_ac.h b/src/command/cmd_ac.h index c0485916..ef715310 100644 --- a/src/command/cmd_ac.h +++ b/src/command/cmd_ac.h @@ -59,6 +59,5 @@ void cmd_ac_add_form_fields(DataForm* form); void cmd_ac_remove_form_fields(DataForm* form); char* cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean previous); -char* _get_last_message(ProfWin* window); #endif diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 55a05be2..fdf6e3d9 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9569,7 +9569,7 @@ cmd_correct_editor(ProfWin* window, const char* const command, gchar** args) return TRUE; } - gchar* initial_message = _get_last_message(window); + gchar* initial_message = win_get_last_sent_message(window); gchar* message = NULL; if (_get_message_from_editor(initial_message, &message)) { diff --git a/src/ui/ui.h b/src/ui/ui.h index bb81dfc3..5257df60 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -398,6 +398,7 @@ void win_command_exec_error(ProfWin* window, const char* const command, const ch void win_handle_command_list(ProfWin* window, GSList* cmds); void win_handle_command_exec_status(ProfWin* window, const char* const type, const char* const value); void win_handle_command_exec_result_note(ProfWin* window, const char* const type, const char* const value); +char* win_get_last_sent_message(ProfWin* window); // desktop notifications void notifier_initialise(void); diff --git a/src/ui/window.c b/src/ui/window.c index 3123e211..7442ce9c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -398,6 +398,35 @@ win_get_tab_identifier(ProfWin* window) } } +char* +win_get_last_sent_message(ProfWin* window) +{ + char* last_message = NULL; + switch (window->type) { + case WIN_CHAT: + { + ProfChatWin* chatwin = (ProfChatWin*)window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + last_message = chatwin->last_message; + break; + } + case WIN_MUC: + { + ProfMucWin* mucwin = (ProfMucWin*)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + last_message = mucwin->last_message; + } + default: + break; + } + + if (last_message == NULL) { + return NULL; + } + + return last_message; +} + char* win_to_string(ProfWin* window) { -- cgit 1.4.1-2-gfad0