Improving the viewer in Directory Opus

This is a large and continued post meaning that I will come back and add more info to the post. There is a reason the “viewer” is called the viewer in Directory Opus. It is not just an image viewer. It is basically an “everything viewer”. It can preview pretty much all popular file types out there. Word files, excel, mp4, mp3, jpg, RAW, ARW, txt, HTML and the list goes on…

This makes the viewer in Directory Opus beat all other viewers out there because of its plugin support and supported file formats.

Nevertheless there are some default settings that comes with the viewer that either makes no sense or could be adjusted for a more “modern” workflow in my opinion.

Fit image to viewer window

We all like to see “the big picture” right? If you are used to the old Windows Photo viewer or the new Windows 10 Photos app you will remember that the image is always resized to fit the window. So even if the picture dimensions is enormous you can still see the whole picture on the screen.

The photos app in Windows 10 will display the image resized to the window. In Directory Opus however this is not a default option so the picture will look like this.

Directory Opus will not resize the image to fit the window by default What you will need to do in Directory Opus is to turn on “reset zoom level for each picture” to “fit page“.

Directory Opus can resize images to fit the viewer You should also go to “appearance” and set “auto-size viewer window” to “fit every picture“. This will tell Directory Opus one of two things: if the picture is smaller than your screen width and height, the viewer will adjust its frame to the picture dimensions. If the picture is larger than your screen width and height Directory Opus will contain the picture to the viewer frame so you can see the whole picture.

Directory Opus can fit the viewer to the picture.

Use the arrow keys to preview next/previous picture

In most image viewers today you can use the right and left arrow keys to go to the next or previous image if you have multiple photos. In Directory Opus those keys are instead spacebar and backspace. This is not only confusing is just recalcitrant. So how can we set it back to the good old arrow keys? Hotkeys can easily be edited by going to┬áthe “Settings” menu -> “Customize toolbars” and then choose the “Keys” tab. Look for the group called “Image viewer (keys)”. Under you will find “Previous picture” and “next picture”. Double-click on the one of them to edit. Just click in the “Hotkey” field and press the key combo you want and hit OK. Do the same for both previous and next picture.

Note that you can have multiple key combinations for one command. That is you can have both the space bar and the right arrow key as trigger for the next picture if you want. Might be wise to stick to one key combo though…

Syncing viewer and file selection

The Directory Opus developer Leo has made a script that makes the viewer follow the file selection. So if you use the arrow keys on to change image in the viewer, for example, the image you are viewing will be selected in the file list and vice versa. This is a great way to find one of the files you are viewing in the viewer, in the file list.

Syncing viewer and file selection Save the following code as a .js file and import it to Directory Opus. Open Settings > Preferences / Toolbars / Scripts. Drag Viewer Select.js.txt to the list of scripts.

// 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)
{
    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 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;
}

Only one window or instance of the viewer at a time

If you prefer to only have one viewer window open at a time you can go to: Preferences -> Viewer -> Behaviour -> and turn on “Reuse existing viewer window

Sources:

https://resource.dopus.com/t/viewer-select-make-file-display-track-standalone-viewer/23320