| 1: | // RunCommands.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.IO; | |
| 20: | using System.Threading; | |
| 21: | using System.Drawing; | |
| 22: | using System.Drawing.Printing; | |
| 23: | using System.Collections; | |
| 24: | using System.ComponentModel; | |
| 25: | using System.Windows.Forms; | |
| 26: | using System.Diagnostics; | |
| 27: | ||
| 28: | using Core.AddIns; | |
| 29: | using Core.Util; | |
| 30: | using Core.Properties; | |
| 31: | using Core.Gui; | |
| 32: | using Core.Gui.Creators; | |
| 33: | using System.CodeDom.Compiler; | |
| 34: | ||
| 35: | using SharpDevelop.Gui; | |
| 36: | using SharpDevelop.Internal.Project; | |
| 37: | using SharpDevelop.Gui.Dialogs; | |
| 38: | using SharpDevelop.WorkbenchManager; | |
| 39: | ||
| 40: | namespace SharpDevelop.Base.Commands { | |
| 41: | ||
| 42: | public class Compile : AbstractMenuCommand | |
| 43: | { | |
| 44: | public override void Run() | |
| 45: | { | |
| 46: | if (WorkbenchSingleton.Workbench.CurrentOpenCombine != null) { | |
| 47: | WorkbenchSingleton.Workbench.ProjectManager.CompileCombine(); | |
| 48: | ||
| 49: | ||
| 50: | if (WorkbenchSingleton.Workbench.TaskManager.Warnings + | |
| 51: | WorkbenchSingleton.Workbench.TaskManager.Errors == 0) { | |
| 52: | ||
| 53: | WorkbenchSingleton.Workbench.StatusBarManager.SetMessage("${res:MainWindow.StatusBar.SuccessfulMessage}"); | |
| 54: | } else { | |
| 55: | StringParser.Properties["Errors"] = WorkbenchSingleton.Workbench.TaskManager.Errors.ToString(); | |
| 56: | StringParser.Properties["Warnings"] = WorkbenchSingleton.Workbench.TaskManager.Warnings.ToString(); | |
| 57: | WorkbenchSingleton.Workbench.StatusBarManager.SetMessage("${res:MainWindow.StatusBar.ErrorWarningsMessage}"); | |
| 58: | } | |
| 59: | } else { | |
| 60: | if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { | |
| 61: | ILanguageBinding binding = LanguageBindingManager.GetBindingPerFileName(WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName); | |
| 62: | ||
| 63: | if (binding != null) { | |
| 64: | if (binding == null || !binding.CanCompile(WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName)) { | |
| 65: | MessageBox.Show("Language binding " + binding.Language + " can't compile " + WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
| 66: | } else { | |
| 67: | new SaveFile().Run(); | |
| 68: | ICompilerResult res = binding.CompileFile(WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName); | |
| 69: | WorkbenchSingleton.Workbench.TaskManager.Tasks.Clear(); | |
| 70: | foreach (CompilerError err in res.CompilerResults.Errors) { | |
| 71: | WorkbenchSingleton.Workbench.TaskManager.Tasks.Add(new Task(null, err)); | |
| 72: | } | |
| 73: | WorkbenchSingleton.Workbench.TaskManager.CompilerOutput = res.CompilerOutput; | |
| 74: | WorkbenchSingleton.Workbench.TaskManager.NotifyTaskChange(); | |
| 75: | } | |
| 76: | } else { | |
| 77: | MessageBox.Show("No source file for compilation found. Please save unsaved files", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
| 78: | } | |
| 79: | } | |
| 80: | } | |
| 81: | } | |
| 82: | } | |
| 83: | public class CompileAll : AbstractMenuCommand | |
| 84: | { | |
| 85: | public override void Run() | |
| 86: | { | |
| 87: | if (WorkbenchSingleton.Workbench.CurrentOpenCombine != null) { | |
| 88: | ||
| 89: | WorkbenchSingleton.Workbench.ProjectManager.CompileAll(); | |
| 90: | ||
| 91: | if (WorkbenchSingleton.Workbench.TaskManager.Warnings + | |
| 92: | WorkbenchSingleton.Workbench.TaskManager.Errors == 0) { | |
| 93: | ||
| 94: | WorkbenchSingleton.Workbench.StatusBarManager.SetMessage("${res:MainWindow.StatusBar.SuccessfulMessage}"); | |
| 95: | } else { | |
| 96: | StringParser.Properties["Errors"] = WorkbenchSingleton.Workbench.TaskManager.Errors.ToString(); | |
| 97: | StringParser.Properties["Warnings"] = WorkbenchSingleton.Workbench.TaskManager.Warnings.ToString(); | |
| 98: | WorkbenchSingleton.Workbench.StatusBarManager.SetMessage("${res:MainWindow.StatusBar.ErrorWarningsMessage}"); | |
| 99: | } | |
| 100: | } else { | |
| 101: | if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { | |
| 102: | ILanguageBinding binding = LanguageBindingManager.GetBindingPerFileName(WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName); | |
| 103: | ||
| 104: | if (binding != null) { | |
| 105: | if (binding == null || !binding.CanCompile(WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName)) { | |
| 106: | MessageBox.Show("Language binding " + binding.Language + " can't compile " + WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
| 107: | } else { | |
| 108: | new SaveFile().Run(); | |
| 109: | ICompilerResult res = binding.CompileFile(WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName); | |
| 110: | WorkbenchSingleton.Workbench.TaskManager.Tasks.Clear(); | |
| 111: | foreach (CompilerError err in res.CompilerResults.Errors) { | |
| 112: | WorkbenchSingleton.Workbench.TaskManager.Tasks.Add(new Task(null, err)); | |
| 113: | } | |
| 114: | WorkbenchSingleton.Workbench.TaskManager.CompilerOutput = res.CompilerOutput; | |
| 115: | WorkbenchSingleton.Workbench.TaskManager.NotifyTaskChange(); | |
| 116: | } | |
| 117: | } else { | |
| 118: | MessageBox.Show("No source file for compilation found. Please save unsaved files", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
| 119: | } | |
| 120: | } | |
| 121: | } | |
| 122: | } | |
| 123: | } | |
| 124: | ||
| 125: | public class RunCommand : AbstractMenuCommand | |
| 126: | { | |
| 127: | public override void Run() | |
| 128: | { | |
| 129: | WorkbenchSingleton.Workbench.StatusBarManager.SetMessage("${res:MainWindow.StatusBar.ExecutingMessage}"); | |
| 130: | if (WorkbenchSingleton.Workbench.CurrentOpenCombine != null) { | |
| 131: | ||
| 132: | if (WorkbenchSingleton.Workbench.ProjectManager.NeedsCompiling) { | |
| 133: | WorkbenchSingleton.Workbench.ProjectManager.CompileCombine(); | |
| 134: | ||
| 135: | if (WorkbenchSingleton.Workbench.TaskManager.Warnings + | |
| 136: | WorkbenchSingleton.Workbench.TaskManager.Errors == 0) { | |
| 137: | WorkbenchSingleton.Workbench.CurrentOpenCombine.Execute(); | |
| 138: | } | |
| 139: | } else { | |
| 140: | WorkbenchSingleton.Workbench.CurrentOpenCombine.Execute(); | |
| 141: | } | |
| 142: | } else { | |
| 143: | if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { | |
| 144: | new Compile().Run(); | |
| 145: | if (WorkbenchSingleton.Workbench.TaskManager.Warnings + | |
| 146: | WorkbenchSingleton.Workbench.TaskManager.Errors == 0) { | |
| 147: | ILanguageBinding binding = LanguageBindingManager.GetBindingPerFileName(WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName); | |
| 148: | if (binding != null) { | |
| 149: | binding.Execute(WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.WindowContent.ContentName); | |
| 150: | } else { | |
| 151: | MessageBox.Show("No runnable executable found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
| 152: | } | |
| 153: | } | |
| 154: | } | |
| 155: | } | |
| 156: | WorkbenchSingleton.Workbench.StatusBarManager.SetMessage("${res:MainWindow.StatusBar.ReadyMessage}"); | |
| 157: | } | |
| 158: | } | |
| 159: | } |
This page was automatically generated by SharpDevelop.