PutSelectedInRegion.au3

Put the Selected text in a Region

 as the title says, put the selected text in a region for easily manageable blocks of code. 
; https://www.autoitscript.com/forum/topic/208404-scite-plusbar/page/2/#comment-1517023
;------------------------------------------------------------------------------
; Title...........: PutSelectedInRegion.au3
; Description.....: Put the Selected text in a Region
;------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $hScite_Editor_hWnd = ControlGetHandle("[CLASS:SciTEWindow]", '', '[CLASS:Scintilla; INSTANCE:1]')
Global $ClipBack, $ClipData

If Not WinExists("[CLASS:SciTEWindow]") Then
    Exit
EndIf

$ClipBack = ClipGet() ; backup clip data

SciTE_PutItInRegion()

ClipPut($ClipBack) ; Restore clip data

;----------------------------------------------------------------------------------------
Func SciTE_PutItInRegion()  ; Put It In Region

    Local $Line = _SciTE_GetSelectedLineNumber()
    Local $Column = 12

    _SendMessage($hScite_Editor_hWnd, $WM_COPY)
    Local $sClip = ClipGet()

    Local $sTxt = "#Region ===  ===" & @CRLF
    $sTxt &= $sClip & @CRLF
    $sTxt &= "#EndRegion ===  ===" & @CRLF

    ClipPut($sTxt)
    _SendMessage($hScite_Editor_hWnd, $WM_PASTE)

    SendSciTE_Command("goto:" & $Line & "," & $Column)

EndFunc   ;==>SciTE_PutItInRegion
;--------------------------------------------------------------------------------------------
Func SendSciTE_Command($sCmd)
    Opt("WinSearchChildren", 1)
    ; Get SciTE DirectorHandle
    Local $SciTE_hwnd = WinGetHandle("DirectorExtension")
    ;Local $WM_COPYDATA = 74
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $SciTE_hwnd, _
            'Int', $WM_COPYDATA, 'HWnd', 0, _
            'Ptr', DllStructGetPtr($COPYDATA))
EndFunc   ;==>SendSciTE_Command
;----------------------------------------------------------------------------------------
Func _SciTE_GetSelectedLineNumber()
    Return _SciTE_GetLineFromPosition(_SciTE_GetCurrentPosition()) + 1
EndFunc   ;==>_SciTE_GetSelectedLineNumber
;----------------------------------------------------------------------------------------
Func _SciTE_GetCurrentPosition()
    Local Const $SCI_GETCURRENTPOS = 2008
    Return _SendMessage($hScite_Editor_hWnd, $SCI_GETCURRENTPOS)
EndFunc   ;==>_SciTE_GetCurrentPosition
;----------------------------------------------------------------------------------------
Func _SciTE_GetLineFromPosition($iLineNumber)
    Local Const $SCI_LINEFROMPOSITION = 2166
    Return _SendMessage($hScite_Editor_hWnd, $SCI_LINEFROMPOSITION, $iLineNumber)
EndFunc   ;==>_SciTE_GetLineFromPosition
;----------------------------------------------------------------------------------------

Comments

Popular posts from this blog

ControlGetHandle ($hWnd, "", "[REGEXPCLASS:<>; INSTANCE:<>]")

Simple Calculator