static bool DoEnablePaste(ISolutionFolderNode container, IDataObject dataObject)
 {
     if (dataObject == null)
     {
         return(false);
     }
     if (dataObject.GetDataPresent(typeof(ISolutionFolder).ToString()))
     {
         string          guid           = dataObject.GetData(typeof(ISolutionFolder).ToString()).ToString();
         ISolutionFolder solutionFolder = container.Solution.GetSolutionFolder(guid);
         if (solutionFolder == null || solutionFolder == container)
         {
             return(false);
         }
         if (solutionFolder is ISolutionFolderContainer)
         {
             return(solutionFolder.Parent != container &&
                    !((ISolutionFolderContainer)solutionFolder).IsAncestorOf(container.Folder));
         }
         else
         {
             return(solutionFolder.Parent != container);
         }
     }
     return(false);
 }
        public void WriteSolutionItem(ISolutionItem item)
        {
            ISolutionFolder folder  = item as ISolutionFolder;
            IProject        project = item as IProject;

            if (folder != null)
            {
                WriteProjectHeader(ProjectTypeGuids.SolutionFolder, folder.Name, folder.Name, folder.IdGuid);
                // File items are represented as nodes in the tree, but they're actually
                // saved as properties on their containing folder.
                SolutionSection section = new SolutionSection("SolutionItems", "preProject");
                foreach (var file in folder.Items.OfType <ISolutionFileItem>())
                {
                    string location = FileUtility.GetRelativePath(basePath, file.FileName);
                    section.Add(location, location);
                }
                WriteProjectSection(section);
                writer.WriteLine("EndProject");
            }
            else if (project != null)
            {
                string location = FileUtility.GetRelativePath(basePath, project.FileName);
                WriteProjectHeader(project.TypeGuid, project.Name, location, project.IdGuid);
                foreach (var section in project.ProjectSections)
                {
                    WriteProjectSection(section);
                }
                writer.WriteLine("EndProject");
            }
        }
Example #3
0
        public virtual void AddFolder(ISolutionFolder folder)
        {
            if (string.IsNullOrEmpty(folder.IdGuid))
            {
                folder.IdGuid = Guid.NewGuid().ToString().ToUpperInvariant();
            }

            bool isNew = false;

            if (folder.Parent != null)
            {
                folder.Parent.RemoveFolder(folder);
            }
            else
            {
                // this is a new project/solution folder
                isNew = true;
            }
            if (isNew)
            {
                this.ParentSolution.BeforeAddFolderToSolution(folder);
            }
            folder.Parent = this;
            Folders.Add(folder);
            if (isNew)
            {
                this.ParentSolution.AfterAddFolderToSolution(folder);
            }
        }
Example #4
0
 public void FireSolutionFolderRemoved(ISolutionFolder solutionFolder)
 {
     if (SolutionFolderRemoved != null)
     {
         SolutionFolderRemoved(this, new SolutionFolderEventArgs(solutionFolder));
     }
 }
Example #5
0
        /// <summary>
        /// Create, if necessary, the solution folder for the Blackboard
        /// Adds an empty Blackboard data file when the folder is created
        /// </summary>
        /// <param name="solution">The current VS Solution abstraction from import</param>
        /// <returns>Path to Solution</returns>
        private string ProcessSolutionFolder(ISolution solution)
        {
            ISolutionFolder blackboardFolder     = null;
            bool            solutionFolderExists = false;

            foreach (var item in solution.Items)
            {
                if (item.Name == solutionFolderName)
                {
                    solutionFolderExists = true;
                    blackboardFolder     = item as ISolutionFolder;
                    break;
                }
            }

            if (!solutionFolderExists)
            {
                blackboardFolder = solution.CreateSolutionFolder(solutionFolderName);
                blackboardFolder.AddContent(emptyDictionary, solution.Name + defaultBlackboardFileNameBase, false, false);
            }
            else
            {
                //
                // Ok, the solution folder exists, let's see if our file exists
                //
                string bbFileName = Path.Combine(Path.GetDirectoryName(solution.PhysicalPath), solution.Name + defaultBlackboardFileNameBase);
                if (!File.Exists(bbFileName))
                {
                    blackboardFolder.AddContent(emptyDictionary, solution.Name + defaultBlackboardFileNameBase, false, false);
                }
            }

            return(Path.Combine(Path.GetDirectoryName(solution.PhysicalPath), solution.Name + defaultBlackboardFileNameBase));
        }
 public WelcomePageImpl(ISolutionFolder solutionFolder, IDefaultDocumentPolicy defaultDocumentPolicy, IItemOperations itemOperations, IWebServer server)
 {
     _solutionFolder = solutionFolder;
     _itemOperations = itemOperations;
     _defaultDocumentPolicy = defaultDocumentPolicy;
     _server = server;
 }
		internal static string GetInitialDirectorySuggestion(ISolutionFolder solutionFolder)
		{
			// Detect the correct folder to place the new project in:
			int projectCount = 0;
			string initialDirectory = null;
			foreach (ISolutionItem folderEntry in solutionFolder.Items) {
				IProject project = folderEntry as IProject;
				if (project != null) {
					if (projectCount == 0)
						initialDirectory = project.Directory;
					else
						initialDirectory = FileUtility.GetCommonBaseDirectory(initialDirectory, project.Directory);
					projectCount++;
				}
			}
			if (initialDirectory != null) {
				if (projectCount == 1) {
					return FileUtility.GetAbsolutePath(initialDirectory, "..");
				} else {
					return initialDirectory;
				}
			} else {
				return solutionFolder.ParentSolution.Directory;
			}
		}
Example #8
0
        public static void DoPaste(ISolutionFolderNode folderNode)
        {
            if (!DoEnablePaste(folderNode))
            {
                LoggingService.Warn("SolutionFolderNode.DoPaste: Pasting was not enabled.");
                return;
            }

            ExtTreeNode folderTreeNode = (ExtTreeNode)folderNode;
            IDataObject dataObject     = ClipboardWrapper.GetDataObject();

            if (dataObject.GetDataPresent(typeof(ISolutionFolder).ToString()))
            {
                string          guid           = dataObject.GetData(typeof(ISolutionFolder).ToString()).ToString();
                ISolutionFolder solutionFolder = folderNode.Solution.GetSolutionFolder(guid);
                if (solutionFolder != null)
                {
                    folderNode.Container.AddFolder(solutionFolder);
                    ExtTreeView treeView = (ExtTreeView)folderTreeNode.TreeView;
                    foreach (ExtTreeNode node in treeView.CutNodes)
                    {
                        ExtTreeNode oldParent = node.Parent as ExtTreeNode;
                        node.Remove();

                        node.AddTo(folderTreeNode);
                        if (oldParent != null)
                        {
                            oldParent.Refresh();
                        }
                    }
                    ProjectService.SaveSolution();
                }
            }
            folderTreeNode.Expand();
        }
 static bool DoEnablePaste(ISolutionFolder container, System.Windows.IDataObject dataObject)
 {
     if (dataObject == null)
     {
         return(false);
     }
     if (dataObject.GetDataPresent(typeof(ISolutionItem).ToString()))
     {
         Guid          guid         = Guid.Parse(dataObject.GetData(typeof(ISolutionItem).ToString()).ToString());
         ISolutionItem solutionItem = container.ParentSolution.GetItemByGuid(guid);
         if (solutionItem == null || solutionItem == container)
         {
             return(false);
         }
         if (solutionItem is ISolutionFolder)
         {
             return(solutionItem.ParentFolder != container &&
                    !((ISolutionFolder)solutionItem).IsAncestorOf(container));
         }
         else
         {
             return(solutionItem.ParentFolder != container);
         }
     }
     return(false);
 }
        public virtual void AddFolder(string folderDirectory)
        {
            if (folderDirectory == null)
            {
                throw new ArgumentNullException(nameof(folderDirectory));
            }

            var solutionDirectory = SolutionDirectory;

            if (!folderDirectory.StartsWith(solutionDirectory))
            {
                throw new ArgumentOutOfRangeException(nameof(folderDirectory), "Required to be in solution directory - " + solutionDirectory);
            }

            var subPath = folderDirectory.Substring(solutionDirectory.Length);

            var subDirectories = subPath.Split(Path.DirectorySeparatorChar).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

            ISolutionFolder carryProject = null;

            foreach (var subFolder in subDirectories)
            {
                if (carryProject == null)
                {
                    carryProject = AddSolutionFolder(subFolder);
                }
                else
                {
                    carryProject = carryProject.AddSubFolder(subFolder);
                }
            }
            carryProject.CopyFilesIntoSolutionFolder(folderDirectory);
        }
Example #11
0
		public virtual void AddFolder(ISolutionFolder folder)
		{
			if (folder.Parent != null) {
				folder.Parent.RemoveFolder(folder);
			}
			folder.Parent = this;
			Folders.Add(folder);
		}
Example #12
0
        protected virtual ISolutionItem CreateSolutionItem(ISolutionFolder parentFolder, IItemPath path, IItemProperties properties)
        {
            Assert.ValidateReference(parentFolder);
            Assert.ValidateReference(path);
            Assert.ValidateReference(properties);

            return(new SolutionItem(path, parentFolder, properties));
        }
Example #13
0
        protected SolutionTreeNode(ISolutionFolder parent, ITreeNodePath path, ITreeNodeProperties properties)
        {
            this.Parent     = parent;
            this.Path       = path;
            this.Properties = properties;

            UpdateName();
            InitIsDirty();
        }
Example #14
0
 public void Initialize()
 {
     this.guidanceManager = VsIdeTestHostContext.ServiceProvider.GetService<IGuidanceManager>();
     this.guidanceManager.ActiveGuidanceExtension = null;
     this.launchService = VsIdeTestHostContext.ServiceProvider.GetService<IShortcutLaunchService>();
     this.solution = VsIdeTestHostContext.ServiceProvider.GetService<ISolution>();
     this.solution.Open(this.PathTo(@"Runtime.IntegrationTests.Content\Shortcuts\Shortcuts.sln"));
     this.solutionItemsFolder = this.solution.SolutionFolders.Single(sf => sf.Name == NuPattern.VisualStudio.Solution.SolutionExtensions.SolutionItemsFolderName);
 }
Example #15
0
 public void Initialize()
 {
     this.guidanceManager = VsIdeTestHostContext.ServiceProvider.GetService <IGuidanceManager>();
     this.guidanceManager.ActiveGuidanceExtension = null;
     this.launchService = VsIdeTestHostContext.ServiceProvider.GetService <IShortcutLaunchService>();
     this.solution      = VsIdeTestHostContext.ServiceProvider.GetService <ISolution>();
     this.solution.Open(this.PathTo(@"Runtime.IntegrationTests.Content\Shortcuts\Shortcuts.sln"));
     this.solutionItemsFolder = this.solution.SolutionFolders.Single(sf => sf.Name == NuPattern.VisualStudio.Solution.SolutionExtensions.SolutionItemsFolderName);
 }
Example #16
0
 public virtual void AddFolder(ISolutionFolder folder)
 {
     if (folder.Parent != null)
     {
         folder.Parent.RemoveFolder(folder);
     }
     folder.Parent = this;
     Folders.Add(folder);
 }
        public NewProjectDialogViewModel(ISolutionFolder solutionFolder) : this()
        {
            _solutionFolder = solutionFolder;

            if (_solutionFolder != null)
            {
                location = _solutionFolder.Solution.CurrentDirectory;
            }
        }
Example #18
0
        protected void AddExpandedFolder(ISolutionFolder folder)
        {
            Assert.ValidateReference(folder);

            if (!ExpandedFolderList.Contains(folder))
            {
                ExpandedFolderList.Add(folder);
            }
        }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SolutionFolder"/> class.
        /// </summary>
        /// <param name="parent">The parent folder path.</param>
        /// <param name="path">The folder path.</param>
        /// <param name="properties">The folder properties.</param>
        public SolutionFolder(ISolutionFolder parent, IFolderPath path, IFolderProperties properties)
            : base(parent, path, properties)
        {
            if (parent == null)
            {
                return;
            }

            ChildrenInternal = new SolutionTreeNodeCollection(this, parent.NodeComparer);
        }
Example #20
0
        public MoveOperation(ISolutionRoot root, ITreeNodePath path, ISolutionFolder oldParent, ISolutionFolder newParent)
            : base(root)
        {
            Assert.ValidateReference(path);
            Assert.ValidateReference(oldParent);
            Assert.ValidateReference(newParent);

            this.Path      = path;
            this.OldParent = oldParent;
            this.NewParent = newParent;
        }
 internal static void MoveItem(ISolutionItem solutionItem, ISolutionFolder folder)
 {
     // Use a batch update to move the item without causing projects
     // be removed from the solution (and thus disposed).
     using (solutionItem.ParentFolder.Items.BatchUpdate()) {
         using (folder.Items.BatchUpdate()) {
             solutionItem.ParentFolder.Items.Remove(solutionItem);
             folder.Items.Add(solutionItem);
         }
     }
 }
Example #22
0
        public override void Redo()
        {
            Add(PathTable);
            base.Redo();

            ISolutionFolder ParentFolder = Root.FindTreeNode(DestinationFolderPath) as ISolutionFolder;

            Assert.ValidateReference(ParentFolder);

            AddExpandedFolder(ParentFolder);
        }
Example #23
0
        private static ISolutionFolder CreateFolderPath(ISolutionFolder rootFolder, string folderPath)
        {
            var paths = folderPath.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var path in paths)
            {
                rootFolder = rootFolder.CreateSolutionFolder(path);
            }

            return(rootFolder);
        }
Example #24
0
        internal static void SetParentInternal(this ISolutionItem item, ISolutionFolder parent)
        {
            if (item.Parent != null)
            {
                item.Parent.Items.Remove(item);
            }

            item.Parent = parent;

            parent?.Items.InsertSorted(item);
        }
Example #25
0
 public virtual void RemoveFolder(ISolutionFolder folder)
 {
     for (int i = 0; i < Folders.Count; ++i)
     {
         if (folder.IdGuid == Folders[i].IdGuid)
         {
             Folders.RemoveAt(i);
             break;
         }
     }
 }
        /// <summary>
        /// Adds a folder to the list.
        /// </summary>
        /// <param name="folder">The new folder.</param>
        protected void AddExpandedFolder(ISolutionFolder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException(nameof(folder));
            }

            if (!ExpandedFolderList.Contains(folder))
            {
                ExpandedFolderList.Add(folder);
            }
        }
Example #27
0
        private string BuildAndEnsureDirectoryStructure(ISolutionFolder solutionFolder)
        {
            var parentPath = System.IO.Path.HasExtension(Parent.PhysicalPath) ?
                System.IO.Path.GetDirectoryName(Parent.PhysicalPath) :
                Parent.PhysicalPath;

            var path = System.IO.Path.Combine(parentPath, this.Name);

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            return path;
        }
Example #28
0
        /// <summary>
        /// Creates a URI for the given solution folder.
        /// </summary>
        /// <remarks>solution://root/SolutionFolderPath</remarks>
        private Uri CreateSolutionFolderUri(ISolutionFolder solutionFolder)
        {
            Guard.NotNull(() => solutionFolder, solutionFolder);

            // Use full solution path format
            var builder = new StringBuilder()
                          .Append(this.UriScheme)
                          .Append(Uri.SchemeDelimiter)
                          .Append(RootPrefix)
                          .Append(MakeUriPath(solutionFolder.GetLogicalPath()));

            return(new Uri(builder.ToString()));
        }
Example #29
0
 static void HandleRemovedSolutionFolder(ISolutionFolder folder)
 {
     if (folder is IProject)
     {
         OpenSolution.RemoveProjectConfigurations(folder.IdGuid);
         ParserService.RemoveProjectContentForRemovedProject((IProject)folder);
     }
     if (folder is ISolutionFolderContainer)
     {
         // recurse into child folders that were also removed
         ((ISolutionFolderContainer)folder).Folders.ForEach(HandleRemovedSolutionFolder);
     }
 }
Example #30
0
        public override void Run()
        {
            AbstractProjectBrowserTreeNode node = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedNode;
            ISolutionFolderNode            solutionFolderNode = node as ISolutionFolderNode;

            if (node != null)
            {
                ISolutionFolder newSolutionFolder = solutionFolderNode.Folder.CreateFolder(ResourceService.GetString("ProjectComponent.NewFolderString"));
                solutionFolderNode.Solution.Save();

                SolutionFolderNode newSolutionFolderNode = new SolutionFolderNode(newSolutionFolder);
                newSolutionFolderNode.InsertSorted(node);
                ProjectBrowserPad.Instance.StartLabelEdit(newSolutionFolderNode);
            }
        }
Example #31
0
        public bool IsAncestorOf(ISolutionFolder folder)
        {
            object curParent = folder;

            while (curParent != null && curParent is ISolutionFolder)
            {
                ISolutionFolder curFolder = (ISolutionFolder)curParent;
                if (curFolder == this)
                {
                    return(true);
                }
                curParent = curFolder.Parent;
            }
            return(false);
        }
Example #32
0
        public static void Delete(this ISolutionFolder folder)
        {
            Guard.NotNull(() => folder, folder);

            var project = folder.As <EnvDTE.Project>();

            if (project != null)
            {
                var solutionFolder = project.Object as EnvDTE80.SolutionFolder;
                if (solutionFolder != null)
                {
                    project.Delete();
                }
            }
        }
Example #33
0
        public async void ShowNewProjectWpfDialog(ISolutionFolder solutionFolder, IEnumerable <TemplateCategory> templates)
        {
                        #if DEBUG
            SD.Templates.UpdateTemplates();
                        #endif
            ICSharpCode.SharpDevelop.Services.Gui.Dialogs.Wpf.NewProjectDialog npdlg =
                new ICSharpCode.SharpDevelop.Services.Gui.Dialogs.Wpf.NewProjectDialog();
            ICSharpCode.SharpDevelop.Services.Gui.Dialogs.Wpf.NewProjectDialogViewModel npdlgViewModel =
                new ICSharpCode.SharpDevelop.Services.Gui.Dialogs.Wpf.NewProjectDialogViewModel(
                    templates ?? SD.Templates.TemplateCategories, solutionFolder == null, npdlg);


            npdlg.SetDataContext(npdlgViewModel);
            var result = await(SD.Workbench as Window).ShowDialog(npdlg, ClosingEventHandler);
        }
Example #34
0
        protected void SolutionFolderRemoved(ISolutionFolder solutionFolder)
        {
            IProject project = solutionFolder as IProject;

            if (project != null)
            {
                treeView.RemoveProject(project);
            }

            if (solutionFolder is ISolutionFolderContainer)
            {
                // recurse into child folders that were also removed
                ((ISolutionFolderContainer)solutionFolder).Folders.ForEach(SolutionFolderRemoved);
            }
        }
        private void ChangeParent(ISolutionFolder oldParent, ISolutionFolder newParent)
        {
            ISolutionTreeNode?Node = Root.FindTreeNode(Path);

            if (Node != null)
            {
                ISolutionTreeNodeCollection OldChildrenCollection = (ISolutionTreeNodeCollection)oldParent.Children;
                OldChildrenCollection.Remove(Node);

                ISolutionTreeNodeCollection NewChildrenCollection = (ISolutionTreeNodeCollection)newParent.Children;
                NewChildrenCollection.Add(Node);

                NewChildrenCollection.Sort();
            }
        }
Example #36
0
			internal bool AddContents(ISolutionFolder parentFolder, ProjectTemplateResult templateResult, string defaultLanguage)
			{
				// Create sub projects
				foreach (SolutionFolderDescriptor folderDescriptor in solutionFoldersDescriptors) {
					ISolutionFolder folder = parentFolder.CreateFolder(folderDescriptor.name);
					if (!folderDescriptor.AddContents(folder, templateResult, defaultLanguage))
						return false;
				}
				foreach (ProjectDescriptor projectDescriptor in projectDescriptors) {
					IProject newProject = projectDescriptor.CreateProject(templateResult, defaultLanguage);
					if (newProject == null)
						return false;
					parentFolder.Items.Add(newProject);
				}
				return true;
			}
Example #37
0
		public SolutionFolderNode(ISolutionFolder folder)
		{
			sortOrder = 0;
			canLabelEdit = true;
			
			ContextmenuAddinTreePath = "/SharpDevelop/Pads/ProjectBrowser/ContextMenu/SolutionFolderNode";
			this.solution  = folder.ParentSolution;
			this.folder    = folder;
			this.Tag       = folder;
			Text           = folder.Name;
			autoClearNodes = false;
			
			OpenedImage = "ProjectBrowser.SolutionFolder.Open";
			ClosedImage = "ProjectBrowser.SolutionFolder.Closed";
			Initialize();
		}
Example #38
0
        public ProjectTemplateResult ShowNewProjectDialog(ISolutionFolder solutionFolder, IEnumerable<TemplateCategory> templates)
        {
            #if DEBUG
            SD.Templates.UpdateTemplates();
            #endif
            using (NewProjectDialog npdlg = new NewProjectDialog(templates ?? SD.Templates.TemplateCategories, createNewSolution: solutionFolder == null)) {
                npdlg.SolutionFolder = solutionFolder;
                if (solutionFolder != null) {
                    npdlg.InitialProjectLocationDirectory = AddNewProjectToSolution.GetInitialDirectorySuggestion(solutionFolder);
                }

                // show the dialog to request project type and name
                if (npdlg.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) {
                    return npdlg.result;
                } else {
                    return null;
                }
            }
        }
Example #39
0
		public virtual void AddFolder(ISolutionFolder folder)
		{
			if (string.IsNullOrEmpty(folder.IdGuid)) {
				folder.IdGuid = Guid.NewGuid().ToString().ToUpperInvariant();
			}
			
			bool isNew = false;
			if (folder.Parent != null) {
				folder.Parent.RemoveFolder(folder);
			} else {
				// this is a new project/solution folder
				isNew = true;
			}
			if (isNew) {
				this.ParentSolution.BeforeAddFolderToSolution(folder);
			}
			folder.Parent = this;
			Folders.Add(folder);
			if (isNew) {
				this.ParentSolution.AfterAddFolderToSolution(folder);
			}
		}
 internal bool AddContents(ISolutionFolder parentFolder, ProjectTemplateResult templateResult, string defaultLanguage)
 {
     return mainFolder.AddContents(parentFolder, templateResult, defaultLanguage);
 }
		public void CallSolutionFolderRemoved(ISolutionFolder folder)
		{
			base.SolutionFolderRemoved(folder);
		}
		protected void SolutionFolderRemoved(ISolutionFolder solutionFolder)
		{
			IProject project = solutionFolder as IProject;
			if (project != null) {
				treeView.RemoveProject(project);
			}
			
			if (solutionFolder is ISolutionFolderContainer) {
				// recurse into child folders that were also removed
				((ISolutionFolderContainer)solutionFolder).Folders.ForEach(SolutionFolderRemoved);
			}
		}
Example #43
0
		static bool DoEnablePaste(ISolutionFolder container, System.Windows.IDataObject dataObject)
		{
			if (dataObject == null) {
				return false;
			}
			if (dataObject.GetDataPresent(typeof(ISolutionItem).ToString())) {
				Guid guid = Guid.Parse(dataObject.GetData(typeof(ISolutionItem).ToString()).ToString());
				ISolutionItem solutionItem = container.ParentSolution.GetItemByGuid(guid);
				if (solutionItem == null || solutionItem == container)
					return false;
				if (solutionItem is ISolutionFolder) {
					return solutionItem.ParentFolder != container
						&& !((ISolutionFolder)solutionItem).IsAncestorOf(container);
				} else {
					return solutionItem.ParentFolder != container;
				}
			}
			return false;
		}
		//Show prompt, create files from template, create project, execute command, save project
		public bool CreateProject(ProjectTemplateResult templateResults, string defaultLanguage, ISolutionFolder target)
		{
			var projectCreateOptions = templateResults.Options;
			var parentSolution = templateResults.Options.Solution;
			IProject project = null;
			bool success = false;
			try
			{
				string language = string.IsNullOrEmpty(languageName) ? defaultLanguage : languageName;
				ProjectBindingDescriptor descriptor = SD.ProjectService.ProjectBindings.FirstOrDefault(b => b.Language == language);
				IProjectBinding languageinfo = (descriptor != null) ? descriptor.Binding : null;
				
				if (languageinfo == null) {
					MessageService.ShowError(
						StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.CantCreateProjectWithTypeError}",
						                   new StringTagPair("type", language)));
					return false;
				}
				
				DirectoryName projectBasePath = projectCreateOptions.ProjectBasePath;
				string newProjectName = StringParser.Parse(name, new StringTagPair("ProjectName", projectCreateOptions.ProjectName));
				Directory.CreateDirectory(projectBasePath);
				FileName projectLocation = projectBasePath.CombineFile(newProjectName + descriptor.ProjectFileExtension);
				ProjectCreateInformation info = new ProjectCreateInformation(parentSolution, projectLocation);
				info.TargetFramework = projectCreateOptions.TargetFramework;
				
				StringBuilder standardNamespace = new StringBuilder();
				// filter 'illegal' chars from standard namespace
				if (!string.IsNullOrEmpty(newProjectName)) {
					char ch = '.';
					for (int i = 0; i < newProjectName.Length; ++i) {
						if (ch == '.') {
							// at beginning or after '.', only a letter or '_' is allowed
							ch = newProjectName[i];
							if (!Char.IsLetter(ch)) {
								standardNamespace.Append('_');
							} else {
								standardNamespace.Append(ch);
							}
						} else {
							ch = newProjectName[i];
							// can only contain letters, digits or '_'
							if (!Char.IsLetterOrDigit(ch) && ch != '.') {
								standardNamespace.Append('_');
							} else {
								standardNamespace.Append(ch);
							}
						}
					}
				}
				
				info.TypeGuid = descriptor.TypeGuid;
				info.RootNamespace = standardNamespace.ToString();
				info.ProjectName = newProjectName;
				if (!string.IsNullOrEmpty(defaultPlatform))
					info.ActiveProjectConfiguration = new ConfigurationAndPlatform("Debug", defaultPlatform);
				
				RunPreCreateActions(info);
				
				StringParserPropertyContainer.FileCreation["StandardNamespace"] = info.RootNamespace;
				
				if (File.Exists(projectLocation))
				{
					
					if (!MessageService.AskQuestion(
						StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteProjectQuestion}",
						                   new StringTagPair("projectLocation", projectLocation)),
						"${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion.InfoName}"))
					{
						return false; //The user doesnt want to overwrite the project...
					}
				}
				
				//Show prompt if any of the files exist
				StringBuilder existingFileNames = new StringBuilder();
				foreach (FileDescriptionTemplate file in files)
				{
					string fileName = Path.Combine(projectBasePath, StringParser.Parse(file.Name, new StringTagPair("ProjectName", info.ProjectName)));
					
					if (File.Exists(fileName))
					{
						if (existingFileNames.Length > 0)
							existingFileNames.Append(", ");
						existingFileNames.Append(Path.GetFileName(fileName));
					}
				}
				
				bool overwriteFiles = true;
				if (existingFileNames.Length > 0)
				{
					if (!MessageService.AskQuestion(
						StringParser.Parse("${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion}",
						                   new StringTagPair("fileNames", existingFileNames.ToString())),
						"${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion.InfoName}"))
					{
						overwriteFiles = false;
					}
				}
				
				
				
				#region Copy files to target directory
				foreach (FileDescriptionTemplate file in files)
				{
					string fileName = Path.Combine(projectBasePath, StringParser.Parse(file.Name, new StringTagPair("ProjectName", info.ProjectName)));
					if (File.Exists(fileName) && !overwriteFiles)
					{
						continue;
					}
					
					try
					{
						if (!Directory.Exists(Path.GetDirectoryName(fileName))) {
							Directory.CreateDirectory(Path.GetDirectoryName(fileName));
						}
						if (!String.IsNullOrEmpty(file.BinaryFileName)) {
							// Binary content
							File.Copy(file.BinaryFileName, fileName, true);
						} else {
							// Textual content
							StreamWriter sr = new StreamWriter(File.Create(fileName), SD.FileService.DefaultFileEncoding);
							string fileContent = StringParser.Parse(file.Content,
							                                        new StringTagPair("ProjectName", projectCreateOptions.ProjectName),
							                                        new StringTagPair("SolutionName", projectCreateOptions.SolutionName),
							                                        new StringTagPair("FileName", fileName));
							fileContent = StringParser.Parse(fileContent);
							if (SD.EditorControlService.GlobalOptions.IndentationString != "\t") {
								fileContent = fileContent.Replace("\t", SD.EditorControlService.GlobalOptions.IndentationString);
							}
							sr.Write(fileContent);
							sr.Close();
						}
					}
					catch (Exception ex)
					{
						MessageService.ShowException(ex, "Exception writing " + fileName);
					}
				}
				#endregion
				
				#region Create Project
				try {
					info.InitializeTypeSystem = false;
					project = languageinfo.CreateProject(info);
				} catch (ProjectLoadException ex) {
					MessageService.ShowError(ex.Message);
					return false;
				}
				#endregion
				
				#region Create Project Items, Imports and Files
				// Add Project items
				if (!project.Items.IsReadOnly)
				{
					foreach (ProjectItem projectItem in projectItems) {
						ProjectItem newProjectItem = new UnknownProjectItem(
							project,
							StringParser.Parse(projectItem.ItemType.ItemName),
							StringParser.Parse(projectItem.Include,
							                   new StringTagPair("ProjectName", projectCreateOptions.ProjectName),
							                   new StringTagPair("SolutionName", projectCreateOptions.SolutionName))
						);
						foreach (string metadataName in projectItem.MetadataNames) {
							string metadataValue = projectItem.GetMetadata(metadataName);
							// if the input contains any special MSBuild sequences, don't escape the value
							// we want to escape only when the special characters are introduced by the StringParser.Parse replacement
							if (metadataValue.Contains("$(") || metadataValue.Contains("%"))
								newProjectItem.SetMetadata(StringParser.Parse(metadataName), StringParser.Parse(metadataValue));
							else
								newProjectItem.SetEvaluatedMetadata(StringParser.Parse(metadataName), StringParser.Parse(metadataValue));
						}
						project.Items.Add(newProjectItem);
					}
				}
				
				// Add properties from <PropertyGroup>
				// This must be done before adding <Imports>, because the import path can refer to properties.
				if (projectProperties.Count > 0) {
					if (!(project is MSBuildBasedProject))
						throw new Exception("<PropertyGroup> may be only used in project templates for MSBuildBasedProjects");
					
					foreach (ProjectProperty p in projectProperties) {
						((MSBuildBasedProject)project).SetProperty(
							StringParser.Parse(p.Configuration),
							StringParser.Parse(p.Platform),
							StringParser.Parse(p.Name),
							StringParser.Parse(p.Value),
							p.Location,
							p.ValueIsLiteral
						);
					}
				}
				
				// Add Imports
				if (clearExistingImports || projectImports.Count > 0) {
					MSBuildBasedProject msbuildProject = project as MSBuildBasedProject;
					if (msbuildProject == null)
						throw new Exception("<Imports> may be only used in project templates for MSBuildBasedProjects");
					try {
						msbuildProject.PerformUpdateOnProjectFile(
							delegate {
								var projectFile = msbuildProject.MSBuildProjectFile;
								if (clearExistingImports) {
									foreach (var import in projectFile.Imports.ToArray())
										projectFile.RemoveChild(import);
								}
								foreach (Import projectImport in projectImports) {
									projectFile.AddImport(projectImport.Key).Condition = projectImport.Value;
								}
								
							});
					} catch (InvalidProjectFileException ex) {
						string message;
						if (string.IsNullOrEmpty(importsFailureMessage)) {
							message = "Error creating project:\n" + ex.Message;
						} else {
							message = importsFailureMessage + "\n\n" + ex.Message;
						}
						throw new ProjectLoadException(message, ex);
					}
				}
				
				// Add Files
				if (!project.Items.IsReadOnly) {
					
					foreach (FileDescriptionTemplate file in files) {
						string fileName = Path.Combine(projectBasePath, StringParser.Parse(file.Name, new StringTagPair("ProjectName", projectCreateOptions.ProjectName)));
						FileProjectItem projectFile = new FileProjectItem(project, project.GetDefaultItemType(fileName));
						
						projectFile.Include = FileUtility.GetRelativePath(project.Directory, fileName);
						
						file.SetProjectItemProperties(projectFile);
						
						project.Items.Add(projectFile);
					}
				}
				
				#endregion
				
				RunCreateActions(project);
				
				project.ProjectCreationComplete();
				
				// Save project
				project.Save();
				
				// HACK : close and reload
				var fn = project.FileName;
				project.Dispose();
				ProjectLoadInformation loadInfo = new ProjectLoadInformation(parentSolution, fn, fn.GetFileNameWithoutExtension());
				project = SD.ProjectService.LoadProject(loadInfo);
				target.Items.Add(project);
				project.ProjectLoaded();
				
				SD.GetRequiredService<IProjectServiceRaiseEvents>().RaiseProjectCreated(new ProjectEventArgs(project));
				templateResults.NewProjects.Add(project);
				success = true;
				return true;
			} finally {
				if (project != null && !success)
					project.Dispose();
			}
		}
Example #45
0
		protected void SolutionFolderRemoved(ISolutionFolder solutionFolder)
		{
			treeView.RemoveSolutionFolder(solutionFolder);
		}
Example #46
0
		static void HandleRemovedSolutionFolder(ISolutionFolder folder)
		{
			IProject project = folder as IProject;
			if (project != null) {
				OpenSolution.RemoveProjectConfigurations(project.IdGuid);
				ParserService.RemoveProjectContentForRemovedProject(project);
				project.Dispose();
			}
			if (folder is ISolutionFolderContainer) {
				// recurse into child folders that were also removed
				((ISolutionFolderContainer)folder).Folders.ForEach(HandleRemovedSolutionFolder);
			}
		}
		public SolutionFolderEventArgs(ISolutionFolder solutionFolder)
		{
			this.solutionFolder = solutionFolder;
		}
		public SolutionFolderRemoveVisitor(ISolutionFolder folder)
		{
			this.folder = folder;
		}
Example #49
0
		internal void AfterAddFolderToSolution(ISolutionFolder folder)
		{
			IProject project = folder as IProject;
			if (project != null && !isLoading) {
				FixSolutionConfiguration(new[] { project });
			}
		}
Example #50
0
		internal void AfterAddFolderToSolution(ISolutionFolder folder)
		{
			IProject project = folder as IProject;
			if (project != null && !isLoading) {
				var projectConfigurations = project.ConfigurationNames;
				var solutionConfigurations = this.GetConfigurationNames();
				var projectPlatforms = project.PlatformNames;
				var solutionPlatforms = this.GetPlatformNames();
				foreach (string config in solutionConfigurations) {
					string projectConfig = config;
					if (!projectConfigurations.Contains(projectConfig))
						projectConfig = projectConfigurations.FirstOrDefault() ?? "Debug";
					foreach (string platform in solutionPlatforms) {
						string projectPlatform = FixPlatformNameForProject(platform);
						if (!projectPlatforms.Contains(projectPlatform))
							projectPlatform = projectPlatforms.FirstOrDefault() ?? "AnyCPU";
						
						CreateMatchingItem(config, platform, project, projectConfig + "|" + FixPlatformNameForSolution(projectPlatform));
					}
				}
			}
		}
Example #51
0
		internal static void MoveItem(ISolutionItem solutionItem, ISolutionFolder folder)
		{
			// Use a batch update to move the item without causing projects
			// be removed from the solution (and thus disposed).
			using (solutionItem.ParentFolder.Items.BatchUpdate()) {
				using (folder.Items.BatchUpdate()) {
					solutionItem.ParentFolder.Items.Remove(solutionItem);
					folder.Items.Add(solutionItem);
				}
			}
		}
		public void FireSolutionFolderRemoved(ISolutionFolder solutionFolder)
		{
			if (SolutionFolderRemoved != null) {
				SolutionFolderRemoved(this, new SolutionFolderEventArgs(solutionFolder));
			}
		}
Example #53
0
		static void HandleRemovedSolutionFolder(ISolutionFolder folder)
		{
			if (folder is IProject) {
				OpenSolution.RemoveProjectConfigurations(folder.IdGuid);
				ParserService.RemoveProjectContentForRemovedProject((IProject)folder);
			}
			if (folder is ISolutionFolderContainer) {
				// recurse into child folders that were also removed
				((ISolutionFolderContainer)folder).Folders.ForEach(HandleRemovedSolutionFolder);
			}
		}
Example #54
0
		public void RemoveSolutionFolder(ISolutionFolder solutionFolder)
		{
			IProject project = solutionFolder as IProject;
			if (project != null) {
				RemoveProject(project);
			}
			
			ISolutionFolderContainer solutionFolderContainer = solutionFolder as ISolutionFolderContainer;
			if (solutionFolderContainer != null) {
				foreach (ISolutionFolder subSolutionFolder in solutionFolderContainer.Folders) {
					RemoveSolutionFolder(subSolutionFolder);
				}
			}
		}
Example #55
0
		public bool IsAncestorOf(ISolutionFolder folder)
		{
			object curParent = folder;
			while (curParent != null && curParent is ISolutionFolder) {
				ISolutionFolder curFolder = (ISolutionFolder)curParent;
				if (curFolder == this) {
					return true;
				}
				curParent = curFolder.Parent;
			}
			return false;
		}
Example #56
0
		internal void BeforeAddFolderToSolution(ISolutionFolder folder)
		{
			IProject project = folder as IProject;
			if (project != null && !isLoading) {
				// HACK: don't deal with configurations during loading
				if (this.GetConfigurationNames().Count == 0) {
					foreach (string config in project.ConfigurationNames) {
						foreach (string platform in project.PlatformNames)
							AddSolutionConfigurationPlatform(config, FixPlatformNameForSolution(platform), null, false, false);
					}
				}
			}
		}
Example #57
0
		public virtual void RemoveFolder(ISolutionFolder folder)
		{
			for (int i = 0; i < Folders.Count; ++i) {
				if (folder.IdGuid == Folders[i].IdGuid) {
					Folders.RemoveAt(i);
					break;
				}
			}
		}
Example #58
0
		public override void AddFolder(ISolutionFolder folder)
		{
			base.AddFolder(folder);
			guidDictionary[folder.IdGuid] = folder;
		}