Ctrl-clicking on a UNL string in a node is supposed to navigate to that 
location, even if it's in another outline.  That outline should open if 
it's not already.  But after the recent changes to the UNL design, the 
functionality only works within the same outline.  It won't open an outline 
and navigate to the target node.

A fix is in the works, but Edward and Felix don't have a lot of extra 
cycles right now to review and approve the PR.  So here is a monkey-patch 
that restores the navigation capability in advance of merging the PR.  This 
is basically the same code as is in the PR, packaged as a little outline 
that can do the monkey-patching.  The code changes g.openUNLFile().

To use, open the outline, select its top-level node, and run its script 
(with CTRL-b).  The patch will need to be applied again each time you start 
Leo.

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/e9f6f810-a0c2-40eb-b406-9f7691af0f15n%40googlegroups.com.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo: https://leo-editor.github.io/leo-editor/leo_toc.html -->
<leo_file xmlns:leo="https://leo-editor.github.io/leo-editor/namespaces/leo-python-editor/1.1"; >
<leo_header file_format="2"/>
<globals/>
<preferences/>
<find_panel_settings/>
<vnodes>
<v t="tom.20231209125148.1"><vh>openUNLFile Monkey-patch</vh>
<v t="tom.20231209125148.2"><vh>&lt;&lt; well-known outlines &gt;&gt;</vh></v>
</v>
</vnodes>
<tnodes>
<t tx="tom.20231209125148.1">import os
def openUNLFile(c, s):
    """
    Open the commander for filename s, the file part of an unl.

    Return None if the file can not be found.
    
    Look for locations in the following places in order:
        1. The currently selected outline
        2. All open outlines
        3. Files specified in an @data setting named 'unl-path-prefixes'
        4. Certain well-known files like PyLeoRef.leo
        5. The outlines listed in the Recent Files menu.
    """
    base = os.path.basename
    norm = os.path.normpath
    c_name = c.fileName()
    path = ''

    def standard(path: str) -&gt; str:
        """Standardize the path for easy comparison."""
        return norm(path).lower()

    if not s.strip():
        return None
    if s.startswith('//') and s.endswith('#'):
        s = s[2:-1]
    if not s.strip():
        return None
    # Always match within the present file.
    if os.path.isabs(s) and standard(s) == standard(c_name):
        return c
    if not os.path.isabs(s) and standard(s) == standard(base(c_name)):
        return c
    if os.path.isabs(s):
        path = standard(s)
    else:
        # Check for outlines defined in 'unl-path-prefixes' settings
        # Values of d should be directories.
        d = g.parsePathData(c)
        path = base_s = base(s)
        directory = d.get(base_s)
        if directory and os.path.exists(directory):
            path = standard(os.path.join(directory, base_s))
            if path == standard(c_name):
                return c
    # Search all open commanders.
    # This is a good shortcut, and it helps unit tests.
    # "path" is always going to be a filename without directories
    for c2 in g.app.commanders():
        if path.lower() == base(standard(c2.fileName())):
            return c2
    # Check well-known files and recent files list
    &lt;&lt; well-known outlines &gt;&gt;
    all = well_known + g.app.recentFilesManager.getRecentFiles()
    for f in all:
        if path.lower() == base(standard(f)):
            if os.path.exists(f):
                return g.openWithFileName(f)
            break  # In Recent Files but no longer exists
    return None

g.openUNLFile = openUNLFile</t>
<t tx="tom.20231209125148.2">ld = g.app.loadDir
well_known = [
    f'{ld}/LeoPyRef.leo',
    f'{ld}/../doc/CheatSheet.leo',
    f'{ld}/../doc/LeoDocs.leo',
    f'{ld}/../doc/leoSlideShows.leo',
    f'{ld}/../scripts/scripts.leo',
]
</t>
</tnodes>
</leo_file>

Reply via email to