Community
    • Login

    Replace 1 + lines?

    Scheduled Pinned Locked Moved General Discussion
    43 Posts 7 Posters 34.1k 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.
    • guy038G
      guy038
      last edited by guy038

      Hello, @claudia-frank, @Scott-sumner, @pouemes44, @go2to, @jorge-campos, @herofiles, @azjio-azjio, @alan-kilborn and All

      Thanks to @claudia-frank, this present topic and the discussions, below, about multi-lines search AND multi-lines Replacement :

      https://notepad-plus-plus.org/community/topic/13823/replace-function/1

      https://notepad-plus-plus.org/community/topic/13684/feature-request-textarea-search-replace/1

      have, now, an ELEGANT solution, with her Python’s script, just above !

      You just need to be able to do multiple selections ( Option Settings > Preferences… > Editing > Multi-Editing Settings > Enable CHECKED )


      BTW, the upper limit of 2046 characters, in the Find what: box of the Find/Replace dialog, only, could be by-passed, easily :-). Indeed, just use the Regular expression search mode and use the generic regex (?s)Left-boundary.+?Right-boundary !

      For instance, you can choose a particular character, which does not exist,yet, in your file(s) to be modified, and build the regex :

      (?s)(#####\R).+?\1

      This regex contains any non-null amount of characters between TWO same complete lines #####, with their line-breaks

      So :

      • Do a normal selection of this regex (?s)(#####\R).+?\1, using the mouse

      • Then, with a Ctrl + Left Click action, simply, select your Replace block, multi-lines or not

      • Run the Claudia’s script above

      => Immediately, the Find/Replace dialog pops-up and :

      • The Find what: box is filled with the regex (?s)(#####\R).+?\1

      • The Replace with: box is filled with the block of text, which must replace the searched text

      Best Regards,

      guy038

      P.S. :

      @claudia-frank, I understand your point of view. Your script is quite flexible :-D. For instance, I was able to :

      • First, do a Ctrl + Clic selection of a multi-lines block of text

      • Run your script => Find what: box empty and Replace with: box filled with that multi-lines block

      • Select an second file, containing the text (?s)(#####\R).+?\1

      • Do a normal selection of that regex

      • Run again, your script => The find.Replace dialog, presently in the background, is, then, updated with this regex, filled in the Find what: box

      • Select a third file, containing the ##### boundaries lines

      • Perform the S/R on the contents of this third file

      Et voilà !!

      Many thanks, again, for this very, very, valuable script, indeed !!!

      Hum… Already 3 h 25 !! I’d better go to bed : working tomorrow !

      1 Reply Last reply Reply Quote 1
      • AZJIO AZJIOA
        AZJIO AZJIO
        last edited by

        It would be nice if the author would make an additional window when the button is clicked
        [http://radikal.ru/big/m0wcdchejv3ve](link url)

        1 Reply Last reply Reply Quote 0
        • AZJIO AZJIOA
          AZJIO AZJIO
          last edited by

          The external program is working. I make a plugin and no longer works (EnumChildWindows).

          1 Reply Last reply Reply Quote 0
          • Eko palypseE
            Eko palypse
            last edited by

            Sorry, but what are you try to tell us?
            Which external program and which meaning has EnumChildWindows API in this context?

            1 Reply Last reply Reply Quote 0
            • AZJIO AZJIOA
              AZJIO AZJIO
              last edited by

              I wrote a program for the test of regular expressions. It serves as a database. When you click a button, it fills in the search and replace fields.
              I decided to make a plugin that will do the same. But the same program (exe and dll) work differently. EXE fills the fields, but the DLL can not fill.
              I tried using EnumChildWindows to find the elements of the window, as is done in the examples above. But as a result, he found only 3 elements.
              0 hwnd = 725602 Class = Button Title = Caption
              1 hwnd = 2233572 Class = Static Title =
              2 hwnd = 1707882 Class = SysTabControl32 Title = Tab1

              Eko palypseE 1 Reply Last reply Reply Quote 0
              • Eko palypseE
                Eko palypse @AZJIO AZJIO
                last edited by

                @AZJIO-AZJIO

                without seeing/understanding the actual code it is hard to say what might be the issue
                but, personally, I would not recommend using EnumChildWindows when trying to find a
                dialog control window handle, instead use GetDlgItem.

                1 Reply Last reply Reply Quote 0
                • AZJIO AZJIOA
                  AZJIO AZJIO
                  last edited by

                  ; PureBasic
                  hwnd = FindWindowEx_(NppData_nppHandle, 0, “#32770”, 0) ; hwnd = yes
                  If Not IsWindowVisible_(hwnd)
                  SendMessage_(NppData_nppHandle, #NPPM_MENUCOMMAND, 0, #IDM_SEARCH_REPLACE) ; Показать диалог поиска используя команду меню
                  EndIf
                  hwndEdit_1 = GetDlgItem_(hwnd, 1601) ; hwndEdit_1 = 0
                  hwndEdit_2 = GetDlgItem_(hwnd, 1602) ; hwndEdit_2 = 0
                  SendMessage_(hwndEdit_1,#WM_SETTEXT,0,GetGadgetItemText(#Combo_2 , n-1, 0))
                  SendMessage_(hwndEdit_2,#WM_SETTEXT,0,GetGadgetItemText(#Combo_2 , n-1, 1))

                  1 Reply Last reply Reply Quote 0
                  • Eko palypseE
                    Eko palypse
                    last edited by

                    @AZJIO-AZJIO said:

                    #32770

                    be careful about searching for the ordinal only, as every dialog uses it.
                    https://docs.microsoft.com/en-us/windows/desktop/winmsg/about-window-classes
                    Most plugins and internal npp windows are dialogs.

                    1 Reply Last reply Reply Quote 0
                    • AZJIO AZJIOA
                      AZJIO AZJIO
                      last edited by

                      I know it. I do not set the window class. I have no way to change this. The external program, as I said, works.
                      https://a.radikal.ru/a21/1902/55/0723e06a798a.png

                      Eko palypseE 1 Reply Last reply Reply Quote 0
                      • Eko palypseE
                        Eko palypse @AZJIO AZJIO
                        last edited by

                        @AZJIO-AZJIO

                        Sorry, didn’t recognize the update.
                        Windows, sometimes, treats retrieving external and internal information differently.
                        Means, something you retrieved from an exe might differ from something
                        you want to retrieve within its own process.

                        In python, I would it do like this

                        import ctypes
                        user32 = ctypes.WinDLL('user32')
                        hwnd = user32.FindWindowExW(None, None, u'#32770', u'Replace')
                        hwndEdit_1 = user32.GetDlgItem(hwnd, 1601)
                        hwndEdit_2 = user32.GetDlgItem(hwnd, 1602)
                        

                        This takes care that only the dialog with name Replace is found.

                        1 Reply Last reply Reply Quote 1
                        • AZJIO AZJIOA
                          AZJIO AZJIO
                          last edited by

                          I have done just that. Keyword only “Extended”. But using AutoIt3

                          $hWnd = WinGetHandle(“[CLASS:Notepad++]”)
                          If Not @error Then
                          If BitAND(WinGetState($hWnd), 16) Then WinActivate($hWnd)
                          _SendMessage($hWnd, $NPPM_MENUCOMMAND, 0, $IDM_SEARCH_REPLACE)
                          $hWnd = WinWait(“[CLASS:#32770]”, “Extended”, 2)
                          If $hWnd Then
                          ControlSetText($hWnd, “Extended”, “Edit1”, _GUICtrlRichEdit_GetText($hRichEdit_SPE))
                          ControlSetText($hWnd, “Extended”, “Edit2”, GUICtrlRead($PtnRep))
                          ControlCommand($hWnd, “Extended”, “Button18”, ‘Check’) ; 18 - regular expression (16 - normal)
                          EndIf
                          EndIf


                          on PureBasic code is the same for exe and dll. Search window “#32770” starts at the top, so it does not cause a problem. There are either no such windows or they are below.

                          1 Reply Last reply Reply Quote 0
                          • Eko palypseE
                            Eko palypse
                            last edited by

                            Maybe I have a wrong assumption what you are actually doing.
                            When you talk about an exe I assume that this is a different standalone program, correct?
                            When you talked about dll I assumed that this might be a npp plugin.
                            Now I get the feeling this is incorrect. Would you mind to explain what exactly is what
                            and what your ultimate goal is?

                            1 Reply Last reply Reply Quote 0
                            • AZJIO AZJIOA
                              AZJIO AZJIO
                              last edited by

                              Thank! The previous code helped. I saw in it the absence of a handle in FindWindowExW(None
                              I am intensively writing 2 plugins

                              1 Reply Last reply Reply Quote 1
                              • AZJIO AZJIOA
                                AZJIO AZJIO
                                last edited by

                                As a result, several plugins, but there is much to strive for.
                                https://yadi.sk/d/VYtvMq8ECMou9g

                                1 Reply Last reply Reply Quote 1
                                • Alan KilbornA Alan Kilborn referenced this topic on
                                • Alan KilbornA Alan Kilborn referenced this topic on
                                • First post
                                  Last post
                                The Community of users of the Notepad++ text editor.
                                Powered by NodeBB | Contributors