📄 newprojectdialog.cs
字号:
// NewProjectDialog.cs
// Copyright (C) 2001 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 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 SharpDevelop.Gui;
using SharpDevelop.Internal.Modules;
using SharpDevelop.Internal.Project;
using SharpDevelop.Internal.Templates;
using SharpDevelop.Tool.Data;
using SharpDevelop.Tool.Function;
using SharpDevelop.Tool.Text;
namespace SharpDevelop.Gui.Dialogs {
/// <summary>
/// This class displays a new project dialog and sets up & creates a a new project,
/// the project types are described in an XML options file
/// </summary>
public class NewProjectDialog : Form
{
Container components = new System.ComponentModel.Container();
TextBox solutionnametextbox = new TextBox();
TextBox nametextbox = new TextBox();
ComboBox locationcombobox = new ComboBox();
Label label1 = new Label();
Label label2 = new Label();
Label label4 = new Label();
Label label5 = new Label();
Label label6 = new Label();
Label label7 = new Label();
Label descriptionlabel = new Label();
Label createdinlabel = new Label();
Button browsebutton = new Button();
Button helpbutton = new Button();
Button cancelbutton = new Button();
Button okbutton = new Button();
CheckBox checkBox1 = new CheckBox();
RadioButton smalliconbutton = new RadioButton();
RadioButton largeiconbutton = new RadioButton();
ListView templateview = new ListView();
TreeView projecttypetree = new TreeView();
ArrayList alltemplates = new ArrayList();
ArrayList categories = new ArrayList();
Hashtable icons = new Hashtable();
MainWindow window;
ToolTip tooltip;
public NewProjectDialog(MainWindow window)
{
InitializeComponent();
this.window = window;
this.Owner = window;
InitializeTemplates();
InitializeView();
projecttypetree.Select();
locationcombobox.Text = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "\\SharpDevelop Projects";
StartPosition = FormStartPosition.CenterParent;
Icon = null;
}
void InitializeView()
{
ImageList smalllist = new ImageList();
ImageList imglist = new ImageList();
imglist.ImageSize = new Size(32, 32);
smalllist.ImageSize = new Size(16, 16);
smalllist.Images.Add(Resource.GetBitmap("Icons.32x32.EmptyProjectIcon"));
imglist.Images.Add(Resource.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 = FileUtility.GetBitmap(entry.Key.ToString());
if (bitmap != null) {
smalllist.Images.Add(bitmap);
imglist.Images.Add(bitmap);
tmp[entry.Key] = ++i;
} else
Console.WriteLine("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];
}
templateview.LargeImageList = imglist;
templateview.SmallImageList = smalllist;
InsertCategories(null, categories);
if (categories.Count > 0)
projecttypetree.SelectedNode = (TreeNode)projecttypetree.Nodes[0];
}
void InsertCategories(TreeNode node, ArrayList catarray)
{
foreach (Category cat in catarray) {
if (node == null) {
projecttypetree.Nodes.Add(cat);
} else {
node.Nodes.Add(cat);
}
InsertCategories(cat, cat.Categories);
}
}
// TODO : insert sub categories
Category GetCategory(string categoryname)
{
foreach (Category category in categories) {
if (category.Text == categoryname)
return category;
}
Category newcategory = new Category(categoryname);
categories.Add(newcategory);
return newcategory;
}
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"
Category cat = GetCategory(titem.Template.Category);
cat.Templates.Add(titem);
if (cat.Templates.Count == 1)
titem.Selected = true;
alltemplates.Add(titem);
}
}
void CategoryChange(object sender, TreeViewEventArgs e)
{
templateview.Items.Clear();
if (projecttypetree.SelectedNode != null) {
foreach (TemplateItem item in ((Category)projecttypetree.SelectedNode).Templates) {
templateview.Items.Add(item);
}
}
}
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)
{
solutionnametextbox.ReadOnly = !checkBox1.Checked;
if (solutionnametextbox.ReadOnly) { // unchecked created own directory for solution
NameTextChanged(null, null); // set the value of the solutionnametextbox to nametextbox
}
}
void NameTextChanged(object sender, EventArgs e)
{
if (!checkBox1.Checked)
solutionnametextbox.Text = nametextbox.Text;
}
string ProjectSolution {
get {
string name = "";
if (checkBox1.Checked)
name += '\\' + solutionnametextbox.Text;
return ProjectLocation + name;
}
}
string ProjectLocation {
get {
string location = locationcombobox.Text.TrimEnd( new char[] { '\\' });
string name = nametextbox.Text;
return location + '\\' + name;
}
}
// TODO : Format the text
void PathChanged(object sender, EventArgs e)
{
createdinlabel.Text = Resource.GetString("Dialog.NewProject.ProjectAtDescription") + ProjectSolution;
}
void IconSizeChange(object sender, EventArgs e)
{
templateview.View = smalliconbutton.Checked ? View.List : View.LargeIcon;
}
void OpenEvent(object sender, EventArgs e)
{
if (templateview.SelectedItems.Count == 1) {
if (!locationcombobox.Text.Equals("") && !solutionnametextbox.Text.Equals("")) {
TemplateItem item = (TemplateItem)templateview.SelectedItems[0];
System.IO.Directory.CreateDirectory(ProjectSolution);
ISdLanguageModule languageinfo = ModuleManager.GetModulePerLanguageName(item.Template.LanguageName).LanguageModule;
if (languageinfo == null || languageinfo.ProjectCreator == null) {
MessageBox.Show("Can't create project with type :" + item.Template.LanguageName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
ProjectCreateInformation cinfo = new ProjectCreateInformation();
cinfo.Solution = ProjectSolution;
cinfo.Location = ProjectLocation;
cinfo.Description = item.Template.Description;
cinfo.Name = nametextbox.Text;
cinfo.ProjectTemplate = item.Template;
ISdProject project = languageinfo.ProjectCreator.CreateProject(cinfo);
foreach (FileDescriptionTemplate file in item.Template.ProjectFiles) {
string filename = ProjectSolution + "\\" + StringParser.Parse(file.Name, new string[,] { {"PROJECT", nametextbox.Text}});
project.Files.Add(filename);
StreamWriter sr = File.CreateText(filename);
sr.Write(StringParser.Parse(file.Content, new string[,] { {"PROJECT", nametextbox.Text}, {"FILE", filename}}));
sr.Close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -