using System;
using System.Diagnostics;
using System.Web;
using System.Windows.Forms;
using JetBrains.Omea.OpenAPI;
namespace JetBrains.Omea.SamplePlugins.WordPress
{
/// <summary>
/// Plugin for JetBrains Omea which allows you to blog about the
/// selected recource if it is displayed in the browser of Omea.
/// </summary>
public class WordPressPlugin: IPlugin
{
/// <summary>
/// The first method called during plugin startup. Registers the context
/// menu action.
/// </summary>
public void Register()
{
// Register the action group where the action will be placed.
const string actionGroupName = "WordPressPlugin.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 WordPressLookupAction(),
actionGroupName, ListAnchor.Last, "Blog this in WordPress", null, null );
}
/// <summary>
/// The method which is called after the Register() method has been called
/// for all plugins. Nothing to do here.
/// </summary>
public void Startup()
{
}
/// <summary>
/// The method called at Omea shutdown. Nothing to do here.
/// </summary>
public void Shutdown()
{
}
}
/// <summary>
/// The action to perform the opening of the popup.
/// </summary>
public class WordPressLookupAction : IAction
{
/// <summary>
/// Initializes the popup and displayes it
/// </summary>
/// <param name="context">Actioncontext</param>
public void Execute( IActionContext context )
{
IResourceList list = context.SelectedResources;
if(list.Count == 1)
{
//Retrieves the subject of the resource.
string popupTitle = HttpUtility.UrlEncode(list[0].GetStringProp("Subject"));
string selectedText = "";
if(context.SelectedPlainText != null)
{
//Retrieves the selected text on the currently displayed resource
selectedText = HttpUtility.UrlEncode( context.SelectedPlainText.Trim() );
}
//Retrieves the URL of the displayed resource
string currentUrl = HttpUtility.UrlEncode( list[0].GetStringProp("Link"));
//Lets show the popup window
Process.Start( String.Format("http://skorozsi.blogsome.com/wp-admin/bookmarklet.php?text={0}&popupurl={1}&popuptitle={2}",selectedText, currentUrl, popupTitle)); }
}
/// <summary>
/// Enable the action only if there is a selected resource.
/// </summary>
public void Update( IActionContext context, ref ActionPresentation presentation )
{
presentation.Visible = context.SelectedResources.Count == 1;
}
}
}
using System.Diagnostics;
using System.Web;
using System.Windows.Forms;
using JetBrains.Omea.OpenAPI;
namespace JetBrains.Omea.SamplePlugins.WordPress
{
/// <summary>
/// Plugin for JetBrains Omea which allows you to blog about the
/// selected recource if it is displayed in the browser of Omea.
/// </summary>
public class WordPressPlugin: IPlugin
{
/// <summary>
/// The first method called during plugin startup. Registers the context
/// menu action.
/// </summary>
public void Register()
{
// Register the action group where the action will be placed.
const string actionGroupName = "WordPressPlugin.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 WordPressLookupAction(),
actionGroupName, ListAnchor.Last, "Blog this in WordPress", null, null );
}
/// <summary>
/// The method which is called after the Register() method has been called
/// for all plugins. Nothing to do here.
/// </summary>
public void Startup()
{
}
/// <summary>
/// The method called at Omea shutdown. Nothing to do here.
/// </summary>
public void Shutdown()
{
}
}
/// <summary>
/// The action to perform the opening of the popup.
/// </summary>
public class WordPressLookupAction : IAction
{
/// <summary>
/// Initializes the popup and displayes it
/// </summary>
/// <param name="context">Actioncontext</param>
public void Execute( IActionContext context )
{
IResourceList list = context.SelectedResources;
if(list.Count == 1)
{
//Retrieves the subject of the resource.
string popupTitle = HttpUtility.UrlEncode(list[0].GetStringProp("Subject"));
string selectedText = "";
if(context.SelectedPlainText != null)
{
//Retrieves the selected text on the currently displayed resource
selectedText = HttpUtility.UrlEncode( context.SelectedPlainText.Trim() );
}
//Retrieves the URL of the displayed resource
string currentUrl = HttpUtility.UrlEncode( list[0].GetStringProp("Link"));
//Lets show the popup window
Process.Start( String.Format("http://skorozsi.blogsome.com/wp-admin/bookmarklet.php?text={0}&popupurl={1}&popuptitle={2}",selectedText, currentUrl, popupTitle)); }
}
/// <summary>
/// Enable the action only if there is a selected resource.
/// </summary>
public void Update( IActionContext context, ref ActionPresentation presentation )
{
presentation.Visible = context.SelectedResources.Count == 1;
}
}
}
Colorized by: CarlosAg.CodeColorizer

