Keep Scroll Position After Folder Resize?

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

ivanatpr
New Member
Posts: 4
Joined: 2012 Jan 09, 22:16

Keep Scroll Position After Folder Resize?

Post by ivanatpr »

Right now, if I have a file selected and I change the sort order (by clicking on the column header in details view), xplorer2 will scroll to the selected file after doing the sort. However this is rarely what I want. If I open a folder with many files and then sort by Size, I generally want to maintain my scroll position at the top because I want to see the biggest files in the folder.

So is there a way to disable this behavior so that sorting doesn't automatically scroll to the selected file?
Kilmatead
Platinum Member
Platinum Member
Posts: 4879
Joined: 2008 Sep 30, 06:52
Location: Baile Átha Cliath

Re: Keep Scroll Position After Folder Resize?

Post by Kilmatead »

It's actually scrolling to the currently focused object, which is not necessarily one that is technically "selected". However, that's neither here nor there - at present the answer is no, when x2 refreshes or resorts the pane view, it automatically takes the focus into account (on the theory that the focused item is the one the user is most interested in or working with).

To quickly force the display to the top scroll position, press <Ctrl+Home>.

If you use <Home> by itself, this not only sets the focus to the top item, but any other current "selections" will be lost each time as well, which could be impractical, so <Ctrl+Home> is the simplest way, short of just dragging the scroll-bar.
ivanatpr
New Member
Posts: 4
Joined: 2012 Jan 09, 22:16

Re: Keep Scroll Position After Folder Resize?

Post by ivanatpr »

OK, Thanks for the info and for the tip about Ctrl+Home!

On that note, do you know if there is a way to clear the focused object for a given pane? If I close and reopen xplorer2, my folders tabs all start out with no focused object (so each sort causes a scroll to top i.e. my desired behavior), however once I select an object there seems to be no way that I can see to go back to that original state since unselecting an item doesn't remove focus.
Kilmatead
Platinum Member
Platinum Member
Posts: 4879
Joined: 2008 Sep 30, 06:52
Location: Baile Átha Cliath

Re: Keep Scroll Position After Folder Resize?

Post by Kilmatead »

There is no "built-in" command or keyboard shortcut to do what you want (since it's a rather niche request), but it is possible with scripting.

Since I was bored, I whipped up a small script which will essentially de-select any selections and de-focus any specific focused-item - and move the current scroll position to the top (just for fun), thus allowing you to switch between column sorting to your heart's content. You just have to remember to hit the user-command before you start clicking columns. :wink:

Basically, just download NoFocus.zip, and make either the x86 or the x64 EXE into a user-command, and then into a toolbar-button. When the user-command is executed, the currently active pane becomes "virginal", which, as you discovered, means it has no distinctly focused item.

I admit, this is not a perfect solution (in terms of workflow), but it's a proof-of-concept and something for you to play with if you get bored and want to let your imagination go through a black-hole. :D (For example, with a little bit of extra thought, you could have a single toolbar button to de-focus everything and then auto-sort by Modified Date, or Size or something - without needing to do it in separate actions.)

The ZIP file above includes pre-compiled versions as well as the script itself. Below is the script-text (in the AutoIt language) for those who might be interested in "how" it does what it does, but have no interest in actually downloading stuff. :shrug:

Hint: The juicy-bit uses LVM_GETNEXTITEM/LVNI_FOCUSED.

Code: Select all

#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global Const $ADDRESSBAR = 1001
Global Const $MARK_DESELECTALL = 32803
Global Const $INVOKE_ADDRESSBAR = 33131

Global $hWin = WinActivate("[REGEXPCLASS:ATL:(Explorer)|(Scrap)Frame]")
Global $ActivePane = _GetActivePane()
Global $hCtrl = ControlGetHandle($hWin, "", $ActivePane)

_SendMessage($hWin, $WM_COMMAND, $MARK_DESELECTALL)
Global $Focus = _SendMessage($hCtrl, $LVM_GETNEXTITEM, -1, $LVNI_FOCUSED)
_GUICtrlListView_SetItemFocused($hCtrl, $Focus, False)

ControlSend($hWin, "", $hCtrl, "^{Home}")

Func _GetActivePane()
	Local $Focus = ControlGetFocus($hWin)

	If StringLeft($Focus, 19) = "ATL:BrowserListView" Then Return $Focus

	ControlSetText($hWin, "", $ADDRESSBAR, "")
	_SendMessage($hWin, $WM_COMMAND, $INVOKE_ADDRESSBAR)

	Return ControlGetFocus($hWin)
EndFunc
ivanatpr
New Member
Posts: 4
Joined: 2012 Jan 09, 22:16

Re: Keep Scroll Position After Folder Resize?

Post by ivanatpr »

Very, very, cool! And remarkably understandable for a script that interacts with win32 APIs. I had no idea that one process could directly interact with GUI controls owned by another process.

Thank you very much, both for the solution and for showing me a really neat trick :biggrin: