Jump to content

Key to insert text into SciTE


Recommended Posts

I am working on a script that, amongst other things, will insert a line of text into a .au3 file open in SciTE -- at a line specified by a user.

The GUI of my script instructs the user to open the file in SciTE, position the cursor on his chosen line, and then press a key to insert the text, or press Esc to return to my script's GUI.

My question is: what key does SciTE not already use that I can use for this purpose?

The code below fails because Ctrl_Ins causes the mouse wheel to zoom.

Or is there a way I can have the user double-click to have the text inserted?

Func InsertEnableOrDisable($filspc, ByRef $hDLL,$enableOrDisable)
    ; title may have an * in it so can't just use WinWaitActive with timeout argument
    While True
        If WinWaitActive($filspc,'',10)<>0 Then ; didn't time out
            Local $title = WinGetTitle('[ACTIVE]')
            If StringInStr($title,'SciTE') Then
                ExitLoop
            EndIf
        EndIf
        If MsgBox(4,'','Waiting for '&$filspc&' to be activated in SciTE. Wait longer?')=7 Then ; yes/no no
            Return
        EndIf
    WEnd

    If $hDLL=-1 Then
        $hDLL = DllOpen("user32.dll")
    EndIf
    while True
        If _IsPressed('11',$hDLL) And _IsPressed('2D',$hDLL) Then ; Ctrl and Ins keys
            Send('{HOME}{HOME}',0)
            Local $homeX = (WinGetCaretPos())[0]
            Send('{END}',0)
            Local $endX = (WinGetCaretPos())[0]
            Send('{HOME}{HOME}',0)
            Send(';TraceCalls:trace='&$enableOrDisable,1)   ; raw
            If $endX<>$homeX Then           ; if stuff already on this line
                Send('{ENTER}',0)
            EndIf
            ExitLoop
        ElseIf _IsPressed('1B') Then    ; Esc
            ExitLoop
        EndIf
        Sleep(50)
    WEnd
    WinActivate($gForm1)
EndFunc

 

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

  • Developers

I would use the SciTE DIrector interface with a script like this:

;
$Input_File="D:\test\test.txt"
$text="this is the new text."
$Input_File2=StringReplace($Input_File,"\","\\")
$Line=3
$Column=10

SendSciTE_Command('open:' & $Input_File2)
SendSciTE_Command("goto:" & $Line & ":" &$Column)
SendSciTE_Command("insert:" & $text)
;
;
Func SendSciTE_Command($sCmd)
    Opt("WinSearchChildren", 1)
    ; Get SciTE DirectorHandle
    $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

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Jos , You have changed this function. Then it has 3 parameters, but now only one. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

I mean the old "Send_SciTE_Command" function has 3 parameters. Now you  shrunk it to one. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Developers

There is no official one and have several versions depending whether I just want to send a command without a reply like here, or whether I am requesting information from SciTE.
In the latter case it would also need my window handle where it will send the COPYDATA message to.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Few weeks ago, when you gave me the old function, i just used it in my programs without study deeply. But now i want to study the function deeply. Especially WM_COPYDATA.

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Developers

Just open the "SciTE Director interface" page in the SciTE4AutoIt3 helpfile to start reading. (Search: Director) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

To answer the bedrock question:

what key does SciTE not already use that I can use for this purpose?

I built something similar a while back and just had the user push a button to "throw the string" to the scite window where the cursor is blinking.

The script is in my sig if you are interested...

I also added a short tutorial how to open this program with keyboard shortcut which is CTRL + ALT+ S.

cya,

Bill

Link to comment
Share on other sites

@Jos Thanks. :)

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • 4 weeks later...

Jos, I have studied the code you have provided in this thread, and that you provided to I3ill, and the Director Interface page in the SciTeE4AU3 help.

My needs have changed a bit. In the currently visible buffer in SciTE, I would now like be able to do the following from a GUI:

  • If the user requests enabling, if the current line is empty, have the script key in ;TraceCalls:trace=enable
  • If the user requests enabling, if the current line contains ;TraceCalls:trace=disable, the line is blanked
  • If the user requests disabling, if the current line is empty, have the script key in ;TraceCalls:trace=disable
  • If the user requests disabling, if the current line contains ;TraceCalls:trace=enable, the line is blanked
  • If the user requests enabling, and the cursor is on a line that contains neither ;TraceCalls:trace=enable nor ;TraceCalls:trace=enable, insert a line first

You have told me how to insert text into a line.

Now I need to retrieve the contents of a line into my script.

How do I do this?

 

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

  • Developers

Just have a look at the work @guinness has done in SciTEJump, which contains an Scite.au3 include file with many UDFs to control SciTE.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Jos, This is a feature request. If it is not possible, then please forgive me. 

1. When we create a a new file in SciTE, that file should come with pre written include files.

I can explain. For example, in the FormBuilder, it creates each new script from a model au3 file. If we add some most wanted include statements in that model file, then when we click new file menu in FormBuilder, it starts with all those include statements. 

2. An option for creating pre saved au3 files. Think if i find a set of code which i don't know, then i want to check that code in SciTE to know what will be the result. Then i can copy paste that piece of code to a new file and run. But now, SciTE asks me to save the file. That is a burden. If there is an option to create a pre saved temporary file, then it will be easy for learners. 

I hope i have made my points clear.

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Developers

So what is stopping you from creation a LUA function in personalTools.lua in %localappdata\AutoIt v3\SciTE to do this for you with an assigned shortcut?  ;)

Jos

 

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok. I am starting it. I hope you will guide me if i faced any obstacles. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Chris (c.haslam) here again. I am trying to retrieve the current line from SciTE.

I have reached the point where I have this code:

Local $hSciTEWindow = WinGetHandle('[CLASS:SciTEWindow]')
Local $hSciTEEdit = ControlGetHandle($hSciTEWindow, '', '[CLASS:Scintilla; INSTANCE:1]')

I wish to get SciTE to return the line where the cursor is to an AutoIt script, so I need SCI_GETCURLINE ( 2027).

I think I need GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') and

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam

    Local Const $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local Const $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
    Local Const $iIDFrom = DllStructGetData($tNMHDR, 'IDFrom')
    Local Const $iCode = DllStructGetData($tNMHDR, 'Code')

then

Switch $iCode
        Case

I see in the Scintilla documentation SCI_GETCURLINE(int textLen, char *text NUL-terminated)

Where do I go from here?

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

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...