How to set key equivalent programmatically - objective-c

I want to set a key equivalent on a button. To set it in the Attributes Inspector in XCode does not work. I want to set 'fn + enter'. How can I do this programmatically?

Related

Save a user popup selection in a custom Automator Action

Using Xcode 5.* for a cocoa-applescript automator action.
Interface is a a simple popup menu that gets populated using an outlet with:
tell thePopupMenu to removeAllItems()
tell thePopupMenu to addItemsWithTitles_(theList)
When the action is used in a workflow (a Service actually), I want the next time it is run and the action dialog shows up (I will have "Options:Show when run" selected), I want the popup menu to change the selection to the last one that was selected. Right now, the default first item shows, even though last time it was run, the user selected a different item in the popup menu.
My thought was that I need to capture a change in the popup menu with a Sent Action handler, and then set some type of default. I have a working handler:
on thePopupMenuSentAction_(sender)
set popupValue to (popupSelectedValue of my parameters()) as string
-- save this selection somewhere???
end
What's the right way to save this? Do I use User Defaults? My Bindings are currenly all tied through Parameter object/controller. If I should use User Defaults, can someone give example code for setting up User Defaults, and then how to get and set a new value using Cocoa-Applescript?
If I can get the name string of the menu item saved somewhere, I can get the string and then change the selection of the popup menu in the
on opened {}
-- set up the action interface
end
handler which gets called just before the action is displayed each time.
Thanks for any help,
Joe
I did mine a bit differently. I will assume you are referring to what XCode calls a "pop up button" (somewhat misleading). I did not use the parameters at all, although that is probably better for larger projects. Have a look at the code:
script Insert_Picture_into_Powerpoint_Slide_Show
property parent : class "AMBundleAction"
property menuChoices : {"Insert a Beginning", "Insert at End"}
property menuSelection : missing value
if (menuSelection as string) is "missing value"
set menuSelection to 0 as integer -- sets default value
end if
end script
I bound Content Values to File's Owner and under Model Key Path I put menuChoices.
Then you just bind the Selected Index to File's Owner and for the Model Key Path type menuSelection.
Defaults
On the initial run, if the user does not click anything, the menuSelection will be missing value. Because I couldn't find a way around this, I created a conditional which tests for this and sets it to the first choice by default (the one that is shown when you add the action).
When the user selections one of the menu choices, the choice is remembered on sequential runs.

disabling navigation keys for xamNumericEditor using properties

Is there any property to disable UP/Down keys that are incrementing/decrementing the xamNumericEditor value using any property of numericeditor?
If you set the SpinIncrement property to 0 the up/down arrow keys will not affect the value of the editor.

key Equiv. for nsbutton is not working properly for multiple nsbuttons

I have two nsbuttons in my interface builder.For all of these three nsbuttons I have set Key Equilant to "Return" key.And also I set nextkey view to all of these buttons.
I have 3 different actions for all of these three buttons and connections has made properly.
If I use mouse click appropriate actions are getting executed.
After running the Application,initially my first button has focus,presses return key, 1st button's action is executed.Next I pressed tab key,focussed has changed to 2nd button,pressed return key but 1st button's action is executed.Again I pressed tab key,focussed has changed to 3rd button,pressed return key still 1st button's action is executed.
What I am missing here.Why the appropiate action is not happenning on pressing Return key over nsbutton even focus is highlighted.
It sounds like you're using keyboard navigation to switch between buttons and activate the selected one. In that case, the Return key would normally correspond to pressing the selected button. However, since you've assigned Return as a shortcut for one or more of the buttons, the responder chain searches for and finds a button with a matching key equivalent, so that button's message is sent instead.
Try clearing the key equivalent for all three of your buttons. I think that'll give the behavior you're looking for.
If you're not using keyboard navigation, it's not clear why the tab button has any effect. Nevertheless, if you're trying to do something like make the default button cycle from one button to the next, you'll need to change the keyboard equivalent each time a button is pressed. I wouldn't recommend that generally -- I don't think users would like to have the default button change from one moment to the next. If you must though, here's some code:
- (IBAction)nextButton:(NSButton*)sender
{
int tag = [sender tag];
NSView *superview = [sender superview];
if ([sender.keyEquivalent isEqualToString:#"\r"]) {
NSButton *nextButton = [superview viewWithTag:(tag % 3) + 1];
nextButton.keyEquivalent = #"\r";
sender.keyEquivalent = #"";
}
}
This assumes that you've got three buttons, and each is configured with the nextButton: method as its action. Also, the buttons have tags 1, 2, and 3 respectively. The idea here is that when the default button (i.e. the one with the return key as its equivalent) is selected, it sets the next button's key equivalent to Return and sets its own equivalent to nothing.
You can obviously change the way the code works -- you may want each button to call a different action, for example. In that case, just have each action call a common method that does the same job as the code above.
The lesson here is that if you set the same key equivalent for several buttons, the first one to be found will be "pressed". If you want the key equivalent to change, you need to change the equivalent set for your various buttons.
I'm not sure what you mean about the focus changing when you press the tab key -- I don't see this behavior (I've set up the initial first responder and next key connections). All three buttons are blue, but only the first one pulsates, no matter what keys I press. After experimenting a bit, I found that the button that is at the top of the list (in the window's object list) is the one whose action is performed on clicking return.
I can't find any documentation on this, but I don't think you can set the same key equivalent for multiple buttons in the same window.

How to set NSToggleButton to start in state 0 from Interface Builder?

How can I in Interface Builder set NSButton of type toggle with Title and Alt.Title to start with the Title (e.g. the state 0)?
The moment I set the button as toggle and set the Alt.Title it displays Alt.Title in View and I can't find the option to set it to start in the 'default' state (state 0).
I could set it pragmatically but is there an option to set it in IB?
I've solved it before but forgot how.
Does unchecking the "state" checkbox not work for you? That should be all it takes.

VBA disable/enable shortcut key combinations

I need to enable and disable the shortcut key for select all "Ctrl + A".
FindKey(BuildKeyCode(wdKeyControl, wdKeyA)).Disable
FindKey(BuildKeyCode(wdKeyControl, wdKeyA)).Rebind wdKeyCategoryCommand, ??
What is the command parameter for Ctrl + A??
I cannot find this information anywhere!
Also I want to apply it only for my templates:
CustomizationContext = ActiveDocument.AttachedTemplate
This doesn't seem to work. it seems to apply to the normal template because if I open any word instance the shortcut key is still disabled.
Entering
?FindKey(BuildKeyCode(wdKeyControl, wdKeyA)).Command
in the Immediate Window of the VBA editor shows
EditSelectAll
so I guess that is what you are looking for.
To your second question: did you check that ActiveDocument.AttachedTemplate is not equal to NormalTemplate when you disabled "Ctrl + A" ?