📄 abstractproject.cs
字号:
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krger" email="mike@icsharpcode.net"/>
// <version value="$version"/>
// </file>
using System;
using System.Globalization;
using System.IO;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Reflection;
using System.ComponentModel;
using System.Xml;
using System.Windows.Forms;
using ICSharpCode.Core.Properties;
using ICSharpCode.Core.AddIns;
using ICSharpCode.SharpDevelop.Internal.Project.Collections;
using ICSharpCode.SharpDevelop.Internal.Project;
using ICSharpCode.Core.Services;
using ICSharpCode.SharpDevelop.Services;
using ICSharpCode.SharpDevelop.Gui.Components;
namespace ICSharpCode.SharpDevelop.Internal.Project
{
/// <summary>
/// External language bindings must extend this class
/// </summary>
[XmlNodeName("Project")]
public abstract class AbstractProject : LocalizedObject, IProject
{
readonly static string currentProjectFileVersion = "1.1";
readonly static string configurationNodeName = "Configuration";
protected string basedirectory = String.Empty;
[XmlAttribute("name")]
protected string projectname = "New Project";
[XmlAttribute("standardNamespace")]
protected string standardNamespace = "NewProject";
[XmlAttribute("description")]
protected string description = "";
[XmlAttribute("newfilesearch")]
protected NewFileSearch newFileSearch = NewFileSearch.None;
[XmlAttribute("enableviewstate")]
protected bool enableViewState = true;
[XmlSetAttribute(typeof(ProjectFile), "Contents")]
protected ProjectFileCollection projectFiles = new ProjectFileCollection();
[XmlSetAttribute(typeof(ProjectReference), "References")]
protected ProjectReferenceCollection projectReferencess = new ProjectReferenceCollection();
protected DeployInformation deployInformation = new DeployInformation();
FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
bool isDirty = true;
[Browsable(false)]
public bool IsDirty {
get {
return isDirty;
}
set {
isDirty = value;
}
}
[Browsable(false)]
public string BaseDirectory {
get {
return basedirectory;
}
}
[LocalizedProperty("${res:ICSharpCode.SharpDevelop.Internal.Project.Project.Name}",
Description ="${res:ICSharpCode.SharpDevelop.Internal.Project.Project.Description}")]
public string Name {
get {
return projectname;
}
set {
if (projectname != value && value != null && value.Length > 0) {
IProjectService projectService = (IProjectService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
if (!projectService.ExistsEntryWithName(value)) {
string oldName = projectname;
projectname = value;
projectService.OnRenameProject(new ProjectRenameEventArgs(this, oldName, value));
OnNameChanged(EventArgs.Empty);
}
}
}
}
[LocalizedProperty("${res:ICSharpCode.SharpDevelop.Internal.Project.Project.StandardNamespace}",
Description ="${res:ICSharpCode.SharpDevelop.Internal.Project.StandardNamespace.Description}")]
public string StandardNamespace {
get {
return standardNamespace;
}
set {
standardNamespace = value;
}
}
[LocalizedProperty("${res:ICSharpCode.SharpDevelop.Internal.Project.ProjectClass.Description}",
Description = "${res:ICSharpCode.SharpDevelop.Internal.Project.ProjectClass.Description.Description}")]
[DefaultValue("")]
public string Description {
get {
return description;
}
set {
description = value;
}
}
[Browsable(false)]
public ProjectFileCollection ProjectFiles {
get {
return projectFiles;
}
}
[Browsable(false)]
public ProjectReferenceCollection ProjectReferences {
get {
return projectReferencess;
}
}
protected ConfigurationCollection configurations = new ConfigurationCollection();
protected IConfiguration activeConfiguration = null;
[Browsable(false)]
public ConfigurationCollection Configurations {
get {
return configurations;
}
}
[LocalizedProperty("${res:ICSharpCode.SharpDevelop.Internal.Project.Project.ActiveConfiguration}",
Description = "${res:ICSharpCode.SharpDevelop.Internal.Project.Project.ActiveConfiguration.Description}")]
[TypeConverter(typeof(ProjectActiveConfigurationTypeConverter))]
public IConfiguration ActiveConfiguration {
get {
if (activeConfiguration == null && configurations.Count > 0) {
return (IConfiguration)configurations[0];
}
return activeConfiguration;
}
set {
activeConfiguration = value;
IProjectService projectService = (IProjectService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
projectService.OnActiveConfigurationChanged(new ConfigurationEventArgs(value));
if (!IsDirty) {
projectService.MarkProjectDirty(this);
isDirty = true;
}
}
}
[LocalizedProperty("${res:ICSharpCode.SharpDevelop.Internal.Project.Project.NewFileSearch}",
Description = "${res:ICSharpCode.SharpDevelop.Internal.Project.Project.NewFileSearch.Description}")]
[DefaultValue(NewFileSearch.None)]
public NewFileSearch NewFileSearch {
get {
return newFileSearch;
}
set {
newFileSearch = value;
}
}
[Browsable(false)]
public bool EnableViewState {
get {
return enableViewState;
}
set {
enableViewState = value;
}
}
[LocalizedProperty("${res:ICSharpCode.SharpDevelop.Internal.Project.Project.ProjectType}",
Description = "${res:ICSharpCode.SharpDevelop.Internal.Project.Project.ProjectType.Description}")]
public abstract string ProjectType {
get;
}
[Browsable(false)]
public DeployInformation DeployInformation {
get {
return deployInformation;
}
}
public AbstractProject()
{
configurations.ItemAdded += new EventHandler(configurationAdded);
configurations.ItemRemoved += new EventHandler(configurationRemoved);
}
void configurationAdded(object sender, EventArgs e)
{
IProjectService projectService = (IProjectService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
projectService.OnConfigurationAdded(new EventArgs());
}
void configurationRemoved(object sender, EventArgs e)
{
IProjectService projectService = (IProjectService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
projectService.OnConfigurationRemoved(new EventArgs());
}
public bool IsFileInProject(string filename)
{
string fileNameUppered = null;
try {
fileNameUppered = Path.GetFullPath(filename).ToUpper();
}
catch (Exception) {
return false;
}
foreach (ProjectFile file in projectFiles) {
// WINDOWS DEPENDENCY:
if (Path.GetFullPath(file.Name).ToUpper() == fileNameUppered) {
return true;
}
}
return false;
}
public bool IsCompileable(string fileName)
{
LanguageBindingService languageBindingService = (LanguageBindingService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(LanguageBindingService));
return languageBindingService.GetBindingPerLanguageName(ProjectType).CanCompile(fileName);
}
public void SearchNewFiles()
{
if (newFileSearch == NewFileSearch.None) {
return;
}
StringCollection newFiles = new StringCollection();
StringCollection collection = fileUtilityService.SearchDirectory(basedirectory, "*");
foreach (string file in collection) {
string extension = Path.GetExtension(file).ToUpper();
if (!IsFileInProject(file) &&
extension != ".SCC" && // source safe control files -- Svante Lidmans
extension != ".DLL" &&
extension != ".PDB" &&
extension != ".EXE" &&
extension != ".CMBX" &&
extension != ".PRJX" &&
!Path.GetDirectoryName(file).EndsWith("CVS") &&
!Path.GetDirectoryName(file).EndsWith(".svn") &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -