Menu

Clickable links

2007-11-02
2012-11-13
  • Nobody/Anonymous

    Is there any reason for not including 'file://' and 'mailto:' in the 'Clickable links'?
    I would like to have them too.

     
    • Vivian De Smedt

      Vivian De Smedt - 2007-12-02

      I finally did what I have proposed I have modified the

      in Notepad_Plus.cpp I have make the following changes:

          const char *urlHttpRegExpr = "http://[a-z0-9_\\-\\+.:?&@=/%#]*";

      become:

          const char *urlHttpRegExpr = "\"([a-z\\.:]+[/\\\\].*)\"";

      I have slightly modified:

      <pre>
          case SCN_HOTSPOTDOUBLECLICK :
          {
              _pEditView->execute(SCI_SETWORDCHARS, 0, (LPARAM)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-+.:?&@=/\\%#");
             
              int pos = _pEditView->execute(SCI_GETCURRENTPOS);
              int startPos = static_cast<int>(_pEditView->execute(SCI_WORDSTARTPOSITION, pos, false));
              int endPos = static_cast<int>(_pEditView->execute(SCI_WORDENDPOSITION, pos, false));

              _pEditView->execute(SCI_SETTARGETSTART, startPos);
              _pEditView->execute(SCI_SETTARGETEND, endPos);
         
              int posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(urlHttpRegExpr), (LPARAM)urlHttpRegExpr);
              if (posFound != -1)
              {
                  startPos = int(_pEditView->execute(SCI_GETTARGETSTART));
                  endPos = int(_pEditView->execute(SCI_GETTARGETEND));
              }

              char currentWord[MAX_PATH*2];
              _pEditView->getText(currentWord, startPos, endPos);

      <b>
              if (strlen(currentWord) <= 0)
                  break;

              const char *fileName = _pEditView->getCurrentTitle();
              //::GetFullPathName(fileName, MAX_PATH, longFileName, NULL);
              char folderName[MAX_PATH];
              strcpy(folderName, fileName);

              for (int i = strlen(folderName); i > 0;) {
                  char c = folderName[--i];
                  if (c != '\\')
                      continue;

                  folderName[i] = '\0';
                  break;
              }

              if (currentWord[0] == '.') {
                  char fileName[MAX_PATH];
                  strcpy(fileName, folderName);
                  strcat(fileName, "\\");

                  int len = strlen(currentWord);
                  if (currentWord[len - 1] == '"')
                      currentWord[len - 1] = '\0';

                  for (int i = len; i > 0;) {
                      char c = currentWord[--i];
                      if (c == '/')
                          currentWord[i] = '\\';
                  }

                  strcat(fileName, currentWord);
                  doOpen(fileName);
              }
              else {
                  ::ShellExecute(_hSelf, "open", currentWord, NULL, folderName, SW_SHOW);
              }
      </b>
              _isHotspotDblClicked = true;
              _pEditView->execute(SCI_SETCHARSDEFAULT);
              break;
          }
      </pre>

      To open the file into notpad instead that into the default shell editor.

      And since the regular expression check for quote for backward compatibility I did change the function that highlight the link:

          int posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(urlHttpRegExpr), (LPARAM)urlHttpRegExpr);

          while (posFound != -1)
          {
              int start = int(_pEditView->execute(SCI_GETTARGETSTART)) <b>+ 1</b>;
              int end = int(_pEditView->execute(SCI_GETTARGETEND)) <b>- 1</b>;
              int foundTextLen = end - start;
              int idStyle = _pEditView->execute(SCI_GETSTYLEAT, posFound);

              if (end < posBegin2style - 1)
              {
                  if (style_hotspot > 1)
                      style_hotspot--;
              }
              else

       
    • Vivian De Smedt

      Vivian De Smedt - 2007-12-02

      Don,

      Sorry for the previous post that seems more or less unreadable. I just write it to tell you that I did some change in my version of Notepad++ and I'm happy with it.

      When I have a file opened in NotePad++ that reference an another one the new feature let me jump from the first to the second in one double-click :-)

      It is nice to jump to the .css file or the .js used in an html file.
      It is nice for my configuration files that reference other configuration files.

      It is exactly the same feature that UltraEdit and PsPad have. It is just better because you just have to double click instead of using an context menu or a keyboard shortcuts.

      It could be improved for c++ since I don't underline
          #include "brol.h"
      or
          #include <stdio.h>

      and all the path are considered relative to the path of the file itself and in c++ you can have special folder where the preprocessor will look for includes. But maybe this is too sophisticate for a text editor.

      But for html and configuration I think it is a nice addition.

      Please tell me what you think about my proposition.
      I'll be very proud to contribute a bit to Notepad++

      If you plan consider my patch don't hesitate to ask me any information you want that can help you inserting my code into the main trunk.

      Yours,
      Vivian De Smedt.

       
      • Don HO

        Don HO - 2007-12-03

        Please send your patch to :
        don_POINT_h_AT_free_POINT_fr

        I will try it out and tell you what I think.

        Don

         
    • Vivian De Smedt

      Vivian De Smedt - 2007-12-04

      Done from vds@aisystems.be :-)

      I sent you a .zip file containing my version of Notepad_plus.cpp if you prefer a diff please tell me so.

      Vivian.

       
    • Vivian De Smedt

      Vivian De Smedt - 2007-11-02

      This small message to add my voice to this request.

      I use texteditor to manage configuration files. These configuration files often refers to other configuration files and it is very convenient to switch from one to the other using the link functionality. In particular it is a very good way of:
      - being sure that you open the right file or of
      - being sure that you didn't misspelled the path

      It will be nice if we could have such a link, with a default to the file: protocol, for every quoted string. It will address the configuration file problem but also the C++ #include and html links.

      I'm currently using such functionality implemented in other text editor and I love it :-)

      Vivian.

      Thank you very much for Notepad++ which is wonderful and even more impressive at each release.

       
      • Don HO

        Don HO - 2007-11-02

        This feature uses the scintilla native reg exp which is quite limited.
        So for long term the reg exp part should be enhanced in Notepad++, it will resolve a lot of issue, include this one.

        OTOH, you are welcome to look into the source code concerning this part :
        If you have another solution to add another protocol WITHOUT PARSING THE SECOND TIME the whole file, please let me know.

        Don

         
    • Vivian De Smedt

      Vivian De Smedt - 2007-11-19

      Thank you for you answer. I'll try to know more about scintilla in order to be able to make you some propositions :-)

       
    • Vivian De Smedt

      Vivian De Smedt - 2007-11-19

      Could we imagine to let the user choose the regular expression that you use to parse the file and extract the url to open?

      If the string contains a protocol (http://, ftp://, file://) notepad++ could use that protocol to open the file. If the string do not contains any protocol notepad++ will use a default file:// protocol.

      I'm thinking about using "([a-z\.:]+[/\\].*)" that should match:
          "http://myhost.com/myscript.js"
          "file://C:/myfolder/myscript.js"
          "./myfolder/myscript.js"
          "C:\myfolder\myscript.js"

      But not:
          "hello"
          "tom:"
          " This is a sentence."

      Basically the string that contains a '/' or a '\' will be candidate for path.

      Tell me what you think about my proposition.

      Vivian.

       
    • Vivian De Smedt

      Vivian De Smedt - 2007-11-19

      Post Script: My first version of the regular expression was not correct. I have tested the following one on scite which should then a better candidate:
          "([a-z\.:]+[/\\].*)"

      Vivian.

       
    • Vivian De Smedt

      Vivian De Smedt - 2007-12-19

      Don,

      Sorry to bother you with that, you are probably busy with other things but I'll be glad if you could tell me if you received my patch and if yes if it is in a form that you can deal with.

      Regards,
      Vivian.