How to add shortcuts ("templates") to eclipse properties through my plugin? - eclipse-plugin

I'm developing a plugin for visualization of objects by calling Doo.dle(Object o).
Now I'd like to automatically define a shortcut like sysout for System.out.println(), e.g. doodle.
I already know how to do it by hand:
Window > Preferences > Java > Editor > Templates
Is there an extension point or something similar to do this automatically with my plugin?

I managed to do it on my own:
I had to define a javaCompletionProposalComputer extension and implement an ICompletionProposal.
It's not exactly what I intended, but it's working too.
Update:
I finally found it out:
The key is to define an extension for org.eclipse.ui.editors.templates. Patterns etc. can be cheated off predifined templates in eclipse properties (see question).

Related

Is there a plugin to tell IntelliJ not to format a particular block when I use auto format?

My question is a duplicate of: How to turn off the Eclipse code formatter for certain sections of Java code? but for IntelliJ.
Does a similar feature exist for IntelliJ?
Yes, and It works the same way with:
#formatter:off
and
#formatter:on
Navigate to:
Settings > Editor > Code Style > Formatter control

Adding custom code generator

When I work with certain types of files, such as: Java file, HTML file or Jasmine Test file I can generate some useful code snippets using Code > Generate option, for example:
if I am working with Java file Code > Generate allows me to insert getter, setter, constructor etc
if I am working with HTML file Code > Generate allows me to insert an XML tag
if I am working with Jasmine Text file Code > Generate allows me to insert a scaffolding of a test suit or a singe test case
I was wondering if (and how) I can add my own 'generator'. I know I can use Live Templates, but I like the fact that Code > Generate gives me a quick list of all available generators.
Yes, you can do it by writing an IntelliJ plugin and extending this class:
com.intellij.openapi.actionSystem.Action
If you create an intelliJ plugin project (just google intellij plugin developmentfor information on how to get started), hit alt-enter somewhere in your project source tree and select Action, you will get a dialog which allows you to configure where your action should appear.
You want to place it in relation to another action which already exists, for example right below it. In your case - have a look at the menu group named GenerateGroup (Generate).
Once your action is defined in this manner in your plugin.xml, build and run your plugin in the sandbox.
Now, when your action is triggered, the AnActionEvent will be fired which contains references to all the necessary information you need (current project, file, position of cursor within file, psi tree, etc).
Try to get this working so far and come back with any specific questions.
Good luck!

Creating Dijit > Editor > Plugins

I have been googling this subject for hours. Does anyone have an examples of a custom plugin being deployed in Dijit's Editor. I'd be really interested to look at it because I have been following this without much success and of the few examples that exist out there none of them come with working examples :(
(I'm looking to create a pulldown menu like the one for font selection)
There's no difference between a custom plugin and a "builtin" plugin, so I suggest just looking at a small builtin example like TabIndent, and then move on to the font selection itself.

Custom key bindings Xcode 4?

Awhile back I asked a question about custom key bindings in Xcode. I ended up recreating some of TextMate's key commands in Xcode. Just updated to Xcode 4 and it appears that the PBKeyBinding file no longer has any effect. What's the new hotness for custom key bindings, specifically for Xcode 4?
Yes, it can be done (at least for the moment). After spending the better part of a day searching, experimenting and digging through the bowls of /Developer I finally figured out how to accomplish this.
Open IDETextKeyBindingsSet.plist located in /Developer/Library/PrivateFrameworks/IDEKit.framework/Resources/
This bindings plist is formatted differently than others used throughout the system, the most important distinction is that all the methods must be listed in the same string, i.e.
<string>moveToBeginningOfParagraph:, insertText:, foo</string>
edit:
I have not tested this, but it looks like the new location in Xcode is
Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
You can use Keymando to create any keybinding you like in Xcode 4 and any other OSX application.
The answer now seems to be to use the idekeybindings files — these are tied to the custom keyboard shortcut sets you create in the preferences — stored at ~/Library/Developer/Xcode/UserData/KeyBindings/. More information can be found in the Key Bindings Preferences Help. However it sounds like people are having no luck trying to combine multiple actions under one keyboard shortcut (as you can do with the older-style key bindings dict files). But presumably you could still do this in DefaultKeyBinding.dict, as long as you don't mind the shortcut also working in other applications :) If this doesn't work, I think you're out of luck for now. Sorry; file a bug!
Kike here http://www.codedojo.com/?p=580
you use this binding set
Download
http://www.codedojo.com/files/MSVC_xcode_config.zip
unzip it and place MSVC.pbxkeys in YourUserName/Library/Developer/Xcode/userdata/keybindings
and rename it to msvc.idekeybindings
then from
Xcode -> preferences -> keybindings
just pick msvc
Go to Xcode 4 > Preferences > Key Bindings and fiddle with them all you like. :)

How to disable code formatting for some part of the code using comments?

I'd like to selectively disable the IntelliJ IDEA code formatter for a portion of code just like I can in Eclipse. Does IntelliJ support this feature, and if so, how do I use it?
Since version 13 it's possible to wrap the code with
// #formatter:off
...
// #formatter:on
IntelliJ IDEA v.2018+:
File > Settings > Editor > Code Style
IntelliJ IDEA v.2016+:
Preferences > Editor > Code Style
IntelliJ IDEA v.14+:
Preferences > Editor > Code Style > Formatter Control
You can change the formatter control markers, as long as they're in comments.
Ensure formatter markers in comments are enabled, as shown in the following figure:
Note for Carlos' answer of #formatter:off and #formatter:on to work, you may need to enable the preference first:
Discovered via How to config intellij-idea not format some part of the code?
IDEA-56995 Disabled code formatting per region using comments
In xml files, use:
<!-- #formatter:off -->
<!-- #formatter:on -->
Obsolete answer from 2010:
No, it's not possible right now, I've submitted a new issue which you can track.
As a temporary solution you can use external formatter plug-in for IDEA which can utilize Eclipse code formatter (I didn't check whether this particular option is supported).
It's currently not possible to exclude entire files (like regression test data xmls) from formatting. See https://youtrack.jetbrains.com/issue/IDEA-167112