| 0: | // Run.cs | |
| 1: | // Copyright (C) 2000 Mike Krueger | |
| 2: | // | |
| 3: | // This program is free software; you can redistribute it and/or modify | |
| 4: | // it under the terms of the GNU General Public License as published by | |
| 5: | // the Free Software Foundation; either version 2 of the License, or | |
| 6: | // (at your option) any later version. | |
| 7: | // | |
| 8: | // This program is distributed in the hope that it will be useful, | |
| 9: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11: | // GNU General Public License for more details. | |
| 12: | // | |
| 13: | // You should have received a copy of the GNU General Public License | |
| 14: | // along with this program; if not, write to the Free Software | |
| 15: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 16: | ||
| 17: | using Microsoft.Win32; | |
| 18: | using System; | |
| 19: | using System.Collections; | |
| 20: | using System.IO; | |
| 21: | using System.ComponentModel; | |
| 22: | using System.Windows.Forms; | |
| 23: | using System.Drawing; | |
| 24: | using System.Diagnostics; | |
| 25: | using System.CodeDom.Compiler; | |
| 26: | using System.Xml; | |
| 27: | using System.Reflection; | |
| 28: | ||
| 29: | using SharpDevelop.Actions; | |
| 30: | using SharpDevelop.Gui; | |
| 31: | using SharpDevelop.Gui.Dialogs; | |
| 32: | using SharpDevelop.Gui.Window; | |
| 33: | using SharpDevelop.Tool.Data; | |
| 34: | using SharpDevelop.Internal.Project; | |
| 35: | using SharpDevelop.Internal.Modules; | |
| 36: | using SharpDevelop.Internal.Messages; | |
| 37: | ||
| 38: | namespace SharpDevelop.Actions.Menu { | |
| 39: | ||
| 40: | public class Compile : ISdPlugin | |
| 41: | { | |
| 42: | public ISdMessageHandler MessageHandler { | |
| 43: | get { | |
| 44: | return null; | |
| 45: | } | |
| 46: | } | |
| 47: | public void Execute(ISdPluginExecutor executor) | |
| 48: | { | |
| 49: | try { | |
| 50: | ||
| 51: | // save all open files | |
| 52: | SaveAll sa = new SaveAll(); | |
| 53: | sa.Execute(executor); | |
| 54: | ||
| 55: | CompilerResults res = null; | |
| 56: | ||
| 57: | executor.Main.StatusBarText = String.Format(Resource.GetString("MainWindow.StatusBar.CompilingMessage"), " "); | |
| 58: | ||
| 59: | ContentWindow window = executor.Main.ActiveContentWindow; | |
| 60: | ||
| 61: | if (!executor.Main.ProjectMode && window.Untitled) { | |
| 62: | MessageBox.Show("you must first save the file\nbefore you can compile.", "Warning", | |
| 63: | MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
| 64: | return; | |
| 65: | } | |
| 66: | ||
| 67: | foreach (ContentWindow cwindow in executor.Main.MdiChildren) { | |
| 68: | if (cwindow.HasTextArea) { | |
| 69: | cwindow.TextArea.ErrorDrawer.ClearErrors(); | |
| 70: | } | |
| 71: | } | |
| 72: | ||
| 73: | // ModuleManager.GetModulePerLanguageName(executor.Main.ProjectBrowser.Project.ProjectType) : | |
| 74: | // (window == null ? null : ); | |
| 75: | ||
| 76: | if (executor.Main.ProjectMode) { | |
| 77: | executor.Main.ProjectBrowser.Combine.BuildAll(executor.Main); | |
| 78: | } else { | |
| 79: | SharpDevelop.Internal.Modules.Module module = ModuleManager.GetModulePerFileName(window.FileName); | |
| 80: | ||
| 81: | ICompiler csc = (module == null || module.LanguageModule == null) ? null : module.LanguageModule.Compiler; | |
| 82: | ||
| 83: | if (csc == null) { | |
| 84: | MessageBox.Show("can't find specific compiler", "Can't compile", | |
| 85: | MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
| 86: | return; | |
| 87: | } | |
| 88: | ||
| 89: | if (window != null && window.HasTextArea) { | |
| 90: | res = csc.CompileFile(window.FileName); | |
| 91: | executor.Main.CompilerMessageView.Text = csc.CompilerOutput; | |
| 92: | executor.Main.ShowErrors(res); // Path.GetPathRoot(window.FileName) | |
| 93: | executor.Main.OpenTaskView.ShowResults(res, Path.GetPathRoot(window.FileName)); | |
| 94: | } | |
| 95: | } | |
| 96: | if (executor.Main.OpenTaskView.Errors == 0 && | |
| 97: | executor.Main.OpenTaskView.Warnings == 0) { | |
| 98: | executor.Main.StatusBarText = Resource.GetString("MainWindow.StatusBar.SuccessfulMessage"); | |
| 99: | ||
| 100: | executor.Main.ShouldRecompile = false; | |
| 101: | executor.Main.HideOutputWindow(); | |
| 102: | ||
| 103: | // TODO : Hope this works :) | |
| 104: | executor.Main.ClassBrowser.Parse(executor.Main.ProjectBrowser.Combine); | |
| 105: | } else { | |
| 106: | executor.Main.StatusBarText = String.Format(Resource.GetString("MainWindow.StatusBar.ErrorWarningsMessage"), executor.Main.OpenTaskView.Errors, executor.Main.OpenTaskView.Warnings); | |
| 107: | ||
| 108: | executor.Main.ShouldRecompile = true; | |
| 109: | executor.Main.ShowOutputWindow(); | |
| 110: | } | |
| 111: | } catch (Exception ex) { | |
| 112: | MessageBox.Show(ex.ToString(), "Can't compile", | |
| 113: | MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
| 114: | } | |
| 115: | } | |
| 116: | } | |
| 117: | ||
| 118: | public class Run : ISdPlugin | |
| 119: | { | |
| 120: | public ISdMessageHandler MessageHandler { | |
| 121: | get { | |
| 122: | return null; | |
| 123: | } | |
| 124: | } | |
| 125: | public void Execute(ISdPluginExecutor executor) | |
| 126: | { | |
| 127: | ContentWindow window = executor.Main.ActiveContentWindow; | |
| 128: | if (!executor.Main.ProjectMode && (window == null || !window.HasTextArea)) | |
| 129: | return; | |
| 130: | ||
| 131: | if (executor.Main.ShouldRecompile) { | |
| 132: | Compile comp = new Compile(); | |
| 133: | comp.Execute(executor); | |
| 134: | } | |
| 135: | ||
| 136: | if (!executor.Main.ProjectMode && window.Untitled) { | |
| 137: | MessageBox.Show("you must first save & compile the file\nbefore you can execute the program.", "Warning", | |
| 138: | MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
| 139: | return; | |
| 140: | } | |
| 141: | ||
| 142: | executor.Main.StatusBarText = Resource.GetString("MainWindow.StatusBar.ExecutingMessage"); | |
| 143: | ||
| 144: | ILanguageModule module = executor.Main.ProjectMode ? null : (window == null ? null : ModuleManager.GetModulePerFileName(window.FileName).LanguageModule); | |
| 145: | ||
| 146: | if (executor.Main.ProjectMode) { | |
| 147: | Console.WriteLine("Call Execute"); | |
| 148: | executor.Main.ProjectBrowser.Combine.Execute(executor.Main); | |
| 149: | Console.WriteLine(".done"); | |
| 150: | // module.Execute(executor.Main, executor.Main.ProjectBrowser.Project); | |
| 151: | } else { | |
| 152: | if (window != null && window.HasTextArea) { | |
| 153: | string filename = window.FileName; | |
| 154: | module.Execute(executor.Main, filename); | |
| 155: | } | |
| 156: | } | |
| 157: | executor.Main.StatusBarText = Resource.GetString("Dialogs.TestEnvironment.ReadyMessage"); | |
| 158: | } | |
| 159: | } | |
| 160: | } |
This page was automatically generated by SharpDevelop.