📄 newprojectdialog.cs
字号:
}
void IconSizeChange(object sender, EventArgs e)
{
((ListView)ControlDictionary["templateListView"]).View = ((RadioButton)ControlDictionary["smallIconsRadioButton"]).Checked ? View.List : View.LargeIcon;
}
public bool IsFilenameAvailable(string fileName)
{
return true;
}
public void SaveFile(IProject project, string filename, string content, bool showFile)
{
project.ProjectFiles.Add(new ProjectFile(filename));
StreamWriter sr = File.CreateText(filename);
sr.Write(stringParserService.Parse(content, new string[,] { {"PROJECT", ((TextBox)ControlDictionary["nameTextBox"]).Text}, {"FILE", Path.GetFileName(filename)}}));
sr.Close();
if (showFile) {
string longfilename = fileUtilityService.GetDirectoryNameWithSeparator(ProjectSolution) + stringParserService.Parse(filename, new string[,] { {"PROJECT", ((TextBox)ControlDictionary["nameTextBox"]).Text}});
IFileService fileService = (IFileService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IFileService));
fileService.OpenFile(longfilename);
}
}
public string NewProjectLocation;
public string NewCombineLocation;
void OpenEvent(object sender, EventArgs e)
{
PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
if (((TreeView)ControlDictionary["categoryTreeView"]).SelectedNode != null) {
propertyService.SetProperty("Dialogs.NewProjectDialog.LastSelectedCategory", ((TreeView)ControlDictionary["categoryTreeView"]).SelectedNode.Text);
propertyService.SetProperty("Dialogs.NewProjectDialog.LargeImages", ((RadioButton)ControlDictionary["largeIconsRadioButton"]).Checked);
}
FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
string solution = ((TextBox)ControlDictionary["solutionNameTextBox"]).Text;
string name = ((TextBox)ControlDictionary["nameTextBox"]).Text;
string location = ((TextBox)ControlDictionary["locationTextBox"]).Text;
if (!fileUtilityService.IsValidFileName(solution) || solution.IndexOf(Path.DirectorySeparatorChar) >= 0 ||
!fileUtilityService.IsValidFileName(name) || name.IndexOf(Path.DirectorySeparatorChar) >= 0 ||
!fileUtilityService.IsValidFileName(location)) {
MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.IllegalProjectNameError}");
return;
}
propertyService.SetProperty("ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.AutoCreateProjectSubdir", ((CheckBox)ControlDictionary["autoCreateSubDirCheckBox"]).Checked);
if (((ListView)ControlDictionary["templateListView"]).SelectedItems.Count == 1 && ((TextBox)ControlDictionary["locationTextBox"]).Text.Length > 0 && ((TextBox)ControlDictionary["solutionNameTextBox"]).Text.Length > 0) {
TemplateItem item = (TemplateItem)((ListView)ControlDictionary["templateListView"]).SelectedItems[0];
try {
System.IO.Directory.CreateDirectory(ProjectSolution);
} catch (Exception) {
IMessageService messageService =(IMessageService)ServiceManager.Services.GetService(typeof(IMessageService));
messageService.ShowError("${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.CantCreateDirectoryError}");
return;
}
ProjectCreateInformation cinfo = new ProjectCreateInformation();
cinfo.CombinePath = ProjectLocation;
cinfo.ProjectBasePath = ProjectSolution;
// cinfo.Description = stringParserService.Parse(item.Template.Description);
cinfo.ProjectName = ((TextBox)ControlDictionary["nameTextBox"]).Text;
// cinfo.ProjectTemplate = item.Template;
NewCombineLocation = item.Template.CreateProject(cinfo);
if (NewCombineLocation == null || NewCombineLocation.Length == 0) {
return;
}
if (openCombine) {
item.Template.OpenCreatedCombine();
}
NewProjectLocation = Path.Combine(cinfo.ProjectBasePath, cinfo.ProjectName + ".prjx");
DialogResult = DialogResult.OK;
/*
if (item.Template.LanguageName != null && item.Template.LanguageName.Length > 0) {
}
if (item.Template.WizardPath != null) {
IProperties customizer = new DefaultProperties();
customizer.SetProperty("Template", item.Template);
customizer.SetProperty("Creator", this);
WizardDialog wizard = new WizardDialog("Project Wizard", customizer, item.Template.WizardPath);
if (wizard.ShowDialog() == DialogResult.OK) {
DialogResult = DialogResult.OK;
}
}
NewCombineLocation = fileUtilityService.GetDirectoryNameWithSeparator(ProjectLocation) + ((TextBox)ControlDictionary["nameTextBox"]).Text + ".cmbx";
if (File.Exists(NewCombineLocation)) {
DialogResult result = MessageBox.Show("Combine file " + NewCombineLocation + " already exists, do you want to overwrite\nthe existing file ?", "File already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
switch(result) {
case DialogResult.Yes:
cmb.SaveCombine(NewCombineLocation);
break;
case DialogResult.No:
break;
}
} else {
cmb.SaveCombine(NewCombineLocation);
}
} else {
MessageBox.Show(resourceService.GetString("Dialog.NewProject.EmptyProjectFieldWarning"), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
*/
}
}
void BrowseDirectories(object sender, EventArgs e)
{
// Changes Shankar
FolderDialog fd = new FolderDialog();
if (fd.DisplayDialog() == DialogResult.OK) {
((TextBox)ControlDictionary["locationTextBox"]).Text = fd.Path;
}
// End
}
// list view event handlers
void SelectedIndexChange(object sender, EventArgs e)
{
if (((ListView)ControlDictionary["templateListView"]).SelectedItems.Count == 1) {
ControlDictionary["descriptionLabel"].Text = stringParserService.Parse(((TemplateItem)((ListView)ControlDictionary["templateListView"]).SelectedItems[0]).Template.Description);
ControlDictionary["openButton"].Enabled = true;
} else {
ControlDictionary["descriptionLabel"].Text = String.Empty;
ControlDictionary["openButton"].Enabled = false;
}
}
protected void InitializeComponents()
{
base.SetupFromXml(Path.Combine(PropertyService.DataDirectory, newProjectDialogXfrm));
ImageList imglist = new ImageList();
imglist.ColorDepth = ColorDepth.Depth32Bit;
imglist.Images.Add(IconService.GetBitmap("Icons.16x16.OpenFolderBitmap"));
imglist.Images.Add(IconService.GetBitmap("Icons.16x16.ClosedFolderBitmap"));
((TreeView)ControlDictionary["categoryTreeView"]).ImageList = imglist;
((ListView)ControlDictionary["templateListView"]).DoubleClick += new EventHandler(OpenEvent);
((ListView)ControlDictionary["templateListView"]).SelectedIndexChanged += new EventHandler(SelectedIndexChange);
((TreeView)ControlDictionary["categoryTreeView"]).AfterSelect += new TreeViewEventHandler(CategoryChange);
((TreeView)ControlDictionary["categoryTreeView"]).BeforeSelect += new TreeViewCancelEventHandler(OnBeforeExpand);
((TreeView)ControlDictionary["categoryTreeView"]).BeforeExpand += new TreeViewCancelEventHandler(OnBeforeExpand);
((TreeView)ControlDictionary["categoryTreeView"]).BeforeCollapse += new TreeViewCancelEventHandler(OnBeforeCollapse);
((TextBox)ControlDictionary["solutionNameTextBox"]).TextChanged += new EventHandler(PathChanged);
((TextBox)ControlDictionary["nameTextBox"]).TextChanged += new EventHandler(NameTextChanged);
((TextBox)ControlDictionary["nameTextBox"]).TextChanged += new EventHandler(PathChanged);
((TextBox)ControlDictionary["locationTextBox"]).TextChanged += new EventHandler(PathChanged);
PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
((RadioButton)ControlDictionary["largeIconsRadioButton"]).Checked = propertyService.GetProperty("Dialogs.NewProjectDialog.LargeImages", true);
((RadioButton)ControlDictionary["largeIconsRadioButton"]).CheckedChanged += new EventHandler(IconSizeChange);
((RadioButton)ControlDictionary["largeIconsRadioButton"]).FlatStyle = FlatStyle.Standard;
((RadioButton)ControlDictionary["largeIconsRadioButton"]).Image = IconService.GetBitmap("Icons.16x16.LargeIconsIcon");
((RadioButton)ControlDictionary["smallIconsRadioButton"]).Checked = !propertyService.GetProperty("Dialogs.NewProjectDialog.LargeImages", true);
((RadioButton)ControlDictionary["smallIconsRadioButton"]).CheckedChanged += new EventHandler(IconSizeChange);
((RadioButton)ControlDictionary["smallIconsRadioButton"]).FlatStyle = FlatStyle.Standard;
((RadioButton)ControlDictionary["smallIconsRadioButton"]).Image = IconService.GetBitmap("Icons.16x16.SmallIconsIcon");
ControlDictionary["openButton"] .Click += new EventHandler(OpenEvent);
ControlDictionary["browseButton"].Click += new EventHandler(BrowseDirectories);
((CheckBox)ControlDictionary["createSeparateDirCheckBox"]).CheckedChanged += new EventHandler(CheckedChange);
((CheckBox)ControlDictionary["createSeparateDirCheckBox"]).CheckedChanged += new EventHandler(PathChanged);
((CheckBox)ControlDictionary["autoCreateSubDirCheckBox"]).CheckedChanged += new EventHandler(PathChanged);
ToolTip tooltip = new ToolTip();
tooltip.SetToolTip(ControlDictionary["largeIconsRadioButton"], StringParserService.Parse("${res:Global.LargeIconToolTip}"));
tooltip.SetToolTip(ControlDictionary["smallIconsRadioButton"], StringParserService.Parse("${res:Global.SmallIconToolTip}"));
tooltip.Active = true;
Owner = (Form)WorkbenchSingleton.Workbench;
StartPosition = FormStartPosition.CenterParent;
Icon = null;
CheckedChange(this, EventArgs.Empty);
IconSizeChange(this, EventArgs.Empty);
}
/// <summary>
/// Represents a category
/// </summary>
public class Category : TreeNode
{
ArrayList categories = new ArrayList();
ArrayList templates = new ArrayList();
string name;
public Category(string name) : base(name)
{
this.name = name;
ImageIndex = 1;
}
public string Name {
get {
return name;
}
}
public ArrayList Categories {
get {
return categories;
}
}
public ArrayList Templates {
get {
return templates;
}
}
}
/// <summary>
/// Holds a new file template
/// </summary>
public class TemplateItem : ListViewItem
{
ProjectTemplate template;
public TemplateItem(ProjectTemplate template) : base(((StringParserService)ServiceManager.Services.GetService(typeof(StringParserService))).Parse(template.Name))
{
this.template = template;
ImageIndex = 0;
}
public ProjectTemplate Template {
get {
return template;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -