Eclipse plugin:TextSelection cannot resoleve - eclipse-plugin

I am trying to develop my first plug-in.
The plug-in should manipulate the content of the selected text in the active text editor.
I started with the “hello world” example from the “Cheat sheet” which worked perfect.
When tried to modify I found that project not recognizing many types.
I added the following jars to the project build path libraries:
org.eclipse.jface.text_3.5.1.r351_v20090708-0800.jarorg.eclipse.text_3.5.0.v20090513-2000.jarorg.eclipse.ui.editors_3.5.0.v20090527-2000.jar
Now code compiles perfect.
ISelection iSelection = null;
IEditorSite iEditorSite = window.getActivePage().getActiveEditor().getEditorSite();
if (iEditorSite != null) {
ISelectionProvider iSelectionProvider = iEditorSite.getSelectionProvider();
if (iSelectionProvider != null)
{
iSelection = iSelectionProvider.getSelection();
selectedText = ((ITextSelection)iSelection).getText();
}
}
The problem is in line 08. although eclipse recognize the ITextSelection interface, at runtime I get cannot resolve type exception.
When trying to deploy the code I get the following line in the deploy log:
The import org.eclipse.jface.text cannot be resolved

Did you try, in the Run configuration dialog, to open the "Plugins" tab and click the button "add required plug-ins" ?
It might add the right runtime dependencies for you.
See also that same button in the dependencies tab of your plugin project:
alt text http://www.vogella.de/articles/RichClientPlatform/images/product50.gif
(more in the article "Products and Branding")
See also this SO answer for more checks.

Related

Listening for a file being clicked to - Eclipse Plugin

I am trying to write an Eclipse plugin where one of the features requires listening for when the user switches to another file in the editor via clicking.
For example, consider the screenshot below.
I want to know how to listen for when the user switching over to FakeClass.java via double-clicking on it in the Project Explorer or clicking on the tab in the editor. Furthermore, I would like to get information about the element that was clicked. Note that I am asking specifically about changing a file through the two means I asked above.
I am a beginner with Plugin development. It would be helpful to explain with that in mind. Thanks.
You can use an IPartListener to listen for changes to parts including a part being activated:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.addPartListener(listener);
The partActivated method of the listener is probably what you want:
#Override
public void partActivated(final IWorkbenchPart part)
{
if (part instanceof IEditorPart) {
IEditorPart editor = (IEditorPart)part;
IEditorInput input = editor.getEditorInput();
IFile file = input.getAdapter(IFile.class);
if (file != null) {
// TODO handle file
}
}
}
I don't know of a way to tell why the part was activated.

Xamarin Studio, Is there a way to create code snippets as in Xcode

(Might not be the appropriate forum to ask, but..)
Is there a way to add a custom code snippet as in Xcode. In Xamarin, ToolBox section, I found the prebuilt code snippets. But if I had to add a new one, its asking for the Assembly.
In Xcode, its like we can select the code and drag onto the codesnippets pane to add it as one.
Any info regarding the same in Xamarin would be most helpful.
Thanks!
In Xamarin Studio open the settings menu:
Windows: Tools > Options
OS X: Xamarin Studio > Preferences
Navigate To Text Editor -> Code Templates
Here you can edit snippets that come with Xamarin studio as well as add new ones. For syntax I'd recommend just looking at one of the already present properties.
E.g. default property looks like this:
public $type$ $name$ {
get;
set;
}
You could change that to have a backing store:
private $type$ _$name$;
public $type$ $name$ {
get { return _$name$; }
set { _$name$ = value; }
}

Safari extension - how to use the setContextEventUserInfo method

I am building a Safari extension.
On the manual, at the page about "Adding Contextual Menu Items", at the paragraph "Adding Contextual Menu Items Programmatically", it says:
You can add menu items to the contextual menu by responding to the
extension version of the "contextmenu" event in your global page or an
extension bar. If you stored information on the event by calling
setContextEventUserInfo() in your injected script, you can use that
information to help you decide what menu items to add.
Source:
https://developer.apple.com/library/archive/documentation/Tools/Conceptual/SafariExtensionGuide/AddingContextualMenuItems/AddingContextualMenuItems.html#//apple_ref/doc/uid/TP40009977-CH4-SW1
Now, I have this code on my injected script (as I am trying to pass the selected text to the background script):
function handleContextMenu(event) {
var htmlClip = getHtmlClip(event);
setContextEventUserInfo(htmlClip);
}
Unfortunately that generates this error:
ReferenceError: Can't find variable: setContextEventUserInfo
Unfortunately when I searched setContextEventUserInfo on Google, the only result was the page of the Safari manual!
Can please anybody explain to me how I am supposed to use the setContextEventUserInfo method?
This is what you need:
function handleContextMenu(event) {
var htmlClip = getHtmlClip(event);
safari.self.tab.setContextEventUserInfo(event, htmlClip);
}

showing project explorer view and its functionality to RCP

How to add PackageExplorerView's all toolbars and functionalities to eclipse RCP applications? I used PackageExplorer view id to show the PackageExplorer view. It is showing the view in the rcp application. But after creating the project in the PackageExplorer view, it is not showing the project icons for the prjects created. How to ressolve this issue?
This is a known issue in Eclipse RCP applications.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=234252
The work around is to add some code to your ApplicationWorkbenchAdvisor.java
Here's some more documentation about this issue in RCP
http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/guide/cnf_rcp.htm
I've add this code to my initialize method in order to get the images to show up in the Project Explorer, so you'll need to track down the correct images to add for the Package Explorer if those images are different from these.
public void initialize(IWorkbenchConfigurer configurer) {
super.initialize(configurer);
// here's some of my code that does some typical RCP type configuration
configurer.setSaveAndRestore(true);
PlatformUI.getPreferenceStore().setValue(
IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, false);
// here is the work around code
/*
* This is a hack to get Project tree icons to show up in the Project Explorer.
* It is descriped in the Eclipse Help Documents here.
*
* http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/guide/cnf_rcp.htm
*
*/
IDE.registerAdapters();
final String ICONS_PATH = "icons/full/";
Bundle ideBundle = Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);
declareWorkbenchImage(
configurer,
ideBundle,
IDE.SharedImages.IMG_OBJ_PROJECT,
ICONS_PATH + "obj16/prj_obj.gif",
true);
declareWorkbenchImage(
configurer,
ideBundle,
IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED,
ICONS_PATH + "obj16/cprj_obj.gif",
true);
/*
* End of hack in this method...
*/
}
private void declareWorkbenchImage(IWorkbenchConfigurer configurer_p, Bundle ideBundle, String symbolicName, String path, boolean shared)
{
URL url = ideBundle.getEntry(path);
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
configurer_p.declareImage(symbolicName, desc, shared);
}
Hope this helps.
Thanks!

Outlook "save as html" on a mail message toolbar

The medical company I work for has a EMR system setup to keep digital copies of patient files so they are searchable as well as quick to access. A new request has come through to be able to save e-mail to the EMR system, however it does not display .msg files very nicely. It does display files nicely as .htm, so was hoping i could figure out a way to save email messages to a specific folder in a .htm format with the user just hitting a single button.
Should i be looking at making an add-in using vs 2010 to do this simple task? Or would there be a better way to do this?
I've explored making an Add-In breifly over the past few days using command bars but have hit numerous problems with adding the menu item to mail items, as well as losing event handlers or having them fire quite a few times, so i'm wondering if i'm barking up the wrong tree.
Edit: Looking at ribbon bar customization as well, may have to upgrade some users that are still using 2003, but seems like it might be the better option than command bars going forward.
Ribbon bar was the best path i found, however i had trouble finding a great how-to for the start-to-finish project, so i'll make a small write up here.
To add a button to the ribbon for only existing mail messages including a image for the button.
Using VS 2010
New project, Office, select "Outlook 2007 add in", enter a name for your project.
To your newly created project, Add a new item "Ribbon (XML)" name it however you want, i'll call it CustomRibbon
open your newly created CustomRibbon.xml file and change the tab node to have the following
<tab idMso="TabReadMessage">
<group insertBeforeMso="GroupActions" id="CustomGroup" label="GroupNameThatShowsInOutlook">
<button id="btnCustomButton"
label = "Text For The Custom Button"
supertip="tip for the button hover"
onAction ="ButtonClicked"
size="large"
getImage="GetCustomButtonImage" />
</group>
</tab>
This then has 2 callback functions to the CustomRibbon.cs file, one called GetCustomButtonImage, the other ButtonClicked.
open CustomRibbon.cs to fill this in, in the Ribbon Callbacks region add the following
public void ButtonClicked(Office.IRibbonControl Control)
{
//Do work here
}
also add the following in the same section
public stdole.IPictureDisp GetCustomButtonImage(Office.IRibbonControl control)
{
System.Drawing.Image myImage;
myImage = OutlookAddIn.Properties.Resources.ImageName;
return AxHostConverter.ImageToPictureDisp(myImage);
}
this will then show there is a class missing, we'll get to that shortly, but first we are going to add in the last part we need in CustomRibbon.cs. In the IRibbonExtensibility Members region, in GetCustomUI change the existing code
public string GetCustomUI(string ribbonID)
{
if (ribbonID == "Microsoft.Outlook.Mail.Read")
{
return GetResourceText("OutlookAddIn.CustomRibbon.xml");
}
else
{
return "";
}
}
Add a new class to your project call it AxHostConverter, add add this to the top
using System.Windows.Forms;
using System.Drawing;
Then change the class to have the following code
class AxHostConverter : AxHost
{
private AxHostConverter() : base("") { }
static public stdole.IPictureDisp ImageToPictureDisp(Image image)
{
return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
}
static public Image PictureDispToImage(stdole.IPictureDisp pictureDisp)
{
return GetPictureFromIPicture(pictureDisp);
}
}
Add your image for your button to the project, and change the GetCustomButtonImage function to use that resource. I used a PNG and had good luck with transparencies displaying well.
And finally, all that should be left is to add the following to ThisAddIn.cs
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new CustomRibbon();
}
Add whatever code you are wanting to ButtonClicked and you are set.
Deploy using Clickonce and installation is fairly straightforward.