root/csharp/FlashDevelop/plugin/FlexPMDPlugin/trunk/PluginMain.cs

リビジョン 3089, 6.7 kB (コミッタ: bkzen, コミット時期: 3 年 前)

FlexPMD のプラグインうp

Line 
1 using System;
2 using System.ComponentModel;
3 using System.Collections.Generic;
4 using System.Text;
5 using PluginCore;
6 using System.Drawing;
7 using PluginCore.Helpers;
8 using System.IO;
9 using PluginCore.Utilities;
10 using PluginCore.Managers;
11 using System.Diagnostics;
12 using System.Windows.Forms;
13 using FlexPMDPlugin.Properties;
14 using FlexPMDPlugin.Pmd;
15
16 namespace FlexPMDPlugin
17 {
18     public class PluginMain : IPlugin
19     {
20
21         private String pluginName = "FlexPMDPlugin";
22         private String pluginGuid = "567ec95d-6288-405d-9869-01a9cf135b67";
23         private String pluginHelp = "FlexPMD plugin";
24         private String pluginDesc = "Flash Develop FlexPMD Plugin";
25         private String pluginAuth = "bkzen";
26         private Settings settingObject = null;
27         private String settingFilename = "";
28         private Image pluginImage = null;
29         private FlexPMD pmd = null;
30         private ToolStripButton cmdBtn = null;
31
32         #region Required Properties
33
34         /// <summary>
35         /// Name of the plugin
36         /// </summary>
37         public String Name
38         {
39             get { return this.pluginName; }
40         }
41
42         /// <summary>
43         /// GUID of the plugin
44         /// </summary>
45         public String Guid
46         {
47             get { return this.pluginGuid; }
48         }
49
50         /// <summary>
51         /// Author of the plugin
52         /// </summary>
53         public String Author
54         {
55             get { return this.pluginAuth; }
56         }
57
58         /// <summary>
59         /// Description of the plugin
60         /// </summary>
61         public String Description
62         {
63             get { return this.pluginDesc; }
64         }
65
66         /// <summary>
67         /// Web address for help
68         /// </summary>
69         public String Help
70         {
71             get { return this.pluginHelp; }
72         }
73
74         /// <summary>
75         /// Object that contains the settings
76         /// </summary>
77         [Browsable(false)]
78         public Object Settings
79         {
80             get { return this.settingObject; }
81         }
82
83         #endregion
84
85         #region Required Methods
86
87         /// <summary>
88         /// Initializes the plugin
89         /// </summary>
90         public void Initialize()
91         {
92             InitBasics();
93             LoadSettings();
94             AddEventListener();
95             InitLocalization();
96             CreatePluginPanel();
97             CreateMenuItem();
98         }
99
100         /// <summary>
101         /// Disposes the plugin
102         /// </summary>
103         public void Dispose()
104         {
105             SaveSettings();
106         }
107
108         /// <summary>
109         /// Handles the incoming events
110         /// </summary>
111         public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
112         {
113             switch (e.Type)
114             {
115                 case EventType.Command:
116                     DataEvent de = e as DataEvent;
117                     string action = de.Action;
118                     if (action == PMDEvents.CommandEnd)
119                     {
120                         this.cmdBtn.Enabled = true;
121                     }
122                     else if (action == PMDEvents.CommandError)
123                     {
124                         this.cmdBtn.Enabled = true;
125                     }
126                 break;
127                 case EventType.Keys:
128                     e.Handled = HandleKeyEvent(e as KeyEvent);
129                 break;
130             }
131         }
132
133         private bool HandleKeyEvent(KeyEvent keyEvent)
134         {
135             if (keyEvent.Value == settingObject.CmdShortcut)
136             {
137                 FlexPMDCmdLine();
138             }
139             else return false;
140             return true;
141         }
142
143         #endregion
144
145         #region Custom Methods
146
147         private void InitBasics()
148         {
149             String dataPath = Path.Combine(PathHelper.DataDir, "FlexPMDPlugin");
150             if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath);
151             settingFilename = Path.Combine(dataPath, "Settings.fdb");
152             this.pluginImage = PluginBase.MainForm.FindImage("57|16|0|0");
153         }
154
155         public void LoadSettings()
156         {
157             this.settingObject = new Settings();
158             if (!File.Exists(this.settingFilename)) SaveSettings();
159             else
160             {
161                 Object obj = ObjectSerializer.Deserialize(this.settingFilename, this.settingObject);
162                 this.settingObject = (Settings)obj;
163             }
164         }
165
166         public void SaveSettings()
167         {
168             ObjectSerializer.Serialize(this.settingFilename, this.settingObject);
169         }
170
171         private void AddEventListener()
172         {
173             EventManager.AddEventHandler(this, EventType.Command);
174         }
175
176         private void InitLocalization() { }
177
178         private void CreatePluginPanel() { }
179
180         private void CreateMenuItem()
181         {
182             cmdBtn = new ToolStripButton();
183             cmdBtn.Name = Resources.ToolName;
184             cmdBtn.ToolTipText = Resources.ToolTipCmdLine;
185             cmdBtn.Image = pluginImage;
186             cmdBtn.Click += FlexPMDCmdLine;
187             PluginBase.MainForm.ToolStrip.Items.Add(cmdBtn);
188             PluginBase.MainForm.IgnoredKeys.Add(this.settingObject.CmdShortcut);
189             EventManager.AddEventHandler(this, EventType.Keys);
190         }
191
192         private void FlexPMDCmdLine(Object sender, System.EventArgs e)
193         {
194             FlexPMDCmdLine();
195         }
196
197         private void FlexPMDCmdLine()
198         {
199             IProject proj = PluginBase.CurrentProject;
200             try
201             {
202                 if (pmd == null)
203                 {
204                     pmd = new FlexPMD(PluginBase.MainForm.ProcessArgString("$(FlexSDK)"));
205                 }
206                 if (settingObject.CommandLine == "")
207                 {
208                     TraceManager.Add(Resources.ERROR_PMD_PATH, 3);
209                 }
210                 else
211                 {
212                     PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ClearResults");
213                     EventManager.DispatchEvent(this, new NotifyEvent(EventType.ProcessStart));
214                     TraceManager.Add("Start FlexPMD");
215                     pmd.RunFlexPMDCommandLine(settingObject.CommandLine, proj.GetAbsolutePath(proj.SourcePaths[0]));
216                     cmdBtn.Enabled = false;
217                 }
218             }
219             catch (Exception err)
220             {
221                 TraceManager.Add(Resources.ERROR_SDK_PATH + err.Message, 3);
222                 cmdBtn.Enabled = true;
223             }
224         }
225
226
227         #endregion
228
229     }
230
231
232 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。