Community
    • Login

    Save found files?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    26 Posts 5 Posters 3.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Alan KilbornA
      Alan Kilborn
      last edited by Alan Kilborn

      I probably also should add that the files copied by the script are going to be the disk copies of the files. Notepad++ does an in-memory search rather than a disk search when it produces its hit list. So if any of the hit files are dirty/modified/red-iconned when the search is conducted, the file contents that actually get copied are going to be different than the modified contents.

      TL;DR: Save all Notepad++ files (so that none have red icons) before running the script – or when doing Eko’s originally suggested solution!

      1 Reply Last reply Reply Quote 2
      • guy038G
        guy038
        last edited by guy038

        Hi, @ekopalypse, @alan-kilborn and All,

        I did a quick test and I confirm that the Alan’s behavior seems to be the default one !

        My configuration :

        Notepad++ v7.8.1   (32-bit)
        Build time : Oct 27 2019 - 22:46:07
        Path : D:\@@\781\notepad++.exe
        Admin mode : OFF
        Local Conf mode : ON
        OS Name : Microsoft Windows XP (32-bit) 
        OS Build : 2600.0
        Plugins : DSpellCheck.dll ExtSettings.dll mimeTools.dll NppConverter.dll NppExport.dll 
        

        • A Ctrl + A action ( or right-click on the Select All option ), followed with an Ctrl + C action and, finally, a Ctrl + V action, in a new tab, do copy all Find result contents. So your regex works fine, extracting the absolute pathnames of all the files involved in the search !

        • A Ctrl + A action ( or right-click on the Select All option ), followed with a right-click on the Copy option and, finally, a Ctrl + V action, in a new tab, only copy the lines, containing the matched string, from all the files scanned, in the Find result window

        May be a plugin issue ?

        Best Regards

        guy038

        Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 2
        • Alan KilbornA
          Alan Kilborn @guy038
          last edited by

          @guy038 said :

          May be a plugin issue ?

          This is a good point. @Ekopalypse can you try testing this copy/paste behavior again with a very-clean 7.8.1?

          1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @guy038
            last edited by

            @guy038 said in Save found files?:

            • A Ctrl + A action ( or right-click on the Select All option ), followed with an Ctrl + C action and, finally, a Ctrl + V action, in a new tab, do copy all Find result contents. So your regex works fine, extracting the absolute pathnames of all the files involved in the search !

            • A Ctrl + A action ( or right-click on the Select All option ), followed with a right-click on the Copy option and, finally, a Ctrl + V action, in a new tab, only copy the lines, containing the matched string, from all the files scanned, in the Find result window

            I thought I would emphasize this to @Ekopalypse : the behavior is different depending on whether you use keystrokes or menu selection for the copy. I just replicated this on portable 7.8.1-64bit. If you use the Ctrl+C keystroke, it copies the filename; if you use RClick > Copy, it only copies the lines, not the filenames. (I also confirmed that you cannot use File > Copy, because that’s using the active editor window, even when Find result is the foreground pane.) I pasted not only into Notepad++, but into other apps as well, confirming that it’s actually the copy-operation that’s different depending on Ctrl+C vs RClick > Copy.

            I went back to my 7.7.1-64bit, and it behaves the same way, with Ctrl+C vs RClick > Copy having separate behavior.

            Alan KilbornA 1 Reply Last reply Reply Quote 2
            • Alan KilbornA
              Alan Kilborn @PeterJones
              last edited by

              @PeterJones said:

              (I also confirmed that you cannot use File > Copy, because that’s using the active editor window, even when Find result is the foreground pane.)

              Presume you meant:

              (I also confirmed that you cannot use Edit > Copy, because that’s using the active editor window, even when Find result is the foreground pane.)

              1 Reply Last reply Reply Quote 2
              • EkopalypseE
                Ekopalypse
                last edited by

                I’m still a little bit confused as it seems to work most of the time like Peter described
                but sometimes it doesn’t, means I don’t get the filename lines copied into clipboard.
                Using a fresh portable 7.8.1 x64 version. Need to do further tests to see if I can find
                a reproducible way.

                1 Reply Last reply Reply Quote 1
                • Patricia MayerP
                  Patricia Mayer
                  last edited by Patricia Mayer

                  @Alan-Kilborn FANTASTIC! Thank you so much, it works perfectly. My colleague and I are delighted. :))

                  Thank you other guys as well.

                  Awesome forum.

                  1 Reply Last reply Reply Quote 2
                  • Alan KilbornA
                    Alan Kilborn
                    last edited by

                    My script code has a .getText function on the FindResultPanel object.
                    With it I can, obviously, get the text of the Find-result window.
                    However, I’d like to be able to get the matching text, but I don’t know how to accomplish this.
                    Visually, I can see the hit results in the window as red text on a yellow background.
                    Anyone know how I can pull this information?

                    EkopalypseE 1 Reply Last reply Reply Quote 0
                    • EkopalypseE
                      Ekopalypse @Alan Kilborn
                      last edited by

                      @Alan-Kilborn

                      Why not using the styling information to identify the matched text?

                      Alan KilbornA 2 Replies Last reply Reply Quote 2
                      • Alan KilbornA
                        Alan Kilborn @Ekopalypse
                        last edited by

                        @Ekopalypse said in Save found files?:

                        Why not using the styling information to identify the matched text?

                        Well, TBH when I earlier went searching in the N++ source code for SCE_SEARCHRESULT_*, I saw no occurrences of SCE_SEARCHRESULT_WORD2SEARCH occurring at all, so I was confused as to how it worked and was thinking it might not be possible at all to get this info via PS, even with ctypes usage.

                        But with some experimentation with SCI_GETSTYLEAT it seems that I can recall the info; for example, in my “hit” text I get a style result of 4, which is indeed SCE_SEARCHRESULT_WORD2SEARCH.

                        Is N++ source using hardcoded magic numbers for this instead of the “tags”, or some other mechanism that is strange or at least isn’t clear to me?

                        Hmm, had a thought to search the Scintilla part of N++, where I do see SCE_SEARCHRESULT_WORD2SEARCH used. That must be how it is done.

                        1 Reply Last reply Reply Quote 2
                        • Alan KilbornA
                          Alan Kilborn @Ekopalypse
                          last edited by

                          @Ekopalypse

                          BTW, I’m still confused after looking at N++ source on how N++ identifies the hit text, so that the “search result” lexer knows where it is, so if you can shed any light on that… if you’re sufficiently interested in doing so… :-)

                          EkopalypseE 2 Replies Last reply Reply Quote 1
                          • EkopalypseE
                            Ekopalypse @Alan Kilborn
                            last edited by

                            @Alan-Kilborn

                            Is N++ source using hardcoded magic numbers for this instead of

                            Not sure I understand the question correctly.
                            Every lexer has hard coded style ids, which then get mapped
                            with a color via stylers.xml. See searchResult.

                            how N++ identifies the hit text

                            It uses an internal struct MarkingsStruct which seems to be filled and provided
                            as a property to the document. Maybe something you can use to your advantage?

                            1 Reply Last reply Reply Quote 1
                            • EkopalypseE
                              Ekopalypse
                              last edited by

                              Sorry, Forgot to include the structure reference.

                              1 Reply Last reply Reply Quote 1
                              • EkopalypseE
                                Ekopalypse @Alan Kilborn
                                last edited by Ekopalypse

                                @Alan-Kilborn

                                Made me a bit of a headache because I assumed that the pointer was an integer data type
                                but the npp code actually said that it was a const char pointer.
                                In short, here’s a python script that can determine the positions of the matches.

                                I leave the changes from py3 to py2 to you :-)

                                class SearchResultMarking(ctypes.Structure):
                                    _fields_ = [('_start', ctypes.c_long),
                                                ('_end', ctypes.c_long)]
                                
                                
                                class SearchResultMarkings(ctypes.Structure):
                                    _fields_ = [('_length', ctypes.c_long),
                                                ('_markings', ctypes.POINTER(SearchResultMarking))]
                                
                                
                                # const char *addrMarkingsStruct = (styler.pprops)->Get("@MarkingsStruct");
                                addrMarkingsStruct = f_editor.getProperty("@MarkingsStruct").encode()
                                
                                # SearchResultMarkings* pMarkings = NULL;
                                pMarkings = ctypes.pointer(SearchResultMarkings())
                                
                                # sscanf(addrMarkingsStruct, "%p", (void**)&pMarkings);
                                ctypes.cdll.msvcrt.sscanf(addrMarkingsStruct, b"%p", ctypes.byref(pMarkings))
                                
                                for i in range(pMarkings.contents._length):
                                    print(f'line {i} start:{pMarkings.contents._markings[i]._start} - end:{pMarkings.contents._markings[i]._end}')
                                
                                Alan KilbornA 1 Reply Last reply Reply Quote 2
                                • Alan KilbornA
                                  Alan Kilborn @Ekopalypse
                                  last edited by

                                  @Ekopalypse said in Save found files?:

                                  I leave the changes from py3 to py2 to you

                                  Not a big burden, only the “print” line for that…

                                  But…What’s your magic behind f_editor? Instead of that I would have expected something like what I did in the earlier code I posted in this thread; something much messier, like:

                                  ctypes.WinDLL('SciLexer.dll', use_last_error=True).Scintilla_DirectFunction(self.direct_pointer, 2182, length_of_text, text_of_document)```
                                  
                                  but using a different number than `2182` and different parameters, of course...
                                  EkopalypseE 1 Reply Last reply Reply Quote 1
                                  • EkopalypseE
                                    Ekopalypse @Alan Kilborn
                                    last edited by

                                    @Alan-Kilborn

                                    Not a big burden, only the “print” line for that…

                                    and the encode is not needed as py2 returns bytes
                                    as well as the b before the “%p”.

                                    But…What’s your magic behind f_editor?

                                    Nothing, this is just my object which represents the editor in the find in files window.
                                    As you said, what you would have expected must be done on your side.

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post
                                    The Community of users of the Notepad++ text editor.
                                    Powered by NodeBB | Contributors