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

Commit

Permalink
big upgrade!
Browse files Browse the repository at this point in the history
+can sync position with addressbar (thanks to autocart)
+a better xyscript launcher
+syncs font with addressbar (thanks to SKAN)
+copydata receiver (and sender, thanks to binocular222)
+shows basic tooltip
~code cleanup/touchup
  • Loading branch information
bdeshi committed Nov 20, 2015
1 parent 2c3e9b4 commit 6996e43
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 45 deletions.
179 changes: 144 additions & 35 deletions XYAHKLiveFilter.ahk
Original file line number Diff line number Diff line change
@@ -1,40 +1,112 @@
;XYAHKLiveFilter v3
; XYAHKLiveFilter v4
#SingleInstance, Off
OnExit, ExitRoutine
#NoEnv
SetBatchLines, 10ms
SetControlDelay, -1

XYhWnd = %1%
Shortcut = %2%
Main:
Gui, +HwndGUIhWnd -Resize -Border -Caption +OwnDialogs +AlwaysOnTop
Gui, Margin, 1, 1
Gui, Font, s8, Segoe UI
GUI, Add, Checkbox, gUpdateFilter hWndGUIPausehWnd 0x8000 0xc00, P
Gui, Add, Edit, y1 gUpdateFilter hWndGUIEdithWnd R1, ""
DllCall("SetParent","UInt", GUIhWnd, "UInt", XYhWnd)
GuiControlGet, EditPos, Pos, %GUIEdithWnd%
GuiControl, Move, %GUIEdithWnd%, % "w" EditPosW*8
GuiControl, Move, %GUIPausehWnd%, % "h" EditPosH
Gui, Show, X1 Y1 AutoSize
SendInput, {Right}{Left}
OnMessage(0x200, "FocusGUI")
OnMessage(0x02, "Destroyer")
Hotkey, IfWinActive, ahk_id %GUIhWnd%
Hotkey, Tab, lblFocusXY
If (Shortcut) {
Hotkey, IfWinActive, ahk_id %XYhWnd%
Hotkey, %Shortcut%, lblFocusGUI
ABPadding = %3%
ABPadding := (ABPadding+0)="" ? 5 : ABPadding
SyncPos = %4%
TTShow = %5%
AHKhWnd := A_ScriptHwnd + 0
Global ReceivedData

OnExit, ExitRoutine
OnMessage(0x4a, "MsgFromXY")
OnMessage(0x200, "FocusGUI")
OnMessage(0x7e, "Destroyer")

Gui, +HwndGUIhWnd -Border -Caption +OwnDialogs +AlwaysOnTop
Gui, Margin, 1, 1
If (SyncPos = 1)
Gosub, ABattribs
Else {
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)
GuiControlGet, EditPos, Pos, %GUIEdithWnd%
GuiControl, Move, %GUIEdithWnd%, % "w" EditPosW*8
GuiControl, Move, %GUIPausehWnd%, % "h" EditPosH
Gui, Show, X%GUIX% Y%GUIY% AutoSize
SendInput, {Right}{Left}

If (SyncPos = 1) {
WinGetPos, , , GUIW, , ahk_id %GUIhWnd%
GUIX := ABX + ABW - xborder - GUIW
WinMove, ahk_id %GUIhWnd%, , %GUIX%, %GUIY%
SetTimer, UpdatePos, 100
}

Hotkey, IfWinActive, ahk_id %GUIhWnd%
Hotkey, Tab, lblFocusXY
If (Shortcut) {
Hotkey, IfWinActive, ahk_id %XYhWnd%
Hotkey, %Shortcut%, lblFocusGUI
}

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

ABattribs:
MsgToXy("::copydata " AHKHwnd ",get('#660'),0;setlayout('showaddressbar=1');")
ABState := ReceivedData
ReceivedData =
ControlGet, XYABhWnd, Hwnd, , Edit16, ahk_id %XYhWnd%
ControlGetPos, ABX, ABY, ABW, ABH, , ahk_id %XYABhWnd%
SysGet, xborder, 32
SysGet, yborder, 33
SysGet, CaptionH, 4
SysGet, MenuH, 15
GUIX := ABX + ABW - xborder
GUIY := ABY - yborder - CaptionH - MenuH - ABPadding
FontName:= GetFont(XYABhWnd)
FontSize:= A_LastError
Return

UpdatePos:
If WinActive("ahk_id" XYhWnd) {
ControlGet, ABvis, Visible, , , ahk_id %XYABhWnd%
If (ABvis = 0)
MsgToXY("::setlayout('showaddressbar=1')")
PABP = %ABX% %ABY% %ABH% %ABW%
PABH = %ABH%
ControlGetPos, ABX, ABY, ABW, ABH, , ahk_id %XYABhWnd%
CABP = %ABX% %ABY% %ABH% %ABW%
CABH = %ABH%
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%
}
WinMove, ahk_id %GUIhWnd%, , %GUIX%, %GUIY%, , %GUIH%
GuiControl, move, %GUiPausehWnd%, h%GUIH%
GuiControl, move, %GUiEdithWnd%, h%GUIH%
}
}
Return

UpdateFilter:
GuiControlGet, PauseState, , %GUIPausehWnd%
GuiControlGet, StrFilter, , %GUIEdithWnd%
If (PauseState = 1) {
GuiControlGet, Paused, , %GUIPausehWnd%
If (Paused = 1)
Return
}
GuiControlGet, StrFilter, , %GUIEdithWnd%
If (StrFilterLast != StrFilter) {
StrFilterLast := StrFilter
StrFilter = ::filter %StrFilter%;
StrFilter = ::filter %StrFilter%
MsgToXY(StrFilter)
StrFilter := ""
}
Expand All @@ -55,17 +127,34 @@ Return
FocusGUI() {
global
IfWinActive, ahk_id %XYhWnd%
{
WinActivate, ahk_id %GUIEdithWnd%
IfWinActive, ahk_id %GUIhWnd%
{
If (TTShow != 1) {
TTShow = 1
ToolTip
SetTimer, TTOn, 10
}
Return

TTOn:
ToolTip, P: Pause live mode
SetTimer, TTOn, Off
SetTimer, TTOff, 800
Return

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

FocusXY() {
global
IfWinActive, ahk_id %GUIhWnd%
{
WinActivate, ahk_id %XYhWnd%
}
Return
}

Expand All @@ -74,15 +163,15 @@ Destroyer() {
Return
}

;function lifted from binocular222's XYplorer Messenger[AHK], (thanks!)
MsgToXY(arg_Msg) {
global XYhWnd
Size := StrLen(arg_Msg)
If !(A_IsUnicode) {
VarSetCapacity(Data, Size * 2, 0)
StrPut(arg_Msg, &Data, Size, "UTF-16")
} Else {
} Else
Data := arg_Msg
}
VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
NumPut(4194305, COPYDATA, 0, "Ptr")
NumPut(Size * 2, COPYDATA, A_PtrSize, "UInt")
Expand All @@ -91,10 +180,30 @@ MsgToXY(arg_Msg) {
Return
}

;also based on binocular222's code
MsgFromXY(wParam, lParam) {
StringAddress := NumGet(lParam + 2*A_PtrSize)
cbData := NumGet(lParam+A_PtrSize)/2
CopyOfData := StrGet(StringAddress)
StringLeft, ReceivedData, CopyOfData, cbData
Return
}

;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)
}

ExitRoutine:
GUI, Destroy
WinActivate, ahk_id %XYhWnd%
EndMsg := "::filter;unset $p_XYAHKLiveFilter_A,$p_XYAHKLiveFilter_B;"
MsgToXY(EndMsg)
GUI, Hide
If (SyncPos = 1)
MsgToXY("::setlayout('showaddressbar=" ABState "');")
MsgToXY("::filter;unset $p_XYAHKLiveFilter_A,$p_XYAHKLiveFilter_B;")
ExitApp
Return
12 changes: 12 additions & 0 deletions XYAHKLiveFilter.xys
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//XYAHKLiveFilter v4.0.0
perm $p_XYAHKLiveFilter_A, $p_XYAHKLiveFilter_B;
if ($p_XYAHKLiveFilter_A != 1)||($p_XYAHKLiveFilter_B != <hwnd>){
$p_XYAHKLiveFilter_A = 1; $p_XYAHKLiveFilter_B = <hwnd>;

$FocusHotkey = "^`" ; //ex: ^`=CTRL+`, !+'=ALT+SHIFT+', !Space=ALT+SPACE
$SyncToAB = 1 ; //sync filterbox position with AB
$ABPadding = 5 ; //not effective if not $SyncToAB = 1

run trim(<<<#RuncmD
"<xyscripts>\XYAHKLiveFilter.exe" <hwnd> "$FocusHotkey" "$ABPadding" "$SyncToAB"#RuncmD," ",L),, 0;
}
42 changes: 32 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
## [XYAHKLiveFilter](https://www.github.com/SammaySarkar/XYAHKLiveFilter)
http://www.xyplorer.com/xyfc/viewtopic.php?t=12588

####**version 3**
####**version 4**

A live-filter plugin for [XYplorer](http://www.xyplorer.com), made in [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:
* Download and extract the release archive. Or clone this repo and compile the ahk.
* Place **XYAHKLiveFilter.exe** in the `<xyscripts>` folder.
* Next attach the following xyscript to a CTB and/or to a UDC item.
* Next attach the following xyscript to a CTB and/or to a UDC item (it's also available as `XYAHKLiveFilter.xys`).
```
::if($p_XYAHKLiveFilter_A!=1)||($p_XYAHKLiveFilter_B!=<hwnd>){$p_XYAHKLiveFilter_A=1;$p_XYAHKLiveFilter_B=<hwnd>;run "<xyscripts>\XYAHKLiveFilter.exe <hwnd> ^`",,0;};
perm $p_XYAHKLiveFilter_A, $p_XYAHKLiveFilter_B;
if ($p_XYAHKLiveFilter_A != 1)||($p_XYAHKLiveFilter_B != <hwnd>){
$p_XYAHKLiveFilter_A = 1; $p_XYAHKLiveFilter_B = <hwnd>;
$FocusHotkey = "^`" ; //ex: ^`=CTRL+`, !+'=ALT+SHIFT+', !Space=ALT+SPACE
$SyncToAB = 1 ; //sync filterbox position with AB
$ABPadding = 5 ; //not effective if not $SyncToAB = 1
run trim(<<<#RuncmD
"<xyscripts>\XYAHKLiveFilter.exe" <hwnd> "$FocusHotkey" "$ABPadding" "$SyncToAB"#RuncmD," ",L),, 0;
}
```
* That's it! Now just click the CTB or trigger the UDC and filter away! (Don't forget to read about usage & options below.)
* (Don't forget to modify the path in that script to match the actual path of the exe.
Also you can modify it even further to run the source ahk itself via the AutoHotkey interpreter.)


###USAGE:
* The filterbox pops up at the *topleft* of it's parent XYplorer window.
* By default, the filterbox pops up and stays over the right edge of the AB (addressbar), enabling AB if needed.<br/>
See `$SyncToAB` in the **OPTIONS** section below for more details.
* Press the focus hotkey (default:<kbd>CTRL</kbd>+<kbd>\`</kbd>) to focus the filterbox and <kbd>TAB</kbd>
to refocus main XY window. (ofcourse mouse can be used instead too.)<br/>.
* In the launching xyscript, the first commandline parameter given to the exe (or ahk) is the focus hotkey.<br/>
The default value `^\'` means <kbd>CTRL</kbd>+<kbd>\`</kbd>. It follows [Authotkey's hotkey syntax](http://ahkscript.org/docs/Hotkeys.htm).
to refocus main XY window. (ofcourse mouse can be used instead too.)<br/>
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.)
* If you use the script as a UDC with a keyboard shortcut, I suggest setting the same shortcut as Focus Hotkey.
* 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.
* Full content of the filterbox is passed to SC `filter` unchanged, so should be properly escaped according to XYplorer scripting rules when necessary.
* Live-filtering is not suitable for RegExp patterns. Activate the **P** checkbox to pause livemode, enter complex/RegExp pattern, then uncheck it again to submit.
* 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.
* The filterbox uses the same font and fontsize as the addressbar, so you can be sure it'll always match the zoom level of XY.


###OPTIONS:
Some options may be modified in the XYscript.
* `$FocusHotkey`: this value is passed as the shortcut code to instantly focus the filterbox. The default value `^\`` means <kbd>CTRL</kbd>+<kbd>\`</kbd>.<br/>
It follows [Authotkey's hotkey definition syntax](http://ahkscript.org/docs/Hotkeys.htm).
* `$SyncToAB`: if `$SyncToAB` is 1, the filterbox is positioned over right edge the of the addressbar.
This also forces the AB to stay visible as long as livefilter is running, and reverts back to last state when the filter is closed.<br/>
If `$SyncToAB` is not 1, then the filterbox is positioned at the *topleft* of XY, and does not try to modify AB visibility.
* `$ABPadding`: Adjust this value only if the filterbox doesn't horizontal-align exactly with the addressbar.<br/>
The value should be a (small) integer: 0,3,-2 etc.<br/>
The filterbox moves up/down this many pixels. Only effective when `$SyncToAB = 1`.

Each of these variables may be set as empty, eg, `$FocusHotkey = "";`

###IMPORTANT:
* To work correctly, the exe/ahk must be launched from within XY as directed in INSTALL section.
Expand Down

0 comments on commit 6996e43

Please sign in to comment.