Windows Live Writer Plugins: Insert Current Date & Time
2007-05-27 20:35 晓风残月 阅读(560) 评论(0) 编辑 收藏 举报
昨天试用了Windows Live Writer,太棒了!编辑器blog,确实很方便,可以随时保存在本地。
但是没有插入时间和日期的功能,幸运的是WLW提供了API SDK,可以自己扩展,实现起来也很简单。看了下 SDK 提供了那个 HelloWorldPlugin 以及 Document,自己设计了两个插件:DateInserter 和 TimeInserter:
1: #region module comment
2: /***************************************************************************
3: * Copyright (C), 2005-2007, Digdotnet Tech. Co., Ltd. All rights reserved.
4: * FileName: DateInserter.cs
5: * Author: xfwang0724@gmail.com Version: 1.0 Date: 05/26/2007 10:26:29
6: * Description:
7: * Version: 1.0
8: * Function:
9: * 1.
10: * 2.
11: * History:
12: * Author: xfwang0724@gmail.com Version: 1.0 Date: 05/26/2007 10:26:29
13: * Description: initial version
14: ***************************************************************************/
15: #endregion
16:
17: #region using directives
18:
19: using System;
20: using System.Collections.Generic;
21: using System.ComponentModel;
22: using System.Globalization;
23: using System.Text;
24: using System.Windows.Forms;
25:
26: using WindowsLive.Writer.Api;
27:
28: #endregion
29:
30: namespace Digdotnet.WLWPlugins
31: {
32: /// <summary>
33: /// Summary description for DateInserter
34: /// </summary>
35: [WriterPluginAttribute("ea848c93-a3b3-4522-a05a-c5f2ec45e7cd", "Current Date",
36: ImagePath = "images.calendar.gif",
37: PublisherUrl = "http://jinglecat.cnblogs.com",
38: Description = "Insert the current date in your blog posts.")]
39: [InsertableContentSource("Current Date")]
40: public class DateInserter : ContentSource
41: {
42: #region const(s)
43:
44: #endregion
45:
46: #region field(s)
47:
48: #endregion
49:
50: #region ctor(s)
51:
52: public DateInserter()
53: {
54: //
55: // TODO: Add constructor logic here
56: //
57: }
58:
59: #endregion
60:
61: #region public prop(s)
62:
63: #endregion
64:
65: #region public method(s)
66:
67: #endregion
68:
69: #region override
70:
71: public override DialogResult CreateContent(IWin32Window dialogOwner, ref string newContent)
72: {
73: //using (DateTimePicker dtPicker = new DateTimePicker()) {
74: // dtPicker.Show();
75: // DateTime dt = dtPicker.Value;
76: // newContent = dt.ToLongDateString();
77: //}
78: newContent = DateTime.Now.ToLongDateString();
79: return DialogResult.OK;
80: }
81:
82: #endregion
83:
84: #region private method(s)
85:
86: #endregion
87:
88: } // end of class DatePlugin
89: } // end of namespace Digdotnet.DateTime4WLW
1: #region module comment
2: /***************************************************************************
3: * Copyright (C), 2005-2007, Digdotnet Tech. Co., Ltd. All rights reserved.
4: * FileName: TimeInserter.cs
5: * Author: xfwang0724@gmail.com Version: 1.0 Date: 05/26/2007 11:12:46
6: * Description:
7: * Version: 1.0
8: * Function:
9: * 1.
10: * 2.
11: * History:
12: * Author: xfwang0724@gmail.com Version: 1.0 Date: 05/26/2007 11:12:46
13: * Description: initial version
14: ***************************************************************************/
15: #endregion
16:
17: #region using directives
18:
19: using System;
20: using System.Collections;
21: using System.Collections.Generic;
22: using System.Data;
23: using System.Text;
24: using System.Windows.Forms;
25: using System.Xml;
26:
27: using WindowsLive.Writer.Api;
28:
29: #endregion
30:
31: namespace Digdotnet.WLWPlugins
32: {
33: /// <summary>
34: /// Summary description for TimeInserter
35: /// </summary>
36: [WriterPluginAttribute("ca7bb793-d902-4aeb-afcd-947d3ee17d7e", "Current Time",
37: ImagePath = "images.timer.gif",
38: PublisherUrl = "http://jinglecat.cnblogs.com",
39: Description = "Insert the current time in your blog posts.")]
40: [InsertableContentSource("Current Time")]
41: public class TimeInserter : ContentSource
42: {
43: #region const(s)
44:
45: #endregion
46:
47: #region field(s)
48:
49: #endregion
50:
51: #region ctor(s)
52:
53: public TimeInserter()
54: {
55: //
56: // TODO: Add constructor logic here
57: //
58: }
59:
60: #endregion
61:
62: #region public prop(s)
63:
64: #endregion
65:
66: #region public method(s)
67:
68: #endregion
69:
70: #region override
71:
72: public override DialogResult CreateContent(IWin32Window dialogOwner, ref string newContent)
73: {
74: newContent = DateTime.Now.ToLongTimeString();
75: return DialogResult.OK;
76: }
77:
78: #endregion
79:
80: #region private method(s)
81:
82: #endregion
83:
84: } // end of class TimeInserter
85: } // end of namespace Digdotnet.WLWPlugins
完整代码:下载