Author Topic: open any file in a project by name?  (Read 14000 times)

greggman

  • Senior Community Member
  • Posts: 280
  • Hero Points: 14
open any file in a project by name?
« on: March 29, 2007, 06:37:21 AM »
This function might already be in vs and I'm just not aware of it but........

Another developer at work just showed me that in Visual Studio 2005 you can open a command prompt (inside the IDE for issueing IDE commands) and you can type "open filename.cpp" where filename is the name of any file in your project. Visual Studio will find and open the file. This is amazingly useful when your project encompasses hundreds of files spread over a large tree of folders. Manually going through the folders either in the IDE Project Browser or Windows Explorer takes forever when you're not sure which of the 30+ folders the file might be in.

Does vs have any function like that? If not may I suggest it :-)

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: open any file in a project by name?
« Reply #1 on: March 29, 2007, 12:11:35 PM »
Try 'quickfileopen' on the SlickEdit command line.

Also, the new Files toolbar allows you to list all files in the project, and filter the list.

greggman

  • Senior Community Member
  • Posts: 280
  • Hero Points: 14
Re: open any file in a project by name?
« Reply #2 on: March 29, 2007, 05:14:50 PM »
my slickedit (11.0.2) doesn't have a "quickfileopen" command  ???  Is that new in vs 2007?

and I also don't have a Files toolbar either. I have an "Open" toolbar but it only shows the contents of one folder at a time. Is the Files Toolbar new as to vs 2007 as well?
« Last Edit: March 29, 2007, 05:19:18 PM by greggman »

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: open any file in a project by name?
« Reply #3 on: March 29, 2007, 06:15:15 PM »
@greggman:
In v11 there is a project-load [-p] command or 'Project->Open Files from Workspace [Project]'.
Yes, the 'Files' TB is new in SE2007 and it combines the functionality of 'list-buffers'/'project-load [-p]'.

HS2

greggman

  • Senior Community Member
  • Posts: 280
  • Hero Points: 14
Re: open any file in a project by name?
« Reply #4 on: March 29, 2007, 09:07:35 PM »
thanks! that's perfect!

JeffB

  • Senior Community Member
  • Posts: 326
  • Hero Points: 14
Re: open any file in a project by name?
« Reply #5 on: April 04, 2007, 04:20:01 AM »
Is 'quickfileopen' the actual spelling ?  All I see is quick-highlight, quick-replace, and quick-search.

(using  v12.0.0.0)

-Jeff

Lisa

  • Senior Community Member
  • Posts: 238
  • Hero Points: 24
  • User-friendly geek-speak translator extraordinaire
Re: open any file in a project by name?
« Reply #6 on: April 04, 2007, 02:03:09 PM »
Is 'quickfileopen' the actual spelling ?  All I see is quick-highlight, quick-replace, and quick-search.

(using  v12.0.0.0)

-Jeff

Docs to the rescue: I think he is referring to the e file command, where file is the name of the file to create or open. This is found in the Help by typing "quick create" or "quick open" in the Help Index. (Finally, a Help topic with correct markers  ;D )

PS - There is also Help available for e.

(disclaimer: then again, maybe there is another command he is referring to that I'm not aware of)

Good luck,
Lisa
« Last Edit: April 04, 2007, 02:06:05 PM by Lisa »

JeffB

  • Senior Community Member
  • Posts: 326
  • Hero Points: 14
Re: open any file in a project by name?
« Reply #7 on: April 04, 2007, 02:12:54 PM »
Thanks, Lisa.

The original post was for a command-line 'open' command for any file in the project.  For me 'e <file>' either opens a file in the current directory, or creates a new one. (Maybe I'm missing some setting ??)  I was also looking for a quick way to open any workspace/project file just by the name. Some of my projects can have >40k files, which makes the Files TB very slow.

jeffro

  • Community Member
  • Posts: 6
  • Hero Points: 1
Re: open any file in a project by name?
« Reply #8 on: April 05, 2007, 08:17:00 PM »
Here's a set of macros I've been using forever for this purpose.  The ei command will search the following locations for the files specified:

  • The current project
  • The project's root directory
  • Any directory listed in the PROJECT_EI_PATH environment variable
  • Any directory listed in the GLOBAL_EI_PATH environment variable

If a single file is found, it is opened.  If multiple files match the filespec, you're presented with a multi-select list from which to choose.  Wildcards are supported, so ei foo*.h will list all of the foo*.h files in any of the location above.

I had to tweak these macro files a little to remove dependecies on other macro files I have.  Let me know if you have problems compiling or running these.

Jeff

JeffB

  • Senior Community Member
  • Posts: 326
  • Hero Points: 14
Re: open any file in a project by name?
« Reply #9 on: April 09, 2007, 09:05:20 PM »
Thanks for the macros Jeffro.

It appears that jget-line() and jfile_exists() are missing.

jeffro

  • Community Member
  • Posts: 6
  • Hero Points: 1
Re: open any file in a project by name?
« Reply #10 on: April 10, 2007, 08:26:10 PM »
It appears that jget-line() and jfile_exists() are missing.

Sorry about that.  Here they are:

boolean jfile_exists (_str filename)
{
    return (file_date (filename) != "");
}

_str jget_line (int lineNumber = p_line)
{
    typeless oldpos;
    boolean changedPosition = false;

    if (p_line != lineNumber)
    {
        _save_pos2 (oldpos);
        p_line = lineNumber;
        changedPosition = true;
    }

    _str line;
    get_line (line);

    if (changedPosition)
    {
        _restore_pos2 (oldpos);
    }

    return (line);
}

JeffB

  • Senior Community Member
  • Posts: 326
  • Hero Points: 14
Re: open any file in a project by name?
« Reply #11 on: April 10, 2007, 08:32:36 PM »
Thanks, Jeffro.

That got rid of the error, but the macro doesn't seem to work.  Even something basic like 'ei m*' prints: No files found matching "m*".  Complete filenames do not work either.

I'll try to look at it later and post any findings.

-Jeff

jeffro

  • Community Member
  • Posts: 6
  • Hero Points: 1
Re: open any file in a project by name?
« Reply #12 on: April 11, 2007, 05:44:50 PM »
Once ei starts finding files, you'll also need jrelative() (attached).  You haven't hit that error because you haven't found any files to open yet.

Try defining the PROJECT_EI_PATH or GLOBAL_EI_PATH environment variable (in one of: 1. global environment, 2. vslick.ini, or 3. the project's Open command) and see if ei will find a file in one of those paths.  Alternatively, you could modify the ei command to look along a different path, like INCLUDE.

I'm guessing that the problem is in j_append_files_from_project_to_array.  Perhaps GetProjectFiles is failing.

Be aware also that there's a j_dump_array function that you can use to see the contents of an array as you build it up.  Might help with debugging.

JeffB

  • Senior Community Member
  • Posts: 326
  • Hero Points: 14
Re: open any file in a project by name?
« Reply #13 on: April 26, 2007, 06:22:05 PM »
Thanks, Jeffro.

I finally got back to this.  The "j_dump_array()" really helped.  It turns out that the "j_fully_qualify_filenames_in_array()" call in "j_search_path()" was prepending the current working directory, but the files in the array were already fully qualified.  For my purposes, I am only getting files from the project list, so I just changed the line: "files = absolute (files);" to "files = absolute (files,'/');" in "j_fully_qualify_filenames_in_array()" so that the path always starts with '/'.  I'm not sure how this would work for other files in the list obtained via ENV variables (or on Windows, I'm on Linux).  I probably could just take out this call, but this works ok.

Thanks for sharing your macros.

Now I just need to change the list from Project files, to Workspace files.

-Jeff

jeffro

  • Community Member
  • Posts: 6
  • Hero Points: 1
Re: open any file in a project by name?
« Reply #14 on: April 26, 2007, 07:00:49 PM »
Glad you got this working for you.  I'd be interested in seeing the finished product after your mods.  It might give me some clues how I can write my macros more generally.

Jeff