Author Topic: How to copy contents of Search Results window to clipboard in Slick-C  (Read 11931 times)

jbarriewalker

  • Community Member
  • Posts: 16
  • Hero Points: 0
Hi,

I frequently do the following:
1. Search for something through a number of files.
2. Switch to the Search Results window.
3. Select all and copy to clipboard.
4. Create a new fundamental buffer.
5. Paste what was copied.
6. Process the search results using regular expression search and replace.

I currently have from step 3 in a Slick-C macro.
I'd like to add step 2, but how?

In step 1, I could tick the "Output to editor window" box and not have to do step 2, but then I'd need to remember to untick it next search.

Also, I'd like a step 7 that marks the buffer as deletable without being asked. Is that possible?

Or perhaps there are other strategies to achieve this...

Thanks

jbarriewalker

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: How to copy contents of Search Results window to clipboard in Slick-C
« Reply #1 on: October 15, 2009, 10:38:25 AM »
Thought my existing macro might be a helpful reference.

_command MakeBreakFromFind() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _macro('R',1);
//   find_view(srch = buf_match("Search", 1, "H")); // ??? not necessarily the first one of course
   select_all();
   copy_to_clipboard();
   new_file();
   paste();
   while (!replace_buffer_text('(^File .*/(.*)\n)\:b(\:n)\:b.*\n','UEP*','break \2:\3\n\1','0','0','0'));
   replace_buffer_text('^(.*\n)\1+','UEP*','\1','0','0','0');
   replace_buffer_text('^(?!break)(?:\n|.+)\n*','UEP*','','0','0','0');
}


Graeme

  • Senior Community Member
  • Posts: 2821
  • Hero Points: 347
Re: How to copy contents of Search Results window to clipboard in Slick-C
« Reply #2 on: October 15, 2009, 11:39:27 AM »
activate_search will make the search results window active.  To make the buffer deletable without being prompted to save changes, you can do
p_buf_flags |= VSBUFFLAG_THROW_AWAY_CHANGES;
when the buffer is the current buffer. 

You can also use _open_temp_view to create a temporary buffer.

Graeme

jbarriewalker

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: How to copy contents of Search Results window to clipboard in Slick-C
« Reply #3 on: October 16, 2009, 03:00:24 PM »
Thank you for your reply which works a treat.

What doesn't work is a mistake on my part.

The lines:
    select_all();
    copy_to_clipboard();

work on the active buffer, not on the search window.

I'll work on it too, but if you have a pointer that'd be great.

Graeme

  • Senior Community Member
  • Posts: 2821
  • Hero Points: 347
Re: How to copy contents of Search Results window to clipboard in Slick-C
« Reply #4 on: October 16, 2009, 06:24:11 PM »
I guess it doesn't work in the search results toolbar because the edit control shown in that window doesn't have the focus.  Since you probably don't want to actually show the search results window you're probably best to go directly to the buffer.  I think you can do that using a buffer name of
'.search' :+ _get_last_grep_buffer()

Have a look at _create_grep_buffer in tbsearch.e

Graeme

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: How to copy contents of Search Results window to clipboard in Slick-C
« Reply #5 on: October 16, 2009, 06:39:59 PM »
I'd recommend this:   

Code: [Select]
int orig_wid = _find_or_create_temp_view(temp_view_id, '', grep_buffer_name, false, VSBUFFLAG_THROW_AWAY_CHANGES|VSBUFFLAG_HIDDEN|VSBUFFLAG_KEEP_ON_QUIT);

where the grep_buffer_name is ".searchN", where N matches the Search Results window tab Search<N>.  This will return the temp view (in temp_view_id) and that is the view used to store search results.  No need to free this temp view, as it is re-used by search.

jbarriewalker

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: How to copy contents of Search Results window to clipboard in Slick-C
« Reply #6 on: October 19, 2009, 11:36:01 AM »
Thank you, both,

It seems that _get_last_grep_buffer() actually return the number of search buffers there are, rather than the last buffer used (at least in v12.0.3).

The value I really want is in the static variable current_grep_id, so I've added an access function to tbsearch.e:
   int _get_current_grep_buffer()
   {
      return (current_grep_id);
   }


Now, using
   _find_or_create_temp_view(temp_view_id, '', '.search' :+ _get_current_grep_buffer(), false, VSBUFFLAG_THROW_AWAY_CHANGES|VSBUFFLAG_HIDDEN|VSBUFFLAG_KEEP_ON_QUIT);

works a treat.

Not sure that I really ought to be editing tbsearch.e, but not sure what else to do.

Thank you again.
Barrie

Graeme

  • Senior Community Member
  • Posts: 2821
  • Hero Points: 347
Re: How to copy contents of Search Results window to clipboard in Slick-C
« Reply #7 on: October 19, 2009, 12:06:46 PM »
Maybe you could use _get_grep_buffer_view  - I'm not sure what the result is when _tbsearch_form is visible though.

One thing about modifying a slick macro file is that when a hotfix comes along, it gets put in config/hotfixes folder rather than in the installation macro folder, but you probably know that.

Graeme

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: How to copy contents of Search Results window to clipboard in Slick-C
« Reply #8 on: October 19, 2009, 01:07:33 PM »
Adding the call _get_last_grep_buffer is the safest modification for now.  Unfortunately, since the value you need is static local to tbsearch.e, there's no other way to expose it without modifying it.  Like Graeme mentions, just have to aware of hotfixes that might patch the macro file.  I also think it's a good strategy to not make any modifications to the installed macros directory, always keep the original just in case and maintain a seperate directory for macro revisions.

There is really no reason why that value shouldn't be globally available.  I'll make a note of it, and work that into the next major release.

jbarriewalker

  • Community Member
  • Posts: 16
  • Hero Points: 0
Re: How to copy contents of Search Results window to clipboard in Slick-C
« Reply #9 on: October 19, 2009, 01:41:24 PM »
Graeme,

Good call on _get_grep_buffer_view().

   _find_or_create_temp_view(temp_view_id, '', _get_grep_buffer_view().p_buf_name, false, VSBUFFLAG_THROW_AWAY_CHANGES|VSBUFFLAG_HIDDEN|VSBUFFLAG_KEEP_ON_QUIT);

is the business. I can remove my mod now.

Ta
Barrie