How to open a selected file name or file name under cursor via right click?

How to open a selected file name or file name under cursor via right click?

2
NewbieNewbie
2

    Aug 25, 2008#1

    In UE V12.xxx I was able to select a string in a file and right click the mouse to get to a selection to "open" the file name.

    For instance if I had a text file with a line

    foo.txt - this is a sample file name

    and I selected the "foo.txt" part of the line, I could then right click and select "open" to open foo.txt in the editor.

    I cannot find this option in UE V14. How do I get it back? It was one of the features I used literally everyday.

    I was able to open the file, just not if it has a line number after the file name. I used to be able to open a file and position the cursor on a specified line number.

    What is the magic to do this in UE v14?

    Robb Cole

    6,675585
    Grand MasterGrand Master
    6,675585

      Aug 26, 2008#2

      I have run a Find In Files with results to an edit window and it looks as follows:

      Code: Select all

      ----------------------------------------
      Find 'ReceiveVe' in 'F:\Temp\Rs232Ve.cpp':
      F:\Temp\Rs232Ve.cpp(1619):   return ...
      F:\Temp\Rs232Ve.cpp(1654): BOOL ...
      F:\Temp\Rs232Ve.cpp(2010):   if( ...
      F:\Temp\Rs232Ve.cpp(2012):     SendToErrorExtLogPipe( ...
      Found 'ReceiveVe' 4 time(s).
      Search complete, found 'ReceiveVe' 4 time(s). (1 file(s)).
      If I now set the cursor anywhere inside F:\Temp\Rs232Ve.cpp(1619) without selecting it and press the right mouse button, UltraEdit v14.10.0.1024 displays at top of the context menu Open "F:\Temp\Rs232Ve.cpp/1619" and if I click now on this item, the file is opened and the cursor is positioned at start of line 1619. You don't need to select a file name. UltraEdit will always check the string at current cursor position if this is a file name (with line number) or a url when you press the right mouse button in the edit window.

      If I select just the complete file name without (1619) and click the right mouse button, the context menu contains at top Open "F:\Temp\Rs232Ve.cpp" and opens next this file with the cursor at top of this file.

      If I select only Rs232Ve.cpp and click the right mouse button, UltraEdit checks in the background, if a file with that name exists in the current working directory. If this is the case, the context menu shows at top Open "Rs232Ve.cpp" and I can open that file. But if the file does not exist in the current working directory, the context menu does not contain any entry to open a file "selected text".

      So your problem is that the file you want to open is not in the current working directory. What is the current working directory?

      Well, normally it is the directory specified in the shortcut to UltraEdit at Start In. But if you have not started UltraEdit with the shortcut, it is the program directory or the directory of the file you opened with a double click. It can be also the directory of the file you last opened. Or it is the directory of the file which currently has the focus. There are several configuration settings to determine what UltraEdit should use as current working directory.

      So the feature works quite well. UltraEdit just can't find the file with the name you have selected because of missing the path and it can't find a file with that name in the current working directory of UltraEdit.

      By the way: The line number could be also appended to the file name with /1619 instead of (1619).

      And without testing it I think UltraEdit searches for a file with a relative path (file name without full path) additionally to the current working directory also relative to the project directory if a project/workspace is loaded which contains the path to the project directory.

      2
      NewbieNewbie
      2

        Sep 17, 2008#3

        Mofi, that was the answer.

        I was used to having to actually *select* the file name (and manually change the (###) to /### to get to a specific line).

        This new (to me) function is way better. Once again, the UE developer(s) have really improved the product.

        3
        NewbieNewbie
        3

          Mar 04, 2009#4

          Hi,

          I am using v13 of UE. I also use open highlighted file a lot. Problem is that if the highlighted file is not in the same directory as the current file, it doesn't find it. Is there any way to specify a list of paths to look for (either absolute or relative) when using this feature? In the least is there a way to specify to look into the current file directory as well as subdirectories?

          thanks.

          6,675585
          Grand MasterGrand Master
          6,675585

            Mar 07, 2009#5

            So you have in your files only the name of a file without it's path. In this case UltraEdit looks in the current working directory if the file exists in this directory. What is the current working directory? Well, that is not easy to answer.

            The current working directory is by Windows default the directory active on starting an application like UltraEdit. For example if you start UltraEdit with a shortcut on your desktop, it is the directory specified in the shortcut properties under "Start In". If you start uedit32.exe from the command line, the current working directory is the directory where you are currently in when you execute uedit32.exe. If you double click on a file with an extension associated with UltraEdit, the directory of the file is the working directory. I have never analyzed which directory is the current working directory when using the shell integration because I don't use the UltraEdit shell integration (not needed because of using Total Commander as file manager).

            For first "File - Open" after starting UltaEdit without opening a file, where many applications either use the current working directory or always "My Documents", UltraEdit overwrites this default Windows behavior and sets the current working directory to the folder of the last edited file as stored in the INI file or registry. So if you don't use the option to reload all files opend on last exit and for example start UltraEdit with the shortcut, the working directory is the directory of the last edited file. That's great if you want to re-open that file or another one in this directory now.

            But UltraEdit has many other options. With Use default directory from shortcut on initial file open enabled at Configuration - File Handling - Load the special default behavior of UltraEdit can be disabled and the Windows standard behavior for the initial file open using the "start in" folder can be activated.
            I use the setting Use active file directory for file open dialog default also in Configuration - File Handling - Load. With that setting enabled the current working directory for file open is always the directory of the active file. If there is no file open, the directory of the last edited file is used.
            But if no file is open or the setting above is not enabled, it is also possible to use for "File - Open" a directory specified at Configuration - Directories.

            But there is something which most Windows programmers don't know. Whenever a file is opened using the standard Windows "File Open" dialog, the function of the dialog sets the current working directory for this application to the directory of the opened file. So every file open using "File - Open" changes the current working directory of UltraEdit until next "File - Open". That is a problem if a user opens a file, edit something or just look on it, close the file, but not UltraEdit, and now wants to delete the directory. Windows NT, 2K, XP, etc. (not Win98) does not allow you in this case to delete the directory because it is the working directory for still running UltraEdit. That's the reason why since UE v12.20 UltraEdit automatically changes in the background the working directory for itself if no file in this directory is open anymore. I think the working directory is set in this case to the UltraEdit program directory which surely exists and surely can't be deleted while UltraEdit is running, but I have never looked into this behavior.

            I have not yet analyzed for the Open File Under Cursor feature if additionally to the working directory also the specified project directory is searched for a file with a relative or no path as it is done when double clicking on a file name with no or a relative file path in the output window and a project is currently open.


            Back to your question: No, it is not possible to specify a list of directories where UltraEdit should search for a file with a relative path. It is also not possible to specify that UltraEdit should search for a file with a relative path in the current working directory and all subdirectories which would be a very dangerous option if the current working directory is C:\. You can imagine that you would have to wait a very long time until UltraEdit would again respond to your inputs or shows you the context menu when it has to search for a file in all directories of a drive. So you can play only with the configuration settings which determine the current working directory.

            Extra hint: In the dialog opened with "File - Quick Open" you can always see what is the current working directory. And this dialog is very handy to quickly open 1 or more files because you can enter or paste a file name with full path or a file name with a relative path. And it is also possible to use wildcards in this dialog. For example if I know that in the directory I'm currently working in there is a file "resource.h" and there is no other file starting with "res" and I want to open that file, I press Ctrl+Q, enter "res*" and press RETURN.

            3
            NewbieNewbie
            3

              Mar 10, 2009#6

              This is my configuration:

              \source_root
              |--\dirA
              |--\dirB
              ....|--\dirB1
              ....|--\dirB2

              In UE I have files open from one or more directories, which reference files in other directories. so i want to be able to highlight a filename within a file in source_root (or any other directory) and be able to open it. Currently UE only opens the file within the same directory, and fails if the filename is in any other directory.

              It appears that currently we can't do this in UE, but it will be a nice feature to have. build scripts as able to handle files from any directory, so it have become customary not to specify the relative path of the filename in any file.

              6,675585
              Grand MasterGrand Master
              6,675585

                Mar 11, 2009#7

                Well, you could write a script which searches for the unique file name in source_root and all its subdirectories and when the file is found, opens it. For example you can use my function GetListOfFiles to find the file in any directory from a fixed source_root and get the full file name for opening it.

                Code: Select all

                if (UltraEdit.activeDocument.isSel()) {
                   // var g_nDebugMessage = 0;
                   var sFileName = UltraEdit.activeDocument.selection;
                   if (GetListOfFiles (0, "absolute path of source_root\\", sFileName, true)) {
                      UltraEdit.activeDocument.startSelect();
                      UltraEdit.activeDocument.key("END");
                      sFileName = UltraEdit.activeDocument.selection;
                      UltraEdit.activeDocument.endSelect();
                      UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                      UltraEdit.open(sFileName);
                   }
                }
                Add this script to the list of scripts and assign a hotkey. Now you can select a file name and press the hotkey to open that file. By default you get an error message if the file could not be found. You can change this error handling by removing the line comment on the line var g_nDebugMessage = 0;

                3
                NewbieNewbie
                3

                  Mar 16, 2009#8

                  Thanks a lot! This did the trick :)

                  29
                  Basic UserBasic User
                  29

                    Jul 15, 2009#9

                    The posts above were interesting, but does not apply in my case since I am not selecting any text and always have full paths. I can't reproduce it at the moment, but there was a case where I had 2 files open, one pointing to local paths (C:) and another to a network drive (E:) and in the one file it opened them at the correct line with /line number and the other wanted (line number).

                    I assume this is abnormal behaviour...

                    6,675585
                    Grand MasterGrand Master
                    6,675585

                      Jul 15, 2009#10

                      When you next time can reproduce the abnormal behavior, look on the menu item name at top of the context menu before you click on it and verify if UltraEdit has recognized the line number too. The line number is shown also in the context menu after a / when UE has recognized it.

                      29
                      Basic UserBasic User
                      29

                        Jul 15, 2009#11

                        I have the following file content in a file called custom.php:
                        E:\kb\includes\classes\class.search.parent.php/27
                        E:\kb\includes\classes\class.search.parent.php(27)

                        When I right-click on the first it says: Open "E:\kb\includes\classes\class.s..." and it opens on line 27.

                        When I right-click on the second it says: Open "E:\kb\includes\classes\class.s..." and it opens on line 1.

                        Basically, I don't see any line numbers in the context menu.

                        6,675585
                        Grand MasterGrand Master
                        6,675585

                          Jul 15, 2009#12

                          Okay, your file name was too long and therefore truncated in the context menu with ... at the end.

                          So I tried it now with following:

                          F:\Temp\Test.tmp/25
                          F:\Temp\Test.tmp/25:
                          F:\Temp\Test.tmp(25)
                          F:\Temp\Test.tmp(25):

                          Opening Test.tmp and setting cursor to start of line 25 works except for the red written example as I could see even before opening already in the context menu. I can only guess what is the reason. F:\Temp\Test.tmp(25) is a valid file name while the others are not valid file names because of / and/or the : at the end of the string. I further suppose that UltraEdit searches for the file F:\Temp\Test.tmp(25) and can't find it in F:\Temp\ and therefore searches next for F:\Temp\Test.tmp which is found. So the algorithm used now thinks that this string is a file name and (25) is something other, but not a line number.

                          29
                          Basic UserBasic User
                          29

                            Jul 20, 2009#13

                            OK the current situation is that this doesn't work:
                            ..\includes\classes\class.auth.php(30):

                            While this does:
                            ..\includes\classes\class.auth.php/30

                            This seems to indicate that it's not about valid or invalid file names because class.auth.php(30): is not a valid file name. I think we need to report this as a bug...

                            6,675585
                            Grand MasterGrand Master
                            6,675585

                              Jul 21, 2009#14

                              cawoodm wrote:I think we need to report this as a bug...
                              I agree. Please report this bug by email to IDM.

                              I recreated your environment by creating a file F:\includes\classes\class.auth.php with more than 30 lines. Then I opened a new file, pasted your 2 file name strings and saved the file as F:\Temp\Test.tmp. So the working directory is F:\Temp\ and the relative path is therefore correct.

                              Clicking on ..\includes\classes\class.auth.php(30): results in opening the file, but cursor is at top of the file. Doing the same on ..\includes\classes\class.auth.php/30 results in opening the file and cursor is at line 30. So I reproduced the problem.

                              Next I replaced ..\ by F:\ for the first example and now it works correct, the file is opened and the cursor is at line 30.