OK, revised yet again. I didn't originally bother to make it copy characters that need escape. So here it is again, with a few improvements.
Code:
#NoEnv
SendMode Input
SetTimer,GetActiveWindow, 30
ButtonLoadFile: ;;This is where we select the textfile for the tags
Gui Destroy
Gui +OwnDialogs ; Forces user to dismiss the following dialog before using main window.
FileSelectFile, Nestcepas,, 3, Select a file to read:
if not Nestcepas ; The user canceled the dialog.
return
; Allow the user to maximize or drag-resize the window:
Gui +Resize
Menu, MyMenu, Add, Load File, ButtonLoadFile
Menu, TargetMenu, Add, Select Target, ButtonSelect_Target
Menu, TargetMenu, Add, DeSelect, Deselect_Target
Menu, MyMenu, Add, Target, :TargetMenu
Gui, Menu, MyMenu
Gui, Add, Button, Hidden Default H0 W0, OK
Gui, Add, ListView, xm r20 w200 vMyListView gMyListView Grid, Name | Text ; r20 w150
LV_ModifyCol() ; Auto-size each column to fit its contents.
; This is where we get the items from the text file:
FileRead, Durant, %Nestcepas% ;Read file into var Durant
Loop, Parse, Durant, `n, `r ; This should get each tag one at a time
{
If A_LoopField =
Continue
Alpha = %A_Index%
Will = %A_Loopfield%
Loop, Parse, Will, |
{
If A_Index = 1
{
Jersey = %A_LoopField%
StringReplace,Jersey,Jersey,!,`{!`},All
StringReplace,Jersey,Jersey,+,`{`+`},All
StringReplace,Jersey,Jersey,^,`{`^`},All
Gomer%Alpha% = %Jersey%
Jersey =
}
If A_Index = 2
{
Jersey = %A_LoopField%
StringReplace,Jersey,Jersey,!,`{!`},All
StringReplace,Jersey,Jersey,+,`{`+`},All
StringReplace,Jersey,Jersey,^,`{`^`},All
Goober%Alpha% = %Jersey%
}
}
LV_Add("",Gomer%Alpha%,Goober%Alpha%)
LV_ModifyCol() ; Auto-size each column to fit its contents.
LV_ModifyCol(3, 60) ; Make the Size column at little wider to reveal its header.
;GuiControl, +Redraw, MyListView ; Re-enable redrawing (it was disabled above).
}
; performs alphabetical sort:
LV_ModifyCol(1, "Sort", Name)
Gui, +AlwaysOnTop
Gui, Show
return
DeSelect_Target:
Title =
SetTimer,GetActiveWindow,50
Return
ButtonOK:
GuiControlGet, FocusedControl, FocusV
if FocusedControl <> MyListView
return
Durham := % LV_GetNext(0, "Focused")
LV_GetText(RowText2, Durham,2)
Goto Gogo
if A_GuiEvent = DoubleClick
Goto MyListView
MyListView:
SetKeyDelay,21,41
DialNine = %Clipboard%
Clipboard =
LV_GetText(RowText2, A_EventInfo,2) ; Get the text of the second field.
;MsgBox, Rowtext = %Rowtext% `n A_EventInfo = %A_EventInfo%
Gogo:
WinActivate,%Title%
Raster := RowText2
IfInString, Raster, #
{
Loop,Parse,Raster, #
{
If A_Index = 1
{
Defender := A_LoopField
Send,^x
ClipWait,.2
Xevious := Clipboard
StringReplace,Xevious,Xevious,{, `{`{`},All
StringReplace,Xevious,Xevious,`}, `{`}`},All
StringReplace,Xevious,Xevious,{{{}},`{`{`}
StringReplace,Xevious,Xevious,!, `{!`},All
StringReplace,Xevious,Xevious,+, `{+`},All
StringReplace,Xevious,Xevious,^, `{^`},All
StringReplace,Xevious,Xevious,#, `{#`},All
;
Clipboard =
}
Else
{
Asteroids := A_LoopField
}
}
Clipboard := % Defender . Xevious . Asteroids
}
IfNotInstring, Raster, #
{
Clipboard = %Raster%
}
SetKeyDelay,-1,-1
Send,%Clipboard%
Send,%A_Space%
Clipboard =
;Clipboard = %DialNine%
SetKeyDelay,11,11
Return
GuiSize: ; Expand or shrink the ListView in response to the user's resizing of the window.
if A_EventInfo = 1 ; The window has been minimized. No action needed.
return
; Otherwise, the window has been resized or maximized. Resize the ListView to match.
GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 20) ;%
return
GuiClose: ; When the window is closed, exit the script automatically:
^+#Escape::
ExitApp
Clicky:
ButtonSelect_Target:
MsgBox,After pressing OK, click on the Edit field of the word processor or text editor application you would like to have your text placed in. If you don't have that application open now, do so before pressing the "OK" button in this message box. (Hint, The Edit field is where the actual document is displayed.)
SetTimer,GetActiveWindow,Off
Title =
KeyWait,LButton,D
MouseGetPos, , , id, control
WinGetTitle, Title, ahk_id %id%
WinGetClass, class, ahk_id %id%
;Msgbox,%Title% is title`n%class% is class
Return
#!t::
WinGetActiveTitle,Title
If Title = %A_ScriptName%
{
WinHIde %A_ScriptName%
Return
}
Else
WinShow,%A_ScriptName%
WinActivate,%A_ScriptName%
ControlFocus,SysListView321,%A_ScriptName%
Return
^#!t::WinHide,%A_ScriptName%
GetActiveWindow:
WinGetActiveTitle, Nookie
If Nookie != %A_ScriptName%
Title = %Nookie%
Return
And as a side note, so far if you select a target (optional) then for a multitabbed editor, the target is specifically the active tab when you selected. So for multitabbed editors I don't really recommend setting a specific target.