![]() For parameterized and surround templates things are a little bit more complicated so we are going to create parameterized template below.įor example, we want to have custom table with class and id and one row and three columns inside. If we are writing Simple Template then just enter text here. After that you need to add Template text (you can also have Template text set for you in case you select a block of text and invoke menu Tools | Save as Live Template). Enter abbreviation (name by which we are going to invoke this template) and Description. In order to create a new Custom Live Template go to the Live Templates Settings dialog and click on add ( +) button in order to add new template. It would be quite useful to examine predefined Live Templates in order to understand how is it created. We can see a list of predefined Live Templates by groups. Just go to Settings | IDE Settings | Live Templates. Let’s check how can we create a custom template. You can also type template abbreviation and use TAB to make it do coding for you. Use hotkeys in order to get list of templates or use it. Surround templates (work blocks of selected text) CTRL+ALT+J / META + ALT + J.Parameterized template (contains plain text and variables that enable user input) CTRL+J / META + J.Simple template (some fixed code that expands into plain text) CTRL+J / META+J.We’ve got complete and valid JS code and the only thing you need to do is to change variables. Enter itar abbreviation in JS file and press TAB. Just to understand how does it work let’s check predefined example “Iterate elements of array”. This functionality is available in IntelliJ Idea, P圜harm, WebStorm, PhpStorm, RubyMine, AppCode.Įach live template is identified by a template abbreviation. Today we are going to learn how to create custom live templates in order to type less. There are numerous pre-defined templates for CSS, HTML, XSL, JS including Zen Coding and some others, however, sometimes it’s not enough. Live templates contain predefined code fragments so that you can use them to insert frequently-used or custom code constructs into source code quickly, efficiently, and accurately. Live template is a feature helping you to type less and be more productive easily creating and using pattern structures in your code. One of the most important things we should think about while coding is performance – these code patterns are 100% reusable, we don’t use our brain in order to employ it – just mechanically type and this typing requires some time, so that the key factor in making your coding a high-speed one is to spend as little time on routine coding as possible. The argument to the titleCase function is SELECTION, which tells the IntelliJ Platform to operate on the current selection.Usually in our code we have a lot of pattern structures such as conditionals (if, else), loops (for, while, foreach), tag structures (HTML tables, ul listings) and others. The expression for TITLE evaluates to the titleCase function provided by the plugin. The XML representation of an example Live Template using the new titleCase function is listed below. Using the procedures previously discussed for Template Creation and Export the Live Template, add a Live Template to the Markdown.xml file for the plugin. liveTemplates import .* import .macro.MacroBase import .text.StringUtil import public class TitleCaseMacro extends MacroBase Adding a Live Template Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. ![]() The text to be capitalized is retrieved from the Live Template and converted to Title Case. The calculateResult() method gets invoked when the titleCase function is used in a Live Template.The test relies on the MarkdownContext object previously defined in the live_templates plugin. The isAcceptableInContext() method tests whether the macro is available in the current context.The TitleCaseMacro() constructor passes the name and description of the macro to the parent constructor.Three TitleCaseMacro methods are of particular interest: Under the hood, the predefined functions for Live Templates are called macros.Ī new custom function for Live Templates is implemented in TitleCaseMacro, which extends MacroBase. Refer to the SDK code sample live_templates. This tutorial illustrates how to add custom functions to an IntelliJ Platform plugin and make them available for use by Live Templates.Īs an example, a function is created to convert a selection to Title Case. However, sometimes the Predefined Functions are not enough. The Predefined Functions are the building blocks for creating Parameterized Templates and Surround Templates. Adding Live Templates to a Plugin Edit page Creating New Functions for Live Templates
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |