using System; using System.ComponentModel; using System.Collections.Generic; using System.Text; using PluginCore; using System.Drawing; using PluginCore.Helpers; using System.IO; using PluginCore.Utilities; using PluginCore.Managers; using System.Diagnostics; using System.Windows.Forms; using FlexPMDPlugin.Properties; using FlexPMDPlugin.Pmd; namespace FlexPMDPlugin { public class PluginMain : IPlugin { private String pluginName = "FlexPMDPlugin"; private String pluginGuid = "567ec95d-6288-405d-9869-01a9cf135b67"; private String pluginHelp = "FlexPMD plugin"; private String pluginDesc = "Flash Develop FlexPMD Plugin"; private String pluginAuth = "bkzen"; private Settings settingObject = null; private String settingFilename = ""; private Image pluginImage = null; private FlexPMD pmd = null; private ToolStripButton cmdBtn = null; #region Required Properties /// /// Name of the plugin /// public String Name { get { return this.pluginName; } } /// /// GUID of the plugin /// public String Guid { get { return this.pluginGuid; } } /// /// Author of the plugin /// public String Author { get { return this.pluginAuth; } } /// /// Description of the plugin /// public String Description { get { return this.pluginDesc; } } /// /// Web address for help /// public String Help { get { return this.pluginHelp; } } /// /// Object that contains the settings /// [Browsable(false)] public Object Settings { get { return this.settingObject; } } #endregion #region Required Methods /// /// Initializes the plugin /// public void Initialize() { InitBasics(); LoadSettings(); AddEventListener(); InitLocalization(); CreatePluginPanel(); CreateMenuItem(); } /// /// Disposes the plugin /// public void Dispose() { SaveSettings(); } /// /// Handles the incoming events /// public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority) { switch (e.Type) { case EventType.Command: DataEvent de = e as DataEvent; string action = de.Action; if (action == PMDEvents.CommandEnd) { this.cmdBtn.Enabled = true; } else if (action == PMDEvents.CommandError) { this.cmdBtn.Enabled = true; } break; case EventType.Keys: e.Handled = HandleKeyEvent(e as KeyEvent); break; } } private bool HandleKeyEvent(KeyEvent keyEvent) { if (keyEvent.Value == settingObject.CmdShortcut) { FlexPMDCmdLine(); } else return false; return true; } #endregion #region Custom Methods private void InitBasics() { String dataPath = Path.Combine(PathHelper.DataDir, "FlexPMDPlugin"); if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); settingFilename = Path.Combine(dataPath, "Settings.fdb"); this.pluginImage = PluginBase.MainForm.FindImage("57|16|0|0"); } public void LoadSettings() { this.settingObject = new Settings(); if (!File.Exists(this.settingFilename)) SaveSettings(); else { Object obj = ObjectSerializer.Deserialize(this.settingFilename, this.settingObject); this.settingObject = (Settings)obj; } } public void SaveSettings() { ObjectSerializer.Serialize(this.settingFilename, this.settingObject); } private void AddEventListener() { EventManager.AddEventHandler(this, EventType.Command); } private void InitLocalization() { } private void CreatePluginPanel() { } private void CreateMenuItem() { cmdBtn = new ToolStripButton(); cmdBtn.Name = Resources.ToolName; cmdBtn.ToolTipText = Resources.ToolTipCmdLine; cmdBtn.Image = pluginImage; cmdBtn.Click += FlexPMDCmdLine; PluginBase.MainForm.ToolStrip.Items.Add(cmdBtn); PluginBase.MainForm.IgnoredKeys.Add(this.settingObject.CmdShortcut); EventManager.AddEventHandler(this, EventType.Keys); } private void FlexPMDCmdLine(Object sender, System.EventArgs e) { FlexPMDCmdLine(); } private void FlexPMDCmdLine() { IProject proj = PluginBase.CurrentProject; try { if (pmd == null) { pmd = new FlexPMD(PluginBase.MainForm.ProcessArgString("$(FlexSDK)")); } if (settingObject.CommandLine == "") { TraceManager.Add(Resources.ERROR_PMD_PATH, 3); } else { PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ClearResults"); EventManager.DispatchEvent(this, new NotifyEvent(EventType.ProcessStart)); TraceManager.Add("Start FlexPMD"); pmd.RunFlexPMDCommandLine(settingObject.CommandLine, proj.GetAbsolutePath(proj.SourcePaths[0])); cmdBtn.Enabled = false; } } catch (Exception err) { TraceManager.Add(Resources.ERROR_SDK_PATH + err.Message, 3); cmdBtn.Enabled = true; } } #endregion } }