(How to)Windows Live Writer插入Latex公式(补充)

   1、打开Visual Studio,创建一个“Class Library”类型的项目。

   newproj

   2、然后在项目中添加WindowsLive.Writer.Api.dll程序集的引用(一般位于C:\Program Files(x86)\Windows Live\Writer\)

   3、右键单击Class Library项目,选择“Properties”。设置Build Events 的Post-build event commend line,让每次编译完成之后自动将该插件拷贝到Windows Live Writer的插件目录下:

XCOPY /D /Y /R "$(TargetPath)" "C:\Program Files (x86)\Windows Live\Writer\Plugins\"

    buildevent

   4、在这个Class Library中新建一个类,并继承于WindowsLive.Writer.Api.ContentSource基类:

[WriterPluginAttribute(
        "24E0269C-D61B-11E0-A846-6D254824019B",
        "LaTeX Chart",
        Description = "A simple LaTeX render plugin for Windows Live Writer",
        HasEditableOptions = false,
        ImagePath = "formula_icon.jpg",
        PublisherUrl = "http://liselsia.org"
    )]
    [InsertableContentSourceAttribute("LaTeX Chart")]
    public class LaTeXPlugin : ContentSource 
    {
        //...
    }

        注意我们为该类添加了WriterPlugin属性:

        1、第一个参数为一个Guid,我们可以用Visual Studio自动生成,其标识的作用。

        2、第二个参数为该插件的名称,将在Windows Live Writer的插件管理器中看到,如图:

    plugin

        3、PublisherUrl为发布者的网站地址。

        4、ImagePath为插件的图标文件路径,注意该图标应为18*16大小,且一定以Embedded Resource形式编译在程序集中。如下:

    embedimg

        5、Description为插件的一小段描述介绍。

        该类还应用了InsertableContentSource属性,其中的参数表示“Insert”菜单和“Insert”快捷面板中该插件的名称。

    plugine

   5、覆写基类的CreateContent()方法

public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content) {
            LaTeXInput input_form = new LaTeXInput();

            if (DialogResult.OK == input_form.ShowDialog()) {
                content = input_form.ResultHTML;
            }

            input_form.Dispose();
            return DialogResult.OK;
        }

       另外覆盖的这个CreateContent方法必须返回DialogResult.OK,其他的如Yes都不行,会导致插件不能插入东西。

   6、运行

       直接F6 Build就可以。build成功之后,启动Live Writer,在插入这一栏中能看到刚刚加入的插件了,如下图的LaTeX Chart。

    plug

   8、调试

       在VS中:debug -- Attach to Process

    debug

      这样在Visual Studio中的插件代码中加入断点,然后切换回Windows Live Writer,启动该插件,Visual Studio将顺利开始调试。

posted on 2012-12-28 18:08  chitti  阅读(441)  评论(0编辑  收藏  举报

导航