| 1: | // MenuItemBuilders.cs | |
| 2: | // Copyright (C) 2002 Mike Krueger | |
| 3: | // | |
| 4: | // This program is free software; you can redistribute it and/or modify | |
| 5: | // it under the terms of the GNU General Public License as published by | |
| 6: | // the Free Software Foundation; either version 2 of the License, or | |
| 7: | // (at your option) any later version. | |
| 8: | // | |
| 9: | // This program is distributed in the hope that it will be useful, | |
| 10: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12: | // GNU General Public License for more details. | |
| 13: | // | |
| 14: | // You should have received a copy of the GNU General Public License | |
| 15: | // along with this program; if not, write to the Free Software | |
| 16: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17: | ||
| 18: | using System; | |
| 19: | using System.Diagnostics; | |
| 20: | using System.IO; | |
| 21: | using System.Collections; | |
| 22: | using System.Windows.Forms; | |
| 23: | ||
| 24: | using Core.AddIns; | |
| 25: | using Core.AddIns.Codons; | |
| 26: | using Core.Util; | |
| 27: | using Core.Properties; | |
| 28: | using Core.Gui; | |
| 29: | using Core.Gui.Creators; | |
| 30: | ||
| 31: | using SharpDevelop.Gui; | |
| 32: | using SharpDevelop.Gui.Components; | |
| 33: | using SharpDevelop.Gui.Dialogs; | |
| 34: | using SharpDevelop.Internal.Project; | |
| 35: | using SharpDevelop.Tool.Data; | |
| 36: | using SharpDevelop.Gui.Navigation.ProjectBrowser; | |
| 37: | using SharpDevelop.Internal.ExternalTool; | |
| 38: | ||
| 39: | namespace SharpDevelop.Base.Commands { | |
| 40: | ||
| 41: | public class ToolMenuBuilder : ISubmenuBuilder | |
| 42: | { | |
| 43: | public MenuItem[] BuildSubmenu(object owner) | |
| 44: | { | |
| 45: | IconMenuStyle iconMenuStyle = (IconMenuStyle)GlobalProperties.GetProperty("IconMenuItem.IconMenuStyle", IconMenuStyle.VSNet); | |
| 46: | MenuItem[] items = new MenuItem[ToolLoader.Tool.Count]; | |
| 47: | for (int i = 0; i < ToolLoader.Tool.Count; ++i) { | |
| 48: | RichMenuItem item = new RichMenuItem(iconMenuStyle, ToolLoader.Tool[i].ToString(), new EventHandler(ToolEvt)); | |
| 49: | item.Description = "Start tool " + ToolLoader.Tool[i].ToString(); | |
| 50: | items[i] = item; | |
| 51: | } | |
| 52: | return items; | |
| 53: | } | |
| 54: | ||
| 55: | void ToolEvt(object sender, EventArgs e) | |
| 56: | { | |
| 57: | MenuItem item = (MenuItem)sender; | |
| 58: | for (int i = 0; i < ToolLoader.Tool.Count; ++i) { | |
| 59: | if (item.Text == ToolLoader.Tool[i].ToString()) { | |
| 60: | ExternalTool tool = (ExternalTool)ToolLoader.Tool[i]; | |
| 61: | StringParser.Properties["StartupPath"] = Application.StartupPath; | |
| 62: | string command = StringParser.Parse(tool.Command); | |
| 63: | ||
| 64: | if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { | |
| 65: | StringParser.Properties["File"] = '"' + WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName + '"'; | |
| 66: | } else { | |
| 67: | StringParser.Properties["File"] = ""; | |
| 68: | } | |
| 69: | ||
| 70: | StringParser.Properties["Assembly"] = ""; | |
| 71: | if (WorkbenchSingleton.Workbench.ProjectManager.CurrentProject != null) { | |
| 72: | ILanguageBinding binding = LanguageBindingManager.GetBindingPerLanguageName(WorkbenchSingleton.Workbench.ProjectManager.CurrentProject.ProjectType); | |
| 73: | if (binding != null) { | |
| 74: | StringParser.Properties["Assembly"] = '"' + binding.GetCompiledOutputName(WorkbenchSingleton.Workbench.ProjectManager.CurrentProject) + '"'; | |
| 75: | } | |
| 76: | } else if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { | |
| 77: | ||
| 78: | string fileName = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName; | |
| 79: | ILanguageBinding binding = LanguageBindingManager.GetBindingPerFileName(fileName); | |
| 80: | if (binding != null) { | |
| 81: | StringParser.Properties["Assembly"] = '"' + binding.GetCompiledOutputName(fileName) + '"'; | |
| 82: | } | |
| 83: | } | |
| 84: | ||
| 85: | string args = StringParser.Parse(tool.Arguments); | |
| 86: | try { | |
| 87: | // TODO : Remove this .NET bugfix | |
| 88: | HelperServices.ExecuteDirect ed = new HelperServices.ExecuteDirect(); | |
| 89: | ed.RunProgram('"'+ command+ "\" " + args, HelperServices.ShowWindowOption.normal); | |
| 90: | ||
| 91: | // ProcessStartInfo startinfo = new ProcessStartInfo(command, args); | |
| 92: | // startinfo.WorkingDirectory = tool.InitialDirectory; | |
| 93: | // Process.Start(startinfo); | |
| 94: | } catch (Exception ex) { | |
| 95: | MessageBox.Show("Error while starting:\n '" + command + " " + args + "'" + "\n" + ex.ToString(), "External program execution failed", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
| 96: | } | |
| 97: | break; | |
| 98: | } | |
| 99: | } | |
| 100: | } | |
| 101: | } | |
| 102: | ||
| 103: | public class OpenContentsMenuBuilder : ISubmenuBuilder | |
| 104: | { | |
| 105: | public MenuItem[] BuildSubmenu(object owner) | |
| 106: | { | |
| 107: | IconMenuStyle iconMenuStyle = (IconMenuStyle)GlobalProperties.GetProperty("IconMenuItem.IconMenuStyle", IconMenuStyle.VSNet); | |
| 108: | int contentCount = WorkbenchSingleton.Workbench.WindowContentCollection.Count; | |
| 109: | if (contentCount == 0) { | |
| 110: | return null; | |
| 111: | } | |
| 112: | MenuItem[] items = new MenuItem[contentCount + 1]; | |
| 113: | items[0] = new RichMenuItem(iconMenuStyle, "-"); | |
| 114: | for (int i = 0; i < contentCount; ++i) { | |
| 115: | IWindowContent content = (IWindowContent)WorkbenchSingleton.Workbench.WindowContentCollection[i]; | |
| 116: | ||
| 117: | RichMenuItem item = new RichMenuItem(iconMenuStyle, content.WorkbenchWindow.Title, new EventHandler(ClickEvent)); | |
| 118: | item.Tag = content.WorkbenchWindow; | |
| 119: | item.Checked = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow == content.WorkbenchWindow; | |
| 120: | item.Description = "Activate this window "; | |
| 121: | items[i + 1] = item; | |
| 122: | } | |
| 123: | return items; | |
| 124: | } | |
| 125: | void ClickEvent(object sender, EventArgs e) | |
| 126: | { | |
| 127: | RichMenuItem item = ((RichMenuItem)sender); | |
| 128: | if (item != null && item.Tag != null) { | |
| 129: | ((IWorkbenchWindow)item.Tag).SelectWindow(); | |
| 130: | } | |
| 131: | } | |
| 132: | } | |
| 133: | ||
| 134: | public class IncludeFilesBuilder : ISubmenuBuilder | |
| 135: | { | |
| 136: | public ProjectBrowserView browser; | |
| 137: | ||
| 138: | public MenuItem includeInCompileItem; | |
| 139: | public MenuItem includeInDeployItem; | |
| 140: | ||
| 141: | class MyMenuItem : RichMenuItem | |
| 142: | { | |
| 143: | IncludeFilesBuilder builder; | |
| 144: | public MyMenuItem(IncludeFilesBuilder builder, IconMenuStyle style, string name, EventHandler handler) : base(style, name, handler) | |
| 145: | { | |
| 146: | this.builder = builder; | |
| 147: | } | |
| 148: | ||
| 149: | protected override void OnMeasureItem(MeasureItemEventArgs e) | |
| 150: | { | |
| 151: | base.OnMeasureItem(e); | |
| 152: | ||
| 153: | ProjectBrowserNode node = (ProjectBrowserNode)builder.browser.SelectedNode; | |
| 154: | ||
| 155: | if (node == null) { | |
| 156: | return; | |
| 157: | } | |
| 158: | string filename = node.FileName; | |
| 159: | FileInformation finfo = WorkbenchSingleton.Workbench.ProjectManager.RetrieveFileInformationForFile(filename); | |
| 160: | if (finfo == null) { | |
| 161: | builder.includeInCompileItem.Enabled = builder.includeInCompileItem.Enabled = false; | |
| 162: | } else { | |
| 163: | if (!builder.includeInCompileItem.Enabled) { | |
| 164: | builder.includeInCompileItem.Enabled = builder.includeInCompileItem.Enabled = true; | |
| 165: | } | |
| 166: | builder.includeInCompileItem.Checked = finfo.BuildAction == BuildAction.Compile; | |
| 167: | builder.includeInDeployItem.Checked = !node.Project.DeployInformation.IsFileExcluded(filename); | |
| 168: | } | |
| 169: | } | |
| 170: | } | |
| 171: | public MenuItem[] BuildSubmenu(object owner) | |
| 172: | { | |
| 173: | IconMenuStyle iconMenuStyle = (IconMenuStyle)GlobalProperties.GetProperty("IconMenuItem.IconMenuStyle", IconMenuStyle.VSNet); | |
| 174: | browser = (ProjectBrowserView)owner; | |
| 175: | ||
| 176: | includeInCompileItem = new MyMenuItem(this, iconMenuStyle, GlobalResources.GetString("ProjectComponent.ContextMenu.IncludeMenu.InCompile"), new EventHandler(ChangeCompileInclude)); | |
| 177: | includeInDeployItem = new MyMenuItem(this, iconMenuStyle, GlobalResources.GetString("ProjectComponent.ContextMenu.IncludeMenu.InDeploy"), new EventHandler(ChangeDeployInclude)); | |
| 178: | ||
| 179: | return new MenuItem[] { | |
| 180: | includeInCompileItem, | |
| 181: | includeInDeployItem | |
| 182: | }; | |
| 183: | ||
| 184: | } | |
| 185: | void ChangeCompileInclude(object sender, EventArgs e) | |
| 186: | { | |
| 187: | ProjectBrowserNode node = (ProjectBrowserNode)browser.SelectedNode; | |
| 188: | ||
| 189: | if (node == null) { | |
| 190: | return; | |
| 191: | } | |
| 192: | ||
| 193: | FileInformation finfo = WorkbenchSingleton.Workbench.ProjectManager.RetrieveFileInformationForFile(node.FileName); | |
| 194: | if (finfo != null) { | |
| 195: | if (finfo.BuildAction == BuildAction.Compile) { | |
| 196: | finfo.BuildAction = BuildAction.Nothing; | |
| 197: | } else { | |
| 198: | finfo.BuildAction = BuildAction.Compile; | |
| 199: | } | |
| 200: | } | |
| 201: | } | |
| 202: | ||
| 203: | void ChangeDeployInclude(object sender, EventArgs e) | |
| 204: | { | |
| 205: | ProjectBrowserNode node = (ProjectBrowserNode)browser.SelectedNode; | |
| 206: | ||
| 207: | if (node == null) { | |
| 208: | return; | |
| 209: | } | |
| 210: | string filename = node.FileName; | |
| 211: | if (node.Project.DeployInformation.IsFileExcluded(filename)) { | |
| 212: | node.Project.DeployInformation.ExcludeFiles.Remove(filename); | |
| 213: | } else { | |
| 214: | node.Project.DeployInformation.ExcludeFiles.Add(filename); | |
| 215: | } | |
| 216: | } | |
| 217: | ||
| 218: | } | |
| 219: | ||
| 220: | ||
| 221: | public class ViewMenuBuilder : ISubmenuBuilder | |
| 222: | { | |
| 223: | ||
| 224: | public MenuItem[] BuildSubmenu(object owner) | |
| 225: | { | |
| 226: | /* IconMenuStyle iconMenuStyle = (IconMenuStyle)GlobalProperties.GetProperty("IconMenuItem.IconMenuStyle", IconMenuStyle.VSNet); | |
| 227: | int count = WorkbenchSingleton.Workbench.ViewContentCollection.Count; | |
| 228: | MenuItem[] items = new MenuItem[count]; | |
| 229: | for (int i = 0; i < count; ++i) { | |
| 230: | IViewContent content = (IViewContent)WorkbenchSingleton.Workbench.ViewContentCollection[i]; | |
| 231: | RichMenuItem item = new RichMenuItem(iconMenuStyle, content.Title, new EventHandler(ClickEvent)); | |
| 232: | item.Tag = content; | |
| 233: | item.Checked = content.Control.Visible; | |
| 234: | items[i] = item; | |
| 235: | }*/ | |
| 236: | return null; | |
| 237: | } | |
| 238: | void ClickEvent(object sender, EventArgs e) | |
| 239: | { | |
| 240: | RichMenuItem item = ((RichMenuItem)sender); | |
| 241: | if (item != null && item.Tag != null) { | |
| 242: | IViewContent content = (IViewContent)item.Tag; | |
| 243: | content.Control.Visible = !content.Control.Visible; | |
| 244: | item.Checked = content.Control.Visible; | |
| 245: | if (content.Control.Visible) { | |
| 246: | WorkbenchSingleton.Workbench.WorkbenchLayout.ShowView(content); | |
| 247: | } else { | |
| 248: | WorkbenchSingleton.Workbench.WorkbenchLayout.HideView(content); | |
| 249: | } | |
| 250: | } | |
| 251: | } | |
| 252: | } | |
| 253: | ||
| 254: | } |
This page was automatically generated by SharpDevelop.