How to change Textmate's context menu key binding? - keyboard-shortcuts

In Textmate there is a great shortcut to get to the context menu without using the mouse (I wish it worked systemwide!!!). It is Opt+F2.
When working on my Macbook, however, F2 is mapped to screen brightness, so I have to press fn+opt+F2, for which I have to use both hands - and that's quite uncomfortable.
Is the a way how I could map it to the right opt key, for example?

For TextMate 2 you can create ~/Library/Application Support/TextMate/KeyBindings.dict and let it contain something like:
{ "#d" = "showContextMenu:"; }
Here #d corresponds to ⌘D. See this blog post on how to construct the key equivalent strings.
Source: TextMate mailing list
Key binding files are read in the following order. A new binding for a bound key overrides the previous one:
/System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict
/Library/KeyBindings/DefaultKeyBinding.dict
~/Library/KeyBindings/DefaultKeyBinding.dict
/path/to/TextMate.app/Contents/Resources/KeyBindings.dict
~/Library/Application Support/TextMate/KeyBindings.dict
A relaunch of TextMate (⌃⌘Q) is required before changes take effect.

Related

How can I add an item in the World-menu of Pharo 4.0?

How can I add a new item - Workspace openLabel: 'Workspace' - to the World-menu of Pharo 4.0 ? (What can I say... I prefer Workspace over the new what's-it-called. :-)
I've looked at several menu-related items in the Browser, but couldn't really make head or tails of it. I also tried to find where the menu is stored (it must be somewhere, right?), but couldn't find it.
Also, how would I go about to add it to one of the existing sub-menues of World-menu, and how could I create a new sub-menu (in the World-menu) and add it there?
Add the following class method to any class you like. Best to make one especially for this purpose and load it to your new images:
WorkspaceWorldMenuItem class>>menuCommandOn: aBuilder
menuCommandOn: aBuilder
<worldMenu>
(aBuilder item: #'Workspace')
order: 0.1;
label: 'Workspace';
action: [ Workspace open ]
The interesting part is the <worldMenu> pragma. You usually put it directly after the selector (and comment) and before any other element in the method.
To have a look at example usage open Finder, choose the Pragmas mode and search for worldMenu (without the angle brackets).

Eclipse custom text editor update syntax highlighting

I am writing an Eclipse plugin (Indigo/Juno) that contains a text editor for a custom text format. I am following the tutorial here: http://www.realsolve.co.uk/site/tech/jface-text.php
So far I have everything working. Eclipse will use my editor to edit files. I have partitioning, damaging, repairing, syntax highlighting all working.
I added a preferences page with color pickers to control syntax highlighting. It works mostly correct. If I update the colors, the editor uses them the next time I open or reopen a file.
How do I get an editor tab to update itself without opening a new one? The built-in JDT Java editor does this, but so far I have not been able to decipher how (it is a very large and complex editor).
I gather that I need to create a preferences listener (http://www.vogella.com/articles/EclipsePreferences/article.html). I have done this and can verify that my listener code is being invoked when I set a breakpoint in it.
The missing piece is the wiring between the listener and reinitializing the editor. I have tried reconstructing the partitioning logic, the color logic, the damager/repairer, etc. but nothing seems to work. It either does nothing I can see or at worst will corrupt the display until I scroll the current text out of view to repaint it... with the old colors.
Any ideas?
I think SourceViewer.invalidatePresentation() needs to be called.
It may be already late to you, but if you want you could use LiClipse for that (http://brainwy.github.io/liclipse/) -- one of its targets is easily doing an editor with syntax highlighting, basic code-completion, outline, etc targeting Eclipse.
No java skills are required to add a new language (mostly creating a new .liclipse -- which is a YAML -- file in the proper place and creating some basic rules to say how to partition your language -- i.e.: usually just separating code from comments from strings -- and specifying the keywords you have in the partition would already give you proper syntax highlighting).
If you download it, there are a number of examples at plugins\com.brainwy.liclipse.editor\languages and there's some basic documentation at http://brainwy.github.io/liclipse/supported_languages.html and http://brainwy.github.io/liclipse/scope_definition.html on how to do it.
For anyone coming across this as I did:
My solution involved adding the following lines into the Constructor of my Editor
Activator.getActivator().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
#Override
public void propertyChange(PropertyChangeEvent event) {
getSourceViewer().invalidateTextPresentation();
handlePreferenceStoreChanged(event);
}
});
and then creating a custom class that extended IToken. In the constructor I pass the String of the preference field and then in the 'getObject' method I create the TextAttribute: snippets below
public class MyToken extends Token implements IToken {
public MyToken(Object data) {
super(data);
}
#Override
public Object getData() {
String dataString = (String) super.getData();
return getAttributeFromColorName(dataString);
}
private TextAttribute getAttributeFromColorName(String preferenceField) {
Color color = new Color(Display.getCurrent(), StringConverter.asRGB(Activator.getActivator().getPreferenceStore().getString(preferenceField)));
return new TextAttribute(color);
}
}
When I generate my Rules I have all of my tokens as my custom class and this allowed me to change syntax color dynamically.
I also added an example for updating the coloring if the preference changes to https://www.vogella.com/tutorials/EclipseEditors/article.html#exercise-allow-user-to-customize-the-colors
This is using the Generic editor (currently the best approach to implement a customer editor) but it should be possible to adjust this to any Eclipse editor implementation.

Suppress messages from embedded Windows Media PLayer

I'm working on a Windows Form Application in which I have embedded a Windows Media Player that lets you play video files. The unique thing is that I have changed the extension of the media files (for reasons which I can't get into here). For instance, "xyz.wmv" might be called "xyz.ext". They play just fine, but before they play, I get the message:
"The file you are attempting to play has an extension that does not match the file format. Playing the file may result in unexpected behaviour. Do you want the Player to try to play the file?"
You can click yes and you can even check the box to not show that message again, but I don't want that for all the obvious reasons including the fact that it confuses users. I have looked into the .settings properties but I cannot find a way to suppress this message and more importantly other messages that might come up.
The .ext (for example) extension is not known to media player, hence the warning.
What you can do to change this is modify the registry and register this extension. This is described officially here: File Name Extension Registry Settings
The most simple way to do it is to create a registry key like this:
HKEY_CURRENT_USER\Software\Microsoft\MediaPlayer\Player\Extensions\.ext
And add two key values:
Runtime (DWORD): 6
Permissions (DWORD): 15 (or 0xF in hexa)
This is shown here:
NOTE: this answer was originally in response to a bounty question and edit which was removed on how to do this via code. Parts of this are still relevant to the original question.
You can do this pretty straight forward IF you have admin rights as you need to edit the registry. Not sure how far you will get without admin rights and can test later, but here is how to do this via code (in a real implementation I would do this as part of a setup - or check if the keys exist each time which seems wasteful):
You need to add one key (showing two here for registering the extensions, you may need additional keys for auto-play or a setting on the player):
private void Form1_Load(object sender, EventArgs e) {
/*This first key is not necessary - and if you will be using common
* extensions like mp4, skip this step altogether!!
*/
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true)
.OpenSubKey("Classes", true);
key.CreateSubKey(".myExt");
key = key.OpenSubKey(".myExt", true);
key.SetValue("", "WMP11.AssocFile.myExt");
key.SetValue("Content Type", "video/x-ms-wmv");
key.SetValue("PerceivedType", "video");
/*Here is the magic key which will make the dialog go away*/
key = Registry.CurrentUser.OpenSubKey("Software", true)
.OpenSubKey("Microsoft", true)
.OpenSubKey("MediaPlayer", true)
.OpenSubKey("Player", true)
.OpenSubKey("Extensions", true);
key.CreateSubKey(".myExt");
key = key.OpenSubKey(".myExt", true);
key.SetValue("", "");
key.SetValue("Permissions", 0x20);
axWindowsMediaPlayer1.URL = #"C:\Users\Public\Documents\Wildlife.myExt";
}
Media Player creates other keys when you add through its dialog, but the only one definitely needed is: HKEY_Current_User.Software.Microsoft.MediaPlayer.Player.Extensions
If you want to see all the keys Media Player adds,
choose a crazy extension,
click always allow when prompted and then
search the registry for all the keys that get created.
The above code is tested and working for me - confirming the dialog before adding the keys and the lack of any dialog after.
This is a good generic process for programmatically adding file associations and default programs to the Windows Registry from .NET. You have to be careful about registering the extension (the first key I set above) IF the extension already exists (TEST FOR THIS). Otherwise the above code will happily overwrite your current values. All you really should need is the one added to: HKEY_Current_User.Software.Microsoft.MediaPlayer.Player.Extensions anyway. Think it through, check in advance, and test before you go crazy in the registry!!
It is also always a great idea to backup your registry before playing with it.
Final note: missed your question on how to reproduce once you have clicked always allow: just remove the entry in HKEY_Current_User.Software.Microsoft.MediaPlayer.Player.Extensions and voila!
This answer assumes you have a working knowledge of regedit.
Final note #2: Response geared to the questions in the Bounty. Other errors can be suppressed by setting telling Media Player to allow you to handle error events and then writing your custom handler. I have not done this before so cannot comment on the ease and what can/cannot be controlled through this method.
The Windows Media Player control does not raise an exception when it encounters an error such as an invalid URL. Instead, it signals an event. Your application should handle error events sent by the Player.
These can then be handled by creating / registering a MediaError event:
private void axWindowsMediaPlayer1_MediaError(object sender, AxWMPLib._WMPOCXEvents_MediaErrorEvent e) {
// Handle errors and profit!
}
Then set this as the handler in the Events property window for your control - same for other events such as ErrorEvent.

How to set Command+ as a key equivalent?

I want to have command-plus as a key equivalent for a menu item, however, when I try to enter command-plus, it shows up as command-shift-equals instead of a plus. And when I press command-plus, it shows up as command-equals. Does anyone know how I can get around this?
In Xcode 8.2 when entering a key equivalent, if you hit ⇧⌘= you get a little popup button saying "alternates" inside the field. It presents you ⇧⌘= and ⌘+ as alternates (importantly, this only shows if you enter the key equivalent from the text field in the inspector, not by double-clicking the key equivalent slot for a menu item in IB). This is where I presume you are intended to choose ⌘+ if you want it presented like that.
However, that doesn't actually appear to work at least when compiling my app in macOS Sierra 10.12 / with Xcode 8.2.1. I'm posting this as a solution as the key equivalent looks correct in Interface Builder after doing this, and issue with it happens only during runtime so I assume there is a version of the Xcode build toolchain or Cocoa where this actually works.
Interestingly, editing the storyboard gives the same symptom (the equivalent works fine in IB but shows up blank ):
<menuItem title="Increase Image Size" keyEquivalent="+" id="SCO-e4-3zd">
<modifierMask key="keyEquivalentModifierMask" command="YES" />
<connections>
<action selector="increaseRowHeight:" target="Ady-hI-5gd" id="pu1-6E-HSr"/>
</connections>
</menuItem>
A third solution has the same runtime symptoms too (assign an outlet to the item and set it in code):
decreaseThumbnailSizeItem.keyEquivalent = "+"
decreaseThumbnailSizeItem.keyEquivalentModifierMask = NSCommandKeyMask
The same works when setting either NSShiftKeyMask or NSAlternateKeyMask together with + as the key.
To type a + sign you actually have to press Shift+'=', that's why when you put Cmd+ into key equivalent it shows up as Cmd+Shift+=.
This can be done programmatically. Connect the menu item to a property ("zoomInItem") in interface builder. Then set the key equivalent when the application is finished launching.
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
[self.zoomInItem setKeyEquivalent:#"+"];
}
If you have access to a keyboard with a numerical keypad, you could use the numpad + key.
You can open the xib file in a text editor add edit the menu item's key equivalent there:
<menuItem title="Zoom In" keyEquivalent="+" id="hXP-3c-xDr"/>

Custom key bindings Xcode 4?

Awhile back I asked a question about custom key bindings in Xcode. I ended up recreating some of TextMate's key commands in Xcode. Just updated to Xcode 4 and it appears that the PBKeyBinding file no longer has any effect. What's the new hotness for custom key bindings, specifically for Xcode 4?
Yes, it can be done (at least for the moment). After spending the better part of a day searching, experimenting and digging through the bowls of /Developer I finally figured out how to accomplish this.
Open IDETextKeyBindingsSet.plist located in /Developer/Library/PrivateFrameworks/IDEKit.framework/Resources/
This bindings plist is formatted differently than others used throughout the system, the most important distinction is that all the methods must be listed in the same string, i.e.
<string>moveToBeginningOfParagraph:, insertText:, foo</string>
edit:
I have not tested this, but it looks like the new location in Xcode is
Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist
You can use Keymando to create any keybinding you like in Xcode 4 and any other OSX application.
The answer now seems to be to use the idekeybindings files — these are tied to the custom keyboard shortcut sets you create in the preferences — stored at ~/Library/Developer/Xcode/UserData/KeyBindings/. More information can be found in the Key Bindings Preferences Help. However it sounds like people are having no luck trying to combine multiple actions under one keyboard shortcut (as you can do with the older-style key bindings dict files). But presumably you could still do this in DefaultKeyBinding.dict, as long as you don't mind the shortcut also working in other applications :) If this doesn't work, I think you're out of luck for now. Sorry; file a bug!
Kike here http://www.codedojo.com/?p=580
you use this binding set
Download
http://www.codedojo.com/files/MSVC_xcode_config.zip
unzip it and place MSVC.pbxkeys in YourUserName/Library/Developer/Xcode/userdata/keybindings
and rename it to msvc.idekeybindings
then from
Xcode -> preferences -> keybindings
just pick msvc
Go to Xcode 4 > Preferences > Key Bindings and fiddle with them all you like. :)