Menu

Flash Window + Get Search Flags

Yaron
2015-02-23
2015-02-23
  • Yaron

    Yaron - 2015-02-23

    The following script implements "Select and Find First".

    def getExpression():
        if editor.getSelections() == 1: # Never 0.
            expression = editor.getSelText()
            if expression != "":
                return expression
    
            global oldPos
            sPos = editor.wordStartPosition(oldPos, True)
            ePos = editor.wordEndPosition(oldPos, True)
            oldPos = sPos
        else:
            mainSel = editor.getMainSelection()
            sPos = editor.getSelectionNStart(mainSel)
            ePos = editor.getSelectionNEnd(mainSel) 
    
        return editor.getTextRange(sPos, ePos)
    
    def highlightFirst():
        editor.setTargetStart(0)
        editor.setTargetEnd(editor.getLength())
        sSel = editor.searchInTarget(findExpression)
    
        if sSel != -1:  # Would be -1 if not found; - Match whole word etc.
            eSel = sSel + len(findExpression)
            editor.setSel(sSel, eSel)
    
            if oldPos == sSel or oldPos == eSel:
                notepad.messageBox("You have selected the first occurrence.", "Select and Find First", 0)   # Here we should flash the window instead of using messageBox.
    
    oldPos = editor.getCurrentPos()
    findExpression = getExpression()
    
    if findExpression != "":    # A symbol etc.
        highlightFirst()
    

    1) How can I flash the window?
    2) How do I get the current flags in NP Find dialog (Match Case etc.)?

    I'd appreciate your help.

    Thanks to Davey. Select and Find First/Last.

    Python Script: Flash Window + Get Search Flags.

     

    Last edit: Yaron 2015-02-23
  • Dave Brotherstone

    1) To flash the window, you really just want to change the background colour of scintilla briefly. This is (AFAIK) sadly easier said than done. What you need to do is to SCI_STYLESETBACK (editor.setStyleBack(...)) for each style, to either dark or light, depending on what the current theme is.

    2) I don't think there's a way to get the "current" settings for the find dialog. It'd be worth asking Don on the plugin forum if he could add an API call (or several) to get the current flags, maybe last used search term etc. I wouldn't rely on the value in scintilla, (ie. editor.getSearchFlags()), as lots of background things use scintilla's search (tag matching and clickable hyperlinks are two that instantly come to mind), so you never know if you're catching something the user set, or something a "background" task set (or plugin, or whatever).

    Dave.

     
  • Yaron

    Yaron - 2015-02-23

    Hello Dave,

    Thanks for the detailed explanation. I appreciate it.

    editor.getSearchFlags() indeed returns a value regardless of the settings in the find dialog.

    As for asking Don to add an API call: I do think that if the request came from you, it would be granted sooner. :)

    Best regards.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.