Open Text in App - objective-c

I am looking for a way to right click selected text and open it in my app. Eg. via OS X's third party share menu. But I can not find any references at Apple's.

Have a look at the apple docs SysServices for creating a service for you app.
The Docs take you through an example of how to set one up.
Once done you will need to go into System Preferences and Enable the service. Your users will also need to do that.
Here is a quick project that shows an adaption of the apple code.
Update:
Although I think the services work good enough. Creating a Share or Action Extension is possible.
This example uses the same Project as above. But I have added an App Action extension (Target) to it.
The template for the Action is not too hard to understand and it took me 5 minutes to do this quick example.
(So I am not saying everything is as it should be but it works)
For the Action Extension:
Follow the instructions here
Which basically is:
After you choose the extension point that makes sense for your app
extension, add a new target to your containing app. The easiest way to
add an app extension target is to use an Xcode template that provides
a target preconfigured for your extension point.
To add a new target to your Xcode app project, choose File > New >
Target. In the sidebar on the left side of the new target dialog,
choose Application Extension for iOS or OS X. In the pane on the right
side of the dialog, Xcode displays the templates you can choose
Do read the above docs to understand better of what you need to do.
Once you have added the Extension. You can actually run it straight away.
Xcode provides you an option to choose a test app to test it in i.e TextEdit.app and takes you through the whole process of temporarily enabling the Extension.
In this example, remember I chose an Action Extension which suited the App.
The App's function in life is to do a basic encryption of selected text and then display the result.
The App's Action Extension will do the same but instead of displaying it, it will replace the selected text with the encryption text.
All that was needed for me to do, was copy the encryption method from the main app, over to the Extension.
I did have to adjust a couple of things though. Namely the original code deals with a NSString, where as the Extension deals with a NSAttributedString.
The conversion I did works but styling attributes are lost. For this example that does not really matter.
An Action Extension does not use the Share contextual menu. It uses an Action menu.
To see the menu, select some text and the hover the cursor over the selected text. You then should see a discloser button on the left of the text.
Like this:
Click it and choose the Extension.
If you do not see it, go to the 'more' option. This will take you to the system preferences where you can grant access to the extension.
The documentation is mainly concerned about distributing the extension and App via the App store.
But you can code sign your App and extension and do a normal archive export.
From there, all should work ok with gatekeeper.
But again refer to the Docs for a fuller understanding.
Here is a link for the code signed app and also the new Project.
Encrypto2

Related

IntelliJ Plugin Development: LookupElement with class preview

For a custom language I created a CompletionContributor. Everything works fine. But I'm limited to the information I can display (only in the list or the bottom "advertisement" and only 1 line).
When trying to auto-complete on a java class name it will display more information on the selected line in a small side window. I would like to exploit that mechanism but I really don't know how it is done.
When looking at the options provided, I can use a custom LookupElementRenderer but there is no method in LookupElementPresentation related to the right window.
Any idea how it is done?
Are you referring to documentation popup which may be displayed if the corresponding setting (Setting->Editor->General->Code completion->Show the documentation popup in) is turned on?
If you want the feature to work for your language you have to use lang.documentationProvider extension point.

Making localization work

I have an app that needs to be localized.
After fiddling with the settings for a while, I managed to get the project to the state where it builds a nl.lproj (amongst others) directory in the Resources directory of the app bundle, which contains a MainMenu.strings file that contains all my translations; they seem correct at first glance.
The XIB file is marked as translatable, and seems to be part of the right target:
However, if I run the app in a dutch environment, the localized strings are not shown in the UI. I added
NSLocale *loc = [NSLocale autoupdatingCurrentLocale];
NSString *lang = [loc languageCode];
NSLog(#"Current language: %#",lang);
to verify that the Dutch language is active, and it is.
This question suggests that doing a clean followed by a rebuild of the app should fix such issues. I've tried that, but it did not resolve the issue.
How can I figure out why my app isn't being translated? What else could go wrong? Are there any diagnostics I could be checking?
The application in question is open source, and can be found at https://github.com/Fedict/eid-mw. Select the "eID Viewer" target, and build that, to see what's happening.
There are two different things with the localization. One is localization the UI. This is done by checking those boxes and then editing the string files in the dialog underneath the xib file.
The second is the localization of the Userfacing strings in code. This is done by the Macro NSLocalizedString(#"*key*", *comment*); where key is the key and comment is a provided comment for localization purpose.
These strings are the to edit in the File Localizable.strings.
Here a link with a Beginner Tutorial. And the Apple Docs
To activate the debug function in Xcode for localized strings: pass in -NSShowNonLocalizedStrings YES as launch argument in Xcode. You find it under Product/Scheme/Edit Scheme -Arguments
Hope this helps
You need called .strings file with name "Localizable.strings".
And add language target ( in inspector ) and fill target language file.
Have you tried a check with pseudolocalozations?
Are you setting properly the language and region on your mac?
Are you also trying launching it specifically in Dutch from XCode:
To launch your app in a specific language and region
Click the target in the Run destination menu and choose Edit Scheme.
On the right, select Options.
Optionally, choose a language from the Application Language pop-up menu.
Optionally, choose a region from the Application Region pop-up menu.
Click the Close button.
Click Run to launch your app in the language and region you specified.
It turns out that localisation is supported with OSX 10.8 and above. My app had selected 10.7 as deployment target (we do need to support a few older versions of OSX). Switching the deployment target to 10.8 makes the translations appear.

How to add a button to the main toolbar in Eclipse programmatically

I've a question. I cannot find the way, how to add buttons to main toolbar programmatically. My problem is, that I've the task to dynamically (based on XML configuration file) build menus and toolbar. I found how to add a menu item programmatically, but not toolbar button.
Tutorials mostly show how to create buttons and menus using plugin descriptor (plugin.xml), but not how to do it programatically. It seems, that it is out of bounds of Eclipse plugin philosophy.
I've just found this:
There might be layout problems with this approach. I also don't
believe the framework will try and re-create your dynamic item except
at random toolbarmanager updates. With Menus they can be updated on an
SWT.Show event, which is why CompoundContributionItem only applies to
Menus.
What shall I do? Can I say Sorry, there is no way to build toolbar dynamically. I can do it just for menus? Collegue says, that it must be possible, but he does neither know how.
The only way to be able to create main toolbar entries programmatically is in an RCP app, where you supply the ActionBarAdvisor for the workbench window. This isn't dynamic, however, just called on window creation.
Another way to do it would be to use org.eclipse.ui.menus and contribute org.eclipse.ui.menus.ExtensionContributionFactory. It also works only on workbench window creation (not really dynamic), but you could read your own XML and provide IContributionItems for the main menu or toolbar.
How dynamic are you trying to be? Most solutions work well on startup/window creation.
PW
Whenever you try to do something programmatically in Eclipse that is normally done through plugin definitions you are walking on thin ice. I've tried it on a few occasions and it rarely ended up being easy or good.
Instead, think of what it is that you only know at runtime and need to be able to change on the fly. Is it the name or icon of the button? That can be changed at runtime.
Take a look at runtime commands, they can be confusing to define properly, but with them you can for example create buttons that are only visible if a condition is active. That condition could be set at runtime.

Apple's Services Implementation Guide - Sample Code Not Working

Whenever I'm like surfing on the web and I highlight a bunch of text, I see a "New TextWrangler Document with Selection" item on the contextual menu.
How do I replicate this functionality with my app so that whenever a user selects text in any other application, he can see a "New (My App) Document with Selection" item in the contextual menu and upon clicking on it, it feeds the selected text into my app?
Update
To try to answer my own question, I followed the sample code here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SysServices/Articles/providing.html
which implements a simple rot13 encryption service on highlighted text. but it ain't working.
Although my "Encrypt Text" appears in the system preferences menu like "New TextWrangler Document with Selection" as shown above, it doesnt actually appear in an application's services menu or right-click contextual menu when text is selected.
Can someone tell me why the sample code in apple's documentation is not working
#PeterHosey here it is, with NSRequiredContext too:
my app name is called "simpleEncrypt" and the message is exactly the same as the one copied from apple's services implementation guide.
- (void)simpleEncrypt:(NSPasteboard *)pboard
userData:(NSString *)userData error:(NSString **)error;
In the Info.plist for my Translate Text application, I'm using NSStringPboardType as the send type for each of its services.
The system-declared UTIs list says that the modern equivalent to that is public.utf8-plain-text, so try changing your service's send and return types to that.
If it works, it'd probably be a good idea to list all the plain-text variants. Those are listed there in the Uniform Type Identifiers Reference; they're the types that conform to public.plain-text.
You need to include an NSRequiredContext dictionary in your service dictionary that describes when the service is appropriate to enable. Until you do, it is disabled in all contexts by default. (I'm not sure why it still doesn't show up even after you enabled it, but this is a required first step.)

NSToolbar looks different in Leopard and Snow Leopard

I have a Cocoa app I'm working on and I get a different result in appearance for the NSToolbar I am using for the main window.
Specifically, I'm using a search field as the last NSToolbarItem and, whereas under Snow Leopard it is displayed correctly:
it is cut under Leopard:
Looking at those two versions it appears that the spaces I put between the items are not respected under Leopard. I also saw that sometimes, after I make some update at the toolbar in Interface Builder, these changes are not mirrored in the running application even under Snow. I have to drag the default bar from the customizing menu in order to see them.
UPDATE
The reason for the NSToolbar not always mirroring what is in the .nib file resides in the autosave mechanism that was enabled for me, as NSGod suggested.
What can be the cause of this misbehavior?
Is there something about constraints, (minimum and maximum) sizes that I should have taken into account?
Feel free to point some documentation to me
UPDATE 2
Is there a way to programmatically introduce item and spaces into a NSToolbar or check the consistency (at run time) of those entered with Interface Builder?
While I do recall having a couple of oddities with search fields in NSToolbars, I've never seen the behavior where the right side of it is cut off.
Are the NSToolbarItems that are spaces the fixed one-unit space, or the flexible spaces?
"I also saw that sometimes, after I
make some update at the toolbar in
Interface Builder, these changes are
not mirrored in the running
application even under Snow. I have to
drag the default bar from the
customizing menu in order to see them."
You need to keep in mind that if you've enabled user customization and autosave behavior in the toolbar, then when the user explicitly makes a change, it will be saved to user defaults. If you then re-arrange your toolbar in IB and run the app, it's possible that the configuration saved in user defaults is overriding the default configuration you've specified in the nib file.
What I usually do is during testing, delete the prefs file for my app so changes can't be overridden. (FWIW, I usually use an AppleScript saved as an application that I keep in my Dock. It just runs a do shell script command which deletes the prefs file. Being a GUI-oriented type of person, it's easier for me to just click it to have it run right before debugging. This version of the script asks for the prefs file to delete, though it can also be customized: http://www.markdouma.com/developer/DeleteAppPrefs.zip. If you've never run it before, you get the choose file dialog, and the chosen file is saved as an alias inside the actual AppleScript, so you're not asked again. You can drag the icon onto AppleScript Editor to take a look at the script or change it).
Anyway, then, if I'm going to release a new version of an app that uses a new toolbar layout, and want to prevent the config from being overridden, I'll change the toolbar's identifier (or autosave name) to something like "docToolbar2.0".