GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Provide functionality to find and locate template scripts · Issue #6 · scijava/script-editor

Provide functionality to find and locate template scripts #6

New issue
Copy link
New issue
Copy link
Open
Open
Provide functionality to find and locate template scripts#6
Copy link

Description

@imagejan
imagejan
opened on Dec 6, 2016
Issue body actions

It would be helpful to have a tool to quickly search for a specific script template in the Templates menu, as well as locating its source (i.e. from which jar file, from which update site).

Maybe some code of the ImageJ CommandFinder can be re-used for this, at it provides the same functionality for menu commands?

Reacted by Hadrien Mary

Activity

  1. imagejan commented on Jan 8, 2018

    @imagejan
    imagejan
    on Jan 8, 2018
    MemberAuthor
    More actions

    With the new SearchActionFactory interface in place, it would probably sufficient to factor out the logic from here:

    script-editor/src/main/java/org/scijava/ui/swing/script/TextEditor.java

    Lines 870 to 926 in 5478a77

    /**
    * Initializes the Templates menu.
    * <p>
    * Other components can add templates simply by providing scripts in their
    * resources, identified by a path of the form
    * {@code /script_templates/<menu path>/<menu label>}.
    * </p>
    *
    * @param templatesMenu the top-level menu to populate
    */
    private void addTemplates(final JMenu templatesMenu) {
    final File baseDir = appService.getApp().getBaseDirectory();
    for (final String templatePath : TEMPLATE_PATHS) {
    for (final Map.Entry<String, URL> entry : new TreeMap<>(
    FileUtils.findResources(null, templatePath, baseDir)).entrySet())
    {
    final String key = entry.getKey();
    final String ext = FileUtils.getExtension(key);
    // try to determine the scripting language
    final ScriptLanguage lang = ext.isEmpty() ? null :
    scriptService.getLanguageByExtension(ext);
    final String langName = lang == null ? null : lang.getLanguageName();
    final String langSuffix = lang == null ? null : " (" + langName + ")";
    final String path = adjustPath(key, langName);
    // create a human-readable label
    final int labelIndex = path.lastIndexOf('/') + 1;
    final String label = ext.isEmpty() ? path.substring(labelIndex) :
    path.substring(labelIndex, path.length() - ext.length() - 1);
    final ActionListener menuListener = new ActionListener() {
    @Override
    public void actionPerformed(final ActionEvent e) {
    loadTemplate(entry.getValue());
    }
    };
    // add script to the secondary language-sorted menu structure
    if (langName != null) {
    final String langPath = "[by language]/" + langName + "/" + path;
    final JMenu langMenu = getMenu(templatesMenu, langPath, true);
    final JMenuItem langItem = new JMenuItem(label);
    langMenu.add(langItem);
    langItem.addActionListener(menuListener);
    }
    // add script to the primary Templates menu structure
    final JMenu menu = getMenu(templatesMenu, path, true);
    final JMenuItem item = new JMenuItem(label + langSuffix);
    menu.add(item);
    item.addActionListener(menuListener);
    }
    }
    }

    to generate a list of available templates that is usable by both the current script editor (when creating its Templates menu) and a newly created OpenTemplateActionFactory or some such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.