SlickEdit Community
SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: msCoder on July 08, 2020, 01:16:39 PM
-
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.
#include "slick.sh"
_command last_recorded_macro() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
_macro('R',1);
_mffind2("hello","WI",'C:\one-project\i5-laptop\',"*.*",'',"64",'0','0','0','');
}
-
Thank you Graeme, for your quick response.
I tried the implementation that you mentioned:
_mffind2("hello","WI",'C:\one-project\i5-laptop\',"*.*",'',"64",'0','0','0','');
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 se.search.generate_search_summary(hello,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?
Thanks,
Mark
-
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,
Mark
-
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.
if (_no_child_windows()) return;
_mdi.p_child._mffind2("hello", "WI", folderName, "*.*", '', MFFIND_THREADED/*, '0', '0', '0', ''*/);
-
Hi Mark
Regarding getting the pathname, a few years ago I posted some code here that added some options to the right click menu in the projects toolwindow. I haven't used it for a while but I had a quick look and there's a function you can see below that might do what you want.
In slick macro source ptoolbar.e you'll see this function - it's probably what you want.
static _str _projecttbTreeGetCurFolderPath(int index = -1)
https://community.slickedit.com/index.php/topic,5633.msg23443.html#msg23443 (https://community.slickedit.com/index.php/topic,5633.msg23443.html#msg23443)
/**
* Determine the path of the current item in the projects toolbar. This can
* be used when auto-folder is set to directory view or custom view.
* Package view is untested. The types of tree node that this can be called
* for are project node, folder node or project file node.
*
* @return _str - path to current item in the projects toolbar
*/
_str projecttb_get_current_absolute_path()
{
/***************************************************************************
// don't need to find the window id, but this is how
int treeWid;
_str name, fullPath;
treeWid= _find_object("_tbprojects_form._proj_tooltab_tree",'N');
if (treeWid) {
treeWid.TreeWithSelection(projecttbMaybeEditFile);
}
***************************************************************************/
int index = _TreeCurIndex();
int orig_index = index;
_str path1 = '';
if (_projecttbIsProjectNode(index)) {
_str name = _TreeGetCaption(index);
_str relpath="";
parse name with name "\t" relpath;
// might need this some day?
// if (_IsEclipseWorkspaceFilename(_workspace_filename)) {
// // For eclipse we only put the name of the file and the directory, but
// // not the whole file. It looks a little more like the way Eclipse
// // actually does things that way.
// ProjectName=VSEProjectFilename(_AbsoluteToWorkspace(relpath:+name:+PRJ_FILE_EXT));
// }else{
// ProjectName=VSEProjectFilename(_AbsoluteToWorkspace(relpath));
// }
return strip_filename(relpath, 'N');
}
if (_projecttbIsProjectFileNode(index)) {
_str name, fullpath;
parse _TreeGetCaption(index) with name "\t" fullpath;
return (strip_filename(fullpath,'N'));
}
if (_projecttbIsFolderNode(index)) {
path1 = '';
// first go down the tree and try to find a file node because file nodes
// have full path info
while (index > 0) {
index = _TreeGetFirstChildIndex(index);
if (index > 0) {
if (_projecttbIsProjectFileNode(index)) {
break;
}
path1 = path1 :+ _TreeGetCaption(index) :+ FILESEP;
}
}
// if we found a file node, remove the sub-path from the end
if (index > 0 && _projecttbIsProjectFileNode(index)) {
_str name, fullpath;
parse _TreeGetCaption(index) with name "\t" fullpath;
fullpath = strip_filename(fullpath, 'N');
int len1 = length(fullpath);
int len2 = length(path1);
if (len2 == 0) {
return (fullpath);
}
if ((len1 - len2) > 2) {
int pos1 = pos(path1, fullpath, len1 - len2 - 2);
if (pos1 > 1) {
return (substr(fullpath, 1, pos1-1));
}
}
}
// this is a folder node, try going back up the tree to the project node
index = orig_index;
path1 = _TreeGetCaption(index) :+ FILESEP;
while (_TreeGetDepth(index) > 1) {
index = _TreeGetParentIndex(index);
if (!_projecttbIsProjectNode(index)) {
path1 = _TreeGetCaption(index) :+ FILESEP :+ path1;
}
else {
_str name = _TreeGetCaption(index);
_str relpath="";
parse name with name "\t" relpath;
// might need this some day?
// if (_IsEclipseWorkspaceFilename(_workspace_filename)) {
// // For eclipse we only put the name of the file and the directory, but
// // not the whole file. It looks a little more like the way Eclipse
// // actually does things that way.
// ProjectName=VSEProjectFilename(_AbsoluteToWorkspace(relpath:+name:+PRJ_FILE_EXT));
// }else{
// ProjectName=VSEProjectFilename(_AbsoluteToWorkspace(relpath));
// }
return (absolute(path1, strip_filename(relpath,'N')));
}
}
}
_message_box("Unable to determine pathname." :+ "\n" :+ path1, "Project toolbar add item");
return '';
}
-
Big thanks to Graeme & Dennis :D
I have incorporated BOTH those suggestions and I now have something workable.
Appreciated,
Mark