Ejemplo n.º 1
0
        /// <summary>
        /// Create a file node based on absolute file name.
        /// </summary>
        public override FileNode CreateFileNode(string absFileName)
        {
            // Avoid adding files to the project multiple times.  Ultimately
            // we should not use project items and instead should have virtual items.
            string path = absFileName;

            if (absFileName.Length > ProjectDir.Length &&
                String.Compare(ProjectDir, 0, absFileName, 0, ProjectDir.Length, StringComparison.OrdinalIgnoreCase) == 0)
            {
                path = absFileName.Substring(ProjectDir.Length);
                if (path.StartsWith("\\"))
                {
                    path = path.Substring(1);
                }
            }


            var prjItem = GetExistingItem(absFileName);

            if (prjItem == null)
            {
                if (IsCodeFile(absFileName))
                {
                    prjItem = BuildProject.AddItem("Compile", path)[0];
                }
                else
                {
                    prjItem = BuildProject.AddItem("Content", path)[0];
                }
            }
            ProjectElement prjElem = new ProjectElement(this, prjItem, false);

            return(CreateFileNode(prjElem));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Provide UI to add a JAR reference.
        /// </summary>
        private void AddJarReference()
        {
            // Get the current project
            var project = (IVsHierarchy)GetCurrentProject();

            using (var dialog = new AddJarReferenceDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var jarPath    = dialog.JarPath;
                    var libName    = dialog.LibraryName;
                    var importCode = dialog.ImportCode;

                    var item = BuildProject.AddItem("JarReference", jarPath).Single();
                    if (!string.IsNullOrEmpty(libName))
                    {
                        item.SetMetadataValue("LibraryName", libName);
                    }
                    if (importCode)
                    {
                        item.SetMetadataValue("ImportCode", "yes");
                    }

                    // Save project
                    BuildProject.Save();

                    // Unload the project - also saves the modifications
                    ErrorHandler.ThrowOnFailure(solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, project, 0));

                    // Reload project
                    dte.ExecuteCommand("Project.ReloadProject", "");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a folder node based on absolute folder path.
        /// </summary>
        public new virtual FolderNode CreateFolderNode(string absFolderPath)
        {
            //This code builds folder node in such a way that it won't be added to the
            //project as build item and the project won't be go dirty.
            var            prjItem = GetExistingItem(absFolderPath) ?? BuildProject.AddItem("None", absFolderPath)[0];
            ProjectElement prjElem = new ProjectElement(this, prjItem, false);

            return(new CommonFolderNode(this, absFolderPath, prjElem));
        }
Ejemplo n.º 4
0
        public ProjectElement MakeProjectElement(string type, string path)
        {
            var item = BuildProject.AddItem(type, path)[0];

            return(new ProjectElement(this, item, false));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Add a file to the project with given item type.
 /// </summary>
 private void AddFileToProject(string path, string itemType)
 {
     BuildProject.AddItem(itemType, path);
 }