Log Window F1 handling
authorColin Clark <colin.clark@cclark.uk>
Fri, 15 Dec 2023 12:56:20 +0000 (12:56 +0000)
committerColin Clark <colin.clark@cclark.uk>
Fri, 15 Dec 2023 12:56:20 +0000 (12:56 +0000)
- Pressing F1 in the Log Window send the selected text or complete line
to the command specified in Edit/Preferences/Behavior/Log Window F1
Command. It is left to the user to determine the action taken.
- Debug statements parameter order changed from  __FILE__, __func__,
__LINE__ to  __FILE__, __LINE__, __func__

CODING.md
src/debug.cc
src/debug.h
src/logwindow.cc
src/options.cc
src/preferences.cc

index 00b4391..7613a81 100644 (file)
--- a/CODING.md
+++ b/CODING.md
@@ -47,19 +47,17 @@ Sample command line call:
 Prints a backtrace.
 Use only for temporary debugging i.e. not in code in the repository
 
-```text
-When the LogWindow has focus, the F1 key executes the following action as a command line program:
-<options->log_window.action> <selected text>
-The log_window.action value must be set by editing the geeqierc.xml file manually.
-If no text is selected when the F1 key is pressed, the text either side of the cursor delimited by a space character or the beginning or end of the line is selected.
-This feature may be used to open an editor at a file location listed in the backtrace.
-```
-
 ### DEBUG_FD()
 
 Prints a dump of the FileData hash list as a ref. count followed by the full path of the item.
 Use only for temporary debugging i.e. not in code in the repository
 
+### Log Window
+
+When the Log Window has focus, the F1 key executes the action specified in `Edit/Preferences/Behavior/Log Window F1 Command` with the selected text as a parameter.
+If no text is selected, the entire line is passed to the command.
+This feature may be used to open an editor at a file location in the text string.
+
 ---
 
 ## GPL header
index 4c16224..5654297 100644 (file)
@@ -117,8 +117,7 @@ void log_domain_print_message(const gchar *domain, gchar *buf)
        g_free(buf);
 }
 
-void log_domain_print_debug(const gchar *domain, const gchar *file_name, const gchar *function_name,
-                                                                       int line_number, const gchar *format, ...)
+void log_domain_print_debug(const gchar *domain, const gchar *file_name, int line_number, const gchar *function_name, const gchar *format, ...)
 {
        va_list ap;
        gchar *message;
@@ -131,12 +130,11 @@ void log_domain_print_debug(const gchar *domain, const gchar *file_name, const g
 
        if (options && options->log_window.timer_data)
                {
-               location = g_strdup_printf("%s:%s:%s:%d:", get_exec_time(), file_name,
-                                                                                               function_name, line_number);
+               location = g_strdup_printf("%s:%s:%d:%s:", get_exec_time(), file_name, line_number, function_name);
                }
        else
                {
-               location = g_strdup_printf("%s:%s:%d:", file_name, function_name, line_number);
+               location = g_strdup_printf("%s:%d:%s:", file_name, line_number, function_name);
                }
 
        buf = g_strconcat(location, message, NULL);
@@ -268,10 +266,10 @@ gchar *get_regexp()
  * Format printed is: \n
  * <full path to source file>:<line number>
  *
- * The log window F1 command and options->log_window.action may be used
- * to open an editor at a backtrace location.
+ * The log window F1 command and Edit/Preferences/Behavior/Log Window F1
+ * Command may be used to open an editor at a backtrace location.
  */
-void log_print_backtrace(const gchar *file, const gchar *function, gint line)
+void log_print_backtrace(const gchar *file, gint line, const gchar *function)
 {
        FILE *fp;
        char **bt_syms;
@@ -345,7 +343,7 @@ void log_print_backtrace(const gchar *file, const gchar *function, gint line)
                }
 }
 #else
-void log_print_backtrace(const gchar *, const gchar *, gint)
+void log_print_backtrace(const gchar *, gint, const gchar *)
 {
 }
 #endif
index 5a9dcb3..5e65eb2 100644 (file)
 #define DOMAIN_INFO  "info"
 
 void log_domain_printf(const gchar *domain, const gchar *format, ...) G_GNUC_PRINTF(2, 3);
-void log_domain_print_debug(const gchar *domain, const gchar *file_name, const gchar *function_name,
-                                                       int line_number, const gchar *format, ...) G_GNUC_PRINTF(5, 6);
-void log_print_file_data_dump(const gchar *file, const gchar *function_name, gint line_number);
-void log_print_backtrace(const gchar *file, const gchar *function_name, gint line_number);
+void log_domain_print_debug(const gchar *domain, const gchar *file_name, int line_number, const gchar *function_name, const gchar *format, ...) G_GNUC_PRINTF(5, 6);
+void log_print_file_data_dump(const gchar *file, gint line_number, const gchar *function_name);
+void log_print_backtrace(const gchar *file, gint line_number, const gchar *function_name);
 
 #define log_printf(...) log_domain_printf(DOMAIN_INFO, __VA_ARGS__)
 
@@ -55,7 +54,7 @@ void init_exec_time();
                                        {               \
                                        if (debug_level != 1) \
                                                { \
-                                               log_domain_print_debug(DOMAIN_DEBUG, __FILE__, __func__, __LINE__, __VA_ARGS__); \
+                                               log_domain_print_debug(DOMAIN_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__);\
                                                } \
                                        else \
                                                { \
@@ -78,12 +77,12 @@ void init_exec_time();
 
 #define DEBUG_BT() do \
                                { \
-                               log_print_backtrace(__FILE__, __func__, __LINE__); \
+                               log_print_backtrace(__FILE__, __LINE__, __func__);     \
                                } while(0)
 
 #define DEBUG_FD() do \
                                { \
-                               log_print_file_data_dump(__FILE__, __func__, __LINE__); \
+                               log_print_file_data_dump(__FILE__, __LINE__, __func__);\
                                } while(0)
 #else /* DEBUG */
 
index e49faa6..672c771 100644 (file)
@@ -59,22 +59,6 @@ static void hide_cb(GtkWidget *, LogWindow *)
 {
 }
 
-static gboolean iter_char_search_cb(gunichar ch, gpointer data)
-{
-       gboolean ret;
-
-       if (ch == GPOINTER_TO_UINT(data))
-               {
-               ret = TRUE;
-               }
-       else
-               {
-               ret = FALSE;
-               }
-
-       return ret;
-}
-
 /**
  * @brief Handle escape and F1 keys
  * @param UNUSED
@@ -83,23 +67,23 @@ static gboolean iter_char_search_cb(gunichar ch, gpointer data)
  * @returns
  *
  * If escape key pressed, hide log window. \n
- * If no text selected, form a selection bounded by space characters or
- * start and end of line. \n
+ * If no text selected, select the entire line. \n
  * If F1 pressed, execute command line program: \n
  * <options->log_window.action> <selected text>
  *
 */
 static gboolean key_pressed(GtkWidget *, GdkEventKey *event, LogWindow *logwin)
 {
+       gchar *cmd_line;
+       gchar *sel_text;
        GtkTextBuffer *buffer;
        GtkTextIter chr_end;
+       GtkTextIter chr_marker;
        GtkTextIter chr_start;
        GtkTextIter cursor_iter;
        GtkTextIter line_end;
        GtkTextIter line_start;
        GtkTextMark *cursor_mark;
-       gchar *cmd_line;
-       gchar *sel_text;
 
        if (event && event->keyval == GDK_KEY_Escape)
                gtk_widget_hide(logwin->window);
@@ -119,21 +103,15 @@ static gboolean key_pressed(GtkWidget *, GdkEventKey *event, LogWindow *logwin)
                                gtk_text_iter_set_line_offset(&line_start, 0);
                                line_end = cursor_iter;
                                gtk_text_iter_forward_to_line_end(&line_end);
-
-                               chr_start = cursor_iter;
-                               gtk_text_iter_backward_find_char(&chr_start, static_cast<GtkTextCharPredicate>(iter_char_search_cb), GUINT_TO_POINTER(' '), &line_start);
-
-                               chr_end = cursor_iter;
-                               gtk_text_iter_forward_find_char(&chr_end, static_cast<GtkTextCharPredicate>(iter_char_search_cb), GUINT_TO_POINTER(' '), &line_end);
-
-                               gtk_text_buffer_select_range(buffer, &chr_start, &chr_end);
+                               chr_marker = line_end;
+                               gtk_text_buffer_select_range(buffer, &line_start, &line_end);
                                }
 
                        if (gtk_text_buffer_get_selection_bounds(gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text)), &chr_start, &chr_end))
                                {
                                sel_text = gtk_text_buffer_get_text( gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text)), &chr_start, &chr_end, FALSE);
 
-                               cmd_line = g_strconcat(options->log_window.action, " ", sel_text, NULL);
+                               cmd_line = g_strconcat(options->log_window.action, " \"", sel_text, "\"", NULL);
 
                                runcmd(cmd_line);
 
index 81c0c69..e16a553 100644 (file)
@@ -204,7 +204,7 @@ ConfOptions *init_options(ConfOptions *options)
        options->log_window.line_wrap = FALSE;
        options->log_window.paused = FALSE;
        options->log_window.timer_data = FALSE;
-       options->log_window.action = g_strdup("");
+       options->log_window.action = g_strdup("echo");
 
        options->read_metadata_in_idle = FALSE;
        options->star_rating.star = STAR_RATING_STAR;
index 6b000da..080613b 100644 (file)
@@ -152,6 +152,8 @@ static GtkWidget *external_preview_extract_entry;
 static GtkWidget *sidecar_ext_entry;
 static GtkWidget *help_search_engine_entry;
 
+static GtkWidget *log_window_f1_entry;
+
 
 #define CONFIG_WINDOW_DEF_WIDTH                700
 #define CONFIG_WINDOW_DEF_HEIGHT       600
@@ -470,6 +472,7 @@ static void config_window_apply()
 
 #ifdef DEBUG
        set_debug_level(debug_c);
+       config_entry_to_option(log_window_f1_entry, &options->log_window.action, nullptr);
 #endif
 
 #ifdef HAVE_LCMS
@@ -3644,6 +3647,14 @@ static void config_tab_behavior(GtkWidget *notebook)
 
        pref_spin_new_int(group, _("Log Window max. lines:"), nullptr,
                          1, 99999, 1, options->log_window_lines, &options->log_window_lines);
+
+       hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
+       pref_label_new(hbox, _("Log Window F1 command: "));
+       log_window_f1_entry = gtk_entry_new();
+       gq_gtk_entry_set_text(GTK_ENTRY(log_window_f1_entry), options->log_window.action);
+       gq_gtk_box_pack_start(GTK_BOX(hbox), log_window_f1_entry, FALSE, FALSE, 0);
+       gtk_entry_set_width_chars(GTK_ENTRY(log_window_f1_entry), 15);
+       gtk_widget_show(log_window_f1_entry);
 #endif
 }