Custom Context-Sensitive Commands

It is straightforward to add support for custom menu items in the context menu of a freeform project’s root node. Just open the project’s Properties dialog, and in Build and Run add entries to the Custom Menu Items table.

It is also not too hard to bind standard context-sensitive actions in the IDE, such as Compile File or Run File, to Ant targets. Details:

General Metadata—Actions

However on occasion you may wish to create your own context-sensitive actions and bind them to targets in one or more freeform projects. This module helps you do so:

  1. First edit your project.xml and build.xml to include one or more bindings for a new context-sensitive action. Pick any action name you like. For example:

    <action name="reformat">
        <target>run-jalopy-on-files</target>
        <context>
            <property>includes</property>
            <folder>${src.dir}</folder>
            <pattern>\.java$</pattern>
            <format>relative-path</format>
            <arity>
                <separated-files>,</separated-files>
            </arity>
        </context>
    </action>
                    
    <target name="run-jalopy-on-files">
        <jalopy …options…>
            <fileset dir="${src.dir}" includes="${includes}"/>
        </jalopy>
    </target>
                    
  2. Right-click the project and select Create Custom Command... from the context menu. The Command should be preselected (here, reformat). Choose a display name (e.g. Custom Reformat). Pick a menu (e.g. Source) and position (e.g. Reformat Code ↔ Shift Left). Click Finish.

  3. Now you should be able to select some Java sources in your project and select Source > Custom Reformat 3 Files to run Jalopy on them.

  4. You should be able to use Tools > Options > Keymap to add keyboard bindings. To add a toolbar button, find the new action in Tools > Options > Advanced Options > IDE Configuration > Look and Feel > Actions, copy it, and paste to a subfolder of Toolbars.

This feature should be considered experimental. In particular, there is not yet any way to customize the action name or display name once it is created; you will need to delete the old action from Menu Bar and rerun the wizard.