Jump to content

Add 'Find in All Docs' to the context menu


Recommended Posts

I have code in the au3.properties file to use Findstr to find words in the current file and it works as I want it to. However, now I want to find words in all opened files, but I cannot figure how to get the list of buffers/openfiles onto the Findstr command line.

Here is the code I'm using:

findcmd=C:WindowsSystem32Findstr.exe

#
# Find All in Current Document
#
command.name.43=Find All in Current Document
command.43.=$(findcmd) /N /I /C:"$(CurrentWord)" "$(FilePath)" nul
command.subsystem.43=0
#                            2 = Don't save before running this command
command.save.before.43=2

#
# Find All in all open Documents
#
command.name.44=Find All in All Open Document
command.44.=$(findcmd) /N /I /C:"$(CurrentWord)" $(FilePath) nul
command.subsystem.44=0
command.save.before.44=2

#
# Add my commands to the user context menu
#
user.context.menu=
||
40 - Find Definition | 1140 |
41 - Find References | 1141 |
||
42 - Function List   | 1142 |
43 - Find All in Current Doc | 1143 |
44 - Find All in All Open Docs | 1144 |
Edited by AndyS01
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

If you know the Lua command to have Scite save it's current session, you can then read in that session file which will contain all the currently open files and their paths. I'm not all that familiar with Lua so I can't be of much help there.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 2 weeks later...

I'm almost there.

I couldn't find a way to do it with LUA.

However, using an external AutoIT script, I locate the AutoIT SciTe window and parse the window properties for the filenames, then search each file for the pattern. It's pretty convoluted right now, but it seems to work.

I have one issue I need to solve before I can clean up my code and tell the world about it:

My script uses ConsoleWrite() statements to display each matching line in this syntax:

<filename>:<linenum> <matching line>

like this:

D:tempfile.txt:2 Text line with a matching pattern

D:tempfile2.txt:2 Another text line with a matching pattern

Now my problem is:

How do I make it so when I double click on the line in the Console output window, the editor goes to that line (like when you do a compile and double click on resulting error lines)?

I do all this by entering this info in the au3.properties file:

command.name.44=Find Selected text in All Open Documents

command.44.=D:UtilMiscAutoITTabNames.exe "$(CurrentWord)"

command.subsystem.44=0

command.save.before.44=1

When I run it, I see all of the matching lines in all of the open files in the console output window, but when I double click on the results, nothing happens.

Link to comment
Share on other sites

OK, I solved that one. I was not formatting the message correctly.

Now I can do what I wanted to do. I wrote a UDF that extracts the names of all of the open files in the editor. I built a script around it that searches each file for a specified word.

I implemented my "Find in all files" by entering this info in the au3.properties file:

#
# Find Selected Text in the Current Document
#
findcmd=C:\Windows\System32\Findstr.exe
command.43.=$(findcmd) /N /I /C:"$(CurrentWord)" "$(FilePath)" nul
command.subsystem.43=0
command.save.before.43=1

#
# Find Selected Text in all Open Documents
#
command.44.=D:\Util\Misc\AutoITFileNames.exe -find "$(CurrentWord)"
command.subsystem.44=0
command.save.before.44=0

user.context.menu=\
||\
43 - Find Selected Text in the Current Doc | 1143 |\
44 - Find Selected Text in All Opened Docs | 1144 |\

Back in the Autoit editor, I right click of a word I want to find, and select "Find Selected Text in All Opened Docs".

Here is my UDF to extract all open filenames from the running AutoIT editor. Pretty crude, but it works

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <File.au3>
#include <GuiTab.au3>
Opt('MustDeclareVars', 1)

; #FUNCTION# ====================================================================================================================
; Name ..........: _GetAutoITFilenames
; Description ...: Get an array of the names of all files being edited by the AutoIT editor.
; Syntax ........: _GetAutoITFilenames()
; Parameters ....: None
; Return values .: Success: An array of full pathnames
;                          (element [0] = The #of filenames in the array)
;                          @error = 0
;                 Failure: 0
;                          @error = 1 - The editor is not running
;                          @error = 2 - The editor is not editing any files

; Author ........: Andy Scharmer
; Modified ......:
; Remarks .......: The Filenames are obtained from the AutoIT (SciTE) editor by
;                 obtaining the handle to its main window, and the handle to the
;                 Tab control (if it's editing more than 1 file).
;                 For a non-tabbed window, the full pathname is in the window's title,
;                 which is extracted into the output array.
;                 For a tabbed window, focus is set to each tab (which puts the full
;                 path name in the window's title) and the full pathname is extracted
;                 into the output array before settitn focus on the next tab.
;                 Focus is then restored to the originally focused tab.
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GetAutoITFilenames()
Local $hWnd, $iIndex, $iCount, $iCurSel
Local $sFilename, $aFilenames[1], $aWindows, $sClass
    local $hWnd_main = 0, $hWnd_tabs = 0

; Look at the class of all windows, looking for the
; AutoIT main window and for its Tab control
$aWindows = _WinAPI_EnumWindows()
For $iIndex = 1 To $aWindows[0][0]
$sClass = $aWindows[$iIndex][1]

; Remember only the first occurrence of each window or Tab control
If ($hWnd_tabs == 0) And ($sClass = "SciTeTabCtrl") Then
$hWnd_tabs = $aWindows[$iIndex][0] ; Save the handle to the Tab control
ElseIf ($hWnd_main == 0) And ($sClass = "SciTEWindow") Then
$hWnd_main = $aWindows[$iIndex][0] ; Save the handle to the main window
EndIf
Next

If ($hWnd_main == 0) Then Return (SetError(1, 1, 0)) ; No handle to the main win

If ($hWnd_tabs <> 0) Then
; Found a Tab control (multiple files being edited)

$iCurSel = _GUICtrlTab_GetCurFocus($hWnd_tabs) ; Remember which Tab has focus
$iCount = _GUICtrlTab_GetItemCount($hWnd_tabs) ; #of tabs = #of open files

; For each Tab, set the focus on it, then get its
; full filename from the main window's title.
For $iIndex = 0 To $iCount - 1
_GUICtrlTab_SetCurFocus($hWnd_tabs, $iIndex); Set the focus on this tab
_ArrayAdd($aFilenames, WinGetTitle($hWnd_main)) ; Save the raw filename
Next
_GUICtrlTab_SetCurFocus($hWnd_tabs, $iCurSel) ; Put the focus back to where it was
Else
; No tab control - it's a single window (1 file being edited)
_ArrayAdd($aFilenames, WinGetTitle($hWnd_main)) ; Save the raw filename
EndIf

$aFilenames[0] = UBound($aFilenames) - 1 ; Set element [0] to the filenames count

If ($aFilenames[0] < 1) Then Return (SetError(2, 0, 0)) ; @error = 2 - No filenames found

; Loop through all raw filenames and for each one,
; strip off everything but the full pathname
For $iIndex = 1 To UBound($aFilenames) - 1
$sFilename = $aFilenames[$iIndex]
        ; Strip out the " - SciTE"
$sFilename = StringRegExpReplace($sFilename, "(?i)[\s]+[-][\s]+scite", "")
; Strip out the leading '&n '
$sFilename = StringRegExpReplace($sFilename, "[&][0-9]*[\s]*", "")
; Strip out the "[x of x]"
$sFilename = StringRegExpReplace($sFilename, "[[][\d]*[\s]+[oO][fF][\s]+\d*[]]", "")
; Strip out the 'Modified' asterisk and all text that follows
$sFilename = StringRegExpReplace($sFilename, "[*].*$", "")
; Remove leading/trailing whitespace
$sFilename = StringStripWS($sFilename, 3)
$aFilenames[$iIndex] = $sFilename
Next

Return (SetError(0, 0, $aFilenames)) ; Return the array and set @error = 0
EndFunc   ;==>_GetAutoITFilenames
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...