Exemplo n.º 1
0

        
Exemplo n.º 2
0
        //public override int ImageIndex
        //{
        //  get
        //  {
        //    if (IsFormSubType)
        //    {
        //      return (int)ProjectNode.ImageName.WindowsForm;
        //    }
        //    if (this.FileName.ToLower().EndsWith(".py"))
        //    {
        //      return PythonProjectNode.ImageOffset + (int)PythonProjectNode.PythonImageName.PyFile;
        //    }
        //    return base.ImageIndex;
        //  }
        //}

        ///// <summary>
        ///// Open a file depending on the SubType property associated with the file item in the project file
        ///// </summary>
        //protected override void DoDefaultAction()
        //{
        //  FileDocumentManager manager = this.GetDocumentManager() as FileDocumentManager;
        //  Debug.Assert(manager != null, "Could not get the FileDocumentManager");

        //  Guid viewGuid = (IsFormSubType ? NativeMethods.LOGVIEWID_Designer : NativeMethods.LOGVIEWID_Code);
        //  IVsWindowFrame frame;
        //  manager.Open(false, false, viewGuid, out frame, WindowFrameShowAction.Show);
        //}

        //protected internal override StringBuilder PrepareSelectedNodesForClipBoard()
        //{
        //  DelphiProjectNode lProjectMgr = this.ProjectMgr as DelphiProjectNode;
        //  Debug.Assert(lProjectMgr != null, " No project mananager available for this node " + ToString());
        //  Debug.Assert(lProjectMgr.GetItemsDraggedOrCutOrCopied() != null, " The itemsdragged list should have been initialized prior calling this method");
        //  List<IVsHierarchy> lItemsDragged = lProjectMgr.GetItemsDraggedOrCutOrCopied();
        //  StringBuilder sb = new StringBuilder();
        //  string projref = String.Empty;
        //  IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;
        //  bool lFailed = (this.ID == VSConstants.VSITEMID_ROOT || solution == null);
        //  if (!lFailed)
        //  {
        //    // Get all nodes for drag and drop or cut copy
        //    HierarchyNode lNode = this;
        //    do
        //    {
        //      lItemsDragged.Add(lNode);
        //      // file must exist or no dragging can occur
        //      if (!File.Exists(lNode.Url))
        //        lFailed = true;
        //      ErrorHandler.ThrowOnFailure(solution.GetProjrefOfItem(this.ProjectMgr, lNode.ID, out projref));
        //      if (!String.IsNullOrEmpty(projref))
        //      {
        //        sb.Append(projref);
        //        sb.Append('\0');
        //      }
        //      else
        //        lFailed = true;
        //      if (lNode is DelphiFileNode)
        //        lNode = lNode.FirstChild;
        //      else
        //        lNode = lNode.NextSibling;
        //    } while (lNode != null);
        //  }
        //  // it did not work
        //  if (lFailed)
        //  {
        //    lItemsDragged.Clear();// abort
        //    sb = new StringBuilder();
        //  }
        //  return sb;
        //}

        protected override int ExecCommandOnNode(Guid guidCmdGroup, uint cmd, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (guidCmdGroup == Microsoft.VisualStudio.Shell.VsMenus.guidStandardCommandSet97)
            {
                switch ((VsCommands)cmd)
                {
                case VsCommands.Delete:
                    HierarchyNode lNode = this.FirstChild;
                    while (lNode != null)
                    {
                        lNode.Remove(true);
                        lNode = this.FirstChild;
                    }
                    this.Remove(true);
                    return(VSConstants.S_OK);
                }
            }
            //Debug.Assert(this.ProjectMgr != null, "The PythonFileNode has no project manager");

            //if (this.ProjectMgr == null)
            //{
            //  throw new InvalidOperationException();
            //}

            //if (guidCmdGroup == PythonMenus.guidIronPythonProjectCmdSet)
            //{
            //  if (cmd == (uint)PythonMenus.SetAsMain.ID)
            //  {
            //    // Set the MainFile project property to the Filename of this Node
            //    ((PythonProjectNode)this.ProjectMgr).SetProjectProperty(PythonProjectFileConstants.MainFile, this.GetRelativePath());
            //    return VSConstants.S_OK;
            //  }
            //}
            return(base.ExecCommandOnNode(guidCmdGroup, cmd, nCmdexecopt, pvaIn, pvaOut));
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method is used to move dependant items from the main level (1st level below project node) to
        /// and make them children of the modules they belong to.
        /// </summary>
        /// <param name="child"></param>
        /// <returns></returns>
        internal bool AddDependant(HierarchyNode child)
        {
            // If the file is not a XSharpFileNode then drop it and create a new XSharpFileNode
            XSharpFileNode dependant;
            String         fileName = child.Url;

            try
            {
                child.Remove(false);
            }
            catch (Exception e)
            {
                XSharpProjectPackage.Instance.DisplayOutPutMessage("AddDependant failed");
                XSharpProjectPackage.Instance.DisplayException(e);
            }
            dependant = (XSharpFileNode)ProjectMgr.CreateDependentFileNode(fileName);

            // Like the C# project system we do not put a path in front of the parent name, even when we are in a subfolder
            // but we do put a path before the parent name when the parent is in a different folder
            // In that case the path is the path from the base project folder
            string parent = this.ItemNode.GetMetadata(ProjectFileConstants.Include);

            parent = Path.GetFileName(parent);
            if (!this.IsNonMemberItem)
            {
                string parentPath = Path.GetDirectoryName(Path.GetFullPath(this.Url));
                string childPath  = Path.GetDirectoryName(Path.GetFullPath(dependant.Url));
                if (String.Equals(parentPath, childPath, StringComparison.OrdinalIgnoreCase))
                {
                    dependant.ItemNode.SetMetadata(ProjectFileConstants.DependentUpon, parent);
                }
                else
                {
                    string projectPath   = this.ProjectMgr.ProjectFolder;
                    Uri    projectFolder = new Uri(projectPath);
                    Uri    relative      = projectFolder.MakeRelativeUri(new Uri(parentPath));
                    parentPath = relative.ToString() + Path.DirectorySeparatorChar;
                    dependant.ItemNode.SetMetadata(ProjectFileConstants.DependentUpon, parentPath + parent);
                }
            }
            // Make the item a dependent item
            dependant.HasParentNodeNameRelation = true;
            // Insert in the list of children
            dependant.NextSibling = this.FirstChild;
            this.FirstChild       = dependant;
            ProjectMgr.OnItemsAppended(this);
            this.OnItemAdded(this, dependant);
            // Set parent and inherit the NonMember Status
            dependant.Parent          = this;
            dependant.IsDependent     = true;
            dependant.IsNonMemberItem = this.IsNonMemberItem;
            return(true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Deletes the mapping file.
 /// </summary>
 public void DeleteMappingFile()
 {
     using (HierarchyNode item = InternalGetOrCreateMappingFile())
     {
         if (item != null)
         {
             item.Remove();
             File.Delete(GetMappingFileName());
             ReloadMappingFile();
         }
     }
 }
Exemplo n.º 5
0
        public void RemoveItem()
        {
            MockVSHierarchy hierarchy = new MockVSHierarchy();
            MockVsSolution  solution  = new MockVsSolution(hierarchy);
            MockVSHierarchy project   = new MockVSHierarchy("Project3.project");

            hierarchy.AddProject(project);
            ProjectNode   projectNode = new ProjectNode(solution, project.GUID);
            string        itemName    = "item1";
            HierarchyNode node        = projectNode.AddItem(itemName);

            Assert.IsNotNull(projectNode.FindByName(itemName));
            node.Remove();
            Assert.IsNull(projectNode.FindByName(itemName));
        }
 private void FileDeleted(object sender, FileSystemEventArgs e)
 {
     Debug.Assert(e.ChangeType == WatcherChangeTypes.Deleted);
     ThrottleFileUpdate(e, () => {
         HierarchyNode child = FindChild(e.FullPath);
         if (child != null)
         {
             // TODO: We shouldn't be closing any documents, we probably need to pass a flag in here.
             // Unfortunately it's not really simple because when we remove the child from the parent
             // the file is no longer savable if it's already open.  So for now the file just simply
             // disappears - deleting it from the file system means you better want it gone from
             // the editor as well.
             child.Remove(false);
         }
     });
 }
Exemplo n.º 7
0
        protected virtual void AddDelphiDirectiveFiles(DelphiFileNode aDelphiFileNode, string aDirectiveSourcePath)
        {
            if (aDelphiFileNode == null)
            {
                return;
            }
            if (!this.IsCodeFile(aDelphiFileNode.FileName))
            {
                return;
            }
            if (!Directory.Exists(aDirectiveSourcePath))
            {
                return;
            }
            string[] lDirectiveFiles = aDelphiFileNode.GetDirectiveFiles();
            // root the path for all resource files so they get copied to the new output folder
            // sorry no referencing these files as the are a part of code file
            for (int i = 0; i < lDirectiveFiles.Length; i++)
            {
                if (!Path.IsPathRooted(lDirectiveFiles[i]))
                {
                    lDirectiveFiles[i] = Path.Combine(aDirectiveSourcePath, Path.GetFileName(lDirectiveFiles[i]));
                }
            }

            // remove all existing children
            for (HierarchyNode lChild = aDelphiFileNode.FirstChild; lChild != null; lChild = lChild.NextSibling)
            {
                lChild.Remove(true);
            }
            // add the new children and modify the code file
            CopyFilesToVSProject(lDirectiveFiles, aDelphiFileNode, false);

            // Notify tracker
            for (HierarchyNode lChild = aDelphiFileNode.FirstChild; lChild != null; lChild = lChild.NextSibling)
            {
                this.Tracker.OnItemAdded(lChild.Url, VSADDFILEFLAGS.VSADDFILEFLAGS_NoFlags);
            }
        }
Exemplo n.º 8
0
 private static bool RemoveSubnodeFromHierarchy(RustProjectNode root, HierarchyNode node, bool deleteFromStorage)
 {
     node.Remove(deleteFromStorage);
     return(true);
 }
Exemplo n.º 9
0
 private static bool RemoveSubnodeFromHierarchy(RustProjectNode root, HierarchyNode node, bool deleteFromStorage)
 {
     node.Remove(deleteFromStorage);
     return true;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Renames a file node.
        /// </summary>
        /// <param name="label">The new name.</param>
        /// <returns>An errorcode for failure or S_OK.</returns>
        /// <exception cref="InvalidOperationException" if the file cannot be validated>
        /// <devremark>
        /// We are going to throw instead of showing messageboxes, since this method is called from various places where a dialog box does not make sense.
        /// For example the FileNodeProperties are also calling this method. That should not show directly a messagebox.
        /// Also the automation methods are also calling SetEditLabel
        /// </devremark>

        public override int SetEditLabel(string label)
        {
            // IMPORTANT NOTE: This code will be called when a parent folder is renamed. As such, it is
            //                 expected that we can be called with a label which is the same as the current
            //                 label and this should not be considered a NO-OP.
            if (this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return(VSConstants.E_FAIL);
            }

            // Validate the filename.
            if (String.IsNullOrEmpty(label))
            {
                throw new InvalidOperationException(SR.GetString(SR.ErrorInvalidFileName, label));
            }
            else if (label.Length > NativeMethods.MAX_PATH)
            {
                throw new InvalidOperationException(SR.GetString(SR.PathTooLong, label));
            }
            else if (Utilities.IsFileNameInvalid(label))
            {
                throw new InvalidOperationException(SR.GetString(SR.ErrorInvalidFileName, label));
            }

            for (HierarchyNode n = this.Parent.FirstChild; n != null; n = n.NextSibling)
            {
                // TODO: Distinguish between real Urls and fake ones (eg. "References")
                if (n != this && String.Equals(n.Caption, label, StringComparison.OrdinalIgnoreCase))
                {
                    if (File.Exists(n.Url))
                    {
                        //A file or folder with the name '{0}' already exists on disk at this location. Please choose another name.
                        //If this file or folder does not appear in the Solution Explorer, then it is not currently part of your project. To view files which exist on disk, but are not in the project, select Show All Files from the Project menu.
                        throw new InvalidOperationException(SR.GetString(SR.FileOrFolderAlreadyExists, label));
                    }
                    else
                    {
                        // Check if the file is open in the editor, if so, we need to close it, and if it's dirty
                        // let the user save it.
                        DocumentManager manager = n.GetDocumentManager();
                        if (manager != null)
                        {
                            int close = manager.Close(__FRAMECLOSE.FRAMECLOSE_PromptSave);
                            if (close == VSConstants.E_ABORT || close == VSConstants.S_FALSE)
                            {
                                // User cancelled operation in message box.
                                throw new InvalidOperationException(SR.GetString(SR.FileOpenDoesNotExist, label));
                            }
                        }

                        if (File.Exists(n.Url))
                        {
                            // The file was dirty and the user saved it.
                            throw new InvalidOperationException(SR.GetString(SR.FileOrFolderAlreadyExists, label));
                        }

                        // The file is no longer open in the editor and isn't on disk.  We can try removing it now.
                        if (!n.Remove(false))
                        {
                            throw new InvalidOperationException(SR.GetString(SR.UnableToRemoveFile, label));
                        }
                    }
                }
            }

            string fileName = Path.GetFileNameWithoutExtension(label);

            // Verify that the file extension is unchanged
            string strRelPath = Path.GetFileName(this.ItemNode.GetMetadata(ProjectFileConstants.Include));

            if (!Utilities.IsInAutomationFunction(this.ProjectMgr.Site) &&
                !String.Equals(Path.GetExtension(strRelPath), Path.GetExtension(label), StringComparison.OrdinalIgnoreCase))
            {
                // Prompt to confirm that they really want to change the extension of the file
                string     message = SR.GetString(SR.ConfirmExtensionChange, label);
                IVsUIShell shell   = this.ProjectMgr.Site.GetService(typeof(SVsUIShell)) as IVsUIShell;

                Utilities.CheckNotNull(shell, "Could not get the UI shell from the project");

                if (!VsShellUtilities.PromptYesNo(message, null, OLEMSGICON.OLEMSGICON_INFO, shell))
                {
                    // The user cancelled the confirmation for changing the extension.
                    // Return S_OK in order not to show any extra dialog box
                    return(VSConstants.S_OK);
                }
            }


            // Build the relative path by looking at folder names above us as one scenarios
            // where we get called is when a folder above us gets renamed (in which case our path is invalid)
            HierarchyNode parent = this.Parent;

            while (parent != null && (parent is FolderNode))
            {
                strRelPath = Path.Combine(parent.Caption, strRelPath);
                parent     = parent.Parent;
            }

            return(SetEditLabel(label, strRelPath));
        }
Exemplo n.º 11
0
 /// <include file='doc\Automation.uex' path='docs/doc[@for="OAProjectItem.Remove"]/*' />
 public virtual void Remove()
 {
     node.Remove(false);
 }