private uint GetId(string itemPath, uint searchBelow)
            {
                if (string.IsNullOrEmpty(itemPath))
                {
                    throw new ArgumentNullException("itemPath");
                }

                uint id;

                if (_map.TryGetValue(itemPath, out id))
                {
                    return(id);
                }

                foreach (string s in _walker.GetSccFiles(_hier, searchBelow, ProjectWalkDepth.AllDescendants, _map))
                {
                    if (string.Equals(itemPath, s, StringComparison.OrdinalIgnoreCase))
                    {
                        if (_map.TryGetValue(itemPath, out id))
                        {
                            return(id);
                        }
                    }
                }

                if (_map.TryGetValue(itemPath, out id))
                {
                    return(id);
                }
                else
                {
                    return(VSItemId.Nil);
                }
            }
Esempio n. 2
0
        public void Load()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_loaded || !_opened)
            {
                return;
            }

            _loaded             = true;
            _checkedProjectFile = false;
            _projectFile        = null;
            _svnProjectInstance = null;

            if (ExcludedFromScc)
            {
                return;
            }

            _inLoad = true;
            try
            {
                Debug.Assert(_files.Count == 0);

                ISccProjectWalker walker = GetService <ISccProjectWalker>();

                if (walker != null)
                {
                    Dictionary <string, uint> ids = new Dictionary <string, uint>(StringComparer.OrdinalIgnoreCase);
                    foreach (string file in walker.GetSccFiles(ProjectHierarchy, VSItemId.Root, ProjectWalkDepth.AllDescendantsInHierarchy, ids))
                    {
                        AddPath(file, ids); // GetSccFiles returns normalized paths
                    }
                }

                IFileStatusMonitor monitor = GetService <IFileStatusMonitor>();
                if (monitor != null)
                {
                    // Make sure we see all files as possible pending changes
                    monitor.ScheduleGlyphUpdate(GetAllFiles());
                }
                Hook(true);
            }
            finally
            {
                _inLoad = false;
            }
        }
Esempio n. 3
0
        public IList <string> GetSubFiles()
        {
            if (_subFiles != null)
            {
                return(_subFiles);
            }

            ISccProjectWalker walker = _context.GetService <ISccProjectWalker>();

            List <string> files = new List <string>(walker.GetSccFiles(Project.ProjectHierarchy, ProjectItemId, ProjectWalkDepth.SpecialFiles, null));

            files.Remove(Filename);

            _subFiles = files.AsReadOnly();

            return(_subFiles);
        }
Esempio n. 4
0
        private void TryFindOrigin(string newName, out string origin)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_fileOrigins.TryGetValue(newName, out origin))
            {
                if (origin != null)
                {
                    return;
                }
            }
            else
            {
                _fileOrigins.Add(newName, null);
            }

            // We haven't got the project file origin for free via OnQueryAddFilesEx
            // So:
            //  1 - The file is really new or
            //  2 - The file is drag&dropped into the project from the solution explorer or
            //  3 - The file is copy pasted into the project from an other project or
            //  4 - The file is added via add existing item or
            //  5 - The file is added via drag&drop from another application (OLE drop)
            //
            // The only way to determine is walking through these options
            SortedList <string, string> nameToItem = new SortedList <string, string>();

            nameToItem[Path.GetFileName(newName)] = newName;
            foreach (KeyValuePair <string, string> kv in _fileOrigins)
            {
                if (kv.Value != null)
                {
                    continue;
                }

                nameToItem[Path.GetFileName(kv.Key)] = kv.Key;
            }

            // 2 -  If the file is drag&dropped in the solution explorer
            //      the current selection is still the original selection

            // **************** Check the current selection *************
            // Checks for drag&drop actions. The selection contains the original list of files
            // BH: resx files are not correctly included if we don't retrieve this list recursive
            foreach (string file in SelectionContext.GetSelectedFiles(true))
            {
                if (_fileOrigins.ContainsKey(file))
                {
                    continue;
                }

                string name = Path.GetFileName(file);
                if (nameToItem.ContainsKey(name))
                {
                    string item = nameToItem[name];

                    CheckForMatch(item, file);
                }
            }

            // **************** Check the clipboard *********************
            // 3 - Copy & Paste in the solution explorer:
            //     The original hierarchy information is still on the clipboard

            IDataObject dataObject;
            string      projectItemType;

            if (null != (dataObject = SafeGetDataObject()) && SolutionExplorerClipboardItem.CanRead(dataObject, out projectItemType))
            {
                IVsSolution       solution = GetService <IVsSolution>(typeof(SVsSolution));
                ISccProjectWalker walker   = GetService <ISccProjectWalker>();

                foreach (string projref in SolutionExplorerClipboardItem.DecodeProjectItemData(dataObject, projectItemType))
                {
                    IVsHierarchy project;
                    uint         itemid;
                    {
                        string updatedRef;
                        VSUPDATEPROJREFREASON[] updateReason = new VSUPDATEPROJREFREASON[1];
                        if (!VSErr.Succeeded(solution.GetItemOfProjref(projref, out project, out itemid, out updatedRef, updateReason)))
                        {
                            continue;
                        }
                    }

                    foreach (string rawFile in walker.GetSccFiles(project, itemid, ProjectWalkDepth.AllDescendantsInHierarchy, null))
                    {
                        if (!SvnItem.IsValidPath(rawFile))
                        {
                            continue;
                        }

                        string file = SvnTools.GetNormalizedFullPath(rawFile);

                        if (_fileOrigins.ContainsKey(file))
                        {
                            continue;
                        }

                        string name = Path.GetFileName(file);
                        if (nameToItem.ContainsKey(name))
                        {
                            string item = nameToItem[name];

                            CheckForMatch(item, file);
                        }
                    }
                }
            }


            // **************** Check external hints ********************
            // Checks for HandsOff events send by the project system
            foreach (string file in _fileHints)
            {
                if (_fileOrigins.ContainsKey(file))
                {
                    continue;
                }

                string name = Path.GetFileName(file);
                if (nameToItem.ContainsKey(name))
                {
                    string item = nameToItem[name];

                    CheckForMatch(item, file);
                }
            }

            // The clipboard seems to have some other format which might contain other info
            origin = _fileOrigins[newName];

            if (origin == null)
            {
                bool   first = true;
                string path  = null;

                foreach (KeyValuePair <string, string> kv in _fileOrigins)
                {
                    if (kv.Value == null)
                    {
                        continue;
                    }

                    if (SvnItem.IsBelowRoot(kv.Key, newName))
                    {
                        string itemRoot = kv.Value.Substring(0, kv.Value.Length - kv.Key.Length + newName.Length);
                        if (first)
                        {
                            path  = itemRoot;
                            first = false;
                        }
                        else if (path != itemRoot)
                        {
                            origin = null;
                            return;
                        }
                    }
                }
                origin = path;
            }
        }
Esempio n. 5
0
        public void AddPath(string path)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (ExcludedFromScc)
            {
                return;
            }

            bool alreadyLoaded = _loaded && !_inLoad;

            if (alreadyLoaded && WebLikeFileHandling)
            {
                uint fid = VSItemId.Nil;

                if (TryGetProjectFileId(path, out fid))
                {
                    // OK: Websites try to add everything they see below their directory
                    // We only add these files if they are actually SCC items

                    bool add = false;
                    ISccProjectWalker walker = GetService <ISccProjectWalker>();

                    foreach (string file in walker.GetSccFiles(ProjectHierarchy, fid, ProjectWalkDepth.SpecialFiles, null))
                    {
                        if (string.Equals(file, path, StringComparison.OrdinalIgnoreCase))
                        {
                            add = true;
                            break;
                        }
                    }

                    if (!add)
                    {
                        return;
                    }
                }
                else
                {
                    // File is either not in project or a scc special file
                    // Pass
                }
            }

            if (alreadyLoaded && GetService <IAnkhConfigurationService>().Instance.AutoAddEnabled)
            {
                GetService <IFileStatusMonitor>().ScheduleAddFile(path);
            }

            SccProjectFileReference reference;

            if (_files.TryGetValue(path, out reference))
            {
                reference.AddReference();
            }
            else
            {
                reference = new SccProjectFileReference(_context, this, Map.GetFile(path));
                _files.Add(reference);

                if (alreadyLoaded)
                {
                    GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(path);
                }
            }

            if (string.Equals(path, ProjectFile, StringComparison.OrdinalIgnoreCase))
            {
                reference.IsProjectFile = true;
            }

            if (alreadyLoaded && !string.IsNullOrEmpty(ProjectFile))
            {
                ISccProjectWalker walker = GetService <ISccProjectWalker>();

                if (walker != null)
                {
                    walker.SetPrecreatedFilterItem(null, VSItemId.Nil);
                }

                ClearIdCache();

                SetDirty();
            }
        }