Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
+RETURN keypress updates filter while paused
Browse files Browse the repository at this point in the history
+pause status change triggers filter update
+comments!!!
(actually, sourcecode snapshots so far had been
retrieved from compiled executables that stored
scripts in a minified and commentstripped form)
  • Loading branch information
bdeshi committed Nov 20, 2015
1 parent 6996e43 commit 6931f0e
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 72 deletions.
157 changes: 90 additions & 67 deletions XYAHKLiveFilter.ahk
Original file line number Diff line number Diff line change
@@ -1,80 +1,87 @@
; XYAHKLiveFilter v4
#SingleInstance, Off
#NoEnv
SetBatchLines, 10ms
SetControlDelay, -1

XYhWnd = %1%
Shortcut = %2%
ABPadding = %3%
ABPadding := (ABPadding+0)="" ? 5 : ABPadding
SyncPos = %4%
;XYAHKLiveFilter.ahk//v4.1
;Author:SammaySarkar//Credits:autocart, binocular222, SKAN (AHK forum)
;http://xyplorer.com/xyfc/viewtopic.php?t=12588
#SingleInstance, Off ;multiple instances can run for multiple XY instances
#NoEnv ;(recommended)
SetBatchLines, 10ms ;good balance of speed/CPU (so says AHK doc)
SetControlDelay, -1 ;fastest possible control operations

XYhWnd = %1% ;parent/target XY window
Shortcut = %2% ;hotkey to focus filterbox
ABPadding = %3% ;manual adjustent of GUI Y (for same Y of AB)
ABPadding := (ABPadding+0)="" ? 5 : ABPadding ;default ABPadding = 5
SyncPos = %4% ;keep GUI position synced with AB (else at the topleft of XY)
TTShow = %5%
AHKhWnd := A_ScriptHwnd + 0
Global ReceivedData
AHKhWnd := A_ScriptHwnd + 0 ;pass as hwnd to SC copydata
Global ReceivedData ;holds WM_COPYDATA return (temporarily)

OnExit, ExitRoutine
OnMessage(0x4a, "MsgFromXY")
OnMessage(0x200, "FocusGUI")
OnMessage(0x7e, "Destroyer")
OnMessage(0x4a, "MsgFromXY") ;WM_COPYDATA
OnMessage(0x200, "FocusGUI") ;WM_MOUSEMOVE
OnMessage(0x7e, "Destroyer") ;WM_DESTROY

;create GUI and hotkeys
Gui, +HwndGUIhWnd -Border -Caption +OwnDialogs +AlwaysOnTop
Gui, Margin, 1, 1
If (SyncPos = 1)
Gosub, ABattribs
Else {
Gosub, ABattribs ;obtain AB attribs
Else { ;else gui will be at topleft of XY clientarea
GUIX = 1
GUIY = 1
FontName = Segoe UI
FontSize = 8
}
Gui, Font, s%FontSize%, %FontName%
GUI, Add, Checkbox, gUpdateFilter hWndGUIPausehWnd 0xc00, P
Gui, Add, Edit, y1 gUpdateFilter hWndGUIEdithWnd R1, ""
DllCall("SetParent", "UInt", GUIhWnd, "UInt", XYhWnd)
GUI, Add, Checkbox, gCallUpdateFilter hWndGUIPausehWnd 0xc00, P ;livemode toggle
Gui, Add, Edit, y1 gCallUpdateFilter hWndGUIEdithWnd R1, "" ;the filterbox
DllCall("SetParent", "UInt", GUIhWnd, "UInt", XYhWnd) ;set child of XY
GuiControlGet, EditPos, Pos, %GUIEdithWnd%
GuiControl, Move, %GUIEdithWnd%, % "w" EditPosW*8
GuiControl, Move, %GUIPausehWnd%, % "h" EditPosH
GuiControl, Move, %GUIEdithWnd%, % "w" EditPosW*8 ;a ~standard width
GuiControl, Move, %GUIPausehWnd%, % "h" EditPosH ;chkbox H==edit H:center-align
Gui, Show, X%GUIX% Y%GUIY% AutoSize
SendInput, {Right}{Left}

If (SyncPos = 1) {
SendInput, {Right}{Left} ;put cursor between default quotes
If (SyncPos = 1) { ;right align filterbox
WinGetPos, , , GUIW, , ahk_id %GUIhWnd%
GUIX := ABX + ABW - xborder - GUIW
GUIX := ABX + ABW - xborder - GUIW ;account for GUIWidth
WinMove, ahk_id %GUIhWnd%, , %GUIX%, %GUIY%
SetTimer, UpdatePos, 100
SetTimer, UpdatePos, 100 ;turn on the synchronizer
}

Hotkey, IfWinActive, ahk_id %GUIhWnd%
Hotkey, Tab, lblFocusXY
Hotkey, Tab, lblFocusXY ;tab to give focus to XY
;Hotkey, IfWinActive, ahk_id %GUIhWnd%
Hotkey, Enter, UpdateFilter ;ENTER to force filter update
If (Shortcut) {
Hotkey, IfWinActive, ahk_id %XYhWnd%
Hotkey, %Shortcut%, lblFocusGUI
Hotkey, %Shortcut%, lblFocusGUI ;hotkey to refocus filterbox
}

Return
;=== END OF AUTO-EXECUTION SECTION =============================================

;obtain AddressBar attributes, called only if SyncPos=1
ABattribs:
;ensure AB is visible
MsgToXy("::copydata " AHKHwnd ",get('#660'),0;setlayout('showaddressbar=1');")
ABState := ReceivedData
;^get(#660) AB visibility (1/0)
ABState := ReceivedData ;remember prev AB visibility (for reverting)
ReceivedData =
;infer AB position relative to clientarea (thanks, autocart :) )
ControlGet, XYABhWnd, Hwnd, , Edit16, ahk_id %XYhWnd%
;^Edit16 isn't a static idenifier either, fingers crossed ...
ControlGetPos, ABX, ABY, ABW, ABH, , ahk_id %XYABhWnd%
SysGet, xborder, 32
SysGet, yborder, 33
SysGet, CaptionH, 4
SysGet, MenuH, 15
GUIX := ABX + ABW - xborder
GUIX := ABX + ABW - xborder ;^ GUIWidth is accounted for after GUI, Show
GUIY := ABY - yborder - CaptionH - MenuH - ABPadding
FontName:= GetFont(XYABhWnd)
FontSize:= A_LastError
FontName:= GetFont(XYABhWnd), FontSize:= A_LastError ;font of AB
Return

;update filterbox position to match AB. Called by timer
UpdatePos:
If WinActive("ahk_id" XYhWnd) {
ControlGet, ABvis, Visible, , , ahk_id %XYABhWnd%
If (ABvis = 0)
ControlGet, ABvis, Visible, , , ahk_id %XYABhWnd% ;get AB visiblity
If (ABvis = 0) ;so you hid the AB? Not allowed while I'm syncing, sorry.
MsgToXY("::setlayout('showaddressbar=1')")
PABP = %ABX% %ABY% %ABH% %ABW%
PABH = %ABH%
Expand All @@ -84,26 +91,32 @@ UpdatePos:
If (PABP != CABP) {
GUIX := ABX + ABW - xborder - GUIW
GUIY := ABY - yborder - CaptionH - MenuH - ABPadding
GUIH := ABH + ABPadding + 1
If (PABH <> CABH) {
FontName:= GetFont(XYABhWnd),
FontSize:= A_LastError
Gui, Font, s%FontSize%, %FontName%
GuiControl, Font, %GUiPausehWnd%
GuiControl, Font, %GUiEdithWnd%
GUIH := ABH + ABPadding + 1 ;1 is to account for margin
If (PABH <> CABH) { ;change of height means font change
FontName:= GetFont(XYABhWnd), FontSize:= A_LastError ;new font
Gui, Font, s%FontSize%, %FontName% ;set new font
GuiControl, Font, %GUiPausehWnd% ;apply to filterbox
GuiControl, Font, %GUiEdithWnd% ;and P chkbox
}
WinMove, ahk_id %GUIhWnd%, , %GUIX%, %GUIY%, , %GUIH%
GuiControl, move, %GUiPausehWnd%, h%GUIH%
GuiControl, move, %GUiEdithWnd%, h%GUIH%
WinMove, ahk_id %GUIhWnd%, , %GUIX%, %GUIY%, , %GUIH% ;sync pos with AB
GuiControl, move, %GUIPausehWnd%, h%GUIH% ;set equal height to filter...
GuiControl, move, %GUIEdithWnd%, h%GUIH% ;...and chkbox to center align
}
}
Return

UpdateFilter:
GuiControlGet, Paused, , %GUIPausehWnd%
;triggered by filterbox content change. Passes box scontent to SC filter
CallUpdateFilter:
GuiControlGet, Paused, , %GUIPausehWnd% ;get 'P'ause state
If (Paused = 1)
Return
Return ;stop msging (ie live-flitering) while paused
GoSub, UpdateFilter
Return

;get filterbox content and pass to XY
UpdateFilter:
GuiControlGet, StrFilter, , %GUIEdithWnd%
;same filter twice resets VF, guard against this
If (StrFilterLast != StrFilter) {
StrFilterLast := StrFilter
StrFilter = ::filter %StrFilter%
Expand All @@ -124,10 +137,12 @@ lblFocusGUI:
FocusGUI()
Return

;focus the GUI .Here triggered on WM_Mouseover (else ctrl under GUI gets focus)
FocusGUI() {
global
IfWinActive, ahk_id %XYhWnd%
WinActivate, ahk_id %GUIEdithWnd%
;show a little tooltip
IfWinActive, ahk_id %GUIhWnd%
{
If (TTShow != 1) {
Expand All @@ -136,21 +151,19 @@ FocusGUI() {
SetTimer, TTOn, 10
}
Return

TTOn:
ToolTip, P: Pause live mode
ToolTip, % "CHECK 'P': Pause live mode`nTEXTBOX: enter filter`nFOCUS HOTKEY:"
. (Shortcut = "" ? "None": Shortcut)
SetTimer, TTOn, Off
SetTimer, TTOff, 800
SetTimer, TTOff, 1000
Return

TTOff:
ToolTip
SetTimer, TTOff, Off
Return
}
Return
}

FocusXY() {
global
IfWinActive, ahk_id %GUIhWnd%
Expand All @@ -163,7 +176,9 @@ Destroyer() {
Return
}

;function lifted from binocular222's XYplorer Messenger[AHK], (thanks!)
;=== MsgToXY() =================================================================
;send arg_Msg to %XYhWnd% via WM_COPYDATA
;functin lifted from binocular222's XYplorer Messenger[AHK], (thanks!)
MsgToXY(arg_Msg) {
global XYhWnd
Size := StrLen(arg_Msg)
Expand All @@ -179,7 +194,9 @@ MsgToXY(arg_Msg) {
SendMessage, 0x4A, 0, &COPYDATA, , ahk_id %XYhWnd%
Return
}

;=== End of MsgToXY() ==========================================================
;=== MsgFromXY() ===============================================================
;receive WM_COPYDATA from %XYhWnd% to %ReceivedData%
;also based on binocular222's code
MsgFromXY(wParam, lParam) {
StringAddress := NumGet(lParam + 2*A_PtrSize)
Expand All @@ -188,21 +205,27 @@ MsgFromXY(wParam, lParam) {
StringLeft, ReceivedData, CopyOfData, cbData
Return
}
;=== End of MsgFromXY() ========================================================

;=== GetFont() =================================================================
;returns font (and it's size) used in a ctrl with hwnd of arg_hWnd
;fontname = function return, and fontsize = A_LastError
;By SKAN www.autohotkey.com/forum/viewtopic.php?p=465438#465438
GetFont(arg_hwnd) {
SendMessage 0x31, 0, 0, , ahk_id %arg_hwnd%
IfEqual, ErrorLevel, FAIL, Return
hFont := Errorlevel, VarSetCapacity(LF, szLF := 60*(A_IsUnicode ? 2:1))
DllCall("GetObject", UInt, hFont, Int, szLF, UInt, &LF)
hDC := DllCall("GetDC", UInt, hwnd), DPI := DllCall("GetDeviceCaps", UInt, hDC, Int, 90)
DllCall("ReleaseDC", Int, 0, UInt, hDC), S := Round((-NumGet(LF, 0, "Int")*72)/DPI)
Return DllCall("MulDiv", Int, &LF+28, Int, 1, Int, 1, Str), DllCall("SetLastError", UInt, S)
SendMessage 0x31,0,0,,ahk_id %arg_hwnd%
IfEqual,ErrorLevel,FAIL,Return
hFont := Errorlevel,VarSetCapacity(LF,szLF := 60*(A_IsUnicode ? 2:1))
DllCall("GetObject",UInt,hFont,Int,szLF,UInt,&LF)
hDC := DllCall("GetDC",UInt,hwnd),DPI := DllCall("GetDeviceCaps",UInt,hDC,Int,90)
DllCall("ReleaseDC",Int,0,UInt,hDC),S := Round((-NumGet(LF,0,"Int")*72)/DPI)
Return DllCall("MulDiv",Int,&LF+28,Int,1,Int,1,Str),DllCall("SetLastError",UInt,S)
}
;=== End of GetFont() ==========================================================

;cleanup filter and perms on exit. Triggered on "normal" script/GUI exit
ExitRoutine:
GUI, Hide
If (SyncPos = 1)
GUI, Hide ;exiting "looks" slightly faster
If (SyncPos = 1) ;if so then revert AB visibility to pre-exec
MsgToXY("::setlayout('showaddressbar=" ABState "');")
MsgToXY("::filter;unset $p_XYAHKLiveFilter_A,$p_XYAHKLiveFilter_B;")
ExitApp
Expand Down
3 changes: 2 additions & 1 deletion XYAHKLiveFilter.xys
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//XYAHKLiveFilter v4.0.0
//XYAHKLiveFilter.ahk//v4.1//author:SammaySarkar
//http://xyplorer.com/xyfc/viewtopic.php?f=7&t=12588
perm $p_XYAHKLiveFilter_A, $p_XYAHKLiveFilter_B;
if ($p_XYAHKLiveFilter_A != 1)||($p_XYAHKLiveFilter_B != <hwnd>){
$p_XYAHKLiveFilter_A = 1; $p_XYAHKLiveFilter_B = <hwnd>;
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## [XYAHKLiveFilter](https://www.github.com/SammaySarkar/XYAHKLiveFilter)
http://www.xyplorer.com/xyfc/viewtopic.php?t=12588

####**version 4**
**version 4.1.0**

A live-filter plugin for [XYplorer](http://www.xyplorer.com), made in [AutoHotkey](http://www.ahkscript.org)
A live-filter plugin for [XYplorer](http://www.xyplorer.com), made with [AutoHotkey](http://www.ahkscript.org)
Live-filters the file list as you type into a textbox. Uses SC `filter`, so all its syntax is available.

###INSTALL:
Expand Down Expand Up @@ -33,6 +33,7 @@ Live-filters the file list as you type into a textbox. Uses SC `filter`, so all
See `$FocusHotkey` in the **OPTIONS** section below for more details.
* Press <kbd>ESCAPE</kbd> while the filterbox is focused to close it. (also quits automatically when parent XY window is closed.)
* Live-filtering is not suitable for RegExp patterns. Check the **P** checkbox to pause livemode, enter complex/RegExp pattern, then uncheck it again to submit.
* You can press <kbd>ENTER</kbd> to force a filter update while livemode is paused.
* Full content of the filterbox is passed to SC `filter` unchanged, so should be properly escaped according to XYplorer scripting rules when necessary.
* If you use the script as a UDC with a keyboard shortcut, I suggest setting the same shortcut as `$FocusHotkey`.<br/>
This way, you can use the same keypresses to launch the filterbox and focus it subsequently.
Expand Down Expand Up @@ -62,6 +63,5 @@ Each of these variables may be set as empty, eg, `$FocusHotkey = "";`
Well, that's about it.
*Happy filtering!*

======================

I know the script can benefit from some improvements, bugfixes. All such help is welcome!
*I know the script can benefit from some improvements, bugfixes. All such help is welcome!*

0 comments on commit 6931f0e

Please sign in to comment.