Пример #1
0
        /// <summary>
        /// Saves all dirty documents within the provided selection
        /// </summary>
        /// <param name="selection">The selection.</param>
        /// <param name="context">The context.</param>
        protected static void SaveAllDirtyDocuments(ISelectionContext selection, IAnkhServiceProvider context)
        {
            if (selection == null)
                throw new ArgumentNullException("selection");
            if (context == null)
                throw new ArgumentNullException("context");

            IAnkhOpenDocumentTracker tracker = context.GetService<IAnkhOpenDocumentTracker>();
            if (tracker != null)
                tracker.SaveDocuments(selection.GetSelectedFiles(true));
        }
Пример #2
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;
            }
        }