netbeansyii2netbeans-8netbeans-pluginscode-templates

Netbeans IDE code template on selected text


In framework and other PHP frameworks, there is a translation function used for . I'm using IDE and I have created the following code template:

Yii::t('app', ${selection})${cursor}

The abbreviation for the above code template is yiit. The purpose of this template is to making easy selecting a text in the code and wrap it in the translation function. Suppose the following:

<?=Html::a('Home',['site/index']);?>

So, when selecting 'Home' and applying the code template it should replac the 'Home' with: Yii::t('app', 'Home')

The problem in applying the code template there is no any way to call the code template other than writing its abbreviation, yiit followed by Tab and of course this delete the selected text 'Home' and the result is the code template with empty replacement string Yii::t('app', ).

Is there any work around?


Solution

  • Finally, I found the solution. It is macro. Tools->Options->Editor tab->Macros tab Then click New give the new Macro a name, I named it Yii Translate then enter the following code into Macro Code:

    cut-to-clipboard "Yii::t('app'," paste-from-clipboard ")"
    

    Click Apply, then press Set Shortcut button to make an initiator keyboard shortcut, I set it to be Alt+NUMPAD0

    Now go to the editor and select any string then press ALT+NUMPAD0 will cut the string and paste it in the desired code.

    For reference this is a list of Macro codes