Viewer Select - Make file display track standalone viewer

Thanks!
Can you elaborate on the script code?

It would require writing a script in javascript or vbscript - like the link I posted. It's not a 5 minute job though.

Here you go. Download this script: SimpleView.js.txt (3.6 KB) and drag it to Preferences / Toolbars / Scripts.

Then create a button with the command "SimpleView". The dialog will remember it's last used position/size.

This works but it's VERY basic - you can use it as a starting point.

Thanks!
i got it to work as i wanted: full screen on secondary monitor.
The only "issue" there is a latency / delay when displaying the images,(not large files and in fast ssd)
Is there a way around this?

Not really. The only way to check for a change in the selected file is through using a timer. Its set to 100 which you could lower further I guess. Search for the line dlg.SetTimer(100, "timer"); and change the 100 to a lower number - it won't make much difference though.

Its never going to be as good as the built in Viewer. Don't forget it also has to resize the image file to fit the dialog.

There’s also a slight lag if the image has rotation/orientation metadata. Very minimal but I can see it here on an i7 with fast ssd.

The latest beta adds a way for script dialogs to monitor tabs for events like file selection. Give it a try :slight_smile:

1 Like

Thanks @jon, @leo.

Here's an update which uses the new tab monitor instead of timers.

Now keeps working when user changes listers/source/dest.
Added a couple of configuration options - remember_position and no_rotate_image.

Works nicely, thanks.

Simple View 1.1.js.txt (4.6 KB) (Needs DOpus 12.20.3)

1 Like

Is there a way to make this work in checkbox mode?

What do you want it to do? Check the current file and uncheck all the others?

Hello,

Sorry, It appears to not keep the previously checked files in checkbox mode.

Understood, thanks! I can't think of a way to do that though.

Ok Thanks for looking into it regardless.

1 Like

@sfuller

I'd like a toggle in viewer preferences "Keep viewer in sync with the launching lister".

Add this toggle button to your viewer

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" separate="yes" textcol="none">
	<label>Autotrack File</label>
	<icon1>#default:selectinvert</icon1>
	<function type="normal">
		<instruction>@toggle:if $glob:AutotrackFile</instruction>
		<instruction>@if:$glob:AutotrackFile</instruction>
		<instruction>@set glob:AutotrackFile</instruction>
		<instruction>@if:else</instruction>
		<instruction>@set glob:AutotrackFile=on</instruction>
		<instruction>@toggle:update</instruction>
	</function>
</button>

And this modified version to your scripts (replace old code)

// Viewer Select
// (c) 2016-2017 Leo Davidson

// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
// See https://resource.dopus.com/viewtopic.php?f=35&t=27361 for information about this specific script.

// Called by Directory Opus to initialize the script
function OnInit(initData)
{
	initData.name = "Viewer Select";
	initData.version = "1.3";
	initData.copyright = "(c) 2016-2017 Leo Davidson";
	initData.url = "https://resource.dopus.com/viewtopic.php?f=35&t=27361";
	initData.desc = "The file display selection will track the standalone viewer's current file.";
	initData.default_enable = true;
	initData.min_version = "12.2";
	
	initData.vars.Set("VMapPaths", DOpus.Create.Map());
	initData.vars("VMapPaths").persist = false;
}

// Called when an event takes place in the standalone viewer
function OnViewerEvent(viewerEventData)
{
	if(!IsVariableSet("$glob:AutotrackFile"))
		return;
	
	var viewer   = viewerEventData.viewer;
	var tab      = viewer.parenttab;
	var mapPaths = Script.vars("VMapPaths").value;

	if (viewerEventData.event == "load")
	{
		if (!mapPaths.exists(viewer))
		{
			// For the first file, verify the tab contains the file we open with.
			// If it doesn't, the viewer may have been launched from outside of Opus,
			// or via a command which explicitly displays a file from a path which isn't
			// visible in the folder tab. Those situations still associate the viewer with
			// a lister/tab if one exists, and we want to leave those tabs alone.

			if (TabContainsFile(tab, viewer.current))
			{
				mapPaths(viewer) = tab.path + ""; // Store string, not Path object.
			}
			else
			{
				mapPaths(viewer) = ""; // Make a note to ignore this viewer.
			}
		}
		

		var path = mapPaths(viewer);
		var file = viewerEventData.item;

		// Still in the starting folder?
		if (typeof tab  != "undefined"
		&&  typeof path != "undefined"
		&&  typeof file != "undefined"
		&&  path != ""
		&&  tab.path == path)
		{

			var cmd = DOpus.Create.Command();
			cmd.SetSourceTab(tab);

			cmd.AddFile(file);
			cmd.RunCommand("Select FROMSCRIPT SETFOCUS DESELECTNOMATCH");
		}

		return;
	}

	if (viewerEventData.event == "destroy")
	{
		mapPaths.erase(viewer);
		return;
	}
}

function IsVariableSet(variableName)
{
	var objCmd = DOpus.CreateCommand;
	if (objCmd.IsSet(variableName))
	{
		DOpus.Output("The '" + variableName + "' variable is set!");
		return true;
	}
	return false;
}

function TabContainsFile(tab, item)
{
	// Workaround to avoid error if no valid file is passed.

	if (typeof tab  == "undefined"
	||  typeof item == "undefined")
	{
		return false;
	}

	// Simple test is usually enough. Is the tab showing the folder the file is in?
	// (It's possible the file is hidden, but that would be weird in this context, so we ignore that.)

	if (DOpus.FSUtil.ComparePath(DOpus.FSUtil.Resolve(tab.path), item.path))
	{
		return true;
	}

	// To work in collections, libraries and flat view, we need to go through the actual list of files.
	// This could be slow as we don't currently have a quicker way than looping through the files.

	var itemPathString = item + "";

	// It'll usually be a selected file if the viewer opened via double-click. Try them first.

	for (var eItems = new Enumerator(tab.selected_files); !eItems.atEnd(); eItems.moveNext())
	{
		// Compare the path strings, not the item objects.
		if ((eItems.item() + "") == itemPathString)
		{
			return true;
		}
	}

	for (var eItems = new Enumerator(tab.files); !eItems.atEnd(); eItems.moveNext())
	{
		// Compare the path strings, not the item objects.
		// Skip selected files as we already checked them.
		if (!eItems.item().selected && (eItems.item() + "") == itemPathString)
		{
			return true;
		}
	}

	return false;
}

The modification is this

	if(!IsVariableSet("$glob:AutotrackFile"))
		return;

checking if the variable set from toggle button exists and depending on this running the rest of the code or returning without execution.

However, the toggle button only shows its new toggle state (changing the background color) AFTER changing the file in the viewer. The code is from the docs and i dont know if this behaviour is intended or a bug. @Leo do you have ideas on this? Also the @toggle:update does not help here.

@GQJ17

Is there a way to make this work in checkbox mode?

Even though its not checkbox mode, you might have a look at my selection script here Add current viewer file to selection in lister tab

Appreciate your help,

That is part of want I want to do, make selections from the viewer (and your button keeps them), but ideally I would like to use selection mode to pick the file that displays in the viewer, and checkbox mode to "mark" it. Only difference being that I can skim through the thumbnails in DO.

@toggle:update wasn't hooked up for viewer toolbars, but we've changed that in the next beta.

1 Like

Actually i never tried it with checkbox mode (i dont use that mode). It seems to be working with checkboxmode for me aswell, give it a try.

1 Like

We'll add a way to do this in the next beta. Remind me to update the script if I haven't by the time the beta is released. (I already have the update written, but it doesn't make sense to put it up yet.)

We'll also add a better way to do this, for scripts in general, without needing to edit the script code or create variables to toggle things. (I'll add the details to the root post once the beta is released.)

2 Likes

Now that Directory Opus 12.22.3 (Beta) is released, I've updated the root post:

  • New script version which handles checkbox mode better. (Moves the selection and leaves the checkboxes alone.)

  • Added a section on how to make a toolbar button which toggles the script, using the new command for doing so.

1 Like

It works perfectly. Scrollable documentation in the viewer window while manipulating files in another tab.

1 Like

The script seems to work well, but I'm having constant script errors all of the sudden:

2021-05-17 3:58 PM Viewer Select: Error at line 92, position 5
2021-05-17 3:58 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-17 8:12 PM Viewer Select: Error at line 92, position 5
2021-05-17 8:12 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-17 8:13 PM Viewer Select: Error at line 92, position 5
2021-05-17 8:13 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-17 8:16 PM Viewer Select: Error at line 92, position 5
2021-05-17 8:16 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-17 8:50 PM Viewer Select: Error at line 96, position 2
2021-05-17 8:50 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-17 9:26 PM Viewer Select: Error at line 96, position 2
2021-05-17 9:26 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-17 9:26 PM Viewer Select: Error at line 96, position 2
2021-05-17 9:26 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:22 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:22 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:25 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:25 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:26 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:26 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:26 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:26 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:26 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:26 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:32 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:32 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:34 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:34 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:34 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:34 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:44 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:44 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 6:54 PM Viewer Select: Error at line 96, position 2
2021-05-18 6:54 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 7:08 PM Viewer Select: Error at line 96, position 2
2021-05-18 7:08 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 7:12 PM Viewer Select: Error at line 96, position 2
2021-05-18 7:12 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 7:12 PM Viewer Select: Error at line 96, position 2
2021-05-18 7:12 PM Viewer Select: Invalid procedure call or argument (0x800a0005)
2021-05-18 7:12 PM Viewer Select: Error at line 96, position 2
2021-05-18 7:12 PM Viewer Select: Invalid procedure call or argument (0x800a0005)