Beispiel #1
0
        /// <include file='doc\Utilities.uex' path='docs/doc[@for="VsShell.OpenDocumentWithSpecificEditor1"]/*' />
        public static void OpenDocumentWithSpecificEditor(IServiceProvider provider, string fullPath, Guid editorType, Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame) {
            windowFrame = null;
            itemID = NativeMethods.VSITEMID_NIL;
            hierarchy = null;
            //open document
            IVsUIShellOpenDocument shellOpenDoc = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            RunningDocumentTable pRDT = new RunningDocumentTable(provider);
            string physicalView = null;
            if (shellOpenDoc != null) {
                NativeMethods.ThrowOnFailure(shellOpenDoc.MapLogicalView(ref editorType, ref logicalView, out physicalView));
                // See if the requested editor is already open with the requested view.
                uint docCookie;
                IVsHierarchy ppIVsHierarchy;
                object docData = pRDT.FindDocument(fullPath, out ppIVsHierarchy, out itemID, out docCookie);
                if (docData != null) {
                    int pfOpen;
                    uint flags = (uint)__VSIDOFLAGS.IDO_ActivateIfOpen;
                    int hr = shellOpenDoc.IsSpecificDocumentViewOpen((IVsUIHierarchy)ppIVsHierarchy, itemID, fullPath, ref editorType, physicalView, flags, out hierarchy, out itemID, out windowFrame, out pfOpen);
                    if (NativeMethods.Succeeded(hr) && pfOpen == 1) {
                        return;
                    }
                }

                IOleServiceProvider psp;
                uint editorFlags = (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_UseEditor | (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen;
                NativeMethods.ThrowOnFailure(shellOpenDoc.OpenDocumentViaProjectWithSpecific(fullPath, editorFlags, ref editorType, physicalView, ref logicalView, out psp, out hierarchy, out itemID, out windowFrame));
                if (windowFrame != null)
                    NativeMethods.ThrowOnFailure(windowFrame.Show());
                psp = null;
            }
        }
Beispiel #2
0
 /// <include file='doc\Utilities.uex' path='docs/doc[@for="VsShell.IsDocumentOpen"]/*' />
 /// Returns true and item hierarchy and window frame if the document is open with the given
 /// logical view.  If logicalView is Guid.Empty, then it returns true if any view is open.
 public static bool IsDocumentOpen(IServiceProvider provider, string fullPath, Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame) {
     windowFrame = null;
     itemID = NativeMethods.VSITEMID_NIL;
     hierarchy = null;
     //open document
     IVsUIShellOpenDocument shellOpenDoc = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
     RunningDocumentTable pRDT = new RunningDocumentTable(provider);
     if (shellOpenDoc != null) {
         uint docCookie;
         uint[] pitemid = new uint[1];
         IVsHierarchy ppIVsHierarchy;
         object docData = pRDT.FindDocument(fullPath, out ppIVsHierarchy, out pitemid[0], out docCookie);
         if (docData == null) {
             return false;
         } else {
             int pfOpen;
             uint flags = (logicalView == Guid.Empty) ? (uint)__VSIDOFLAGS.IDO_IgnoreLogicalView : 0;
             NativeMethods.ThrowOnFailure(shellOpenDoc.IsDocumentOpen((IVsUIHierarchy)ppIVsHierarchy, pitemid[0], fullPath, ref logicalView, flags, out hierarchy, pitemid, out windowFrame, out pfOpen));
             if (windowFrame != null) {
                 itemID = pitemid[0];
                 return (pfOpen == 1);
             }
         }
     }
     return false;
 }
Beispiel #3
0
        public void Suspend() {
            if (this.fSuspending)
                return;

            try {
                RunningDocumentTable pRDT = new RunningDocumentTable(this.site);
                IVsFileChangeEx vsFileChange;
                uint uiVsDocCookie;

                object docData = pRDT.FindDocument(this.strDocumentFileName, out uiVsDocCookie);
           
                if ((uiVsDocCookie == (uint)ShellConstants.VSDOCCOOKIE_NIL) || docData == null)
                    return;

                vsFileChange = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;

                if (vsFileChange != null) {
                    this.fSuspending = true;
                    NativeMethods.ThrowOnFailure(vsFileChange.IgnoreFile(0, this.strDocumentFileName, (int)1));
                    if (docData is IVsDocDataFileChangeControl) {
                        // if interface is not supported, return null
                        IVsPersistDocData ppIVsPersistDocData = (IVsPersistDocData)docData;
                        if (ppIVsPersistDocData is IVsDocDataFileChangeControl){
                            this.fileChangeControl = (IVsDocDataFileChangeControl)ppIVsPersistDocData;
                            if (this.fileChangeControl != null) {
                                NativeMethods.ThrowOnFailure(this.fileChangeControl.IgnoreFileChanges(1));
                            }
                        }
                    }
                }                
            } catch {
            }
            return;
        }
Beispiel #4
0
        /// <include file='doc\Utilities.uex' path='docs/doc[@for="VsShell.RenameDocument"]/*' />
        public static void RenameDocument(IServiceProvider site, string oldName, string newName) {
            RunningDocumentTable pRDT = new RunningDocumentTable(site);

            IVsUIShellOpenDocument doc = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            IVsUIShell uiShell = site.GetService(typeof(SVsUIShell)) as IVsUIShell;

            if (doc == null || uiShell == null) return;

            IVsHierarchy pIVsHierarchy;
            uint itemId;
            uint uiVsDocCookie;
            object docData = pRDT.FindDocument(oldName, out pIVsHierarchy, out itemId, out uiVsDocCookie);

            if (docData != null) {
                pRDT.RenameDocument(oldName, newName, pIVsHierarchy, itemId);
                
                string newCaption = Path.GetFileName(newName);
                // now we need to tell the windows to update their captions.
                IEnumWindowFrames ppenum;
                NativeMethods.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out ppenum));
                IVsWindowFrame[] rgelt = new IVsWindowFrame[1];
                uint fetched;
                while (ppenum.Next(1, rgelt, out fetched) == NativeMethods.S_OK && fetched == 1) {
                    IVsWindowFrame windowFrame = rgelt[0];
                    object data;
                    NativeMethods.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out data));
                    if (IsSameCOMObject(data, docData)) {
                        NativeMethods.ThrowOnFailure(windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, newCaption));
                    }
                }
            }
        }
Beispiel #5
0
        internal void ReportTasks(ArrayList errors)
        {
            TaskProvider taskProvider = this.GetTaskProvider();

            if (errors == null || errors.Count == 0) {
                if (taskProvider.Tasks.Count > 0) {
                    taskProvider.Tasks.Clear();
                }
                return;
            }
            int removed = 0;
            int added = 0;
            int merged = 0;
            int errorMax = this.service.Preferences.MaxErrorMessages;
            string fname = this.GetFilePath();
            RunningDocumentTable rdt = new RunningDocumentTable(this.service.Site);
            IVsHierarchy thisHeirarchy = rdt.GetHierarchyItem(fname);

            // Here we merge errors lists to reduce flicker.  It is not a very intelligent merge
            // but that is ok, the worst case is the task list flickers a bit.  But 99% of the time
            // one error is added or removed as the user is typing, and this merge will reduce flicker
            // in this case.
            errors = GroupBySeverity(errors);
            taskProvider.SuspendRefresh(); // batch updates.
            int pos = 0;
            TaskErrorCategory mostSevere = TaskErrorCategory.Message;

            for (int i = 0, n = errors.Count; i < n; i++) {
                ErrorNode enode = (ErrorNode)errors[i];
                string filename = enode.uri;
                bool thisFile = (!string.IsNullOrEmpty(filename) && NativeMethods.IsSamePath(fname, filename));

                TextSpan span = enode.context;
                Severity severity = enode.severity;
                string message = enode.message;
                if (message == null) continue;

                message = NormalizeString(message);
                // Don't do multi-line squiggles, instead just squiggle to the
                // end of the first line.
                if (span.iEndLine > span.iStartLine) {
                    span.iEndLine = span.iStartLine;
                    NativeMethods.ThrowOnFailure(this.textLines.GetLengthOfLine(span.iStartLine, out span.iEndIndex));
                }
                //normalize text span
                if (thisFile) {
                    FixupMarkerSpan(ref span);
                } else {
                    TextSpanHelper.MakePositive(ref span);
                }
                //set options
                TaskPriority priority = TaskPriority.Normal;
                TaskCategory category = TaskCategory.BuildCompile;
                MARKERTYPE markerType = MARKERTYPE.MARKER_CODESENSE_ERROR;
                TaskErrorCategory errorCategory = TaskErrorCategory.Warning;

                if (severity == Severity.Fatal || severity == Severity.Error) {
                    priority = TaskPriority.High;
                    errorCategory = TaskErrorCategory.Error;
                } else if (severity == Severity.Hint) {
                    category = TaskCategory.Comments;
                    markerType = MARKERTYPE.MARKER_INVISIBLE;
                    errorCategory = TaskErrorCategory.Message;
                } else if (severity == Severity.Warning) {
                    markerType = MARKERTYPE.MARKER_COMPILE_ERROR;
                    errorCategory = TaskErrorCategory.Warning;
                }
                if (errorCategory < mostSevere) {
                    mostSevere = errorCategory;
                }

                IVsHierarchy hierarchy = thisHeirarchy;
                if (!thisFile) {
                    // must be an error reference to another file.
                    hierarchy = rdt.GetHierarchyItem(filename);
                    markerType = MARKERTYPE.MARKER_OTHER_ERROR; // indicate to CreateErrorTaskItem
                }

                bool found = false;
                while (pos < taskProvider.Tasks.Count) {
                    Task current = taskProvider.Tasks[pos];
                    if (current is DocumentTask) {
                        DocumentTask dt = (DocumentTask)current;
                        if (dt.IsMarkerValid && // marker is still valid?
                            NativeMethods.IsSamePath(current.Document, filename) &&
                            current.Text == message && TextSpanHelper.IsSameSpan(span, dt.Span) &&
                            current.Category == category &&
                            current.Priority == priority &&
                            dt.ErrorCategory == errorCategory) {
                            pos++;
                            merged++;
                            found = true;
                            // Since we're reusing the existing entry, let's make sure the line
                            // line number we are displaying the right line number information.
                            // (The DocumentTask gets out of sync with the IVsTextLineMarker because
                            // the IVsTextLineMarker is a bookmark that tracks user edits).
                            if (dt.Column != span.iStartIndex || dt.Line != span.iStartLine) {
                                dt.Column = span.iStartIndex;
                                dt.Line = span.iStartLine;
                                taskProvider.Refresh(); // mark it as dirty.
                            }
                            break;
                        }
                    }
                    removed++;
                    taskProvider.Tasks.RemoveAt(pos);
                }
                if (!found) {
                    added++;
                    DocumentTask docTask = this.CreateErrorTaskItem(span, filename, message, priority, category, markerType, errorCategory);
                    docTask.HierarchyItem = hierarchy;
                    taskProvider.Tasks.Insert(pos, docTask);
                    pos++;
                }
                //check error count
                if (pos == errorMax) {
                    string maxMsg = SR.GetString(SR.MaxErrorsReached);
                    string localFile = this.GetFilePath();
                    span = this.GetDocumentSpan();
                    span.iStartIndex = span.iEndIndex;
                    span.iStartLine = span.iEndLine;
                    DocumentTask error = this.CreateErrorTaskItem(span, localFile, maxMsg, TaskPriority.High, TaskCategory.CodeSense, MARKERTYPE.MARKER_INVISIBLE, mostSevere);
                    error.HierarchyItem = hierarchy;
                    taskProvider.Tasks.Insert(pos, error);
                    pos++;
                    break;
                }
            }
            // remove trailing errors that should no longer exist.
            while (pos < taskProvider.Tasks.Count) {
                removed++;
                taskProvider.Tasks.RemoveAt(pos);
            }
            taskProvider.ResumeRefresh(); // batch updates.
        }