diff --git a/AntPanel/AntPanel.csproj b/AntPanel/AntPanel.csproj index 5ea011e..98ccb4a 100644 --- a/AntPanel/AntPanel.csproj +++ b/AntPanel/AntPanel.csproj @@ -42,7 +42,7 @@ x86 ..\..\..\..\FlashDevelop\Bin\Debug\Plugins\ TRACE - true + false x86 diff --git a/AntPanel/PluginMain.cs b/AntPanel/PluginMain.cs index 8ad4b28..c2feb87 100644 --- a/AntPanel/PluginMain.cs +++ b/AntPanel/PluginMain.cs @@ -15,8 +15,6 @@ namespace AntPanel { - /// - /// public class PluginMain : IPlugin { public readonly List BuildFilesList = new List(); @@ -87,8 +85,8 @@ public void Initialize() public void Dispose() => SaveSettings(); /// - /// Handles the incoming events - /// + /// Adds the required event handlers + /// public void AddEventHandlers() => EventManager.AddEventHandler(this, EventType.UIStarted | EventType.Command); /// @@ -102,7 +100,7 @@ public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) DirectoryNode.OnDirectoryNodeRefresh += OnDirectoryNodeRefresh; break; case EventType.Command: - DataEvent da = (DataEvent)e; + var da = (DataEvent)e; switch (da.Action) { case ProjectManagerEvents.Project: @@ -121,20 +119,14 @@ public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) #region Custom Public Methods - /// - /// - /// public void AddBuildFiles(IEnumerable files) { - foreach (string file in files.Where(file => !BuildFilesList.Contains(file))) + foreach (var file in files.Where(file => !BuildFilesList.Contains(file))) BuildFilesList.Add(file); SaveBuildFiles(); pluginUI.RefreshData(); } - /// - /// - /// public void RemoveBuildFile(string file) { if (BuildFilesList.Contains(file)) BuildFilesList.Remove(file); @@ -142,30 +134,24 @@ public void RemoveBuildFile(string file) pluginUI.RefreshData(); } - /// - /// - /// - /// public void RunTarget(string file, string target) { - string antPath = ((Settings)Settings).AntPath; - string command = Path.Combine(Environment.SystemDirectory, "cmd.exe"); - string arguments = "/c "; + var antPath = ((Settings)Settings).AntPath; + var command = PluginBase.MainForm.CommandPromptExecutable ?? Path.Combine(Environment.SystemDirectory, "cmd.exe"); + var arguments = "/c "; if (string.IsNullOrEmpty(antPath)) arguments += "ant"; else arguments += Path.Combine(Path.Combine(antPath, "bin"), "ant"); arguments += $" -buildfile \"{file}\" \"{target}\""; - PluginBase.MainForm.CallCommand("RunProcessCaptured", command + ";" + arguments); + PluginBase.MainForm.CallCommand("RunProcessCaptured", $"{command};{arguments}"); } - /// - /// public void ReadBuildFiles() { BuildFilesList.Clear(); - string folder = GetBuildFilesStorageFolder(); - string fullName = Path.Combine(folder, StorageFileName); + var folder = GetBuildFilesStorageFolder(); + var fullName = Path.Combine(folder, StorageFileName); if (!File.Exists(fullName)) return; - StreamReader file = new StreamReader(fullName); + var file = new StreamReader(fullName); string line; while ((line = file.ReadLine()) != null) if (!string.IsNullOrEmpty(line) && !BuildFilesList.Contains(line)) @@ -183,9 +169,9 @@ public void ReadBuildFiles() void InitBasics() { pluginImage = PluginBase.MainForm.FindImage("486"); - string dataPath = Path.Combine(PathHelper.DataDir, "AntPanel"); - if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); - settingFilename = Path.Combine(dataPath, "Settings.fdb"); + var path = Path.Combine(PathHelper.DataDir, "AntPanel"); + if (!Directory.Exists(path)) Directory.CreateDirectory(path); + settingFilename = Path.Combine(path, "Settings.fdb"); } /// @@ -193,9 +179,9 @@ void InitBasics() /// void CreateMenuItem() { - ToolStripMenuItem menuItem = new ToolStripMenuItem("Ant Panel", pluginImage, OpenPanel); + var menuItem = new ToolStripMenuItem("Ant Panel", pluginImage, OpenPanel); PluginBase.MainForm.RegisterShortcutItem("ViewMenu.ShowAntPanel", menuItem); - ToolStripMenuItem menu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu"); + var menu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu"); menu.DropDownItems.Add(menuItem); } @@ -229,22 +215,17 @@ void LoadSettings() /// void OpenPanel(object sender, EventArgs e) => pluginPanel.Show(); - /// - /// void SaveBuildFiles() { - string folder = GetBuildFilesStorageFolder(); - string fullName = Path.Combine(folder, StorageFileName); + var folder = GetBuildFilesStorageFolder(); + var fullName = Path.Combine(folder, StorageFileName); if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); - StreamWriter file = new StreamWriter(fullName); - foreach (string line in BuildFilesList) + var file = new StreamWriter(fullName); + foreach (var line in BuildFilesList) file.WriteLine(line); file.Close(); } - /// - /// - /// static string GetBuildFilesStorageFolder() => Path.Combine(Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath), "obj"); #endregion @@ -256,7 +237,7 @@ void SaveBuildFiles() void OnTreeSelectionChanged() { if (!(projectTree?.SelectedNode is FileNode)) return; - string path = Path.GetFullPath(((FileNode)projectTree.SelectedNode).BackingPath); + var path = Path.GetFullPath(((FileNode)projectTree.SelectedNode).BackingPath); if (BuildFilesList.Contains(path) || Path.GetExtension(path) != ".xml") return; projectTree.ContextMenuStrip.Items.Add(new ToolStripSeparator()); projectTree.ContextMenuStrip.Items.Add("Add as Ant Build File", pluginImage, OnAddAsAntBuildFile); @@ -264,7 +245,7 @@ void OnTreeSelectionChanged() void OnAddAsAntBuildFile(object sender, EventArgs e) { - string path = Path.GetFullPath(((FileNode)projectTree.SelectedNode).BackingPath); + var path = Path.GetFullPath(((FileNode)projectTree.SelectedNode).BackingPath); if (BuildFilesList.Contains(path)) return; BuildFilesList.Add(path); SaveBuildFiles(); diff --git a/AntPanel/PluginUI.cs b/AntPanel/PluginUI.cs index 3fc2a32..cdbd134 100644 --- a/AntPanel/PluginUI.cs +++ b/AntPanel/PluginUI.cs @@ -9,30 +9,18 @@ using System.Xml; using PluginCore; using PluginCore.Managers; -using ScintillaNet; namespace AntPanel { - /// - /// public partial class PluginUI : DockPanelControl { - const int ICON_FILE = 0; - const int ICON_INTERNAL_TARGET = 2; - const int ICON_PUBLIC_TARGET = 3; - const Keys EDIT_KEYS = Keys.F4; - const Keys DEL_KEYS = Keys.Delete; - - /// - /// - /// - /// + const int IconFile = 0; + const int IconInternalTarget = 2; + const int IconPublicTarget = 3; + const Keys DelKeys = Keys.Delete; + const Keys EditKeys = Keys.F4; public delegate void PluginUIEventHandler(object sender, PluginUIArgs e); - - /// - /// public event PluginUIEventHandler OnChange; - readonly PluginMain pluginMain; Image removeImage; Image editImage; @@ -68,16 +56,12 @@ void SetupTreeImages() tree.ImageList.Images.Add(PluginBase.MainForm.FindImage("197")); } - /// - /// void InitializeImages() { removeImage = PluginBase.MainForm.FindImage("153"); editImage = PluginBase.MainForm.FindImage("214"); } - /// - /// void InitializeButtons() { add.Image = PluginBase.MainForm.FindImage("33"); @@ -86,11 +70,9 @@ void InitializeButtons() refresh.Image = PluginBase.MainForm.FindImage("66"); } - /// - /// void UpdateButtons() { - bool isNotEmpty = tree.Nodes.Count > 0; + var isNotEmpty = tree.Nodes.Count > 0; remove.Enabled = isNotEmpty; run.Enabled = isNotEmpty; refresh.Enabled = isNotEmpty; @@ -108,12 +90,12 @@ void InitializeContextMenu() }); buildFileMenu.Items.Add(new ToolStripMenuItem("Edit file", editImage, OnMenuEditClick) { - ShortcutKeys = EDIT_KEYS + ShortcutKeys = EditKeys }); buildFileMenu.Items.Add(new ToolStripSeparator()); buildFileMenu.Items.Add(new ToolStripMenuItem("Remove", removeImage, OnMenuRemoveClick) { - ShortcutKeys = DEL_KEYS + ShortcutKeys = DelKeys }); targetMenu = new ContextMenuStrip(); targetMenu.Items.Add(new ToolStripMenuItem("Run target", run.Image, OnMenuRunClick) @@ -122,21 +104,19 @@ void InitializeContextMenu() }); targetMenu.Items.Add(new ToolStripMenuItem("Show in Editor", editImage, OnMenuEditClick) { - ShortcutKeys = EDIT_KEYS + ShortcutKeys = EditKeys }); errorMenu = new ContextMenuStrip(); errorMenu.Items.Add(new ToolStripMenuItem("Show in Editor", editImage, OnMenuEditClick) { - ShortcutKeys = EDIT_KEYS + ShortcutKeys = EditKeys }); errorMenu.Items.Add(new ToolStripMenuItem("Remove", removeImage, OnMenuRemoveClick) { - ShortcutKeys = DEL_KEYS + ShortcutKeys = DelKeys }); } - /// - /// void StartDragHandling() { tree.AllowDrop = true; @@ -145,8 +125,6 @@ void StartDragHandling() tree.DragOver += OnTreeDragOver; } - /// - /// public void RefreshData() { Enabled = PluginBase.CurrentProject != null; @@ -162,13 +140,11 @@ public void RefreshData() } } - /// - /// void FillTree() { tree.BeginUpdate(); tree.Nodes.Clear(); - foreach (string file in pluginMain.BuildFilesList.Where(File.Exists)) + foreach (var file in pluginMain.BuildFilesList.Where(File.Exists)) { TreeNode node; try @@ -177,15 +153,15 @@ void FillTree() } catch (Exception ex) { - string[] strings = ex.Message.Split('.'); - int msgLength = strings.Length - 2; - string positions = strings[msgLength]; - MatchCollection matches = Regex.Matches(positions, @"(\d+)"); + var strings = ex.Message.Split('.'); + var msgLength = strings.Length - 2; + var positions = strings[msgLength]; + var matches = Regex.Matches(positions, @"(\d+)"); if (matches.Count == 0) return; - string text = string.Empty; - for (int i = 0; i < msgLength; i++) text += strings[i]; - string line = matches[0].Value; - string position = (int.Parse(matches[1].Value) - 1).ToString(); + var text = string.Empty; + for (var i = 0; i < msgLength; i++) text += strings[i]; + var line = matches[0].Value; + var position = (int.Parse(matches[1].Value) - 1).ToString(); TraceManager.Add($"{file}:{line}: chars {position}-{position} : {text}.", (int) TraceType.Error); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); node = new ErrorTreeNode(file, 4, int.Parse(line) - 1, int.Parse(position)); @@ -195,30 +171,26 @@ void FillTree() tree.EndUpdate(); } - /// - /// - /// - /// AntTreeNode GetBuildFileNode(string file) { - XmlDocument xml = new XmlDocument(); + var xml = new XmlDocument(); xml.Load(file); - XmlElement documentElement = xml.DocumentElement; + var documentElement = xml.DocumentElement; Debug.Assert(documentElement != null, "documentElement != null"); - XmlAttribute defTargetAttr = documentElement.Attributes["default"]; - string defaultTarget = defTargetAttr?.InnerText ?? ""; - XmlAttribute nameAttr = documentElement.Attributes["name"]; - string projectName = nameAttr?.InnerText ?? file; - XmlAttribute descrAttr = documentElement.Attributes["description"]; - string description = descrAttr?.InnerText ?? ""; + var defTargetAttr = documentElement.Attributes["default"]; + var defaultTarget = defTargetAttr?.InnerText ?? ""; + var nameAttr = documentElement.Attributes["name"]; + var projectName = nameAttr?.InnerText ?? file; + var descrAttr = documentElement.Attributes["description"]; + var description = descrAttr?.InnerText ?? ""; if (string.IsNullOrEmpty(projectName)) projectName = file; - AntTreeNode rootNode = new AntTreeNode(projectName, ICON_FILE) + var rootNode = new AntTreeNode(projectName, IconFile) { File = file, Target = defaultTarget, ToolTipText = description }; - bool skipHiddenTargets = ((Settings)pluginMain.Settings).SkipHiddenTargets; + var skipHiddenTargets = ((Settings)pluginMain.Settings).SkipHiddenTargets; if (skipHiddenTargets) { // no-description targets should be hidden only if at least one target has a description @@ -226,7 +198,7 @@ AntTreeNode GetBuildFileNode(string file) foreach (XmlNode node in documentElement.ChildNodes) { if (node.Name != "target") continue; - XmlAttributeCollection attributes = node.Attributes; + var attributes = node.Attributes; Debug.Assert(attributes != null, "attributes != null"); if (!string.IsNullOrEmpty(attributes["description"]?.InnerText)) { @@ -239,15 +211,15 @@ AntTreeNode GetBuildFileNode(string file) { if (node.Name != "target") continue; // skip private and optionally hidden targets - XmlAttributeCollection attributes = node.Attributes; + var attributes = node.Attributes; Debug.Assert(attributes != null, "attributes != null"); - XmlAttribute targetNameAttr = attributes["name"]; - string targetName = targetNameAttr?.InnerText; + var targetNameAttr = attributes["name"]; + var targetName = targetNameAttr?.InnerText; if (!string.IsNullOrEmpty(targetName) && (targetName[0] == '-')) continue; if (skipHiddenTargets && string.IsNullOrEmpty(attributes["description"]?.InnerText)) continue; - AntTreeNode targetNode = GetBuildTargetNode(node, defaultTarget); + var targetNode = GetBuildTargetNode(node, defaultTarget); targetNode.File = file; rootNode.Nodes.Add(targetNode); } @@ -255,47 +227,38 @@ AntTreeNode GetBuildFileNode(string file) return rootNode; } - /// - /// - /// - /// - /// AntTreeNode GetBuildTargetNode(XmlNode node, string defaultTarget) { - XmlAttributeCollection attributes = node.Attributes; + var attributes = node.Attributes; Debug.Assert(attributes != null, "attributes != null"); - XmlAttribute nameAttr = attributes["name"]; - string targetName = nameAttr?.InnerText ?? ""; - XmlAttribute descrAttr = attributes["description"]; - string description = descrAttr?.InnerText ?? ""; + var nameAttr = attributes["name"]; + var targetName = nameAttr?.InnerText ?? string.Empty; + var descrAttr = attributes["description"]; + var description = descrAttr?.InnerText ?? string.Empty; AntTreeNode result; if (targetName == defaultTarget) { - result = new AntTreeNode(targetName, ICON_PUBLIC_TARGET) + result = new AntTreeNode(targetName, IconPublicTarget) { NodeFont = new Font(tree.Font.Name, tree.Font.Size, FontStyle.Bold) }; } - else if (!string.IsNullOrEmpty(description)) result = new AntTreeNode(targetName, ICON_PUBLIC_TARGET); - else result = new AntTreeNode(targetName, ICON_INTERNAL_TARGET); + else if (!string.IsNullOrEmpty(description)) result = new AntTreeNode(targetName, IconPublicTarget); + else result = new AntTreeNode(targetName, IconInternalTarget); result.Target = targetName; result.ToolTipText = description; return result; } - /// - /// void RunSelectedTarget() { - AntTreeNode node = tree.SelectedNode as AntTreeNode; + var node = tree.SelectedNode as AntTreeNode; if (node != null) pluginMain.RunTarget(node.File, node.Target); } - /// - /// void RemoveSelectedTarget() { - TreeNode node = tree.SelectedNode; + var node = tree.SelectedNode; string file; if (node is AntTreeNode) file = ((AntTreeNode) node).File; @@ -306,34 +269,32 @@ void RemoveSelectedTarget() pluginMain.RemoveBuildFile(file); } - /// - /// void EditSelectedNode() { - TreeNode node = tree.SelectedNode; + var node = tree.SelectedNode; if (node == null) return; string file; string target = null; if (node is AntTreeNode) { - AntTreeNode antTreeNode = (AntTreeNode)node; + var antTreeNode = (AntTreeNode)node; file = antTreeNode.File; target = antTreeNode.Target; } else file = node.Text; PluginBase.MainForm.OpenEditableDocument(file, false); - ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; + var sci = PluginBase.MainForm.CurrentDocument.SciControl; if (!string.IsNullOrEmpty(target)) { - Match match = Regex.Match(sci.Text, $"]+name\\s*=\\s*\"{target}\".*>", RegexOptions.Compiled); + var match = Regex.Match(sci.Text, $"]+name\\s*=\\s*\"{target}\".*>", RegexOptions.Compiled); if (!match.Success) return; - int index = match.Index; + var index = match.Index; sci.SetSel(index, index + match.Length); } else if (node is ErrorTreeNode) { - ErrorTreeNode errorTreeNode = (ErrorTreeNode) node; - int positionFromLine = sci.PositionFromLine(errorTreeNode.Line); + var errorTreeNode = (ErrorTreeNode) node; + var positionFromLine = sci.PositionFromLine(errorTreeNode.Line); positionFromLine += errorTreeNode.Position; sci.SetSel(positionFromLine, positionFromLine); } @@ -350,7 +311,7 @@ void ShowContextMenu(TreeNode node, Point location) void OnAddClick(object sender, EventArgs e) { - OpenFileDialog dialog = new OpenFileDialog + var dialog = new OpenFileDialog { Filter = "BuildFiles (*.xml)|*.XML|All files (*.*)|*.*", Multiselect = true @@ -368,7 +329,7 @@ void OnAddClick(object sender, EventArgs e) void OnTreeNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button != MouseButtons.Right) return; - TreeNode node = tree.GetNodeAt(e.Location); + var node = tree.GetNodeAt(e.Location); if (node == null) return; tree.SelectedNode = node; ShowContextMenu(node, e.Location); @@ -378,35 +339,27 @@ void OnTreeNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) void OnTreePreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { - if (e.KeyCode == EDIT_KEYS || e.KeyCode == DEL_KEYS) e.IsInputKey = true; + if (e.KeyCode == EditKeys || e.KeyCode == DelKeys) e.IsInputKey = true; } void OnTreeKeyDown(object sender, KeyEventArgs e) { - TreeNode node = tree.SelectedNode; + var node = tree.SelectedNode; if (node == null) return; - switch (e.KeyCode) + if (e.KeyCode == EditKeys) EditSelectedNode(); + else if (e.KeyCode == Keys.Enter) RunSelectedTarget(); + else if (e.KeyCode == Keys.Apps) ShowContextMenu(node, node.Bounds.Location); + else if (e.KeyCode == DelKeys) { - case EDIT_KEYS: - EditSelectedNode(); - break; - case Keys.Enter: - RunSelectedTarget(); - break; - case Keys.Apps: - ShowContextMenu(node, node.Bounds.Location); - break; - case DEL_KEYS: - if (node.ImageIndex == ICON_FILE || !(node is AntTreeNode)) RemoveSelectedTarget(); - break; - default: return; + if (node.ImageIndex == IconFile || !(node is AntTreeNode)) RemoveSelectedTarget(); } + else return; e.Handled = true; } void OnTreeMouseDown(object sender, MouseEventArgs e) { - int delta = (int)DateTime.Now.Subtract(lastMouseDown).TotalMilliseconds; + var delta = (int)DateTime.Now.Subtract(lastMouseDown).TotalMilliseconds; preventExpand = delta < SystemInformation.DoubleClickTime; lastMouseDown = DateTime.Now; } @@ -428,14 +381,14 @@ void OnTreeDragEnter(object sender, DragEventArgs e) if (e.Data.GetDataPresent("AntPanel.AntTreeNode")) { TreeNode node = (AntTreeNode)e.Data.GetData(("AntPanel.AntTreeNode")); - if (node.ImageIndex != ICON_FILE) return; + if (node.ImageIndex != IconFile) return; tree.SelectedNode = null; e.Effect = DragDropEffects.Move; } else { - string[] s = (string[])e.Data.GetData(DataFormats.FileDrop); - IEnumerable xmls = s.Where(t => t.EndsWith(".xml", true, null)); + var s = (string[])e.Data.GetData(DataFormats.FileDrop); + var xmls = s.Where(t => t.EndsWith(".xml", true, null)); if (xmls.Any()) { e.Effect = DragDropEffects.Copy; @@ -450,11 +403,11 @@ void OnTreeDragOver(object sender, DragEventArgs e) if (e.Data.GetDataPresent("AntPanel.AntTreeNode")) { TreeNode node = (AntTreeNode)e.Data.GetData(("AntPanel.AntTreeNode")); - if (node.ImageIndex != ICON_FILE) return; - Point p = tree.PointToClient(new Point(e.X, e.Y)); - TreeNode dropTarget = tree.GetNodeAt(p); + if (node.ImageIndex != IconFile) return; + var p = tree.PointToClient(new Point(e.X, e.Y)); + var dropTarget = tree.GetNodeAt(p); if (dropTarget == null) dropTarget = tree.Nodes[tree.Nodes.Count - 1]; - else if (dropTarget.ImageIndex != ICON_FILE) dropTarget = dropTarget.Parent; + else if (dropTarget.ImageIndex != IconFile) dropTarget = dropTarget.Parent; tree.SelectedNode = dropTarget; } else if (dropFiles != null) e.Effect = DragDropEffects.Copy; @@ -465,9 +418,9 @@ void OnTreeDragDrop(object sender, DragEventArgs e) if (e.Data.GetDataPresent("AntPanel.AntTreeNode")) { TreeNode node = (AntTreeNode)e.Data.GetData(("AntPanel.AntTreeNode")); - if (node.ImageIndex != ICON_FILE) return; - Point p = tree.PointToClient(new Point(e.X, e.Y)); - TreeNode dropTarget = tree.GetNodeAt(p); + if (node.ImageIndex != IconFile) return; + var p = tree.PointToClient(new Point(e.X, e.Y)); + var dropTarget = tree.GetNodeAt(p); if (dropTarget == null) { node.Remove(); @@ -475,14 +428,14 @@ void OnTreeDragDrop(object sender, DragEventArgs e) } else { - if (dropTarget.ImageIndex != ICON_FILE) dropTarget = dropTarget.Parent; - int index = dropTarget.Index; + if (dropTarget.ImageIndex != IconFile) dropTarget = dropTarget.Parent; + var index = dropTarget.Index; node.Remove(); tree.Nodes.Insert(index, node); } tree.SelectedNode = node; if (OnChange == null) return; - List paths = (from AntTreeNode antTreeNode in tree.Nodes select antTreeNode.File).ToList(); + var paths = (from AntTreeNode antTreeNode in tree.Nodes select antTreeNode.File).ToList(); OnChange(this, new PluginUIArgs(paths)); } else if (dropFiles != null) pluginMain.AddBuildFiles(dropFiles); @@ -499,16 +452,9 @@ void OnTreeDragDrop(object sender, DragEventArgs e) #endregion } - /// - /// class AntTreeNode : TreeNode { - /// - /// public string File; - - /// - /// public string Target; /// @@ -516,8 +462,7 @@ class AntTreeNode : TreeNode /// /// /// - public AntTreeNode(string text, int imageIndex) - : base(text, imageIndex, imageIndex) + public AntTreeNode(string text, int imageIndex) : base(text, imageIndex, imageIndex) { } } @@ -533,8 +478,6 @@ public ErrorTreeNode(string text, int imageIndex, int line, int position) : base } } - /// - /// public class PluginUIArgs { /// @@ -546,8 +489,6 @@ public PluginUIArgs(IEnumerable paths) Paths = paths; } - /// - /// public IEnumerable Paths { get; private set; } } } \ No newline at end of file