How To Bind Mouse action? - c#-3.0

I have Added following code to add Mouse Gestures in command binding but it looks like Keyboard shortcuts are working but Mouse shortcut isn't working:
gestures = new InputGestureCollection
{
new KeyGesture(Key.Enter, ModifierKeys.Control), new MouseGesture(MouseAction.MiddleClick, ModifierKeys.Control)
};
zoomChartToFitCommand = new RoutedUICommand("Zoom To Fit", "zoomChartToFit", typeof(ZoomCommands), gestures);

Related

Detect CTRL+Click on SWT ToolItem

Is there a way to detect a CTRL-click on a ToolItem? I want to distinguish between CTRL+Click and normal mouse click.
ToolBar toolbar= new ToolBar(parent, SWT.NONE);
ToolItem saveToolItem = new ToolItem(toolbar, SWT.PUSH);
...
saveToolItem.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
// if CTRL+Click {
// specialSave();
// } else
normalSave();
}));
The SelectionEvent passed to the event (in e in your code) has a stateMask field including the modifier keys being pressed. The SWT.CTRL constant for Ctrl.
So:
if ((e.stateMask & SWT.CTRL) == SWT.CTRL)
Tests for the Ctrl key being pressed

Maintain screen position always centered on cursor

I'm trying to write an extension for VSCode where the editor screen is always centered on the cursor. There are other extensions that add a command to center the screen onto the cursor, but you have to press the command to activate it.
Currently the only way I've found to implement this is to rewrite the cursorUp, cursorDown, enter, pageUp, pageDown -- any command that moves the cursor up and down basically, and then use the "revealLine" command with the cursor line position and with the "at" attribute as "center".
Is there a better way? Reimplementing the default editor commands seems very inefficient.
Here's what I've got currently:
"use strict";
import * as vscode from "vscode";
export function activate(context: vscode.ExtensionContext) {
let disposable1 = vscode.commands.registerCommand("cursorUp",() => {
centralizar();
vscode.commands.executeCommand("cursorMove", {
to: "up",
});
}
);
let disposable2 = vscode.commands.registerCommand("cursorDown",() => {
centralizar();
vscode.commands.executeCommand("cursorMove", {
to: "down",
});
}
);
context.subscriptions.push(disposable1);
context.subscriptions.push(disposable2);
}
function centralizar() {
let currentLineNumber = vscode.window.activeTextEditor.selection.start.line;
vscode.commands.executeCommand("revealLine", {
lineNumber: currentLineNumber,
at: "center"
});
}
export function deactivate() {}
Perhaps you can utilize the new (v1.38) command editor.cursorSurroundingLines. See scrollOff release notes.
It takes a number, but if you can get the number of visible lines in an editor window, then set editor.cursorSurroundingLines to the appropriate midpoint that may work. It seems you would not have to listen for scroll events. But would have to update the value if the editor window was resized.
The Scrolloff extension implements this functionality when its "alwaysCenter" option is enabled. It works by listening to window.onDidChangeTextEditorSelection, which fires when the cursor moves.

Gui.Window ContextClick

Is there a way to add an Event.ContextClick to a Gui.Window in a Unity Editor script?
The following is my context menu method that I've tried calling from both OnGUI() and my window's WindowFunction (call sites denoted below as "site: no luck"). I have not been able to get the "Success" message to show up unless I'm right clicking directly in the main editor window. If I right click in any of the Gui.Windows I have created, the ContextClick event doesn't show up.
void OnStateContextMenu(){
Event evt = Event.current;
// Ignore anything but contextclicks
if(evt.type != EventType.ContextClick)return;
Debug.Log("Success");
// Add generic menu at context point
GenericMenu menu = new GenericMenu();
menu.AddItem (new GUIContent ("AddState"),false,AddState,evt.mousePosition);
menu.ShowAsContext ();
evt.Use();
}
And the call site(s):
void doWindow(int id){
// OnStateContextMenu(); //site1: no luck
GUI.DragWindow();
}
void OnGUI(){
OnStateContextMenu(); //site2: no luck here either
BeginWindows();
wndRect = GUI.Window(0,wndRect,doWindow,"StateWnd");
EndWindows();
}
Update
For reference, green area responds to right-click, red area does not. But I want it to. The right-click menu I've created has specific actions I only want visible if the mouse cursor right clicks inside one of my windows, the 'Hello' in the image. Note: Ignore the button, right click doesn't work anywhere inside that window.
This might not directly answer your question but should be able to help
You are trying to achieve a rightclick function inside your red box( as shown in picute )
I had a sort alike question a while back but it was not for a rightclick but for a mouseover
so i figured this might be able to help you
string mouseover; // first of i created a new string
if (GUI.Button (new Rect (100,100,200,200),new GUIContent("Load game", "MouseOverOnButton0") ,menutexture ))
{
//added a mousoveronbutton command to my GUIcontent
executestuff();
}
buttoncheck();
}
void buttoncheck()
{
mouseover = GUI.tooltip;
if(mouseover == "MouseOverOnButton0")
{
GUI.Box(new Rect(380,45,235,25),"Not a implemented function as of yet ");
}
}
this code made a new gui box the moment the mouse hitted the box.
If you created the hello in a seperate box you could use this
if(mouseover == hello)
{
if(rightclick == true)
{
execute the stuff you want
}
}
or something like that. Hope this helps a bit atleast
UPDATE
To obtain the rightclick event you will have to use the
if(Event.current.button == 1 && Event.current.isMouse)
You have to place this in the OnGUI to work properly
this way you first trigger the in box part, then check for a right click and execute the stuff you want.

Mouse wheel event does not fire on GWT FocusPanel, if FocusPanel is on GWT PopupPanel (only in Chrome and Safari)

Here's the code:
public class MyEntryPoint implements EntryPoint {
PopupPanel popupPanel = new PopupPanel(false,true);
FocusPanel focusPanel = new FocusPanel();
VerticalPanel popupContent = new VerticalPanel();
public void onModuleLoad() {
popupContent.add(new Label("Simple popup test"));
popupContent.add(new Label("_"));
focusPanel.add(popupContent);
popupPanel.setWidget(focusPanel);
popupPanel.center();
focusPanel.addMouseWheelHandler(new MouseWheelHandler(){
public void onMouseWheel(MouseWheelEvent event) {
System.out.println("deltaY = " + event.getDeltaY());
}
});
}
}
If you run a GWT app in Firefox, move your mouse over the text "Simple popup test" and scroll the mouse wheel, then onMouseWheel will be called.
If this application is running in Chrome or Safari, place your mouse over the text "Simple popup test" and scroll the mouse wheel, then onMouseWheel not called. If you place the mouse cursor is not on the GWT Label and scroll the mouse wheel, the event will be called onMouseWheel.
Maybe someone has already corrected this? Thank you very much.
The Bug can be found on the GWT issue tracker:
http://code.google.com/p/google-web-toolkit/issues/detail?id=7349
There is a link to a Google goups discussion in the issue text.
I solved the problem by set the popup to modal = false.

Titanium - Event listener for annotation

I am a beginner in Titanium Studio. I am opening a new window, when I select the annotation pin on the mapview.
annotation.addEventListener('click', function(e) {
Ti.API.info("Opening detail window");
navGroup.open(detailWindow);
});
But, it doesn't work every time. It works only for the first time, when the annotation is performed.
How could I make it work, whenever I select the annotation pin, I should move to a new window? Thanks in advance.
You should use annotation right button to open a new window.
To catch the annotation right button click event you have to do this:
var mapView.addEventListener('click', function(e){
// if user click on rightButton of annotaion
if ( evt.clicksource == 'rightButton' ) {
Ti.API.info("Opening detail window");
navGroup.open(detailWindow);
}
});