Author Topic: Open project file macro and new open local symbol macro  (Read 40016 times)

sdayts

  • Community Member
  • Posts: 42
  • Hero Points: 5
Re: Open project file macro and new open local symbol macro
« Reply #15 on: March 04, 2008, 11:24:24 pm »
Asandler/hs2,

This is a fantastic macro.
Thank you both!

asandler

  • Senior Community Member
  • Posts: 303
  • Hero Points: 27
Re: Open project file macro and new open local symbol macro
« Reply #16 on: May 04, 2008, 09:56:52 am »
Hello all.

I brewed a new version of the open project file macro - version 1.0.7.

-> This version supports SlickEdit 2008.
-> It is more responsive thanks to new internal timer mechanism (@hs2 thanks for help).
-> It won't crash on you when working with big projects.
-> It understands slash symbol, thus you can do searches like aaa/bbb to make it look for file named bbb in directory named aaa.
-> I fixed a bug that caused inaccurate search results (adding one extra not matching file name for every search).

You can grab it on my web-site: http://www.alexonlinux.com/stuff/software-projects/slickedit-macros

Alexander.
« Last Edit: May 12, 2013, 01:45:20 pm by asandler »

asandler

  • Senior Community Member
  • Posts: 303
  • Hero Points: 27
Re: Open project file macro and new open local symbol macro
« Reply #17 on: May 06, 2008, 02:52:32 pm »
Found a bug in 1.0.7 that caused backspace not to work properly.
Version 1.0.8 below fixes this.

Have fun!

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Open project file macro and new open local symbol macro
« Reply #18 on: May 06, 2008, 05:39:17 pm »
Using v1.0.8:

I'm having trouble invoking the _open_project_file command:  it says either "unknown command" or "invalid number" for all of the following:  _open_project_file, -open-project-file, open_project_file, open-project-file.  In the completion list it shows -open-project-file, but that results in "invalid number".  When I use Macro->Open Form and choose open_project_file and then Load and Run, then the form comes up and seems to work.

However, when I typed "don" it restricted the list to things that matched "do" but included several things that did not match "don".  When I typed Backspace, then it restricted the list to things that matched "don".  So I think Backspace still isn't working right at the moment, nor is normal typing.

What features (besides newly recognizing the / character) does open_project_file have over the built in Files toolbar?  I have a todo item on my list to make the Files toolbar support matching the FILESEP and FILESEP2 characters (basically I plan to change it so it compares against the full path instead of only the file name, and append "[^"_escape_re_chars(FILESEP:+FILESEP2)"]" to the end of the needle string; modulo whatever tweaks are needed to work successfully ;)).

hs2

  • Senior Community Member
  • Posts: 2738
  • Hero Points: 288
Re: Open project file macro and new open local symbol macro
« Reply #19 on: May 06, 2008, 06:43:13 pm »
@chrisant: Be aware that the Files TB uses a super-fast DLL function _FilterTreeControl() to do the filtering.
For large scale projects it makes a BIG difference in comparison with using the Slick-C macro code (which is still there but #ifdef'd). Maybe it's a good idea to send a feature request regarding an enhancement of this function.
HS2

asandler

  • Senior Community Member
  • Posts: 303
  • Hero Points: 27
Re: Open project file macro and new open local symbol macro
« Reply #20 on: May 06, 2008, 09:23:24 pm »
@chrisant

First, don't try to load it via command line (i.e. SE's command line) or Macro->Open Form. The right way is to assign a keyboard shortcut to -open-project-file.

As for problem with "do"s and "don"s, can you please bit a little more specific. Can you please post names of the files in your project - this will allow me to reproduce the problem and fix it. What was the search pattern you used and what is the result you expected to see. Also, what version of SlickEdit you have?

The idea behind this macro and its main feature is to let you find file-name when you know only part of the file-name and perhaps part of the path to the file relative to project root directory. For example. Let's say you have a file blah/boom/foo/file.c you know that its name is "file.c" and that it is somewhere in blah directory. This is a very common situation with large projects. Using macro you can type in "blah file" and it will locate every file named ".*file.*" located in directory matching ".*blah.*".
The actual '/' character translated into space, so "blah file" and "blah/file" will produce exactly same results. Instead I match last word in the search pattern against file names while earlier words are matched against names of directories in the path (have to mention this somewhere in documentation :D).

I hope this answers your questions.

PS: Found and fixed another bug in the version. 1.0.9 coming tomorrow.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Open project file macro and new open local symbol macro
« Reply #21 on: May 11, 2008, 06:26:50 am »
As for problem with "do"s and "don"s, can you please bit a little more specific. Can you please post names of the files in your project - this will allow me to reproduce the problem and fix it. What was the search pattern you used and what is the result you expected to see. Also, what version of SlickEdit you have?

It's such a basic problem that you couldn't miss it, so maybe it only happens on SE 13, or maybe it is somehow being affected by some other macro.  I'll try to describe it more thoroughly:

SlickEdit 13.0.0 r17, on Vista.

Suppose the project has 3 files:
A.c
Ab.c
D.c

Steps:
1.  Press the key bound to -open-project-file.
      Result: the dialog opens and lists all files:  A.c, Ab.c, D.c.
2.  Type a letter that you expect will filter the list:  in this example, try "a".
      Result: the letter appears in the text box at the top, but the list is not filtered at all yet, it still lists all files:  A.c, Ab.c, D.c (it should list only files that match "a", so it should only list A.c, Ab.c).
3.  Type a second letter that you expect to further filter the list:  in this example, try "b".
      Result: now the list gets filtered per the letter you typed in step 2 (but not step 3):  it lists A.c, Ab.c (it should list only files that match "ab", so it should only list Ab.c).
4.  Press the Backspace key.
      Result: now the list is filtered by both the characters from steps 2 and 3:  it lists only Ab.c (it should list files that match "a", so it should list A.c, Ab.c).

asandler

  • Senior Community Member
  • Posts: 303
  • Hero Points: 27
Re: Open project file macro and new open local symbol macro
« Reply #22 on: May 11, 2008, 07:16:49 am »
@chrisant
Thanks a lot for thorough bug report!
This is the exact problem I fixed in 1.0.9. Here's the new version.

The problem is that tree control in SE refreshes itself before you make change to nodes and not after. So when you pressed "a" character in step 2, it kept showing all files. Then when you pressed "b" in step 3, the tree got redrawn before the macro started modifying tree contents, so it showed files matching "a" pattern.
To fix that, I added a call to _TreeRefresh() every time I make changes to the tree. This makes sure that tree shows most uptodate information.

mikesart

  • Community Member
  • Posts: 56
  • Hero Points: 11
Re: Open project file macro and new open local symbol macro
« Reply #23 on: May 12, 2008, 08:21:40 pm »
I'm having some troubles with this macro and absolute paths. [SE v13 and Windows.] My project properties has files listed as such:

  ..\..\slickedit2008\sysconfig\vscpp.h
  ..\..\slickedit2008\sysconfig\vsparser\vscpp.h
  \dev\smac\bin\b.bat
  \dev\smac\bin\build.php

When I try to open vscpp.h, it works. When I try to open b.bat or build.php, it fails in opf_files.on_change() because of the strip_filename(name, "D") logic. This code:

Code: [Select]
   if (reason == CHANGE_LEAF_ENTER) {
      name = _TreeGetCaption( index );
say("name:'" name "'");
say("strip_filename( name, 'D' ):'" strip_filename( name, "D" ) "'");
      // If after stripping path filename remains the same, we should append project directory
      // to filename as the name is relative to project path. Otherwise we should use the name
      // as is.
      if (strip_filename( name, "D" ) == name) {
         proj = _project_get_filename();
say("proj0:'" proj "'");
         proj = strip_filename( proj, "N" );
say("proj1:'" proj "'");
         name = proj :+ name;
say("name:'" name "'");
      }

produces this result:

  name:'/dev/smac/bin/b.bat'
  strip_filename( name, 'D' ):'/dev/smac/bin/b.bat'
  proj0:'c:\slm\slickedit2008_projects\SlickC\SlickC.vpj'
  proj1:'c:\slm\slickedit2008_projects\SlickC\'
  name:'c:\slm\slickedit2008_projects\SlickC\/dev/smac/bin/b.bat'

I'm not sure what the best way to fix this would be, but I'm guessing that maybe it should be checking for the leading '.' to find relative paths?

Thanks much,
 -Mike

asandler

  • Senior Community Member
  • Posts: 303
  • Hero Points: 27
Re: Open project file macro and new open local symbol macro
« Reply #24 on: May 14, 2008, 07:39:31 am »
@mikesart
Thanks a lot for reporting this. I am sorry but it will take me some time to fix this problem because I don't have SE2008 at the moment - I used trial version to test the macro on SE2008, but this is now over. I'll think of a solution, but it will take some time.

mikesart

  • Community Member
  • Posts: 56
  • Hero Points: 11
Re: Open project file macro and new open local symbol macro
« Reply #25 on: May 14, 2008, 10:23:45 pm »
I changed this line:
    if (strip_filename( name, "D" ) == name) {
to this:
    if(substr_(name, 1, 1) :== '.' ) {

*** Note I had to add the '_' after substr_ otherwise I keep getting "POST to /index.php not supported" when trying to preview or post this message. This occurs in code blocks as well.

And it seemed to work decently well. At least in my projects.

Couple of other things:

 1. Periods are treated as regex match any char. So when trying to open "blah.h", I also got hits for "blah_hook.cpp". I added this line in opf_string_match() to fix this for me:
    regex = stranslate( regex, "\\.", "." );

 2. I also had similar problems with underscores in filenames. So I replaced this line:
    regex = translate( regex, ' ', '_' );
  with this:
    regex = stranslate( regex, "\\_", "_" );

 3. The biggest thing I ran into after all that was the macro only lists files in the current project, not workspace like project-load does. So, for instance, I typically have two projects in my workspace; one is the source code I'm working on and the other is the compiler header files and crt source. Right now opf() won't list any files in the non-default compiler project. I started to took a look at modifying opf() to use code similar to _GetWorkspaceFilesH(), but am a bit short on time at the moment so I'm back to using project-load for now.

These things are probably more specific to how I work though - so please don't worry about spending time adding these features to your macro for just me. I'll make these modifications when I get some more time.

Thanks much asandler,
 -Mike

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Open project file macro and new open local symbol macro
« Reply #26 on: May 14, 2008, 10:33:12 pm »
Re: escaping regex characters, a more general solution would be to call _escape_re_chars which will also catch all of the other regex characters that can lead to problems (such as []()^$ etc).

asandler

  • Senior Community Member
  • Posts: 303
  • Hero Points: 27
Re: Open project file macro and new open local symbol macro
« Reply #27 on: May 18, 2008, 01:46:53 pm »
@mikesart: the substr_() instead of strip_filename() fix you suggested breaks the macro - after changing it this way, it fails to open files located in the root directory of the project.

It's evident - this if statement checks whether the file name as we know it consist of file-name only. I.e. it doesn't have prepended path to the file. If it's true, then macro prepends path to the project file to the filename, assuming that file in the same directory as project file. You can try something like this:
if ((strip_filename( name, "D" ) == name) || (substr_( name, 1, 1 ) :== ".")) {
This takes care of both worlds. Please see if it works for you and if so, I'll release a version with a fix.

I agree with 1. Periods should indeed be translated into periods. However, I want to do something different. I want the macro to filter out all header files when you type .c. I.e. today (even with your fix) when the pattern is "ma.c", it will filter out "main.c". I don't want it to do so. Instead I want it to filter out all header files (in addition to all files that do not match "ma"). See my point? What do you think about that?

I also agree with 2. I'll fix it in the next version of the macro. As for point 3, there may be a problem - it's quiet a change and I'll need some time to implement and test it.

Thanks a lot for your help.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Open project file macro and new open local symbol macro
« Reply #28 on: September 03, 2008, 08:13:23 am »
@chrisant: Be aware that the Files TB uses a super-fast DLL function _FilterTreeControl() to do the filtering.
For large scale projects it makes a BIG difference in comparison with using the Slick-C macro code (which is still there but #ifdef'd). Maybe it's a good idea to send a feature request regarding an enhancement of this function.

I can do one better than sending a feature request.  I've written a macro + DLL which provides a "file open" dialog that lists Project files or Workspace files (like the Files toolbar) or files from a specified directory (like the Open toolbar).  It shows the actual file icons, and retrieves the icons on a background thread (so the editor remains responsive even if some icons take extra time to retrieve).

Unlike the Files toolbar, my dialog defaults to using a prefix match.  It supports * and ? wildcards, so use "*foo" to match "foo" anywhere in the file name.

Also unlike the Files toolbar, the files list in my dialog is sorted only by filename, and the path is shown in parentheses after the filename and is colored in gray.  So for example use "bar\*foo" to match "foo" anywhere in the file name for files in a path ending in "bar".

I'll post it in a separate thread in a week or so after adding a few more minor improvements.  And I'll include full source code, too (even for the DLL).

A couple quick screen shots attached here for illustration.

hs2

  • Senior Community Member
  • Posts: 2738
  • Hero Points: 288
Re: Open project file macro and new open local symbol macro
« Reply #29 on: September 03, 2008, 10:17:23 pm »
Very promising chrisant - and good luck getting it done !
Do you plan to add any options (e.g. strict prefix match, CaSe sens. etc. ) just as variable or maybe even w/ GUI support ?
HS2