find files results title with pattern and content

In the chat with wwp about the find files dialog, I had forgotten about the panelize button. Thanks Chris 
Glur for reminding me. Yes, it does exactly what he was asking, as far as I can tell.

Anyway, in that post I had mentioned that I'd like the find files results window to show the pattern and 
content in the title, to explain what it's doing, where I have 2 mc's in side by side terminals grepping in 
the same directory for different things.

Well, here's a quick & dirty hack that does what I mentioned. It's only a few lines in filemanager/find.c and 
it seems to work for me. I thought I'd post it here to show what I'm talking about, if anyone is interested. 

I used diff -u. Is there a better diff command? I haven't posted one in quite some time.

--- filemanager/find.c~ 2013-08-02 11:02:40.000000000 -0700
+++ filemanager/find.c  2013-09-14 06:35:08.624565755 -0700
@@ -1551,13 +1551,16 @@
 /* --------------------------------------------------------------------------------------------- */
 static void
-setup_gui (void)
+/*setup_gui (void)*/
+setup_gui (const char *pattern, const char *content)
     size_t i;
     int lines, cols;
     int y;
     static gboolean i18n_flag = FALSE;
+    char title[BUF_MEDIUM];
     if (!i18n_flag)
@@ -1577,9 +1580,14 @@
     lines = LINES - 4;
     cols = COLS - 16;
+    if ( content && *content )
+       snprintf (title, BUF_MEDIUM, _("Find File: '%s' Content: '%s'"), pattern, content);
+    else
+       snprintf (title, BUF_MEDIUM, _("Find File: '%s'"), pattern);
     find_dlg =
         dlg_create (TRUE, 0, 0, lines, cols, dialog_colors, find_callback, NULL, "[Find File]",
-                    _("Find File"), DLG_CENTER);
+                    /* _("Find File"), DLG_CENTER); */
+                    title, DLG_CENTER);
     find_calc_button_locations (find_dlg, TRUE);
@@ -1671,7 +1679,7 @@
     int return_value = 0;
     char *dir_tmp = NULL, *file_tmp = NULL;
-    setup_gui ();
+    setup_gui (pattern, content);
     /* FIXME: Need to cleanup this, this ought to be passed non-globaly */
     find_pattern = (char *) pattern;


Something I'm curious about is this: when I pass NULL to printf "%s", I get "(null)" printed. Is this 
standard across platforms, or is it good practice to check for this condition and avoid it? Malformed 
printf's are a notorious source of segfaults.

As a related sidenote, while I'm in here poking around, about that FIXME: 

global char *find_pattern is assigned here and used only in run_process(void). Why can't char *pattern be 
passed to run_process(const char *pattern)? Get rid of another global.

Peace and Cheer

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]