SlickEdit Product Discussion > Slick-C® Macro Programming

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

<< < (2/2)

Graeme:
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


--- Code: ---/**
 * 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 '';
}

--- End code ---

msCoder:
Big thanks to Graeme & Dennis  :D

I have incorporated BOTH those suggestions and I now have something workable.

Appreciated,
Mark

Navigation

[0] Message Index

[*] Previous page

Go to full version