Community
    • Login

    clear and close Search Results

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 548 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.
    • TBugReporterT
      TBugReporter
      last edited by

      Is it possible to make a macro that would clear and close the Search Results pane? If not, would this be possible in a PythonScript?

      (possibly relevant old discussion: Setting to clear previous search results before files search?)

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

        @TBugReporter

        This should help setup a python script that does what you want.
        Find the serach window handle and then SendMessage(notepad.hwnd, NPPM_DMMHIDE, 0, search_result.hwnd).
        Not tested, but should work like this.

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

          This old thread is probably relevant as well:
          Hide (or Toggle) Find Results panel with keyboard command

          Note that clearing the Search results pane is not part of that discussion.
          Is clearing it really important to you?
          (If it is not shown, does it really need to be cleared?)

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

            Borrowing heavily from the script @Ekopalypse linked to, here’s a script that will clear and hide the Search results panel. Note that it only works if the panel is “docked” (the most common case) and not a “free floating” window – the floating case could be handled, with the addition of more code.

            # -*- coding: utf-8 -*-
            
            # refs:
            #  https://community.notepad-plus-plus.org/topic/25580/clear-and-close-search-results
            
            from ctypes import (windll, create_unicode_buffer, WINFUNCTYPE)
            from ctypes.wintypes import BOOL, HWND, LPARAM, WPARAM, UINT
            from Npp import notepad
            
            SendMessage          = windll.user32.SendMessageW
            SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]
            SendMessage.restype  = LPARAM
            
            WNDENUMPROC = WINFUNCTYPE(BOOL, HWND, LPARAM)
            
            FindWindow = windll.user32.FindWindowW
            GetWindowText = windll.user32.GetWindowTextW
            GetWindowTextLength = windll.user32.GetWindowTextLengthW
            EnumChildWindows = windll.user32.EnumChildWindows
            GetClassName = windll.user32.GetClassNameW
            
            curr_class = create_unicode_buffer(256)
            
            WM_CLOSE = 0x010
            WM_COMMAND = 0x111
            WM_USER = 0x400
            NPPMSG = WM_USER + 1000
            NPPM_DMMHIDE = NPPMSG + 31
            NPPM_INTERNAL_SCINTILLAFINDERCLEARALL = WM_USER + 27
            
            try:
                notepad.hwnd
            except AttributeError:
                # PythonScript 2 doesn't have notepad.hwnd predefined like PythonScript 3 does
                notepad.hwnd = FindWindow(u'Notepad++', None)
            
            NPP = 'Notepad++'
            SEARCH_RESULTS = 'Search results'
            window_hwnds = {
                NPP : notepad.hwnd,
                SEARCH_RESULTS : None,
                }
            
            def foreach_window(hwnd, lParam):
                if curr_class[:GetClassName(hwnd, curr_class, 256)] == '#32770':
                    length = GetWindowTextLength(hwnd)
                    if length > 0:
                        buff = create_unicode_buffer(length + 1)
                        GetWindowText(hwnd, buff, length + 1)
                        if buff.value == SEARCH_RESULTS:
                            window_hwnds[buff.value] = hwnd
                            return False
                return True
            if not window_hwnds[SEARCH_RESULTS]: EnumChildWindows(window_hwnds[NPP], WNDENUMPROC(foreach_window), 0)
            
            if window_hwnds[SEARCH_RESULTS]:
                # clear Search-results:
                SendMessage(window_hwnds[SEARCH_RESULTS], WM_COMMAND, NPPM_INTERNAL_SCINTILLAFINDERCLEARALL, 0)
                # hide/~close Search-results:
                SendMessage(window_hwnds[NPP], NPPM_DMMHIDE, 0, window_hwnds[SEARCH_RESULTS])
            
            TBugReporterT 1 Reply Last reply Reply Quote 2
            • Alan KilbornA Alan Kilborn referenced this topic on
            • TBugReporterT
              TBugReporter @Alan Kilborn
              last edited by

              @Alan-Kilborn said in clear and close Search Results:

              here’s a script that will clear and hide the Search results panel.

              Thank you, that works. On my first reading of the script, I was worried that it might get confused when I’m running multiple instances of Npp (which is often; this, along with the session feature, is how I keep multiple tasks organized without them interfering with each other) - but testing shows that this doesn’t happen (unless there’s some edge case that I haven’t hit yet).

              Note that it only works if the panel is “docked”

              Not a problem, because I’ve never undocked the panel; I don’t even know how to do that.

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

                @TBugReporter said in clear and close Search Results:

                I was worried that it might get confused when I’m running multiple instances of Npp

                To be specific, by “confused” you mean that when running the script from one instance, that it might close a different instance’s Search results.

                If you’re running under PS3, then that is probably not a concern. Under PS2, there is the call to FindWindow('Notepad++', ...) to consider. In my understanding, there is nothing that prevents this from finding the “wrong” instance window, so in more-complicated script code that I use I actually verify that the process-id of the found window matches the process-id of the program running the script, to be absolutely certain I have found the correct thing.


                I’ve never undocked the panel; I don’t even know how to do that.

                If you double-click either of these areas:

                5c5d7ad5-fc77-4854-8103-200935d1dbe2-image.png

                then the entire pane/panel will become a free-floating window, detached from the main N++ window.

                Note, however, that in my example I have TWO tabs in that panel, so what you double-click on makes a difference:

                • title bar : opens a new window with all tabs from the original panel
                • tab : opens a new window with only the tab double-clicked

                So after you have the free-floating window open, double clicking the title bar on that will return it to its original location, docked in the main N++ window.

                Why would one undock the Search results into its own window? Well, probably only useful when you have more than one monitor in your system, and you need to see a lot of search data (on one screen) while seeing a lot of actual text you’re editing (on another screen).

                BTW, more info on all of this is in the user manual, HERE.

                TBugReporterT 1 Reply Last reply Reply Quote 1
                • TBugReporterT
                  TBugReporter @Alan Kilborn
                  last edited by

                  @Alan-Kilborn said in clear and close Search Results:

                  by “confused” you mean that when running the script from one instance, that it might close a different instance’s Search results. […]

                  In my understanding, there is nothing that prevents this from finding the “wrong” instance window

                  My concern exactly, but as I said, experimentation hasn’t caused this to occur for me yet.

                  I’ve never undocked the panel; I don’t even know how to do that.

                  If you double-click either of these areas

                  Thank you for the extra effort, but I didn’t mean that comment as a question. I saw that info at the manual site, but the only time I expect to use it is if I do this by mistake - to get things back to normal.

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