Editing a CTB which is physically off the end of the toolbar

Discuss and share scripts and script files...
Post Reply
klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Editing a CTB which is physically off the end of the toolbar

Post by klownboy »

Hi Don, Something I noticed while attempting to modify a CTB whose button is physically off the end of the toolbar with scrolling off (i.e., you have to hit the >> to see the remaining buttons and the CTBs that are off the end show in a list): Hitting control right mouse button does not give the normal "Click, Edit and Customize Toolbar" menu for these CTBs (it just executes the CTB). As a matter of fact it doesn't appear that you can modify the button when it's in that state (i.e., off the end of the toolbar). I had to get into customize toolbar and move the CTB over to the left (so it's physically seen on the toolbar) before I could modify the CTB. I noticed if toolbar scrolling is "ON' then it's not an issue so it's certainly not a big deal and it can wait until after vacation (or forever :) ).

Thanks,
Ken

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

Re: Editing a CTB which is physically off the end of the too

Post by TheQwerty »

As a workaround...

There is an undocumented SC 'userbutton':

Code: Select all

Name:   userbutton
Action: Emulates a click on a user customizable toolbar button.
Syntax: userbutton number, [action=1]
  number: [required] Number of the user button.
          You can retrieve the existing keys using the SC toolbar.
  action: [optional]
    0 = do nothing
    1 = left-click [default]
    2 = right-click
    128 = edit user button dialog

Example:
  userbutton 14, 128;  //opens the Edit User Button dialog for ctb14.
As you can see it is pretty much just an alias to the 'button' SC with some different rules/options, and as a result it is only truly useful to pull up a CTB's Edit dialog.

The problem with this is of course you must identify which CTB needs editing so you can pass in the correct number. To ease that annoyance here is a script which will read in the CTBs from your XYplorer.ini and present them in a menu so that you can select which one to edit.

Note that if you read the script there is a way to bypass the warning about needing to save your configuration.
EditUserButton.xys

Code: Select all

"_Initialize"
	// Edit this value to skip the warning dialog about saving your configuration.
	// 0 = Never Save
	// 1 = Always Save
	Global $G_SAVE_PROMPT_RESPONSE = -1;

	// STOP EDITING

	Global $G_INITIALIZED = True;


"Edit User Button||1 : editUserButton"
	// Ensure things are initialized.
	Global $G_INITIALIZED;
	if (! $G_INITIALIZED) {
		Sub '_Initialize';
	}

	// Determine if the user minds us saving their configuration.
	Global $G_SAVE_PROMPT_RESPONSE;
	if ($G_SAVE_PROMPT_RESPONSE == 1) {
		$response = 1;
	} elseif ($G_SAVE_PROMPT_RESPONSE == 0) {
		$response = 0;
	} else {
		// Prompt to before saving...
		$response = Confirm(<<<#CONFIRM_MSG
To give you an accurate listing of your customized user buttons this script would like to save XYplorer's main configuration file ('<xyini>').

To save and then use the current and correct listing please click 'OK'.
Otherwise the possibly stale and incorrect listing will be used.
#CONFIRM_MSG);
	}

	if ($response == 1) {
		#193; // File | Settings Special | Save Configuration
	}


	$SECTION = 'CustomButtons';

	// Check the serialization version before continuing.
	$version = GetKey('Version', $SECTION);
	if ($version != 1) {
		$response = Confirm(<<<#CONFIRM_MSG
This script was written based on version 1 of the custom user buttons data format.
Your configuration appears to be using version $version.

While it may be possible that this script still works, it might not be able to handle this format.
Please check for an updated version of this script before proceeding!

If you'd like to try continuing click 'OK'.
#CONFIRM_MSG,, 2);
		End $response == 0;
	}

	// Get the number of supported CTBs.
	$count = GetKey('Count', $SECTION);
	// Create the format style.
	$fmt = RegexReplace($count, '.', '0');

	// Stores the final script.
	// Doing this as a script allows us to attepmt to display the icons.
	$ctbScript = '';

	$i = 1;
	while ($i <= $count) {
		$ctb = GetKey($i, $SECTION);

		if ($ctb UnLike '') {
			// Extract the 'name|icon|?|?' portion.
			$ctb = RegexReplace($ctb, '^"([^"]*)".*$', '$1');

			// Get and sanitize the name.
			$name = GetToken($ctb, 1, '|');
			$name = Replace($name, '&', '&&');
			$name = Replace($name, ' : ', ' :: ');

			// Get the icon.
			$icon = GetToken($ctb, 2, '|');
			// If no icon is listed it might be an Open-With button.
			if ($icon == '' && (Exists($name) + 0) > 0) {
				$icon = $name;
			}
			// Attempt to redirect relative icon paths.
			if ($icon Like '.*') {
				$icon = "<xypath>\$icon";
			}

			// Format the index so we have decent alignment and access keys.
			$key = Format($i, $fmt);
			$key = RegexReplace($key, '(.)$', '&$1');

			// Build the script.
			// NOTE: userbutton() is an undocumented SC similar to button().
			$ctbScript = $ctbScript . <<<#CTB_SCRIPT
"CTB $key: $name|$icon" userbutton($i, 128);

#CTB_SCRIPT;
		}

		$i++;
	}

	// Run the script.
	Load $ctbScript, '*', 's';
[/size]
To see the attached files, you need to log into the forum.

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Editing a CTB which is physically off the end of the too

Post by klownboy »

TheQuerty, thanks for the script. It's quite nice for quick access to CTB editing. Obviously the issue I brought up wasn't a big deal, but I figured I'd mention it. Your script though will come in quite handy regardless.
Thanks again,
Ken

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Editing a CTB which is physically off the end of the too

Post by klownboy »

Hi TheQwerty, I noticed that some of the icons for the CTBs which display in the CTB Edit list (in EditUserButton.xys) are not shown, instead I receive a triangle exclamation point. In stepping through the script, I notice it happens only on those CTBs where the icon, as listed in the edit CTB dialog, is the icon name by itself with no path and without using <xyicons>. Obviously this syntax is fine for the CTB edit box (i.e., the icons display fine because the <XYicons> path is established in the ini file). However, it doesn't translate and work when an icon name is listed with no path in a menu as is done in the last section of the script which builds the CTB listing. I actually never realized this until now since I had been accustomed to providing the full path for the icons even before Don incorporated <xyicons>. In the script, you resolve relative paths using <xypath>, but the if statements don't seem to resolve an icon name with no path even though it's in <xyicons> which in my case is set in XYplorer.ini as "D:\Graphics\icons\". If <xyicons>\icon_name is used in the menu it does works fine, but not just an icon_name, it isn't resolved to <xyicons>|icon_name as it is in the CTB edit menu. Is it suppose to...(potential bug)?

So in the script I added this in attempt to take care of all situations, where you could have an icon listed as:
- an internal icon like :tabsets
- icon_name only
- fullpath with icon_name

Code: Select all

	$icon = "<xypath>\$icon"; } //...existing lines in script
   if (!exists("$icon") && ($icon Like '*.ico')) {    //check the icon_name by itself doesn't exist (since there's no path) and check that it's an "ico" file not a internal icon
			        $icon = "<xyicons>\$icon";
			}
Does that make sense? It's probably not the most elegant way to take care of all the different possibilities of how the icon may be expressed, but it seems to work except for label icons..."so-called" label icons like "label: 49F >554433,ffffee" which probably wouldn't display properly in the CBT listing.
Thanks very much.
Ken
Last edited by klownboy on 02 Oct 2013 18:41, edited 1 time in total.

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

Re: Editing a CTB which is physically off the end of the too

Post by TheQwerty »

klownboy wrote:I notice it happens only on those CTBs where the icon, as listed in the edit CTB dialog, is the icon name by itself with no path and without using <xyicons>.
Right... I see that bug now.

There's also an issue since CTBs can use 'label:Caption>FClr,BClr' to create text captions instead of icons.

I'll have to give this a look and some thought (though your solution seems to work for now)...

Thanks for bringing it to my attention!

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

Re: Editing a CTB which is physically off the end of the too

Post by admin »

[moved topic to this forum here]

Post Reply