Reputation: 1045
In intelliJ, is there a way to ungroup the Java Class templates in the New context menu? I would prefer to not have the second popup with a dropdown if possible. (Trivial, I know, but I like to avoid additional steps when possible)
Upvotes: 0
Views: 122
Reputation: 32026
As @vikingsteve indicates, this is not possible shy of writing a plug-in. As a workaround, if it is a case of a few template you use frequently and you want faster access to them, you can record a macro that ends with the New Class Dialog open and the "Kind" field completed with the desired template. Then map that macro to a keyboard shortcut. Here's the steps for recording a macro to Create a Singleton via the Singleton template:
Java Class
to use inline search to select the "Java Class" entry from the list.
K
accelerator key(Alt+K)... however I found this didn't work correctly on playbacksingleton
(or the name of your template) to use inline search to select the template.Keymap
setting. Under Macros, give your macro a shortcut.
To use the macro, just select the directory/package in the Project tool window or the Navigator bar and use the keyboard shortcut to launch the macro. It should end with the New Class dialog open with the correct template selected and the cursor in the Name field ready for you to type. If the class associated with the template has a particular naming convention -- such as always ending in 'Singleton' -- you can enhance the Macro to pre-populate that as well and have the cursor positioned properly.
EDIT
I should mention, if you have several to do, rather than having to repeat the above to record a new macro each time, after recoding one, you can hack/edit the macro settings file. (Unfortunately. while there is an edit macro option in the macro dialog, there is not a copy macro option so you need to edit the config file directly.) Close IDEA. Backup and then open the file config/options/macros.xml
(see Directories used by the IDE to store settings, caches, plugins and logs to locate the config
directory.) Find the <macro>
element with your macro. Copy & paste it, and edit the name
element and typing
element where you entered the template name. (You can look in config/fileTemplates
for the template names, although there is some minor normalization that can occur between the template name and the file name it is saved under.) Repeat for all templates. Save, and restart IDEA. Add key mappings to the new macros.
Upvotes: 3