Eclipse Jface Projection Viewer - no reaction to Ctrl-Z - eclipse-plugin

In my current project I am working with a specific implementation of the jface ProjectionViewer attached to a TextEditor nested in a MultiPageEditor.
My task is now to implement a custom reaction to Ctrl-Z, and from what I get this is best done by attaching a specific implementation of IUndoHandler to the Viewer, all of that would be no problem.
But, pressing Ctrl-Z while having that TextEditor focused fails to cause any reaction that would be expected. While clicking "Undo Typing" in the context menu, which displays the associated key combination Ctrl-Z causes the TextViewerUndoManager.DocumentUndoListener's notification method is called, no line of code in the TextViewerUndoManager is touched when pressing Ctrl-Z.
As a possible source of this problem I assumed that maybe a handler might be defined for this key combination in an extension point, since I had previously experimented with this mechanism, but the plugin.xml does not define any key combinations nor undo handlers apart from one that is associated with a special context menu for a different widget.
It might be worth to note that Ctrl-C and Ctrl-V work as intended.
I need to find out what happens when Ctrl-Z is pressed and why nothing is relayed to the TextViewerUndoManager.
It would be very helpful if someone could describe the progress how eclipse handles these key combinations normally and decides which command is appropriate.
Thanks in advance

Cntrl+Z- undo is processed using OperationHistorySupport. Look at UndoActionHandler class.
Binding support is implemented using keydown event filter using WorkbenchKeyboard ( all keydown events first filtered using this class. this is how BindingService was implemented). This will figure out correspond command for the key binding.
DocumentUndoManager.UndoableTextChange is where undo operation is handled.

Related

Cocoa global hotkey consume key event

I've been trying for hours to use global hotkeys and "consume" the key event so it is not forwarded any more to the application where the key event is originally coming from.
So what I want to do is:
- a user presses a shortcut with application A in front, e.g. Cmd+F3
- my application (application B) receives this shortcut through the global event handler and sends mouse and keyboard events to application A
It's probably easiest to think of it as a macro.
I'm using DDHotkey and it works quite fine. The problem I have is that DDHotkey doesn't "consume" the key events and modifiers. That means that when my application starts sending mouse and keyboard events, the Cmd key from the actual global shortcut is still pressed.
This leads to erroneous behavior in my case (I'm double-clicking a textfield programmatically and that doesn't open when Cmd is pressed for example).
So what I'd like to do is really consume the key event and the modifier keys so that they are not forwarded to application A. Alternatively, I would "flush" the event queue before sending the key events to application A.
Is there any way to achieve this easily?
An even more reliable approach if it works for your use case would likely be to not script the UI by triggering mouse events and key presses, and instead use the Accessibility API to trigger the more high-level actions (like using Accessibility to tell a button it has been pressed). Unless the app contains some unfortunate code, that should not look at the modifier keys.
Telling the OS from an event monitor to remove key states would probably cause lots of issues: It would be confusing if the user then actually released the physical keys and a second keyUp came in. Even if the OS tries to avoid that, it is just asking for other edge case bugs - what if the user pressed a modifier key while your code is scripting the UI?
But if the applications you are scripting do not support Accessibility, nor AppleScript, nor any other more high level approach to automation, what you could do is wait for the user to release your hotkey (i.e. wait for keyUp events) and only then trigger your scripted actions. Might be necessary to use performSelector:withObject:afterDelay:0.0 to get out of the keyUp handler before you do that.

How to get notified every time an Editor is modified?

I'm writing a plugin that needs to be notified as changes happen to open files in an Editor. This needs to happen in real time (similar to how syntax checking is done currently).
ResourceChangeEvents works when I only need to get notified when a file is saved.
IPropertyChangeListener will tell me when a editor is marked as dirty.
This question is similar, but is more geared to getting events on a single editor instance and won't scale well for all editors.
What about keypress notifications in an editor? I'm a little surprised they don't cause PropertyChange events. How can I get such notifications for all editors?
You always have to deal with one text editor at a time. You would create an org.eclipse.ui.IPartListener and start listening to the editor on partActivated and stop listening to the editor on partDeactivated.
Also, I think you probably want to use org.eclipse.jface.text.IDocumentListener to listen to changes in the ITextEditor (instead of targetting the low level widget itself).

how to click on WebArea from QTP ?

In My test I want to click on object of Type WebArea which opens a webelement popup includes some fields that i need to test.
the problem that the popup not open after I click on WebArea object through the code.
the code I use as below.
Browser("WW").page("assessment").WebArea("areaassessment").Click
nothing hapens after the above line excuted.
Look into the HTML of the WebArea and see what action is triggering the popup. Normally it has something like onclick='showPopup();', but in other cases it is onmousedown or onmouseup.
If this is the case, you have to setup QTP accordingly. There are multiple roads to walk here, one is to see how you advanced web settings are configured. Go to Tools>Options>Web>Advanced and look in the Run Settings.
Setting the Replay Type to Event will replay your scripts by events (by default mousedown, mouseup and then mouseclick) or by mouse (You'll see your mouse pointer moving in this mode, QTP will replay by sending WM_* messages through the Windows api for movement to the correct screenlocation and triggering the click).
Allthough it replays a bit faster, if Run only click is checked, it is better to uncheck this to trigger all events / messages.
Events can also be fired by the FireEvent method:
Browser("WW").page("assessment").WebArea("areaassessment").FireEvent("onclick")
or through the object native methods:
call Browser("WW").page("assessment").WebArea("areaassessment").Object.click()
call Browser("WW").page("assessment").WebArea("areaassessment").Object.FireEvent("onclick")
As #AutomateChaos said there is probably an event that QTP isn't simulating, one way to work around this is to do as #AutomateChaos suggests and simulate the needed event. A simpler way is to change to device replay (as I described here and here).

Cocoa Key Equivalent in Menu is not working

I have created a NSStatusItem and I have assigned two key equivalents within interface builder (Xcode 4.0). These are for the preference menu cmd-, and the quit option cmd-q. Both of these will work when the Menu is highlighted/open but will not work otherwise even if the application is the foremost. Any ideas on why this is happening or how I can change this?
The operating system passes key events that it doesn't handle to the front application, which compares them to any key equivalents in its main menu and current window. They are not compared to items in the status bar, and since the status bar is actually a different application, it won't matter that your application is in the foreground. When you have the menu open, it is the window in focus. This is why it works in those circumstances.
Since the status item is only active while the menu is open, you need to get the key equivalents using one of two other methods. The first, newer method is to use event taps. I have never used this, so I can't advise on how to set it up. The other, older option, is to use hot keys. This method may become unsupported in the future, but if you are interested I posted an example in this answer.
My guess: your NSMenu is not in the responder chain. If you can figure out how to get it in there, you can probably get this to work.

Binding key combinations to your application

How can I bind a key combination to my vb.net application? I know it has SOMETHING to do with the registry, but I have no earthly idea what or how to go about doing this. I want the user to be able to hit those keys when the app is open and have it execute my function, but not while the app is closed.
Thanks for the help!
If you are using a dialog, then you can put '&' into the text for some controls (buttons, checkboxes, radio buttons, etc) and this will cause Alt plus the next character in the text to be used as an accelerator/shortcut. i.e. "&Open" would activate the Open button if you press Alt+O. "Op&en" would activate if for Alt+e.
Beyond that, as Jason Irwin said, you need to add an event handler to your Form for KeyDown or KeyPress events, and then check if the keypress is the key combination you are interested in. This will only work if the user activates your form (clicks in it to give it the input focus. If they put it behind another window, it will not react to the key presses)
If you don't want to show a form, or want to react to keypresses when you're not the input-focus application, then it gets a bit more complicated (you either need to use a hidden form or a keyboard hook)
edit
OK, it looks like you want a keyboard hook. This looks like a good article.
It depends on what you are trying to do:
If you have a gui application and you want to handle key events then you can do that in a keydown eventhandler
If you want to do more low-level stuff and have an application that will intercept all key strokes (regardless of whether or not the application has focus/is visible) then you need to use pinvoke to hit the win32 apis. I suggest you read the following:
link text
Please let us know what you are trying to do so we can provide better feedback.
Using Google, I found this Keyhook example.
I've worked with keyhooks before, in Delphi WIN32, so I am a bit familiar with them. (Just not in C#.) If you add one to a DLL, all Hell might break loose since most virus scanners will recognise this as malware behaviour. (Especially if you use them in the wrong way, causing them to be injected in each and every process that's running on your system.)
A keyhook will allow key combinations to be captured from other processes, though.
For a solution without programming requirements: Drop a shortcut for the application on your desktop. Edit it, assign a shortcut, close it. Press shortcut to test...