Script: Dual Location Builder

Discuss and share scripts and script files...
Post Reply
TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Script: Dual Location Builder

Post by TheQwerty »

I'm not going to go into great detail about this since the feature is so new and I have a feeling Don will decide to elevate the Dual Location feature into the GUI rendering this script entirely useless.

This file consists of two user facing scripts:
  1. Show Dual Location (showDual)
  2. Show Dual Location with List Configurations (showDualConfig)
The first generates and displays a dual location string for the active tabs in each pane.
The second does the same but attempts to include the list configurations.


Some notes:
  1. With as new as the feature and script are, it should be obvious but this hasn't been tested much and there are no guarantees that its output is and will always be correct.
  2. I did my best to include Quick Name Searches and Visual Filters but if a tab has both you'll have to pick one or the other. As far as I can tell there is no reliable way to do both to a single tab with Dual Locations.
  3. To retrieve the configurations this script must dive into the INI files and that requires saving the settings. When building a Dual Location with Configurations you will be prompted and if you accept the settings will be saved.
  4. Also, since the INI files are not documented Don is the only one who truly understands them. I think I am collecting the correct data for the configurations but I could very well be wrong.
  5. Lastly, I always try to avoid making unnecessary changes to the current state of XY, however to get all the needed information about the active tabs this script will need to activate the inactive pane. It will return focus to the originally active pane at the end. This could be avoided by retrieving all information from the INI files, but I didn't want to force saving settings for all cases.
Enjoy!
DualLocationBuilder.xys
(2.85 KiB) Downloaded 162 times

Code: Select all

"Show Dual Location||1 : showDual"
	Global $G_LOCATION = '';
	Sub('_buildDual');
	Text $G_LOCATION, /*width*/, /*height*/, 'Dual Location Builder';


"Show Dual Location with List Configurations : showDualConfig"
	End ! Confirm("This will required saving the settings to read values from the INI files.<br><br>Do you wish to continue?");
	Global $G_INCLUDE_SETTINGS = True;
	SaveSettings;
	Sub('showDual');


"- : _-" //---------------------------------------------------------------------


"Build Dual Location||4 : _buildDual"
	Global $G_LOCATION;

	// Get active pane.
	$ap = Get('Pane');

	// Get location for active pane.
	Sub('_getLocation');
	$apl = $G_LOCATION;
	
	// Get location for inactive pane.
	Focus('PI');
	Sub('_getLocation');
	$ipl = $G_LOCATION;
	Focus('PI');

	// Construct location depending on which was originally active.
	$G_LOCATION = "DUAL:$ap";
	if ($ap == 1) {
		$G_LOCATION = "$G_LOCATION.$apl||$ipl";
	} else {
		$G_LOCATION = "$G_LOCATION.$ipl||$apl";
	}


"Get Tab Location||4 : _getLocation"
	Global $G_LOCATION, $G_INCLUDE_SETTINGS;

	// If a tab has both a Visual Filter and a Quick Name Search
	// the term will only contain the search.
	$G_LOCATION = Tab('Get','Term');
	$vf = Get('VisualFilter');

	// If the term does not contain the active visual filter...
	if ($vf && $G_LOCATION UnLike "*|$vf") {
		$vf = Tab('Get', 'Data') . "|$vf";

		// If the term is not a search...
		if ($G_LOCATION UnLike "*?*") {
			// Use generated visual filter location.
			$G_LOCATION = $vf;
		} else {
			// Prompt the user if they want to use the search or the filter.
			$response = InputSelect(<<<#HEREDOC
The active tab in pane <get Pane> has both a quick name search and a visual filter applied.
This cannot be easily recreated with a Dual Location.

Please select your preferred location.#HEREDOC, "$G_LOCATION<crlf>$vf", "<crlf>", 1, /*cancel*/,/*width*/,/*height*/, 'Dual Location Builder');

			// Obey their response
			// But if they didn't select anything we default to the search.
			if ($response) {
				$G_LOCATION = $response;
			}
		}
	}


	// If the user wants to include view settings....
	if ($G_INCLUDE_SETTINGS) {
		// Find the correct pane.ini.
		// It should always be the temp one, but failback safely just in case.
		$paneDir = "<xypane>";
		$paneINI = "$paneDir\t\pane.ini";
		if (Exists($paneINI) != 1) {
			$paneINI = "$paneDir\pane.ini";
			End Exists($paneINI) != 1,, 1;
		}

		// Tab index.
		$tidx = Tab('Get');
		$avalue = GetKey("A$tidx", 'Tabs', $paneINI, 1);
		if ($avalue != '') {
			// A# contains many settings but I believe we only need tokens 4, 9, 14.
			$view = GetToken($avalue,  9, "<tab>", 't');
			$sort = GetToken($avalue,  4, "<tab>", 't');
			$list = GetToken($avalue, 14, "<tab>", 't');

			$G_LOCATION = $G_LOCATION . ">>$view,$sort,$list";
		}
	}
[/size]
Last edited by TheQwerty on 20 Jun 2013 20:37, edited 2 times in total.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Script: Dual Location Builder

Post by TheQwerty »

*reserved*

I'll try to remember to clean this up and do all that perfect presentation and details stuff that Marco and FluxTorpedoe do so nicely, but for now I feel it's better to post it than wait till I feel like doing that. ;)

Stef123

Re: Script: Dual Location Builder

Post by Stef123 »

Thanks. Spares me the trouble of having to consult my cheatsheet each and every time I save a dual location.

Tried to extend it with another option (no paths, only view settings) but couldn't pull it off. I am brand new to scripting - and not really into any kind of programming at all - guess I better stick to other things.

General question: Is it possible to create dialogs - AutoHotkey scripts often have this professional look - with checkboxes and radio buttons and that kind of thing?

admin
Site Admin
Posts: 65180
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Script: Dual Location Builder

Post by admin »

Option "Show Dual Location with List Configurations" does not seem to work here. See no difference to the first option.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Script: Dual Location Builder

Post by TheQwerty »

admin wrote:Option "Show Dual Location with List Configurations" does not seem to work here. See no difference to the first option.
Oops! :oops:

I forgot to unbreak my code after testing it... but I also discovered I was getting bit by not using the XY parser flag in GetKey so all's not a total waste.

Should be fixed now! :whistle:

EDIT: And now I get to regret not taking the time to do the details and adding metadata and version information. *sigh*
Last edited by TheQwerty on 20 Jun 2013 20:46, edited 1 time in total.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Script: Dual Location Builder

Post by TheQwerty »

Stef123 wrote:Tried to extend it with another option (no paths, only view settings) but couldn't pull it off. I am brand new to scripting - and not really into any kind of programming at all - guess I better stick to other things.
I'd rather not add that to this script because the next step would be only searches/filters and that's a bit more difficult to achieve reliably and not something I'm interested in doing.

If you look at how I handle the global variable $G_INCLUDE_SETTINGS (lines, 9, 43, and 76) and in particular the line that builds the location string (95) then I believe you can figure out how to create a "Show Dual List Configurations Only" menu item.
Stef123 wrote:General question: Is it possible to create dialogs - AutoHotkey scripts often have this professional look - with checkboxes and radio buttons and that kind of thing?
There is not a way to build native dialogs like AHK, but you can use the HTML() scripting command to create powerful web interfaces.

Post Reply