Button based on file extension

Hi guys,
On the application toolbar I've dropped the filename of my favorite Editor (EmEditor); arguments {filepath}; Hotkey F4.

So now, when there's a file selected in a panel, pressing F4 will launch EmEditor with that file. But that's not very "handy" if the selected file was e.g. an executable.

Question: it there a possiblity to only let this work if the file has a certain extension (e.g. TXT, XML, LOG [customizable])? I lookad at the modifiers but I couldn't find it.

Thanks in advance! Cheers!

@disablenosel:type=*.(txt|xml|log) on a line in the (advanced) button editor will disable the button unless those extensions are selected.

2 Likes

Hi Leo, thanks! Looks great!

Can also the behavior of the button being disabled? So, if the button is disabled that dragging a file on it, or pressing F4, doesn;t work?

Thank you!

I didn't realise that wouldn't affect the hotkey.

Here's a better solution. You can filter the selected filenames so only the ones matching your pattern are fed to the command. If nothing selected matches the pattern, the command won't be run. If some unwanted things are accidentally included with things you want to edit, they'll be filtered out:

function OnClick(clickData)
{
	var pattern = '*.(txt|xml|log)';
	var wild = DOpus.FSUtil.NewWild(pattern);

	var cmd = clickData.func.command;
	cmd.ClearFiles();
	cmd.deselect = false;

	var fAnyFiles = false;
	
	for (var eSel = new Enumerator(clickData.func.sourcetab.selected_files); !eSel.atEnd(); eSel.moveNext())
	{
		var item = eSel.item();
		if (wild.match(item.name))
		{
			fAnyFiles = true;
			cmd.AddFile(item);
		}
	}

	if (fAnyFiles)
	{
		cmd.RunCommand('"C:\\Windows\\Notepad.exe" {filepath}');
	}
}

Edit the line near the end to change the editor that it runs. JScript needs \\ for each \ in the path.

The button editor should be in Script Function mode, with the language set to JScript:

If you want the @disablenosel:... modifier as well, add that on the Modifiers tab, and remember to keep it in sync with the pattern at the top of the script.

1 Like

Perfect Leo! It works like a charm!

Dankjewel! Thank you!

1 Like

In 12.12.2, we'll make a change so that @disablenosel etc. also disable the hotkey.

Hi Leo, Great! Thanks again!

Hi Leo,

I have another finding in this issue: If the button is disabled it will still accept droppings on that button. Can this behavior also be disabled? So, if the button is disabled: no hotkey and no filedrop is possible.

I'm using the new 12.12.2 version.

Thanks in advance!

Cheers!

I think there is a reason drag & drop overrides it, although I've forgotten exactly why.

But why would you drag & drop files on a button that doesn't do anything with those files? That seems like quite an explicit action, so it'd usually be on purpose (e.g. if the files have the wrong extensions but you know the button will still work on them)?

HI Leo,

You're right: why should I do this? For me you don't have to change this behavior: it's just a suggestion to make it "perfect": if a button is disabled: you can't use it: period.

At this moment I still can (accidentaly) drop a wrong file on this button and it will launch the application with a wrong file.

And again: if you don't want to change this behavior: it's oke for me!

Thank you!

I have this for Ultra Edit:

@disablenosel:type=*.(cs|csv|txt|xml|log)
cd C:\Program Files\IDM Computer Solutions\UltraEdit
@async:"C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe" {filepath|noterm}

I dropped an executable on the (disabled) button:

The script method can be used if you want to be absolutely sure, even with drag & drop. You can combine that with @disablenosel as well if desired.

We might make @disablenosel block drag & drop as well but we need to work out what the reason was for the current behavior. There definitely was a reason for it, but it might not apply to all situations.

Hi Leo,

Thanks for your suggestion. We'll see: Thank you!

And indeed: the combination of the script and the modifier works perfect!