eclipse rcp keybindings don't work - eclipse-rcp

I am trying to make eclipse keybindings work.
I tried to make the rename command work.
I looked at some tutorials and experimented. I enabled command and key binding trace in console (http://eclipsesource.com/blogs/2009/07/08/tip-tracing-keybindings-in-rcp/).
I have created a custom command:
com.mycompany.myproduct.command.rename
This is what I got so far:
1) I tried to follow this tutorial,http://www.vogella.com/tutorials/EclipseCommandsKeybindings/article.html, but I came to the conclusion that this is for e3. This is because you need to add commands plugin that recognize only old e3 handlers. No xmi is involved
2) I tried to use xmi binding contexts. I had my command registered in the top level commands tree and connected to a handler in the top level handlers tree.
In the binding tables section I have a bindingTable that works in Dialog and Windows context. I added a key binding. The sequence is "F2" and it is connected to my custom command.
When I hit F2 I get the following message in trace:
COMMANDS >>> execute >>> starting: id=org.eclipse.ui.edit.rename; event=ExecutionEvent(Command(org.eclipse.ui.edit.rename,Rename,
Rename the selected item,
Category(org.eclipse.ui.category.file,File,null,true),
org.eclipse.ui.internal.MakeHandlersGo#1285594,
,,true),{},Event {type=1 Tree {} time=1480412218 data=null x=0 y=0 width=0 height=0 detail=0},org.eclipse.e4.ui.workbench.modeling.ExpressionContext#177fc1a)
In short the default eclipse IDE rename command is fired (my key binding does nothing), and nothing happens on my application.
However, if I change the sequece to "M1+1" and hit ctrl + 1, a little pop up comes up that lets me choose between "quick fix" (eclipse IDE command) and my rename. If I choose rename the handler fires.
Now, how do I disable eclipse IDE default keybindings. The instructions of the tutorial in step 1 definitely don't do it.
Thanks!

You can try to force E4 to read your key binding as an user one, adding the "type:user" tag to the KeyBinding itself :

I swear sometimes it seems like the application just likes to see us suffer. I had the same issue you had; a while ago my key binding was working just fine and today I notice it doesn't work anymore. Thanks for this post I found 2 solutions:
"type:user" from the above comment
remove org.eclipse.ui from the run configurations; it seems this was added when I pressed add required plugins after adding some plugin myself

Related

Eclipse Ctrl+Shift+D not working With Pydev

When Using Pydev on Eclipse, I wanted to bind Ctrl+Shift+D Copy Lines and Ctrl+D to Delete line. But when I do so, the Ctrl+Shift+D doesn't work.
I removed all the other bindings of Ctrl+Shift+D but it doesn't work.
Fun fact, if I choose Ctrl+Shift+C, it does work, so I'm wondering where is this key binding used.
The problem arrises only in Pydev, ie. when I open the file in Text editor the bindings work.
This was fixed for PyDev 6.3.3.
The problem was that there was a command bound to Ctrl+Shift+D which was not visible there because it wasn't properly categorized.
I fixed this in: https://github.com/fabioz/Pydev/commit/422a0bde1d1a3ac5c091c00e88368a3bc3c0dc5f
Note that you could still override it if at the keybindings dialog you created a command and put the 'When' as 'PyDev editor scope' (which defines when it's active -- it wouldn't work without this because the hidden action had a higher priority given that its scope was narrower).
See details at: https://www.brainwy.com/tracker/PyDev/906

Stop Eclipse Automatically Closing/Completing Comments

When working on C code in Eclipse (Mars, in case that matters), I type /* to begin a stream comment. If I hit [Enter] any time within this stream comment, Eclipse automatically inserts a column of single-space indented stars _* and a single-space indented close stream comment _*/. This is incredibly annoying as this is never the behavior I want after opening a stream comment. I then have to undo-undo or highlight and delete.
I've gone into C/C++ > Editor > Typing and unchecked every option in the Automatically close group-box, but these options only include "Strings", (Parentheses) and [Square Brackets], <Angle> brackets and {Braces}.
There's no /*Comments*/ option.
I've even tried modifying every code template that contains such a stream comment, to no avail.
How can I get Eclipse to stop auto-completing comments?
I've checked these similar questions and found no answer:
Annoying eclipse automatically closing quotes, Stop Eclipse from mangling my comments, eclipse disable completion of xml comment, How to stop Eclipse from auto-adding parentheses?

How to step over method call in Eclipse Debugger?

In Eclise debugger, the default step options are:
F5: Step into method
F6: Step over line
F7: Step out of method
Often I do have code like this:
obj.getMember().doStuff();
Or maybe even worse (please don't question the code design, just making this up):
obj.getInstance().createSomething().getMember().doStuff();
Usually I want to inspect doStuff() only, but F6 will not step over individual method calls, but it will step over the entire line. So I end up hitting F5 and F7 until I reach doStuff().
My question is: Is there any option to step over method calls (= do F5 and F7 in one shortcut)? Would be cool, if I had to tap X, X, X, F5 only to reach doStuff().
// Edit for clarification: I'm looking for a keyboard-only solution. I know there are several ways I can reach my method (e.g. breakpoints), but I'm asking for a combined shortcut for F5 + F7, so to say.
You have to select the method you want to step into and then with the right click of the mouse you will find the option Step into Selection :
Select the Step Into Selection command to step into the currently
selected statement in the active editor.
You must have program execution suspended for this command to be available.
As you can see from the image above you can just press OPTION and F5 on a mac once selected the method to step into ...
Shortcut :ALT + F5
You could also place a breakpoint into doStuff() and, when you reach obj.getInstance().createSomething().getMember().doStuff(); just resume execution (keybinding: F8:
All the intermediate frames will be executed and the debugger will pause directly in doStuff() again. This of course means that you cannot decide from run to run like you can do with aleroot's Step into Selection suggestion.
Alright, something completely different, since I think I understand the core of your question a bit better now.
There's no predefined skip-over-this-method command afaik, so you can build one yourself. This touches some advanced topics so I'll only post some pointers here:
Create an Eclipse plugin.
In that plugin, declare a command with a keybinding like Alt+F8 and implement the command's default handler
In the handler of your command, invoke the built-in commands which are bound to the Step into and Step out actions. You can find their IDs by looking into the Eclipse source or trying the Plugin-Spy feature.
Package up your plugin and start your Eclipse with it included.
This way you'll reuse the predefined functionality and automate your F5 plus F7 mashing into a single command with relatively small effort.

Eclipse - Android - Add "Imports"

Coming from .NET background ...
Is there a way to either via key stroke or by automatic settings to have the "Import" statements added that are needed by the code?
Right now I have to right click each class that I am referencing and choose the add option to have the Imports added and that's slow. I'd like to do them all at once with a single key stroke
I found that SHIFT COMMAND O does the job.
In Eclipse Helios with Android extension, Ctrl+Shift+M works for this purpose.
You can see what you particular key binding is by going to Window->Preferences->General->Keys and enter "import" in the filter widget. Look for "Add import" in the search results.
If it is bound to a key sequence, you can use (or change ) that sequence. If it is not
bound, you can bind it to a key sequence.
+ SHIFT + O for mac users. Had me stuck for a bit but works.

What's the trick to write code faster in Eclipse?

I know there is a trick that when you type quickly code in Eclipse, you can hit some secret keys and it will auto-complete the missing parts. Who knows them?
example: I have someVeryLongVariablesWhichIWantToTypeFast and I start typing someVeryLongVa but nothing happens. Only when I type method names a yellow box appears that wants to help me.
Ctrl + Space is the autocomplete shortcut
All shortcuts you can find under Window -> Preferences -> General -> Keys
As mentioned the command is Ctrl+Space to auto complete.
You can speed it up using camelCase...so in your example:
someVeryLongVariablesWhichIWantToTypeFast
you could start typing sVL then Ctrl+Space should auto complete or list all variables that match.
CamelCase also works for specify classes, searching for classes etc.
Others I like/use:
type sysCtrl+Space to get System.out.println statement (or err)
type foreCtrl+Space after an array/list line to foreach it
Click on an argument to a method and Ctrl+1 to create a field for it and assign it, great for constructors
Ctrl+1 on any local variable to convert to field, split declaration, or inline it
if you have
object.method().method2().method3()
selecting object.method() and type Ctrl+1 to assign to a field or local variable, then you get
Object objLocal=object.method()
objLocal.method2().method3()
//Can now select objLocal.method2() and do the same again
My favourites:
Ctrl + Space - auto complete
Ctrl + 1 - show quick fix options when you are over an error / warning
Shift + Ctrl + L - list short cuts
One trick that I love in Eclipse for Java is writing backwards (meaning you write the client before the code it calls). We typically think of autocomplete to help us with methods and variables that already exist. This is okay, but even cooler is when a method/class does not exist.
Try typing this code into a method (anywhere, really):
Who who = new Who();
who.whatUpMan("hi", 32);
Now left-click on the Who at the beginning. It will give you the choice to create a class, interface, enum, etc.
Now left-click on the whatUpMan. It will prompt you to create the method with the right parameter types and everything.
These are called "Quick Fixes" in Eclipse and they give you total freedom to code from the client "backwards" to classes it utilizes. And when you've already got the method, of course, control-space and control-shift-space (to see parameters for methods) are your friends.
http://eclipse-tools.sourceforge.net/EclipseEmacsKeybindings_3_1.pdf
Some more time savers that don't seem to be mentioned:
Ctrl+3 'Quick Access' which basically let's you reach anything without clicking around too much. E.g. type 'nav' in the popup dialog, rather than Window | Show View | General | Navigator or wherever it is.
Ctrl+O 'Quick Outline': when editing Java (and some other things), pops up a lighweight dialog so that you find anything in the file by a few keystrokes
Shift+Alt+T 'Refactoring', and things below that menu - look for shortcuts there, use 'Rename', 'Move', 'Extract method', 'Change method signature' often
Alt+Up/Down move blocks of code up/down without cut/paste
Alt+Shift+Up/Down select various levels of code (expressions,statements, methods, class) easily
Ctrl+1 on the selected code offers you cool stuff eg. Extract to variable/constant/method; Split variable declaration -- see others above, or just try it on anything
Ctrl+Shift+R find any file in the workspace, similar to Ctrl+Shift+T to find types
Ctrl + Shift + O : resolve all dependances automaticall. In Java, it's a life saver as it cleans old packages and add the required one without a single line to write.
"Right click" then "refactor" : all the features are handy, but I espacially love "rename" (Ctrl + Shift + R, c.f comments) because it will apply the changes to all the project. No more tricky find / replace wit regexp to do ensure you breal nothing else :-)
"Right click" then "source" : equally useful, with a special mention to "generate getter and setter" and "implement methods"
Ctrl + D : delete a line. Kinda cool.
I kind of remember CTRL+SPACE was the shortcut for autocomplete.
Another time-saver is formatting the code automatically using Ctrl + Shift + F.
Formatter preferences http://img187.imageshack.us/img187/5866/eclipseformatter.png
General Eclipse tips
Get rid of all the crap that you'll never use
if you do web-dev ... install the database, php, pydev, modules and plugins
install svn/cvs/git plugin
use Trac
have different code enviornments for different code types, i.e. one for python-dev, c++, and so on.
wait a few weeks to months before updating
i have about 100 premade mini scripts that i use frequently.
learn to develop your own plugins, as it's easy and fun.
For some applications, the answer is to generate the code using EMF. But the EMF learning curve is significant.
I would suggest go to Eclipse -> Preferences -> General -> Editor -> Keys and to configure your own keyboard shortcuts for all common tasks so that you can have custom keybindings that are perfect for you.
Probably this might not exactly answer your question but it is very relevant to your question title.
You can define templates in Eclipse to magically type and get a bunch of code typed for you. For instance you may type something like syso or sout to get System.out.println() in your Java code.
This can be done by following Window -> Preferences -> Java -> Editor -> Templates. You can also add a Template View, which you find at Window -> Show View -> Other -> Search for Templates.
Here is an image to clarify
* Original related answer in here as well.
Hope it is helpful to someone :)