atomman Posted December 19, 2007 Posted December 19, 2007 Need to insert text at a specific line number (already existing) in an edit control, something like _GUICtrlEdit_InsertText, except that does character positioning. I know how to do it with caret position, but that's not reliable in my case.
GaryFrost Posted December 19, 2007 Posted December 19, 2007 Need to insert text at a specific line number (already existing) in an edit control, something like _GUICtrlEdit_InsertText, except that does character positioning.I know how to do it with caret position, but that's not reliable in my case.Might look at _GUICtrlEdit_LineIndex in conjunction with _GUICtrlEdit_InsertText SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
atomman Posted December 19, 2007 Author Posted December 19, 2007 i looked at that before, but didn't understand how to use it.what is a "character index"?Return Value -- Success: the character index of the line specified in the $iIndex parameter
GaryFrost Posted December 19, 2007 Posted December 19, 2007 #include <GuiEdit.au3> Opt('MustDeclareVars', 1) $Debug_Ed = False ; Check ClassName being passed to Edit functions, set to True and use a handle to another control to see it work _Example_Internal() Func _Example_Internal() Local $hGUI, $StatusBar, $hEdit Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\include\changelog.txt" Local $aPartRightSide[2] = [378, -1], $iRandom ; Create GUI $hGUI = GUICreate("(Internal) Edit Line Index", 400, 300) $hEdit = GUICtrlCreateEdit("", 2, 2, 394, 268, BitOR($ES_WANTRETURN, $WS_VSCROLL)) GUISetState() ; Set Margins _GUICtrlEdit_SetMargins ($hEdit, BitOR($EC_LEFTMARGIN, $EC_RIGHTMARGIN), 10, 10) ; Set Text _GUICtrlEdit_SetText ($hEdit, FileRead($sFile)) ; Line Index $iRandom = Random(0, _GUICtrlEdit_GetLineCount ($hEdit) - 1, 1) ConsoleWrite("Inserting Text at Line: " & $iRandom & @LF) _GUICtrlEdit_InsertText($hEdit, "MY INSERTED TEXT", _GUICtrlEdit_LineIndex ($hEdit, $iRandom)) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Example_Internal SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
atomman Posted December 19, 2007 Author Posted December 19, 2007 That's from the manual and i read about the functions used in that example and played with the script. Still, i don't understand how to use '_GUICtrlEdit_GetLineCount' and '_GUICtrlEdit_InsertText' to insert text to a predetermined line number in an edit control. And i'm not seeing how 'Random' can be used to generate the current line number from the caret position. I can convert 'WinGetCaretPos' to a line number, but now i need to write to that line number. I've been toying with different methods of doing this for days and days and none are reliable/work. I'm so close to being done with this script but being able to simply write to a line number like "_FileWriteToLine" does is driving me
GaryFrost Posted December 19, 2007 Posted December 19, 2007 That's from the manual and i read about the functions used in that example and played with the script. Still, i don't understand how to use '_GUICtrlEdit_GetLineCount' and '_GUICtrlEdit_InsertText' to insert text to a predetermined line number in an edit control. And i'm not seeing how 'Random' can be used to generate the current line number from the caret position. I can convert 'WinGetCaretPos' to a line number, but now i need to write to that line number. I've been toying with different methods of doing this for days and days and none are reliable/work. I'm so close to being done with this script but being able to simply write to a line number like "_FileWriteToLine" does is driving me Your looking to hard at it, it's simple, the 'Random' and _GUICtrlEdit_GetLineCount represent the line you want to insert text in, I have no idea what line you want to insert at. For all intents and purposes you only really need to look at _GUICtrlEdit_InsertText($hEdit, "MY INSERTED TEXT", _GUICtrlEdit_LineIndex ($hEdit, 'your line number goes here')) SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
atomman Posted December 19, 2007 Author Posted December 19, 2007 It works! And i can now see why it works. Thank you Gary!I think a UDF would be a good idea here -- _EditWriteToLine -- but that's over my head.
atomman Posted December 20, 2007 Author Posted December 20, 2007 I spoke too soon... I still need to find a way to insert text at an edit control line number. Right now i'm converting WinGetCaretpos() to a line number then using something like this, inside a while loop, to write: If WinActive($Form1) Then $Caret = WinGetCaretPos() $Line = (($Caret[1] - 3) / 13) Case $Button1 _GUICtrlEdit_InsertText($Edit1, $Text1 & @CRLF & $Text2 & @CRLF & @CRLF, _GUICtrlEdit_LineIndex($Edit_TextEditor, $Line)) It seems very finicky... works much of the time, then fails, and it's now frustrating the daylights out of me.
atomman Posted December 20, 2007 Author Posted December 20, 2007 trying this once again and it seems to be working. $Line = (ControlCommand($Win_SBE, "", $Edit_TextEditor, "GetCurrentLine") -1)
atomman Posted December 21, 2007 Author Posted December 21, 2007 nothing works because of the behavior of edit controls -- everything gets selected when you click, or there just isn't a caret, etc.. is there not a simple way of writing to a specified line number in an edit that works?
therks Posted December 21, 2007 Posted December 21, 2007 I think you have to stop saying "specified". To me, specified means you are giving it a specific number, which Gary has given you code for (which works in my tests): _GUICtrlEdit_InsertText($hEdit, "MY INSERTED TEXT" & @CRLF, _GUICtrlEdit_LineIndex ($hEdit, LINENUMBER))It seems to me that the real problem you're having is retrieving the current line number. My AutoIt Stuff | My Github
atomman Posted December 21, 2007 Author Posted December 21, 2007 Yeah, for the most part i think you're right, but i had problems with both. The biggest problem is everything getting selected in an edit control when it's focused.For now i *think* i have it working, but the nature of edit controls (selecting everything) makes it annoying. I asked in another post if there was a way to prevent this and didn't get an answer. If you can help me out, i'd certainly appreciate it.
GaryFrost Posted December 21, 2007 Posted December 21, 2007 (edited) Yeah, for the most part i think you're right, but i had problems with both. The biggest problem is everything getting selected in an edit control when it's focused.For now i *think* i have it working, but the nature of edit controls (selecting everything) makes it annoying. I asked in another post if there was a way to prevent this and didn't get an answer. If you can help me out, i'd certainly appreciate it.Would look at using _GUICtrlEdit_SetSel and set the start and end to the same position where you want to insert the textOr instead of using the built-in edit control you could use the _GUICtrlEdit_Create, doesn't select all when it gets focus. Edited December 21, 2007 by GaryFrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
atomman Posted December 21, 2007 Author Posted December 21, 2007 the latter would be the ticket. was close to trying _GUICtrlEdit_Create before, but i didn't see why i'd need it. now i do! thx
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now