I updated my example script above using the A_CaretX/Y variables as suggested by ahk7. Launch the script to create Gui1. Then, place the caret a various positions and press Alt+q to see Gui2 displayed at the best position considering my needs. You can change the calculation for intGui2X and intGui2Y if your needs differ.
In the end, this has little to do with the Edit library. Sorry jballi for for hijacking your thread...
[Library] Edit v3.0 - Update and Manage any Edit Control
Re: [Library] Edit v2.0 - Update and Manage any Edit Control
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Uber Geek :ugeek:](./images/smilies/icon_e_ugeek.gif)
Re: [Library] Edit v2.0 - Update and Manage any Edit Control
@jballi Any plan to migrate the Edit.ahk library to AHK v2?
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Uber Geek :ugeek:](./images/smilies/icon_e_ugeek.gif)
Re: [Library] Edit v2.0 - Update and Manage any Edit Control
Short answer: Eventually.
I'm fairly sure that converting the Edit project to AutoHotkey 2.0+ will take considerable time and effort. Converting the library and add-ons shouldn't be that difficult but converting all the examples and all of the libraries and add-ons that the examples include will be a major project. I have not been able to wrap my head around all of the work that would be involved. I also haven't identified how I will create a development environment for v2.0+ that will not interfere with 1.1+.
Re: [Library] Edit v2.0 - Update and Manage any Edit Control
I understand. I have the same challenges with my apps. I won't all convert them but I think there will be mid-term benefits to convert Quick Clipboard Editor to v2, especially the future development described here by Lexikos. But there is no ruwh.
Regarding your development environment it depends what tools you use. Having v1.1 and v2 installed on the same machine is easy and well supported. With SciTE4Autohotkey, it is also easy to switch from one version to the other.
Regarding your development environment it depends what tools you use. Having v1.1 and v2 installed on the same machine is easy and well supported. With SciTE4Autohotkey, it is also easy to switch from one version to the other.
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Uber Geek :ugeek:](./images/smilies/icon_e_ugeek.gif)
Re: [Library] Edit v2.0 - Update and Manage any Edit Control
Here is a piece of code to move a line up or down using the Edit library commands. If you have suggestion to improve it, you are welcome.
Code: Select all
#SingleInstance Force
#requires AutoHotkey v1.1
#Include %A_ScriptDir%\Lib\Edit.ahk ; from jballi (https://www.autohotkey.com/boards/viewtopic.php?f=6&t=5063)
Gui, Add, Edit, w200 h150 -Wrap +hwndMyEdit, % "12345678`nABCDEFGH`nabcdefgh`n12345678`nABCDEFGH`nabcdefgh`n"
Gui, Show
Edit_SetSel(MyEdit, -1)
return
^Up::Gosub, MoveLineUp
^Down::Gosub, MoveLineDown
;---------------------
MoveLineUp:
MoveLineDown:
if Edit_IsWordWrap(MyEdit) ; works only if word wrap is turned off
return
intSelStart := Edit_GetSel(MyEdit)
intSelLine := Edit_LineFromChar(MyEdit, intSelStart) ; line of selection start, zero-based
; check if move is out of bound
if (A_ThisLabel = "MoveLineUp" and intSelLine < 1
or (A_ThisLabel = "MoveLineDown" and intSelLine + 3 > Edit_GetLineCount(MyEdit)))
return
Critical, On
GuiControl, -Redraw, %MyEdit%
intLineStart := Edit_LineIndex(MyEdit)
intLineEnd := Edit_LineIndex(MyEdit, intSelLine + 1) ; includes inding CRLF
Edit_SetSel(MyEdit, intLineStart, intLineEnd)
strMovedLine := Edit_GetSelText(MyEdit)
Edit_Clear(MyEdit) ; clear selected moved text
intDestInsert := Edit_LineIndex(MyEdit, intSelLine + (A_ThisLabel = "MoveLineUp" ? -1 : 1))
Edit_SetSel(MyEdit, intDestInsert, intDestInsert) ; insertion point for moved text
Edit_ReplaceSel(MyEdit, strMovedLine) ; insert moved text
Edit_SetSel(MyEdit, intDestInsert, intDestInsert + StrLen(strMovedLine) - 1) ; select moved text (excluding CRLF)
GuiControl, +Redraw, %MyEdit%
Critical, Off
Edit_ScrollCaret(MyEdit) ; make sure the leftmost position of the selection is visible
return
;---------------------
;---------------------
GuiClose:
ExitApp
;---------------------
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Uber Geek :ugeek:](./images/smilies/icon_e_ugeek.gif)
Re: [Library] Edit v2.0 - Update and Manage any Edit Control
@JnLlnd I think that is already done by using Edit_BlockMove (up and down)
Re: [Library] Edit v2.0 - Update and Manage any Edit Control
@ahk7: Ah... I forgot these additional functions. It was fun to code but I could have save these few hours for something else... Thanks.
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Uber Geek :ugeek:](./images/smilies/icon_e_ugeek.gif)
Re: [Library] Edit v3.0 - Update and Manage any Edit Control
v3.0
Major new release. See the Release Notes section of the first post for the details.
This version only runs on AutoHotkey v1.1+. AutoHotkey v2.0+ is not supported. With the exception of bug fixes, this will be the last version that uses AutoHotkey v1.1+. Future versions of this project (if any) will require AutoHotkey v2.0.
Major new release. See the Release Notes section of the first post for the details.
This version only runs on AutoHotkey v1.1+. AutoHotkey v2.0+ is not supported. With the exception of bug fixes, this will be the last version that uses AutoHotkey v1.1+. Future versions of this project (if any) will require AutoHotkey v2.0.
Re: [Library] Edit v3.0 - Update and Manage any Edit Control
Thanks for this major update @jballi . Can't wait to review all these improvements.
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Uber Geek :ugeek:](./images/smilies/icon_e_ugeek.gif)
Re: [Library] Edit v3.0 - Update and Manage any Edit Control
Hi @jballi . Just a follow up on v3 release. I had no issue with existing functions and the only changes I had to do were about functions that were moved to Edit_Util.ahk.
I took the opportunity to add the spell checker to my editor. It's very well done and easy to implement. I considered using the new Zoom feature but will wait because my app could be used on Win 7.
Thanks again for all this!
I took the opportunity to add the spell checker to my editor. It's very well done and easy to implement. I considered using the new Zoom feature but will wait because my app could be used on Win 7.
Thanks again for all this!
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Uber Geek :ugeek:](./images/smilies/icon_e_ugeek.gif)
Re: [Library] Edit v3.0 - Update and Manage any Edit Control
Thank you for your interest. I'm glad that you find the Edit library useful.
About the Zoom feature...
For Windows 10+, Zoom is a feature that is built-in to the Edit control. Once enabled, the user will be able to Zoom in and out without any other programming.
The key is the Edit_EnableZoom function. After the Edit control has been created, just call it once to enable Zoom. Once enabled, the user can use Ctrl+WheelUp and Ctrl+WheelDown to zoom in and out. The other Zoom functions in the Edit library are included just in case you want to add some additional Zoom-related functionality but they are not required.
So, what happens when you call Edit_EnableZoom on a Windows 7 machine? To be honest, I don't know. I don't have access to a Window 7 machine anymore. I'm betting that nothing bad happens but you would have to give it a try to see. If it does nothing on Windows 7 then it should be safe to call on all versions of Windows but it would only work on Windows 10+.
Them be my thoughts. Good luck!
About the Zoom feature...
For Windows 10+, Zoom is a feature that is built-in to the Edit control. Once enabled, the user will be able to Zoom in and out without any other programming.
The key is the Edit_EnableZoom function. After the Edit control has been created, just call it once to enable Zoom. Once enabled, the user can use Ctrl+WheelUp and Ctrl+WheelDown to zoom in and out. The other Zoom functions in the Edit library are included just in case you want to add some additional Zoom-related functionality but they are not required.
So, what happens when you call Edit_EnableZoom on a Windows 7 machine? To be honest, I don't know. I don't have access to a Window 7 machine anymore. I'm betting that nothing bad happens but you would have to give it a try to see. If it does nothing on Windows 7 then it should be safe to call on all versions of Windows but it would only work on Windows 10+.
Them be my thoughts. Good luck!
Re: [Library] Edit v3.0 - Update and Manage any Edit Control
I've tested Edit_EnableZoom and it worked well on my Win 10 system. I don't have access to a Win 7 system myself to test it. I would assume the function does nothing.
I already implemented a Zoom feature in my app using an UpDown control and Ctrl+WheelUp and Ctrl+WheelDown hotkeys to increase/decrease the font size. I'd prefer to use the new zoom function but I'd have to keep the old way as an alternative for Win7 users.
I already implemented a Zoom feature in my app using an UpDown control and Ctrl+WheelUp and Ctrl+WheelDown hotkeys to increase/decrease the font size. I'd prefer to use the new zoom function but I'd have to keep the old way as an alternative for Win7 users.
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Uber Geek :ugeek:](./images/smilies/icon_e_ugeek.gif)
Re: [Library] Edit v3.0 - Update and Manage any Edit Control
I needed it quickly so cobbled together a trim whitespace function, either selected text or all text in the edit control and trim leading, trailing, or both (default is both). Undo works, but caret position or keeping text selected is out the window ![Smile :)](./images/smilies/icon_e_smile.gif)
![Smile :)](./images/smilies/icon_e_smile.gif)
Code: Select all
Edit_Trim(hEdit) ; trim leading+trailing
Edit_Trim(hEdit,1) ; trim leading
Edit_Trim(hEdit,2) ; trim trailing
Code: Select all
;-----------------------------
;
; Function: Edit_Trim
;
; Description:
;
; Trim leading/trailing white space. If nothing is selected, the entire text is trimmed.
;
; Options:
; 1: Leading
; 2: Trailing
; 3: Leading & Trailing (default)
;
; Type:
;
; Add-on function.
;
; Calls To Other Functions:
;
; * <Edit_TextIsSelected>
; * <Edit_GetSelText>
; * <Edit_GetText>
; * <Edit_ReplaceSel>
; * <Edit_ScrollCaret>
; * <Edit_SelectAll>
; * <Edit_SetSel>
;
; Remarks:
;
; * Undo can be used to reverse this action.
;
;-------------------------------------------------------------------------------
Edit_Trim(hEdit,trim=3)
{
;-- Initialize
l_LastSelectedLineIncludesEOL:=False
If Edit_TextIsSelected(hEdit)
l_SelectedText:=Edit_GetSelText(hEdit)
else
l_SelectedText:=Edit_GetText(hEdit)
;[========]
;[ Trim ]
;[========]
If (trim = 3) ; leading & trailing
trimfunc:="Trim"
else If (trim = 2) ; trailing
trimfunc:="RTrim"
else ; leading
trimfunc:="LTrim"
loop, parse, l_SelectedText, `n, `r
l_NewText .= %trimfunc%(A_LoopField, " `t`r`n") "`r`n"
l_NewText:=SubStr(l_NewText,1, -1)
;-- Replace selected text with new text
If Edit_TextIsSelected(hEdit)
Edit_ReplaceSel(hEdit,l_NewText)
else {
Edit_SelectAll(hEdit)
Edit_ReplaceSel(hEdit,l_NewText)
}
;[==============]
;[ Reposition ]
;[==============]
Edit_ScrollCaret(hEdit)
;-- This keeps the original selection in view
Edit_LineScroll(hEdit,"Left")
;-- Fixes a display problem that sometimes occurs if adding lines that
; are wider than the control
}
Re: [Library] Edit v3.0 - Update and Manage any Edit Control
Looks interesting. I'll give a try. Thanks!
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: fiendhunter and 59 guests