The following script implements "Select and Find First".
defgetExpression():ifeditor.getSelections()==1:#Never0.expression=editor.getSelText()ifexpression!="":returnexpressionglobaloldPossPos=editor.wordStartPosition(oldPos,True)ePos=editor.wordEndPosition(oldPos,True)oldPos=sPoselse:mainSel=editor.getMainSelection()sPos=editor.getSelectionNStart(mainSel)ePos=editor.getSelectionNEnd(mainSel)returneditor.getTextRange(sPos,ePos)defhighlightFirst():editor.setTargetStart(0)editor.setTargetEnd(editor.getLength())sSel=editor.searchInTarget(findExpression)ifsSel!=-1:#Wouldbe-1ifnotfound;-Matchwholewordetc.eSel=sSel+len(findExpression)editor.setSel(sSel,eSel)ifoldPos==sSeloroldPos==eSel:notepad.messageBox("You have selected the first occurrence.","Select and Find First",0)#HereweshouldflashthewindowinsteadofusingmessageBox.oldPos=editor.getCurrentPos()findExpression=getExpression()iffindExpression!="":#Asymboletc.highlightFirst()
1) How can I flash the window?
2) How do I get the current flags in NP Find dialog (Match Case etc.)?
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The following script implements "Select and Find First".
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
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.
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.