⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 run.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
// Run.cs
// Copyright (C) 2000 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using Microsoft.Win32;
using System;
using System.Collections;
using System.IO;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using System.CodeDom.Compiler;
using System.Xml;
using System.Reflection;

using SharpDevelop.Actions;
using SharpDevelop.Gui;
using SharpDevelop.Gui.Dialogs;
using SharpDevelop.Gui.Window;
using SharpDevelop.Tool.Data;
using SharpDevelop.Internal.Project;
using SharpDevelop.Internal.Modules;
using SharpDevelop.Internal.Messages;

namespace SharpDevelop.Actions.Menu {
	
	public class Compile : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			try {
				CompilerResults res = null;
				
				// save all open files
				SaveAll sa = new SaveAll();
				sa.Execute(executor);
				
				executor.Main.StatusBarText = "Compiling";
				
				ContentWindow window = executor.Main.ActiveContentWindow;
				
				if (!executor.Main.ProjectMode && window.Untitled) {
					MessageBox.Show("you must first save the file\nbefore you can compile.", "Warning",
								MessageBoxButtons.OK, MessageBoxIcon.Warning);
					return;
				}
				
				foreach (ContentWindow cwindow in executor.Main.MdiChildren) {
		    		if (cwindow.HasTextArea) {
		    			cwindow.TextArea.ErrorDrawer.ClearErrors();
		    		}
		    	}
		    	
				SharpDevelop.Internal.Modules.Module module      = executor.Main.ProjectMode ? ModuleManager.GetModulePerLanguageName(executor.Main.ProjectBrowser.Project.ProjectType) : 
					                  (window == null ? null : ModuleManager.GetModulePerFileName(window.FileName));
				ISdCompiler csc  = (module == null || module.LanguageModule == null) ? null : module.LanguageModule.Compiler;
				Console.WriteLine("languagemodule : " + module.LanguageModule);
				if (csc == null) {
					MessageBox.Show("can't find specific compiler", "Can't compile",
								MessageBoxButtons.OK, MessageBoxIcon.Warning);
					return;
				}
				
				if (executor.Main.ProjectMode) {
					foreach (ISdProject project in executor.Main.ProjectBrowser.Combine.Projects) {
						res = csc.CompileProject(project);
						executor.Main.ShowErrors(res); // , project.WorkingDirectory
						executor.Main.CompilerResultView.ShowResults(res, project.WorkingDirectory);
						if (res.Errors.Count != 0)
							break;
					}
				} else {
					if (window != null && window.HasTextArea) {
						res = csc.CompileFile(window.FileName);
						executor.Main.ShowErrors(res); // Path.GetPathRoot(window.FileName)
						executor.Main.CompilerResultView.ShowResults(res, Path.GetPathRoot(window.FileName));
					}
				}
				if (res.Errors.Count == 0) {
					executor.Main.StatusBarText = "Successful";
					executor.Main.ShouldRecompile = false;
					executor.Main.HideOutputWindow();
				} else {
					executor.Main.StatusBarText = executor.Main.CompilerResultView.Errors + " Errors, " + executor.Main.CompilerResultView.Warnings + " Warnings.";
					executor.Main.ShouldRecompile = true;
					executor.Main.ShowOutputWindow();
				}
			} catch (Exception ex) {
				MessageBox.Show(ex.ToString(), "Can't compile",
								MessageBoxButtons.OK, MessageBoxIcon.Warning);
			}
		}
	}
	
	public class Run : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (!executor.Main.ProjectMode && (window == null || !window.HasTextArea)) 
				return;
			
			if (executor.Main.ShouldRecompile) {
				Compile comp = new Compile();
				comp.Execute(executor);
			}
			
			if (!executor.Main.ProjectMode && window.Untitled) {
					MessageBox.Show("you must first save & compile the file\nbefore you can execute the program.", "Warning",
								MessageBoxButtons.OK, MessageBoxIcon.Warning);
				return;
			}
			
			executor.Main.StatusBarText = "Executing";
			
			ISdLanguageModule module = executor.Main.ProjectMode ? ModuleManager.GetModulePerLanguageName(executor.Main.ProjectBrowser.Project.ProjectType).LanguageModule : (window == null ? null : ModuleManager.GetModulePerFileName(window.FileName).LanguageModule);
			
			if (executor.Main.ProjectMode) {
				module.Execute(executor.Main, executor.Main.ProjectBrowser.Project);
			} else {
				if (window != null && window.HasTextArea) {
					string filename = window.FileName;
					module.Execute(executor.Main, filename);
				}
			}
			executor.Main.StatusBarText = "Ready";
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -