Viewing 1 post (of 1 total)
  • Author
    Posts
  • #5599

    shaohao
    Member

    This macro is useful when you are reading source code.
    How to use:
    1. Add this macro to toolbar as a button.
    2. Open a source code file.
    3. Move the cursor the the include file string (such as : #include “File.h”, move the cursor to “File.h” or just click the file name to select the string)
    4. Press the macro button.
    5. The file will be searched in the pre-defined search list and open it when hit.
    6. Add you own search path to “inc” array variable.


    #title = ""
    #tooltip = "Open file under cursor"

    Debug = 0;

    if ( Debug) Window.OutputBar.Clear();
    function OutputDebugStr(str) {
    if ( Debug) {
    Window.OutputBar.writeln( str);
    Window.OutputBar.Visible = true;
    Window.OutputBar.SetFocus();
    }
    }

    // include path as VC++ does
    inc = new Array( "D:SystemMicrosoft Visual Studio 8VCinclude"
    , "D:SystemMicrosoft Visual Studio 8VCatlmfcinclude"
    , "D:SystemMicrosoft Visual Studio 8VCPlatformSDKinclude"
    , "D:SystemMicrosoft Visual Studio 8SDKv2.0include"
    , "D:SystemWTLinclude"
    , "D:SystemwxWidgets-2.8.7include"
    );

    // get position of current cursor
    row = document.selection.GetActivePointY( eePosLogical);
    column = document.selection.GetActivePointX( eePosLogical);

    // get the text of the line where the cursor pointed to
    text = document.GetLine( row);

    // parse the text to get to the file which is going to be opened
    texta = text.split( ' ');
    col = 0;
    fn = '';
    for (var i in texta) {
    len = texta[i].length;
    if ( len == 0)
    col++;
    else
    col += (len+1);
    if ( col >= column) {
    fn = texta[i];
    break;
    }
    }

    // trim the file name
    fn = fn.replace( /[ "<>]/g, "");

    // find file in all pre-defined include directories
    // add current directory into pre-defined list automatically
    inc.unshift( Window.document.Path);
    for (var dir in inc) {
    path = inc[dir] + "" + fn;
    OutputDebugStr(path);
    fso = new ActiveXObject("Scripting.FileSystemObject");
    if ( fso.FileExists( path)) {
    editor.OpenFile( path, 0, eeOpenAllowNewWindow);
    break;
    }
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

Share with friends... Tweet about this on TwitterShare on FacebookShare on Google+Email this to someone