I'm Keyvan Nayyeri, a 25 years old Ph.D. student at
the Computer Science department of
the University of Texas at San Antonio.
I'm also
a Software Architect and Developer and previously held a B.Sc.
degree in Applied Mathematics.
This is my blog where I publish content about various topics specifically Programming Languages and Compilers, Software
Engineering and Programming.
We're close to a new release of our Windows Live Writer plugins project and I wanted to add a new plugin to this release.
One of things that I use on my blog is XFN relationships. Inserting an XFN relationship link requires adding appropriate relationships as text values to rel attribute of a link. I was putting these texts manually but due to the number of defined relationships in XFN I decided to write a simple plugin for Windows Live Writer to make this process easier and help myself (and probably others) in remembering all these relationships.
Plugin is simple. It enables same options as default Insert Link plugin provided by Windows Live Writer and adds all available XFN relationships as CheckBoxes which you can check to use.
If you need more information about writing a Windows Live Writer plugin in .NET, refer to my post here.
Code for plugin class is very simple:
using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.Api;
using System.Windows.Forms;
namespace XFNLink
{
[WriterPluginAttribute
("557BC8EC-BC09-4b3a-91F3-B0AFF8554042",
"XFN Link",
ImagePath = "Images.XFN.png",
PublisherUrl = "http://nayyeri.net",
Description = "Inserts XFN Links in Blog Posts")]
[InsertableContentSourceAttribute("XFN Link")]
public class Plugin : ContentSource
{
public override DialogResult CreateContent(IWin32Window dialogOwner,
ref string newContent)
{
using (InsertForm insertForm = new InsertForm())
{
DialogResult result = insertForm.ShowDialog();
if (result == DialogResult.OK)
{
newContent = insertForm.GetLink();
}
return result;
}
}
}
}
Main logic for this plugin is lain in a user control named InsertUC. Code for this user control is simple. When user clicks on Ok button following code runs to generate HTML code for link based on what user has chosen. InsertUC class has a Link property which keeps string value of HTML code.
private void btnOk_Click(object sender, EventArgs e)
{
string html = "<a href=\"";
if ((!string.IsNullOrEmpty(txtText.Text)) &&
(!string.IsNullOrEmpty(txtUrl.Text)))
{
html += txtUrl.Text + "\"";
if (!string.IsNullOrEmpty(txtTitle.Text))
{
html += " title=\"" + txtTitle.Text + "\"";
}
if (chkNewWin.Checked)
{
html += " target=\"_new\"";
}
List<string> relations = GetRelations();
if ((relations.Count > 0) ||
(!string.IsNullOrEmpty(cbRel.Text)))
{
html += " rel=\"";
if (!string.IsNullOrEmpty(cbRel.Text))
html += cbRel.Text;
if (relations.Count > 0)
{
string relationsText = string.Join(" ",
(string[])relations.ConvertAll
(new Converter<string, string>(delegate(string value)
{
return Convert.ToString(value);
}
)).ToArray());
if (html.EndsWith("\""))
html += relationsText;
else
html += " " + relationsText;
}
html += "\"";
}
html += ">" + txtText.Text + "</a>";
this.link = html;
}
}
In this class there is a GetRelations function which returns a list of string values for all chosen relations:
private List<string> GetRelations()
{
List<string> relations = new List<string>();
foreach (Control control in gbRelations.Controls)
{
CheckBox chkRelation = control as CheckBox;
if (chkRelation.Checked)
{
relations.Add(chkRelation.Text);
}
}
return relations;
}
Compiling this code and deploying it to Windows Live Writer provides a new option to insert XFN links easily. A demo?! Who is this this guy?!


You can download this plugin with source code from here.
Now playing: Jesse Cook - La Paloma
Anand
Dec 07, 2006 11:59 PM
#
Definitely an interesting feature to put into Windows Live Writer. Looking forward to using it.
Keyvan Nayyeri
Dec 11, 2006 8:03 AM
#
I'm pleased to announce the second version of our Windows Live Writer plugins collection, codenamed Gustnado.
Steve Harman
Jan 20, 2007 8:59 PM
#
TrackBack
Jan 20, 2007 9:48 PM
#
Tonight while working on some blog posts about CodeMash I decided to make use of a new Windows Live Writer plug-in, Insert XNF Link.
Community Blogs
Feb 09, 2007 6:58 AM
#
Gurkan Yeniceri
Feb 24, 2007 6:06 AM
#
portrait painting
Nov 28, 2007 9:15 PM
#
Leave a Comment