private void CreateNewProjectTemplate()
{
if (_RootItem == null)
{
return;
}
string demofolder = "Library";
string rootpath = Path.GetDirectoryName(_RootItem.Path);
string folderpath = Path.Combine(rootpath, demofolder);
string filepath = Path.Combine(folderpath, String.Format("NewScript.csx"));
try
{
Directory.CreateDirectory(folderpath);
ProjectItem folder = new ProjectItem()
{
Name = demofolder,
Path = folderpath,
Type = ProjectItemType.Folder,
Project = this,
};
File.Write(filepath, Services.NewFile.Contents);
ProjectItem file = new ProjectItem()
{
Name = Path.GetFileNameWithoutExtension(filepath),
Path = filepath,
Type = ProjectItemType.File,
Project = this,
};
ProjectItemViewModel newfile = null;
_RootItem.AddChild(folder);
if (_RootItem.Children.Count > 0)
{
foreach (ProjectItemViewModel item in _RootItem.Children)
{
if (item.Type == ProjectItemType.Folder)
{
newfile = item.AddChild(file);
if (item.Children.Count > 0)
{
item.Children[0].IsSelected = true;
}
item.IsExpanded = true;
break;
}
}
}
if (newfile != null)
{
RaiseFileCreated(newfile);
}
}
catch (Exception ex)
{
MessageBox.ShowError("Unable to create new project template", ex);
}
}