/// /// Copyright © 2003-2008 JetBrains s.r.o. /// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder). /// using System; using System.Diagnostics; using System.Web; using JetBrains.Omea.OpenAPI; namespace JetBrains.Omea.SamplePlugins.Dictionary { /// /// Sample plugin for JetBrains Omea which allows to look up the selected word /// at dictionary.reference.com. /// Copyright (C) 2004 by JetBrains s.r.o. All Rights Reserved. /// public class DictionaryPlugin: IPlugin { /// /// The first method called during plugin startup. Registers the context /// menu action. /// public void Register() { // Register the action group where the action will be placed. const string actionGroupName = "DictionaryPlugin.Actions"; Core.ActionManager.RegisterContextMenuActionGroup( actionGroupName, ListAnchor.Last ); // Register the action. The action applies to all resource types, // and no special filters are required. Core.ActionManager.RegisterContextMenuAction( new DictionaryLookupAction(), actionGroupName, ListAnchor.Last, "Look Up in Dictionary", null, null ); } /// /// The method which is called after the Register() method has been called /// for all plugins. Nothing to do here. /// public void Startup() { } /// /// The method called at OmniaMea shutdown. Nothing to do here. /// public void Shutdown() { } } /// /// The action to perform the dictionary lookup. /// public class DictionaryLookupAction : IAction { /// /// Executes the lookup at the dictionary Web site. /// /// public void Execute( IActionContext context ) { string query = HttpUtility.UrlEncode( context.SelectedPlainText.Trim() ); Process.Start( "http://dictionary.reference.com/search?q=" + query ); } /// /// Enable the action only if there is selected text which can be looked up. /// public void Update( IActionContext context, ref ActionPresentation presentation ) { presentation.Visible = ( context.SelectedPlainText != null && context.SelectedPlainText.Length > 0 ); } } }