CodeZine(コードジン)

特集ページ一覧

Windows Live Writer用のプラグインを開発する

Windows Live Writer自作プラグインの開発

  • LINEで送る
  • このエントリーをはてなブックマークに追加
2008/07/25 14:00

目次

SmartContentSourceプラグインでフォームを使用する

 フォームを使用するのは、基本的なContentSourceプラグインを作成したときに説明したプロセスに似ています。主な違いは、最終的なHTMLを作成して返す代わりに、設定をPluginSettingsクラスに保存し、このクラスを後からプラグインのメインクラスのメソッドの中で使用するという点です。

 リスト4は、この例のプラグインで使用するメインフォームのフルコードを示しています。

リスト4 SmartContentSourceプラグインのメインフォームのコード
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace EditPublish
{
   public class frmMain : Form
   {
      PluginSettings m_settings;
      public frmMain(PluginSettings settings)
      {
         m_settings = settings;
         InitializeComponent();
      }
      private void button1_Click(object sender, EventArgs e)
      {
         if (textBox1.Text != "")
         {
            m_settings.PlaceHolder = textBox1.Text;
         }
         else
         {
            MessageBox.Show("You need to set a placeholder", 
               "Big Fat Hairy Error", 
               MessageBoxButtons.OK, 
               MessageBoxIcon.Error);
               return;
         }
         if (textBox2.Text != "")
         {
            m_settings.FinalText = textBox2.Text;
         }
         else
         {
            MessageBox.Show("Enter some text", 
            "Big Fat Hairy Error", 
            MessageBoxButtons.OK, 
            MessageBoxIcon.Error);
            return;
         }
         this.DialogResult = DialogResult.OK;
         this.Close();
      }

      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.IContainer components = null;

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      /// <param name="disposing">
      ///    true if managed resources should be disposed; 
      ///    otherwise, false.</param>
      protected override void Dispose
         (bool disposing)
      {
         if(disposing && (components != null))
         {
            components.Dispose();
         }
         base.Dispose(disposing);
      }

#region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         System.ComponentModel.ComponentResourceManager resources = 
            new System.ComponentModel.ComponentResourceManager(
            typeof(frmMain));
         this.textBox1 = new System.Windows.Forms.TextBox();
         this.textBox2 = new System.Windows.Forms.TextBox();
         this.label1 = new System.Windows.Forms.Label();
         this.label2 = new System.Windows.Forms.Label();
         this.label3 = new System.Windows.Forms.Label();
         this.button1 = new System.Windows.Forms.Button();
         this.button2 = new System.Windows.Forms.Button();
         this.SuspendLayout();
         // 
         // textBox1
         // 
         this.textBox1.Location = new System.Drawing.Point(13, 124);
         this.textBox1.Multiline = true;
         this.textBox1.Name = "textBox1";
         this.textBox1.Size = new System.Drawing.Size(407, 48);
         this.textBox1.TabIndex = 0;
         // 
         // textBox2
         // 
         this.textBox2.Location = new System.Drawing.Point(13, 203);
         this.textBox2.Multiline = true;
         this.textBox2.Name = "textBox2";
         this.textBox2.Size = new System.Drawing.Size(407, 56);
         this.textBox2.TabIndex = 1;
         // 
         // label1
         // 
         this.label1.AutoSize = true;
         this.label1.Location = new System.Drawing.Point(13, 105);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(168, 13);
         this.label1.TabIndex = 2;
         this.label1.Text = "Text to appear in the Writer editor:";
         // 
         // label2
         // 
         this.label2.AutoSize = true;
         this.label2.Location = new System.Drawing.Point(13, 185);
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size(189, 13);
         this.label2.TabIndex = 3;
         this.label2.Text = "Text to appear in the actual blog entry:";
         // 
         // label3
         // 
         this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)
            (((System.Windows.Forms.AnchorStyles.Top | 
               System.Windows.Forms.AnchorStyles.Left) |
               System.Windows.Forms.AnchorStyles.Right)));
         this.label3.Location = new System.Drawing.Point(13, 9);
         this.label3.Name = "label3";
         this.label3.Size = new System.Drawing.Size(407, 96);
         this.label3.TabIndex = 4;
         this.label3.Text = resources.GetString("label3.Text");
         // 
         // button1
         // 
         this.button1.DialogResult
              = System.Windows.Forms.DialogResult.Cancel;
         this.button1.Location = new System.Drawing.Point(264, 272);
         this.button1.Name = "button1";
         this.button1.Size = new System.Drawing.Size(75, 23);
         this.button1.TabIndex = 5;
         this.button1.Text = "Insert";
         this.button1.UseVisualStyleBackColor = true;
         this.button1.Click
            += new System.EventHandler(this.button1_Click);
         // 
         // button2
         // 
         this.button2.DialogResult
              = System.Windows.Forms.DialogResult.Cancel;
         this.button2.Location = new System.Drawing.Point(345, 272);
         this.button2.Name = "button2";
         this.button2.Size = new System.Drawing.Size(75, 23);
         this.button2.TabIndex = 6;
         this.button2.Text = "Cancel";
         this.button2.UseVisualStyleBackColor = true;
         // 
         // frmMain
         // 
         this.AcceptButton = this.button1;
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.CancelButton = this.button2;
         this.ClientSize = new System.Drawing.Size(432, 307);
         this.Controls.Add(this.button2);
         this.Controls.Add(this.button1);
         this.Controls.Add(this.label3);
         this.Controls.Add(this.label2);
         this.Controls.Add(this.label1);
         this.Controls.Add(this.textBox2);
         this.Controls.Add(this.textBox1);
         this.FormBorderStyle
              = System.Windows.Forms.FormBorderStyle.FixedSingle;
         this.MaximizeBox = false;
         this.MinimizeBox = false;
         this.Name = "frmMain";
         this.ShowIcon = false;
         this.ShowInTaskbar = false;
         this.StartPosition
              = System.Windows.Forms.FormStartPosition.CenterParent;
         this.Text = "Insert Placeholder Plugin";
         this.ResumeLayout(false);
         this.PerformLayout();
      }
#endregion
      private System.Windows.Forms.TextBox textBox1;
      private System.Windows.Forms.TextBox textBox2;
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.Label label3;
      private System.Windows.Forms.Button button1;
      private System.Windows.Forms.Button button2;
   }
}

  • LINEで送る
  • このエントリーをはてなブックマークに追加

バックナンバー

連載:japan.internet.com翻訳記事

もっと読む

著者プロフィール

  • Scott Lovegrove(Scott Lovegrove)

    Windows Live MVP for Microsoftであり、Windows Live Writerだけでなく、Windows Live全般に深く関係している。Windows Live専用のコミュニティWebサイト「LiveSide.net」の主要な寄稿者の1人であり、Windows Live...

  • japan.internet.com(ジャパンインターネットコム)

    japan.internet.com は、1999年9月にオープンした、日本初のネットビジネス専門ニュースサイト。月間2億以上のページビューを誇る米国 Jupitermedia Corporation (Nasdaq: JUPM) のニュースサイト internet.com や EarthWeb.c...

あなたにオススメ

All contents copyright © 2005-2021 Shoeisha Co., Ltd. All rights reserved. ver.1.5