XYAHK_customInlineRenameKeys

Discuss and share scripts and script files...
Post Reply
autocart
Posts: 758
Joined: 26 Sep 2013 15:22

XYAHK_customInlineRenameKeys

Post by autocart » 08 Oct 2014 10:39

[edited]

current versions can be downloaded here:
The zips each contain both the ahk-code-file and the compiled exe.
USAGE AT EVERYBODY'S OWN RISK!!!
XYAHK_inlineRenameOldStyle_v0.002.zip
(382.52 KiB) Downloaded 106 times
XYAHK_customInlineRenameMouse++_v0.002.zip
(384.77 KiB) Downloaded 94 times
"ultimate" version:
XYAHK_customInlineRenameKeys_v0.006.zip
(387.33 KiB) Downloaded 120 times
Note: "OldStyle" and "Mouse++" can be run together, if desired. "Ultimate", though, includes the other two already, so do not run it together with them.

Hi all,
Because of this and this thread I decided to make an ahk script, that change the behavior of the keys and mouse-clicks inside the inline-rename-box. It takes effect in pane1, pane2, tree and the catalog.
I made three variations. Since the code is available everybody can adapt it to his/her own likings. For those who don't want to mess around with ahk code I also provide compiled exes (inside the zip-download).

XYAHK_inlineRenameOldStyle:
Implements only small changes: On a current selection the arrow keys behave as in Windows Explorer. The up and down keys switch to the next filename in the list immediately even if there is a current selection (only if the basic XY setting is activated in configuration of course).

XYAHK_customInlineRenameMouse++:
On double click it makes the edit box select only only alpha-numeric connected characters (e.g. excluding the extension-dot from the selection).

XYAHK_customInlineRenameKeys (ultimate version):
The ultimate in XYplorer inline-renaming :mrgreen: (as far as I could make it). If I think of "perfecting" the behaviour of inline-renaming in XYplorer then this is (almost) kind of the way I would want it:

Functionalities of "XYAHK_inlineRenameOldStyle" and "XYAHK_customInlineRenameMouse++" is already build-in.
On top of that it has lots of build-in logic: End and Home first jump to the ends of a current selection. End (without current selection) toggles between end of name base and of extension. Multiple F2 toggles nicer. Up and Down have a smartness of where to put the caret in the next filename.

It has one little (not really important) quirk: Making a selection with Shift+End keys where the caret ends up in front of the selection (which could normally never happen but it can here because End here toggles also to the end of the name base) can be a little slow at times or else it may have a little visual flicker.

Here is the ahk code of the first two (simpler) versions without having to download:

XYAHK_inlineRenameOldStyle_v0.002.ahk:

Code: Select all

; copyright: Stephan Bartl working at gk-medizinmechanik.at, 1st version on October 8th, 2014
; script name: XYAHK_inlineRenameOldStyle
; version 0.002
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
#SingleInstance force
titleMatchStringForXY := "XYplorer ahk_class ThunderRT6FormDC"
SetTitleMatchMode, 2
SetKeyDelay, 0

#if editNNHavingFocus := _XYOneOfEditNNHasFocus("Edit15|Edit17|Edit18|Edit19", titleMatchStringForXY)
Left::
ControlGet, selectedText, Selected, , %editNNHavingFocus%, %titleMatchStringForXY%
if (selectedText)
   ControlSend, %editNNHavingFocus%, {Right}{Left}, %titleMatchStringForXY%
else
   ControlSend, %editNNHavingFocus%, {Left}, %titleMatchStringForXY%
return

Right::
ControlGet, selectedText, Selected, , %editNNHavingFocus%, %titleMatchStringForXY%
if (selectedText)
   ControlSend, %editNNHavingFocus%, {Right}{Right}, %titleMatchStringForXY%
else
   ControlSend, %editNNHavingFocus%, {Right}, %titleMatchStringForXY%
return

Up::
ControlGet, selectedText, Selected, , %editNNHavingFocus%, %titleMatchStringForXY%
if (selectedText)
   ControlSend, %editNNHavingFocus%, {Right}{Up}, %titleMatchStringForXY%
else
   ControlSend, %editNNHavingFocus%, {Up}, %titleMatchStringForXY%
return

Down::
ControlGet, selectedText, Selected, , %editNNHavingFocus%, %titleMatchStringForXY%
if (selectedText)
   ControlSend, %editNNHavingFocus%, {Right}{Down}, %titleMatchStringForXY%
else
   ControlSend, %editNNHavingFocus%, {Down}, %titleMatchStringForXY%
return
#if

_XYOneOfEditNNHasFocus(listOfEditNNs, WinTitle)
{
	ControlGetFocus, focusedControl, %WinTitle%
	return InStr(listOfEditNNs . "|", focusedControl . "|") ? focusedControl : 0
}
XYAHK_customInlineRenameMouse++_v0.002.ahk:

Code: Select all

; copyright: Stephan Bartl working at gk-medizinmechanik.at, 1st version on October 8th, 2014
; script name: XYAHK_customInlineRenameMouse++
; version 0.002
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
#SingleInstance force
SetTitleMatchMode, 2
SetKeyDelay, 0
SetMouseDelay, 0
titleMatchStringForXY := "XYplorer ahk_class ThunderRT6FormDC"
clicks := mouseX1 := mouseY1 := 0

;code for mapping the double click based on http://www.autohotkey.com/board/topic/16321-map-a-double-left-mouse-click-to-a-single-key/?p=105959 by user jonny 
#if (editNNHavingFocus := _XYOneOfEditNNsHasFocus("Edit15|Edit17|Edit18|Edit19", titleMatchStringForXY)) and clicks = 0
~LButton::
CoordMode, Mouse, Window
MouseGetPos, mouseX1, mouseY1
clicks := 1
SetTimer, ClickWait, 400
return

#if (editNNHavingFocus := _XYOneOfEditNNsHasFocus("Edit15|Edit17|Edit18|Edit19", titleMatchStringForXY)) and clicks > 0
LButton::
CoordMode, Mouse, Window
clicks++
if (clicks = 2)
{
	MouseGetPos, mouseX2, mouseY2
	if (mouseX1 = mouseX2 and mouseY1 = mouseY2)
	{
		ControlGetText, textOfEdit, %editNNHavingFocus%, %titleMatchStringForXY%
		caretPos := _Edit_CaretGetPos(editNNHavingFocus, titleMatchStringForXY)
		selectFromPos := 0
		selectToPos := caretPos
		Loop, parse, textOfEdit
		{
			if (A_Index <= caretPos)
			{
				if A_LoopField is not alnum
					selectFromPos := A_Index
			}
			else if (A_Index > caretPos)
				if A_LoopField is alnum
					selectToPos++
				else
					break
		}
		_Edit_Select(selectFromPos, selectToPos, editNNHavingFocus, titleMatchStringForXY)
	}
	else
	{
		SetTimer, ClickWait, off
		clicks := 0
	}
}
else if (clicks = 3)
{
	MouseGetPos, mouseX3, mouseY3
	if (mouseX3 = mouseX2 and mouseY3 = mouseY2)
	{
		_Edit_Select(0, -1, editNNHavingFocus, titleMatchStringForXY)
	}
	else
	{
		SetTimer, ClickWait, off
		clicks := 0
	}
}
return

ClickWait:
SetTimer, ClickWait, off
clicks := 0
return
#if

_XYOneOfEditNNsHasFocus(listOfEditNNs, wintitle)
{
   ; This script retrieves the ahk_id (HWND) of the active window's focused control. - taken from the ahk help file
	GuiThreadInfoSize = 48
	VarSetCapacity(GuiThreadInfo, GuiThreadInfoSize)
	NumPut(GuiThreadInfoSize, GuiThreadInfo, 0)
	if not DllCall("GetGUIThreadInfo", uint, 0, str, GuiThreadInfo)
	{
		focusedHWND := 0
	}
	else
		focusedHWND := NumGet(GuiThreadInfo, 12)  ; Retrieve the hwndFocus field from the struct.
	
	returnValue := 0
	Loop, parse, listOfEditNNs, |
	{
		ControlGet, hEdit, hwnd, , %A_LoopField%, %wintitle%
		if (hEdit = focusedHWND)
			returnValue := A_LoopField
	}
	return returnValue
}

; Gets the current caret position (zero-based) of an edit control having input focus
; (at least for XYplorer inline-edit-controls).
; This function is IMHO preferable over ControlGet, outVar, CurrentCol, ... because
; the build in function is not reliable with the caret position around selections.
;
_Edit_CaretGetPos(editNNHavingFocus, wintitle)
{
	ControlGetFocus, focusedControl, %wintitle%
	if (focusedControl = editNNHavingFocus)
	{
		ControlGet, hEdit, hwnd, , %editNNHavingFocus%, %wintitle%
		ControlGetPos, editX, editY, editW, editH, %editNNHavingFocus%, %wintitle%
		CoordMode, Caret, Window
		_EM_CHARFROMPOS(hEdit, A_CaretX - editX, A_CaretY - editY, charPos, line)
	}
	else
		charPos := ""
	return charPos
}

;***** the following function from http://ahkscript.org/boards/viewtopic.php?f=5&t=4826&p=27883#p27857 by user "just me"
;***** alteration: made the returned index number zero-based
; ======================================================================================================================
; Gets information about the character closest to a specified point in the client area of an edit control.
; X, Y            -  the X- and Y-positions of the point.
; CharPos, Line   -  receive the character position and the line number.
; ======================================================================================================================
_EM_CHARFROMPOS(HWND, X, Y, ByRef CharPos, ByRef Line) {
   ; _EM_CHARFROMPOS = 0x00D7 -> msdn.microsoft.com/en-us/library/bb761566(v=vs.85).aspx
   CharPos := Line := 0
   CharLine := DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", 0x00D7, "Ptr", 0, "UInt", (Y << 16) | X, "Ptr")
   CharPos := (CharLine & 0xFFFF)
   Line := (CharLine >> 16)
   Return True
}

;*******following functions from http://www.autohotkey.com/board/topic/20981-edit-control-functions/ by user Lexikos
; Standard parameters:
;   Control, WinTitle   If WinTitle is not specified, 'Control' may be the
;                       unique ID (hwnd) of the control.  If "A" is specified
;                       in Control, the control with input focus is used.
;
; Standard/default return value:
;   true on success, otherwise false.
_Edit_Standard_Params(ByRef Control, ByRef WinTitle) {  ; Helper function.
    if (Control="A" && WinTitle="") { ; Control is "A", use focused control.
        ControlGetFocus, Control, A
        WinTitle = A
    } else if (Control+0!="" && WinTitle="") {  ; Control is numeric, assume its a ahk_id.
        WinTitle := "ahk_id " . Control
        Control =
    }
}

; Selects text in a text box, given absolute character positions (starting at 0.)
;
; start:    Starting character offset, or -1 to deselect.
; end:      Ending character offset, or -1 for "end of text."
;
_Edit_Select(start=0, end=-1, Control="", WinTitle="")
{
    _Edit_Standard_Params(Control, WinTitle)
    SendMessage, 0xB1, start, end, %Control%, %WinTitle%  ; EM_SETSEL
    return (ErrorLevel != "FAIL")
}
Last edited by autocart on 16 Oct 2014 07:37, edited 10 times in total.
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

SammaySarkar
Posts: 4190
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: XYAHK_customInlineRenameKeys

Post by SammaySarkar » 08 Oct 2014 19:03

May I provide a hint for users that replacing all instances of "Edit18" with "Edit15" in the script makes it 2nd-pane-compatible. :)

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 08 Oct 2014 21:56

correct, thx for pointing it out, Sammay. i skipped this detail because I thought with the ahk skills one needs to adapt it to his/her own needs/wishes one would find that out anyways along the way. Thx anyway.
Besides, I am working on an improved version that will also take care of pane 2 and also of the tree (Edit19) and the catalog (Edit17). Despite there being more Edit-boxes in XY, at least that would then take care of the inline renaming boxes, which this whole thing actually is all about.
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 08 Oct 2014 22:55

alrighty, folks, here it is. For now I tried to bring back the old style (as far as I remember it - if I got something wrong then please feed it back to me). Since the style in this case is pretty much pre-defined I compiled this one into an exe, found together with again the ahk source code in the zip. It takes care of pane1+2, tree and catalog inline rename boxes.
Usage at everybody's own risk!

EDIT:
For the download and code please see the first post: http://www.xyplorer.com/xyfc/viewtopic. ... 04#p112904
Last edited by autocart on 15 Oct 2014 18:29, edited 1 time in total.
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 13 Oct 2014 22:25

2 new downloads:

I) XYAHK_customInlineRenameMouse++:
(compatiple with the download above "XYAHK_inlineRenameOldStyle")
Only selects consecutive alpha-numeric characters on double click when inline-renaming in XYplorer. (selection stops before dots, underscores, dashes, spaces and similar.)

II) XYAHK_customInlineRenameKeys v0.003:
The ultimate in XYplorer inline-renaming :mrgreen: (as far as I could make it). If I think of "perfecting" the behaviour of inline-renaming in XYplorer then this is kind of the way I would want it:

Mouse-improvement of point I) is already build-in.
And lots of build-in logic: End and Home first jump to the ends of a current selection. End (without current selection) toggles between end of base name and of extension. Multiple F2 toggles nicer. Up and Down have a smartness of where to put the caret in the next filename. And of course the "old" left-right-behaviour when "leaving" a current selection.

(I know, in the other thread I was arguing for leaving things as in Windows Explorer, but since I could now build "my" perfect way... :whistle: please don't pelt me with stones. :) )

Only "limitation": Making selections with the End-key when the cursor ends up in front of selection can be a little slow at times.

Each zip contains the the code as ahk-file and a compiled exe.
USAGE AT EVERYBODY'S OWN RISK!!!!

EDIT:
For the download please see the first post: http://www.xyplorer.com/xyfc/viewtopic. ... 04#p112904

ATTENTION!!!Stupid side-effect, that I just found out: It unfortunately stops the double click from working when inline-renaming is NOT active. Trying to fix it. (see also http://www.xyplorer.com/xyfc/viewtopic. ... 51#p113051) ---> fixed. see below.
Last edited by autocart on 15 Oct 2014 18:24, edited 5 times in total.
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 15 Oct 2014 10:34

Hi all,
fixed bug of not working double click if edit-box is NOT active successfully. Enjoy.

The zips again contain the code as ahk-file and a compiled exe.
USAGE AT EVERYBODY'S OWN RISK!!!

EDIT:
For the download please see the first post: http://www.xyplorer.com/xyfc/viewtopic. ... 04#p112904

("XYAHK_customInlineRenameMouse++" is compatiple with the download above "XYAHK_inlineRenameOldStyle". However it is not recommended to use it with the full version of "XYAHK_customInlineRenameKeys" since that version has the mouse-improvement already build-in.)
Last edited by autocart on 15 Oct 2014 18:26, edited 2 times in total.
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 15 Oct 2014 12:49

minor bug-fix

The zip again contains the code as ahk-file and a compiled exe.
USAGE AT EVERYBODY'S OWN RISK!!!

EDIT:
For the download please see the first post: http://www.xyplorer.com/xyfc/viewtopic. ... 04#p112904
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 15 Oct 2014 22:25

I'll give this one a try:

If you, dear XY-user, want your inline-renaming in a special tailor-made way but are too buisy or lazy to deal with the ahk code then tell me (as accurately as possible) how you want it and I will try to tailor it to your wishes. Only I can not give a guarantee as far as what will work and how soon it will be ready (or if I will anyway try it in each case). Plus I will post it here in the forum for public download.
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 15 Oct 2014 23:46

New version:
XYAHK_customInlineRenameKeys_v0.006
bug fix of positioning caret after going up/down to next filename and caret was at Home position.
http://www.xyplorer.com/xyfc/viewtopic. ... 04#p112904
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

sfwood
Posts: 115
Joined: 10 Jan 2012 21:07

Re: XYAHK_customInlineRenameKeys

Post by sfwood » 16 Oct 2014 06:24

This really is quite cool. A seemingly little thing that adds really useful functionality. I thought all I cared about was the mouse dbl-click behavior, but tried XYAHK_customInlineRenameKeys_v0.006 and am sold on the kb enhancements.

I don't know if AHK can overide program key defs, but playing around with renaming w/ your script active, the Tab key really cries out to select the word the cursor is in and then sequentially select words in the file/folder name with additional presses (left to right by def, right to left with shift, of course). Kind of like you have F2 now but finer grained. As far as I can see, Tab just dupes down arrow as is, so no loss. Anyway, if you're bored :-)

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 16 Oct 2014 07:33

Thank you sfwood, I am happy to read that, this is nice of you to say.
The thought about the Tab key should be no problem to implement.
The main questions to me are: What exactly is "a word" to you in this context? Should a word also contain non-alpha-numeric chars? If so, at the beginning or end of the word? Reversly, what to do with non-alpha-numeric chars at the end or beginning of the file name? How to handle the extension dot? Skip or include the extension itself?

Regarding the arrow key: The fine difference is that the Tab key also selects the base of the next file name while up/down does not select anything. But I agree with you that the Tab key could be assigned to something else w/o problem. I think, I will post it as a seperate download, though.
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

sfwood
Posts: 115
Joined: 10 Jan 2012 21:07

Re: XYAHK_customInlineRenameKeys

Post by sfwood » 16 Oct 2014 09:02

autocart wrote:The main questions to me are: What exactly is "a word" to you in this context? Should a word also contain non-alpha-numeric chars? If so, at the beginning or end of the word? Reversly, what to do with non-alpha-numeric chars at the end or beginning of the file name? How to handle the extension dot? Skip or include the extension itself?
Just like for the mouse dbl-click feature. If I have, say, "October 2014 newsletter.doc" or "October-2014-newsletter.doc", w/ in-place rename active, pressing Tab selects "October", or "2014", or "newsletter", or "doc" (whichever is under or to right of cursor). Then pressing again moves to and selects next word. If on ext, pressing again cycles back to first word. So, yes, I would count the ext as a word, but would ignore all non-alphanums/punctuation.
autocart wrote:Regarding the arrow key: The fine difference is that the Tab key also selects the base of the next file name while up/down does not select anything. But I agree with you that the Tab key could be assigned to something else w/o problem. I think, I will post it as a seperate download, though.
Ahh, missed that. Don't think I'd override that. Looks like Ctrl-Tab is avail for cycling selection w/in name, along w/ Ctrl-Shift-Tab for cycling backwards.

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 17 Oct 2014 09:23

Ok, I am working on it... right now a lot going on. couple of days probably.
Improvement of the double click is also coming.
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

autocart
Posts: 758
Joined: 26 Sep 2013 15:22

Re: XYAHK_customInlineRenameKeys

Post by autocart » 04 Nov 2014 11:52

sorry, I was sick and demotivated.
I did not give up though.
please hold on for a little while longer, thx.
customInlineRenameKeys ("OldStyle", "Mouse++" and "Ultimate"), clipboardHelper_and_XYEscToList

Post Reply