📄 newprojectdialog.cs
字号:
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision: 1460 $</version>
// </file>
using System;
using System.Collections;
using System.IO;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Resources;
using System.Windows.Forms;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Gui.XmlForms;
namespace ICSharpCode.SharpDevelop.Project.Dialogs
{
/// <summary>
/// This class displays a new project dialog and sets up and creates a a new project,
/// the project types are described in an XML options file
/// </summary>
public class NewProjectDialog : BaseSharpDevelopForm
{
protected Container components = new System.ComponentModel.Container();
protected ArrayList alltemplates = new ArrayList();
protected ArrayList categories = new ArrayList();
protected Hashtable icons = new Hashtable();
protected bool openCombine;
public NewProjectDialog(bool openCombine)
{
StandardHeader.SetHeaders();
this.openCombine = openCombine;
InitializeComponents();
InitializeTemplates();
InitializeView();
((TreeView)ControlDictionary["categoryTreeView"]).Select();
((TextBox)ControlDictionary["locationTextBox"]).Text = PropertyService.Get("ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.DefaultPath", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "SharpDevelop Projects"));
StartPosition = FormStartPosition.CenterParent;
Icon = null;
}
public NewProjectDialog()
{
}
protected virtual void InitializeView()
{
ImageList smalllist = new ImageList();
ImageList imglist = new ImageList();
smalllist.ColorDepth = ColorDepth.Depth32Bit;
imglist.ColorDepth = ColorDepth.Depth32Bit;
imglist.ImageSize = new Size(32, 32);
smalllist.ImageSize = new Size(16, 16);
smalllist.Images.Add(ResourceService.GetBitmap("Icons.32x32.EmptyProjectIcon"));
imglist.Images.Add(ResourceService.GetBitmap("Icons.32x32.EmptyProjectIcon"));
// load the icons and set their index from the image list in the hashtable
int i = 0;
Hashtable tmp = new Hashtable(icons);
foreach (DictionaryEntry entry in icons) {
Bitmap bitmap = IconService.GetBitmap(entry.Key.ToString());
if (bitmap != null) {
smalllist.Images.Add(bitmap);
imglist.Images.Add(bitmap);
tmp[entry.Key] = ++i;
} else {
LoggingService.Warn("NewProjectDialog: can't load bitmap " + entry.Key.ToString() + " using default");
}
}
// set the correct imageindex for all templates
icons = tmp;
foreach (TemplateItem item in alltemplates) {
if (item.Template.Icon == null) {
item.ImageIndex = 0;
} else {
item.ImageIndex = (int)icons[item.Template.Icon];
}
}
((ListView)ControlDictionary["templateListView"]).LargeImageList = imglist;
((ListView)ControlDictionary["templateListView"]).SmallImageList = smalllist;
InsertCategories(null, categories);
((TreeView)ControlDictionary["categoryTreeView"]).TreeViewNodeSorter = new TemplateCategoryComparer();
((TreeView)ControlDictionary["categoryTreeView"]).Sort();
SelectLastSelectedCategoryNode(((TreeView)ControlDictionary["categoryTreeView"]).Nodes, PropertyService.Get("Dialogs.NewProjectDialog.LastSelectedCategory", "C#"));
}
void InsertCategories(TreeNode node, ArrayList catarray)
{
foreach (Category cat in catarray) {
if (node == null) {
((TreeView)ControlDictionary["categoryTreeView"]).Nodes.Add(cat);
} else {
node.Nodes.Add(cat);
}
InsertCategories(cat, cat.Categories);
}
}
protected Category GetCategory(string categoryname, string subcategoryname)
{
foreach (Category category in categories) {
if (category.Text == categoryname) {
if (subcategoryname == null) {
return category;
} else {
return GetSubcategory(category, subcategoryname);
}
}
}
Category newcategory = new Category(categoryname, TemplateCategorySortOrderFile.GetProjectCategorySortOrder(categoryname));
categories.Add(newcategory);
if (subcategoryname != null) {
return GetSubcategory(newcategory, subcategoryname);
}
return newcategory;
}
Category GetSubcategory(Category parentCategory, string name)
{
foreach (Category subcategory in parentCategory.Categories) {
if (subcategory.Text == name)
return subcategory;
}
Category newsubcategory = new Category(name, TemplateCategorySortOrderFile.GetProjectCategorySortOrder(parentCategory.Name, name));
parentCategory.Categories.Add(newsubcategory);
return newsubcategory;
}
protected virtual void InitializeTemplates()
{
foreach (ProjectTemplate template in ProjectTemplate.ProjectTemplates) {
TemplateItem titem = new TemplateItem(template);
if (titem.Template.Icon != null) {
icons[titem.Template.Icon] = 0; // "create template icon"
}
if (template.NewProjectDialogVisible == true) {
Category cat = GetCategory(StringParser.Parse(titem.Template.Category), StringParser.Parse(titem.Template.Subcategory));
cat.Templates.Add(titem);
if (cat.Templates.Count == 1)
titem.Selected = true;
}
alltemplates.Add(titem);
}
}
protected void CategoryChange(object sender, TreeViewEventArgs e)
{
((ListView)ControlDictionary["templateListView"]).Items.Clear();
if (((TreeView)ControlDictionary["categoryTreeView"]).SelectedNode != null) {
foreach (TemplateItem item in ((Category)((TreeView)ControlDictionary["categoryTreeView"]).SelectedNode).Templates) {
((ListView)ControlDictionary["templateListView"]).Items.Add(item);
}
}
this.SelectedIndexChange(sender, e);
}
void OnBeforeExpand(object sender, TreeViewCancelEventArgs e)
{
e.Node.ImageIndex = 1;
}
void OnBeforeCollapse(object sender, TreeViewCancelEventArgs e)
{
e.Node.ImageIndex = 0;
}
void CheckedChange(object sender, EventArgs e)
{
((TextBox)ControlDictionary["solutionNameTextBox"]).ReadOnly = !((CheckBox)ControlDictionary["createSeparateDirCheckBox"]).Checked;
if (((TextBox)ControlDictionary["solutionNameTextBox"]).ReadOnly) { // unchecked created own directory for solution
NameTextChanged(null, null); // set the value of the ((TextBox)ControlDictionary["solutionNameTextBox"]) to ((TextBox)ControlDictionary["nameTextBox"])
}
}
void NameTextChanged(object sender, EventArgs e)
{
if (!((CheckBox)ControlDictionary["createSeparateDirCheckBox"]).Checked) {
((TextBox)ControlDictionary["solutionNameTextBox"]).Text = ((TextBox)ControlDictionary["nameTextBox"]).Text;
}
}
string ProjectSolution {
get {
string name = String.Empty;
if (((CheckBox)ControlDictionary["createSeparateDirCheckBox"]).Checked) {
name += Path.DirectorySeparatorChar + ((TextBox)ControlDictionary["solutionNameTextBox"]).Text;
}
return ProjectLocation + name;
}
}
string ProjectLocation {
get {
string location = ((TextBox)ControlDictionary["locationTextBox"]).Text.TrimEnd('\\', '/', Path.DirectorySeparatorChar);
string name = ((TextBox)ControlDictionary["nameTextBox"]).Text;
return location + (((CheckBox)ControlDictionary["autoCreateSubDirCheckBox"]).Checked ? Path.DirectorySeparatorChar + name : "");
}
}
void PathChanged(object sender, EventArgs e)
{
string solutionPath = ProjectSolution;
try {
if (solutionPath.Length > 3 && Path.IsPathRooted(solutionPath)) {
solutionPath = solutionPath.Substring(3);
bool didCut = false;
const int maxLength = 62;
while (solutionPath.Length > maxLength && solutionPath.Length > 1) {
int idx = solutionPath.IndexOf(Path.DirectorySeparatorChar, 1);
if (idx < 0) {
break;
}
solutionPath = solutionPath.Substring(idx);
didCut = true;
}
solutionPath = ProjectSolution.Substring(0, 3) + (didCut ? "..." : "") + solutionPath;
if (solutionPath.Length > maxLength + 6) {
solutionPath = solutionPath.Substring(0, maxLength + 3) + "...";
}
}
} catch (ArgumentException) {
ControlDictionary["createInLabel"].Text = ResourceService.GetString("ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.IllegalProjectNameError").Replace("\n", " ").Replace("\r", "");
return;
}
ControlDictionary["createInLabel"].Text = ResourceService.GetString("Dialog.NewProject.ProjectAtDescription")+ " " + solutionPath;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -