How to detect shift down when clicking on ScriptUI button? - adobe-indesign

On my scriptUI panel, I have a button. How can I detect whether the user is holding the shift key when they click on the button?

You can add an eventListener to your button.
var win = new Window ("dialog");
win.aButton = win.add ("button", undefined, "Button");
win.aButton.addEventListener ("click", function (k) {
if (k.shiftKey) {
alert("foo");
}else{
alert("bah");
}
});
win.show ();

Related

how to create row rapidly - Telerik Kendo UI MVC grid pop-up mode

I have a grid similiar that. But I don't want to close pop-up window; after clicking update button, i want to save record and clear all (or some) fields and continue to create (other) new record. So user can re-insert new record rapidly (multiple insert in the same window).
Finally user click the "cancel" (or close) button and popup will be closed. How can I do that.
Subscribe to Grid Edit/Save javascript events and follow the example below
var _PreventWindowClose = false;
var _IsNewMemberAlerted = false;
function onGridEdit(e) {
var window = this.editable.element.data("kendoWindow");
window.bind("close", onWindowEditMemberClose);
}
function onGridSave(e) {
if (e.model.isNew() && !_IsNewMemberAlerted) {
_IsNewMemberAlerted = true;
_PreventWindowClose = true;
}
}
var onWindowEditMemberClose = function (e) {
if (_PreventWindowClose) {
e.preventDefault();
_PreventWindowClose = false;
doClearingFieldsIfNeed();
}
else {
_IsNewMemberAlerted = false;
}
};

Handle two key event in as 2 ctrl + left click

I want to catch both the single left click and the ctrl + left click in as2.
I am using FlashDevelop and coded this (it works):
_mc._back.onRelease = function() :Void
{
var args:Array = new Array();
args.push((_root._xmouse - this._parent._posMiniMapX) * this._parent._ratio);
args.push((_root._ymouse - this._parent._posMiniMapY) * this._parent._ratio + this._parent._bpa / this._parent._ratio);
fscommand("MoveCameraMiniMap", args);
}
How can I handle the both event?
Thank you.
the approach that I've usually taken is to listen to keyboard events on the CTRL key then evaluate that onRelease to determine the correct action.
But you could simply check the key.isDown status within the onRelease
_mc._back.onRelease = function() :Void {
if(Key.isDown(17)) {
// do CTRL + mouse action
} else {
// do standard action
}
}

How to detect right-click on script UI button?

Using Adobe InDesign's extendscript (javascript language), how can I add an onClick function for both left AND right click events?
Adding the left-click event is easy. How do I add the right-click event?
[post answer update (much thanks to Josh Voights for finding that)]
If anyone is interested, I wanted to use this in such a way to apply the handler to the button like this, which works perfectly:
whatbutton.addEventListener("click", function(p){
if(!p.shiftKey){
if (p.button ==2) {
alert("right click");
}else{
alert("left click");
}
}else{
if (p.button ==2) {
alert("shift right click");
}else{
alert("shift left click");
}
}
Here's a code sample from kahrel.plus.com/indesign/scriptui.html that includes watching for a right click. Credit to #fabiantheblind in this stackoverflow answer.
var w =new Window ("dialog");
var b = w.add ("button", undefined, "Qwerty");
b.addEventListener("click", function (k){whatsup (k)});
function whatsup (p)
{
if(p.button == 2){ $.writeln ("Right-button clicked.") }
if(p.shiftKey){ $.writeln ("Shift key pressed.") }
$.writeln ("X: "+ p.clientX);
$.writeln ("Y: "+ p.clientY);
}
w.show ();

how to make jqgrid advanced search dialog keyboard accessible

Answer in how to enable enter in jqgrid advanced search window describes how to enable enter and other keys in jqgrid advanced search dialog.
After clicking Add group, Add subgrup, Delete rule or Delete group button in advanced search dialog Enter and other keys are still ignored. How set focus to added element or after delete remaining element to enable Enter and other keys?
The current version of the Advanced Searching dialog (see definition of jqFilter in the grid.filter.js) recreate all controls of the dialog on change of someone. See the code of reDraw which looks
this.reDraw = function() {
$("table.group:first",this).remove();
var t = this.createTableForGroup(p.filter, null);
$(this).append(t);
if($.isFunction(this.p.afterRedraw) ) {
this.p.afterRedraw.call(this, this.p);
}
};
How one can see the first line $("table.group:first",this).remove(); delete the content of all filter. The current focus will be lost and one have the problems which you described.
I suggest to fix the code of reDraw using document.activeElement element which was introduced in Internet Explorer originally (at least in IE4) and which is supported now in all web browsers because it's part of HTML5 standard (see here). The element which has focus originally will be destroyed and one will unable to set focus on it later. So I suggest to save the element name of the element and it's classes (like input.add-group or input.add-rule.ui-add) and to find the position of the element on the searching dialog. Later, after the dialog element will be recreated we'll set focus on the element with the same index.
I suggest to change the code of reDraw to the following
this.reDraw = function() {
var activeElement = document.activeElement, selector, $dialog, activeIndex = -1, $newElem, $buttons,
buttonClass,
getButtonClass = function (classNames) {
var arClasses = ['add-group', 'add-rule', 'delete-group', 'delete-rule'], i, n, className;
for (i = 0, n = classNames.length; i < n; i++) {
className = classNames[i];
if ($.inArray(className, arClasses) >= 0) {
return className;
}
}
return null;
};
if (activeElement) {
selector = activeElement.nodeName.toLowerCase();
buttonClass = getButtonClass(activeElement.className.split(' '));
if (buttonClass !== null) {
selector += '.' + buttonClass;
if (selector === "input.delete-rule") {
$buttons = $(activeElement).closest('table.group')
.find('input.add-rule,input.delete-rule');
activeIndex = $buttons.index(activeElement);
if (activeIndex > 0) {
// find the previous "add-rule" button
while (activeIndex--) {
$newElem = $($buttons[activeIndex]);
if ($newElem.hasClass("add-rule")) {
activeElement = $newElem[0];
selector = activeElement.nodeName.toLowerCase() + "." +
getButtonClass(activeElement.className.split(' '));
break;
}
}
}
} else if (selector === "input.delete-group") {
// change focus to "Add Rule" of the parent group
$newElem = $(activeElement).closest('table.group')
.parent()
.closest('table.group')
.find('input.add-rule');
if ($newElem.length > 1) {
activeElement = $newElem[$newElem.length-2];
selector = activeElement.nodeName.toLowerCase() + "." +
getButtonClass(activeElement.className.split(' '));
}
}
$dialog = $(activeElement).closest(".ui-jqdialog");
activeIndex = $dialog.find(selector).index(activeElement);
}
}
$("table.group:first",this).remove();
$(this).append(this.createTableForGroup(this.p.filter, null));
if($.isFunction(this.p.afterRedraw) ) {
this.p.afterRedraw.call(this, this.p);
}
if (activeElement && activeIndex >=0) {
$newElem = $dialog.find(selector + ":eq(" + activeIndex + ")");
if ($newElem.length>0) {
$newElem.focus();
} else {
$dialog.find("input.add-rule:first").focus();
}
}
};
Like one can see on the next demo the focus in the Searching Dialog stay unchanged after pressing on the "Add subgroup" or "Add rule" buttons. I set it on the "Add rule" buttons of the previous row group in case of pressing "Delete group".
One more demo use jQuery UI style of the buttons and the texts in the buttons (see the answer). After clicking on the "Delete" (rule or group) button I tried to set the focus to the previous "Add Rule" button because setting of the focus on another "Delete" (rule or group) button I find dangerous.
Additionally in the demo I use
afterShowSearch: function ($form) {
var $lastInput = $form.find(".input-elm:last");
if ($lastInput.length > 0) {
$lastInput.focus();
}
}
because it seems me meaningful to set initial focus on the last input field at the dialog opening.
UPDATED: I find additionally meaningful to set focus on the current clicked buttons "Add subgroup", "Add rule" or "Delete group". The advantage one sees in the case it one first click some button with the mouse and then want to continue the work with keyboard. So I suggest to change the line
inputAddSubgroup.bind('click',function() {
to
inputAddSubgroup.bind('click',function(e) {
$(e.target).focus();
To change the line
inputAddRule.bind('click',function() {
to
inputAddRule.bind('click',function(e) {
$(e.target).focus();
and the line
inputDeleteGroup.bind('click',function() {
to
inputDeleteGroup.bind('click',function(e) {
$(e.target).focus();
and the line
ruleDeleteInput.bind('click',function() {
to
ruleDeleteInput.bind('click',function(e) {
$(e.target).focus();

Watching the InputScope of a TextBox?

How do we grab the event that is generated when the inputscope of a TextBox is set to search and the Arrow is pressed?
1.There is an event OnKeyDown where you can check what key is pressed
textBox.OnKeyDown += (s, e) =>
{
if (e.Key == Key.Enter)
{
// perform search
e.Handler = true;
}
}
2.ScrollViewer automatically scrolls to focused textbox, I guess...

Resources