Ejemplo n.º 1
0
        /// <summary>
        /// Gets the parent document of a document (normally a project or the solution)
        /// </summary>
        /// <param name="document">The document.</param>
        /// <returns></returns>
        internal string GetParentDocument(SccDocumentData document)
        {
            IVsHierarchy hier = document.Hierarchy;

            foreach (SccDocumentData dd in _docMap.Values)
            {
                IVsHierarchy hh = dd.RawDocument as IVsHierarchy;

                if (hh != null && dd.Hierarchy == hier)
                {
                    return(dd.FullPath);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void DoDispose(SccDocumentData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            Debug.Assert(_docMap[data.Name] == data);

            _docMap.Remove(data.Name);

            if (data.Cookie != 0)
            {
                Debug.Assert(_cookieMap[data.Cookie] == data);

                _cookieMap.Remove(data.Cookie);
                data.Cookie = 0;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called before a document is locked in the Running Document Table (RDT) for the first time.
        /// </summary>
        /// <param name="pHier">[in] The <see cref="T:Microsoft.VisualStudio.Shell.Interop.IVsHierarchy"></see> object that owns the document about to be locked.</param>
        /// <param name="itemid">[in] The item ID in the hierarchy. This is a unique identifier or it can be one of the following values: <see cref="F:Microsoft.VisualStudio.VSItemId.Nil"></see>, <see cref="F:Microsoft.VisualStudio.VSItemId.Root"></see>, or <see cref="F:Microsoft.VisualStudio.VSItemId.Selection"></see>.</param>
        /// <param name="pszMkDocument">[in] The path to the document about to be locked.</param>
        /// <returns>
        /// If the method succeeds, it returns <see cref="F:Microsoft.VisualStudio.VSErr.S_OK"></see>. If it fails, it returns an error code.
        /// </returns>
        public int OnBeforeFirstDocumentLock(IVsHierarchy pHier, uint itemid, string pszMkDocument)
        {
            if (string.IsNullOrEmpty(pszMkDocument))
            {
                return(VSErr.S_OK); // Can't be a valid path; don't monitor
            }

            SccDocumentData data;

            if (!_docMap.TryGetValue(pszMkDocument, out data))
            {
                _docMap.Add(pszMkDocument, data = new SccDocumentData(Context, pszMkDocument));

                data.Hierarchy = pHier;
                data.ItemId    = itemid;
            }

            return(VSErr.S_OK);
        }
Ejemplo n.º 4
0
        bool TryPollDirty(SccDocumentData data, out bool dirty)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (!_documentInfo_init)
            {
                _documentInfo_init = true;
                DocumentInfoInit();
            }

            if (data.Cookie == 0 && GetDocumentCookie_cb != null)
            {
                try
                {
                    uint cookie = GetDocumentCookie_cb(data.Name);

                    if (cookie != 0)
                    {
                        data.Cookie        = cookie;
                        _cookieMap[cookie] = data;
                    }
                }
                catch
                { }
            }
            if (IsDocumentDirty_cb != null && data.Cookie != 0)
            {
                try
                {
                    dirty = IsDocumentDirty_cb(data.Cookie);
                    return(true);
                }
                catch
                { }
            }

            return(TryPollDirtyFallback(data, out dirty));
        }
Ejemplo n.º 5
0
        private bool TryGetOpenDocumentFrame(SccDocumentData data, out IVsWindowFrame wf)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (data.Hierarchy == null)
            {
                wf = null;
                return(false);
            }
            Guid           gV = Guid.Empty;
            IVsUIHierarchy hier;

            uint[] openId = new uint[1];

            int open;

            IVsUIShellOpenDocument so = GetService <IVsUIShellOpenDocument>(typeof(SVsUIShellOpenDocument));

            wf = null;

            if (so == null)
            {
                return(false);
            }

            try
            {
                return(VSErr.Succeeded(so.IsDocumentOpen(data.Hierarchy as IVsUIHierarchy, data.ItemId, data.Name, ref gV,
                                                         (uint)__VSIDOFLAGS.IDO_IgnoreLogicalView, out hier, openId, out wf, out open)) &&
                       (open != 0) &&
                       (wf != null));
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        bool TryPollDirtyFallback(SccDocumentData data, out bool dirty)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            bool done = false;

            int            dv;
            IVsWindowFrame wf;
            object         rawDoc = data.RawDocument;

            if (rawDoc != null)
            {
                IVsPersistDocData       pdd;
                IPersistFileFormat      pff;
                IVsPersistHierarchyItem phi;

                // Implemented by most editors
                if (null != (pdd = rawDoc as IVsPersistDocData))
                {
                    if (SafeSucceeded(pdd.IsDocDataDirty, out dv))
                    {
                        if (dv != 0)
                        {
                            dirty = true;
                            return(true);
                        }

                        done = true;
                    }
                }

                // Implemented by the common project types (Microsoft Project Base)
                if (!done && null != (pff = rawDoc as IPersistFileFormat))
                {
                    if (SafeSucceeded(pff.IsDirty, out dv))
                    {
                        if (dv != 0)
                        {
                            dirty = true;
                            return(true);
                        }

                        done = true;
                    }
                }

                // Project based documents will probably handle this
                if (!done && null != (phi = data.Hierarchy as IVsPersistHierarchyItem) && rawDoc != null)
                {
                    IntPtr docHandle = Marshal.GetIUnknownForObject(rawDoc);
                    try
                    {
                        if (VSErr.Succeeded(phi.IsItemDirty(data.ItemId, docHandle, out dv)))
                        {
                            if (dv != 0)
                            {
                                dirty = true;
                                return(true);
                            }

                            done = true;
                        }
                    }
                    catch
                    {
                        // MPF throws a cast exception when docHandle doesn't implement IVsPersistDocData..
                        // which we tried before getting here*/
                    }
                    finally
                    {
                        Marshal.Release(docHandle);
                    }
                }
            }

            // Literally look if the frame window has a modified *
            if (!done && TryGetOpenDocumentFrame(data, out wf) && wf != null)
            {
                object ok;
                if (VSErr.Succeeded(wf.GetProperty((int)__VSFPROPID2.VSFPROPID_OverrideDirtyState, out ok)))
                {
                    if (ok == null)
                    {
                    }
                    else if (ok is bool) // Implemented by VS as bool
                    {
                        if ((bool)ok)
                        {
                            dirty = true;
                            return(true);
                        }
                    }
                }
            }

            dirty = false;
            return(false);
        }
Ejemplo n.º 7
0
        public int OnAfterAttributeChangeEx(uint docCookie, uint grfAttribs, IVsHierarchy pHierOld, uint itemidOld, string pszMkDocumentOld, IVsHierarchy pHierNew, uint itemidNew, string pszMkDocumentNew)
        {
            if ((grfAttribs & TrackedRDTAttributes) == 0)
            {
                return(VSErr.S_OK); // Not interested
            }
            SccDocumentData data;

            if (!TryGetDocument(docCookie, true, out data))
            {
                return(VSErr.S_OK);
            }

            __VSRDTATTRIB attribs = (__VSRDTATTRIB)grfAttribs;

            {
                bool wasInitialized = data.IsDocumentInitialized;

                data.OnAttributeChange(attribs, _poller);

                if (!wasInitialized &&
                    GetDocumentFlags_cb != null &&
                    (attribs & (SccDocumentData.RDTA_DocumentInitialized | SccDocumentData.RDTA_HierarchyInitialized)) != 0)
                {
                    uint newFlags = GetDocumentFlags_cb(data.Cookie);
                    data.SetFlags((_VSRDTFLAGS)newFlags);
                }
            }


            if ((attribs & __VSRDTATTRIB.RDTA_ItemID) == __VSRDTATTRIB.RDTA_ItemID)
            {
                data.ItemId = itemidNew;
            }

            if ((attribs & __VSRDTATTRIB.RDTA_Hierarchy) == __VSRDTATTRIB.RDTA_Hierarchy)
            {
                data.Hierarchy = pHierNew;
            }

            if ((attribs & __VSRDTATTRIB.RDTA_MkDocument) == __VSRDTATTRIB.RDTA_MkDocument &&
                !string.IsNullOrEmpty(pszMkDocumentNew))
            {
                if (data.Name != pszMkDocumentNew)
                {
                    // The document changed names; Handle this as opening a new document

                    SccDocumentData newData;

                    if (!_docMap.TryGetValue(pszMkDocumentNew, out newData))
                    {
                        newData = new SccDocumentData(Context, pszMkDocumentNew);
                        newData.CopyState(data);
                        newData.Cookie = docCookie;
                        data.Dispose();

                        _docMap.Add(pszMkDocumentNew, newData);
                    }
                    else
                    {
                        data.Dispose(); // Removes old item from docmap and cookie map if necessary
                    }

                    _cookieMap[newData.Cookie] = newData;
                    data = newData;
                }

                if (!string.IsNullOrEmpty(pszMkDocumentOld) && pszMkDocumentNew != pszMkDocumentOld)
                {
                    if (SvnItem.IsValidPath(pszMkDocumentNew) && SvnItem.IsValidPath(pszMkDocumentOld))
                    {
                        string oldFile = SvnTools.GetNormalizedFullPath(pszMkDocumentOld);
                        string newFile = SvnTools.GetNormalizedFullPath(pszMkDocumentNew);
                        ProjectTracker.OnDocumentSaveAs(oldFile, newFile);
                    }
                }
            }

            return(VSErr.S_OK);
        }
Ejemplo n.º 8
0
        bool TryGetDocument(uint cookie, bool create, out SccDocumentData data)
        {
            if (cookie == 0)
            {
                data = null;
                return(false);
            }

            if (_cookieMap.TryGetValue(cookie, out data))
            {
                return(true);
            }

            if (!create)
            {
                data = null;
                return(false);
            }

            string       name;
            uint         flags;
            IVsHierarchy hier;
            uint         itemId;
            object       document;

            if (TryGetDocumentInfo(cookie, out name, out flags, out hier, out itemId, out document))
            {
                if (!string.IsNullOrEmpty(name))
                {
                    if (_docMap.TryGetValue(name, out data))
                    {
                        if (data.Cookie != 0)
                        {
                            _cookieMap.Remove(data.Cookie);
                            data.Cookie = 0;
                        }
                    }
                    else
                    {
                        _docMap.Add(name, data = new SccDocumentData(Context, name));

                        if (hier != null)
                        {
                            data.Hierarchy = hier;
                            data.ItemId    = itemId;
                        }
                    }

                    data.SetFlags((_VSRDTFLAGS)flags);

                    if (document != null)
                    {
                        data.RawDocument = document;
                    }

                    data.Cookie = cookie;
                    _cookieMap.Add(cookie, data);
                }
            }
            else
            {
                data = null;
            }

            return(data != null);
        }
Ejemplo n.º 9
0
 bool TryGetDocument(uint cookie, out SccDocumentData data)
 {
     return(TryGetDocument(cookie, false, out data));
 }
Ejemplo n.º 10
0
        bool TryGetDocument(uint cookie, out SccDocumentData data)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            return(TryGetDocument(cookie, false, out data));
        }