SlickEdit Product Discussion > Slick-C® Macro Programming

How to do a find-in-files for a sub-folder in the 'Projects' window?

(1/2) > >>

I would like to be able to execute a find-in-files for a particular folder by right-clicking in the 'Projects' window on a particular sub directory. I have already hooked a call to my own macro by adding a right-click menu item which calls my macro. In my macro, I first get the name of the folder by calling: "_str folderName = _TreeGetCaption(_TreeCurIndex());"
I have the find-in-files dialog popup, but HOW DO I fill in the 'Look in' COMBO box with the folder that I want to search in? I don't really care if the Find-IN-Files dialog pops up or not, as long as I can control the search string and the 'Look in' COMBO box. With or without the Find-in-files dialog presenting itself, how can I do this?

The easiest way is to record a macro that does the kind of search you want, then stop recording and click the "edit" button in the dialog that comes up - you'll see something like the following.  It is possible to pre-populate the find in files dialog if you want but this is easier.  (I just noticed slickedit doesn't show up in my start menu, I wonder why that is). In the slickedit installation docs folder you will see SlickCMacroBestPractices.pdf that has some tips on writing macros - though it's a little out of date.

--- Code: ---#include ""
_command last_recorded_macro() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
--- End code ---

Thank you Graeme, for your quick response.

I tried the implementation that you mentioned:
in my macro, which gets called when I right-click in the 'Projects' window on a folder (because I added a menu item to do that).
I get the following error; however:

This property or method is not allowed on this object
SearchResults.ex 5762,WI,/home/mark/,64,*.*,,,)   p_window_id: 77   p_object: OI_TREE_VIEW   p_name: _proj_tooltab_tree
bgsearch.ex 4884 start_bgsearch(hello,WI,/home/mark/,64,0,0,*.*,,1,0,0,0)   p_window_id: 77   p_object: OI_TREE_VIEW   p_name: _proj_tooltab_tree
mfsearch.ex 328 _mffind(hello,WI,/home/mark/,,64,0,0,*.*,,1,0,0,0)   p_window_id: 77   p_object: OI_TREE_VIEW   p_name: _proj_tooltab_tree
mfsearch.ex 169 _mffind2(hello,WI,/home/mark/,*.*,,64,0,0,0)   p_window_id: 33   p_object: OI_EDITOR   p_name:
vusrmacs.ex 254 projecttbFindInFolder()   p_window_id: 33   p_object: OI_EDITOR   p_name:

I think it happens because the 'Projects' window is the current window that has focus; since I start by right-clicking in it.
Can you help me with that error?


Ok, so I have solved the issue of "This property or method is not allowed on this object" by adding the statements in green, as follows:

    int saveWId = p_window_id;
    p_window_id = _mdi.p_child;
    _mffind2("hello", "WI", folderName, "*.*", '', MFFIND_THREADED/*, '0', '0', '0', ''*/);
    p_window_id = saveWId;

The last issue to solve is getting the full path to the directory. The call I am making to get the folder name is:
    _str folderName = _TreeGetCaption(_TreeCurIndex());
and that works, but ONLY returns the folder name, not the full path. I would need the full path; however, to pass to _mffind2().
Any thoughts?

Thanks again,

Or you could use the object notation.

It's also generally a good idea to check if there are any files open before using _mdi.p_child.

--- Code: ---if (_no_child_windows()) return;
_mdi.p_child._mffind2("hello", "WI", folderName, "*.*", '', MFFIND_THREADED/*, '0', '0', '0', ''*/);

--- End code ---


[0] Message Index

[#] Next page

Go to full version