Beispiel #1
0
        /// <summary>
        /// Saves the hierarchy item to disk.
        /// </summary>
        /// <param name="dwSave">Flags whose values are taken from the VSSAVEFLAGS enumeration.</param>
        /// <param name="silentSaveAsName">File name to be applied when dwSave is set to VSSAVE_SilentSave. </param>
        /// <param name="itemid">Item identifier of the hierarchy item saved from VSITEMID. </param>
        /// <param name="punkDocData">Pointer to the IUnknown interface of the hierarchy item saved.</param>
        /// <param name="pfCancelled">TRUE if the save action was canceled. </param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int SaveItem(VSSAVEFLAGS dwSave, string silentSaveAsName, uint itemid, IntPtr punkDocData, out int pfCancelled)
        {
            // Don't ignore/unignore file changes
            // Use Advise/Unadvise to work around rename situations
            try
            {
                this.StopObservingNestedProjectFile();
                Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");
                Debug.Assert(punkDocData != IntPtr.Zero, "docData intptr was zero");

                // Get an IPersistFileFormat object from docData object (we don't call release on punkDocData since did not increment its ref count)
                IPersistFileFormat persistFileFormat = Marshal.GetTypedObjectForIUnknown(punkDocData, typeof(IPersistFileFormat)) as IPersistFileFormat;
                Debug.Assert(persistFileFormat != null, "The docData object does not implement the IPersistFileFormat interface");

                IVsUIShell uiShell = this.GetService(typeof(SVsUIShell)) as IVsUIShell;
                string     newName;
                ErrorHandler.ThrowOnFailure(uiShell.SaveDocDataToFile(dwSave, persistFileFormat, silentSaveAsName, out newName, out pfCancelled));

                // When supported do a rename of the nested project here
            }
            finally
            {
                // Succeeded or not we must hook to the file change events
                // Don't ignore/unignore file changes
                // Use Advise/Unadvise to work around rename situations
                this.ObserveNestedProjectFile();
            }

            return(VSConstants.S_OK);
        }
Beispiel #2
0
        protected virtual void LockRDTEntry()
        {
            // Define flags for the nested project document
            _VSRDTFLAGS flags = _VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_ProjSlnDocument;;

            // Request the RDT service
            IVsRunningDocumentTable rdt = this.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            Debug.Assert(rdt != null, " Could not get running document table from the services exposed by this project");
            if (rdt == null)
            {
                throw new InvalidOperationException();
            }

            // First we see if someone else has opened the requested view of the file.
            uint         itemid;
            IntPtr       docData = IntPtr.Zero;
            IVsHierarchy ivsHierarchy;
            uint         docCookie;
            IntPtr       projectPtr = IntPtr.Zero;

            try
            {
                ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)flags, this.projectPath, out ivsHierarchy, out itemid, out docData, out docCookie));
                flags |= _VSRDTFLAGS.RDT_EditLock;

                if (ivsHierarchy != null && docCookie != (uint)ShellConstants.VSDOCCOOKIE_NIL)
                {
                    if (docCookie != this.DocCookie)
                    {
                        this.DocCookie = docCookie;
                    }
                }
                else
                {
                    // get inptr for hierarchy
                    projectPtr = Marshal.GetIUnknownForObject(this.nestedHierarchy);
                    Debug.Assert(projectPtr != IntPtr.Zero, " Project pointer for the nested hierarchy has not been initialized");
                    ErrorHandler.ThrowOnFailure(rdt.RegisterAndLockDocument((uint)flags, this.projectPath, this.ProjectMgr, this.ID, projectPtr, out docCookie));

                    this.DocCookie = docCookie;
                    Debug.Assert(this.DocCookie != (uint)ShellConstants.VSDOCCOOKIE_NIL, "Invalid cookie when registering document in the running document table.");

                    //we must also set the doc cookie on the nested hier
                    this.SetDocCookieOnNestedHier(this.DocCookie);
                }
            }
            finally
            {
                // Release all Inptr's that that were given as out pointers
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
                if (projectPtr != IntPtr.Zero)
                {
                    Marshal.Release(projectPtr);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Links a nested project as a virtual project to the solution.
        /// </summary>
        protected internal virtual void AddVirtualProject()
        {
            // This is the second step in creating and adding a nested project. The inner hierarchy must have been
            // already initialized at this point.
            #region precondition
            if (this.nestedHierarchy == null)
            {
                throw new InvalidOperationException();
            }
            #endregion
            // get the IVsSolution interface from the global service provider
            IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;
            Debug.Assert(solution != null, "Could not get the IVsSolution object from the services exposed by this project");
            if (solution == null)
            {
                throw new InvalidOperationException();
            }

            this.InitializeInstanceGuid();

            // Add virtual project to solution.
            ErrorHandler.ThrowOnFailure(solution.AddVirtualProjectEx(this.nestedHierarchy, this.VirtualProjectFlags, ref this.projectInstanceGuid));

            // Now set up to listen on file changes on the nested project node.
            this.ObserveNestedProjectFile();
        }
        public int Close(IOleParentUndoUnit pPUU, int fCommit)
        {
            if (pPUU == null)
            {
                return(VSConstants.S_FALSE);
            }

            if (_openParent == null)
            {
                return(VSConstants.S_FALSE);
            }

            var hr = _openParent.Close(pPUU, fCommit);

            if (VSErrorHandler.Failed(hr))
            {
                return(hr);
            }

            if (_openParent == pPUU)
            {
                _openParent = null;
                if (fCommit != 0)
                {
                    _children.Add(pPUU);
                }
                return(VSConstants.S_OK);
            }
            else
            {
                throw new ArgumentException("Closing the wrong parent unit!");
            }
        }
Beispiel #5
0
        public int OnShellPropertyChange(int propid, object propValue)
        {
            if (Preferences.LocalSettings.GetBool("P4_CONNECTION_TOOLBAR_ACTIVATED", false))
            {
                return(VSConstants.S_OK);
            }
            // --- We handle the event if zombie state changes from true to false
            if ((int)__VSSPROPID.VSSPROPID_Zombie == propid)
            {
                if ((bool)propValue == false)
                {
                    // --- Show the commandbar
                    var        dte = GetService(typeof(DTE)) as DTE2;
                    var        cbs = ((CommandBars)dte.CommandBars);
                    CommandBar cb  = cbs["Helix Connection"];
                    cb.Visible = true;

                    // --- Unsubscribe from events
                    var shellService = GetService(typeof(SVsShell)) as IVsShell;
                    if (shellService != null)
                    {
                        ErrorHandler.ThrowOnFailure(shellService.UnadviseShellPropertyChanges(_EventSinkCookie));
                    }
                    _EventSinkCookie = 0;

                    // set the pref that this has been force-set once
                    // if the user unsets it after that, we do not want to
                    // override that on every launch of Visual Studio
                    Preferences.LocalSettings["P4_CONNECTION_TOOLBAR_ACTIVATED"] = true;
                }
            }
            return(VSConstants.S_OK);
        }
Beispiel #6
0
        ///-------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Returns the current contents of a document
        /// </summary>
        ///-------------------------------------------------------------------------------------------------------------
        public string GetDocumentText()
        {
            string            text    = null;
            IVsPersistDocData docData = null;

            try
            {
                // Get or create the buffer
                IVsTextLines buffer = GetRunningDocumentTextBuffer();
                if (buffer == null)
                {
                    docData = CreateDocumentData();
                    buffer  = docData as IVsTextLines;
                }

                // get the text from the buffer
                if (buffer != null)
                {
                    IVsTextStream textStream = buffer as IVsTextStream;
                    if (textStream != null)
                    {
                        int length;
                        int hr = textStream.GetSize(out length);
                        if (ErrorHandler.Succeeded(hr))
                        {
                            if (length > 0)
                            {
                                IntPtr pText = Marshal.AllocCoTaskMem((length + 1) * 2);
                                try
                                {
                                    hr = textStream.GetStream(0, length, pText);
                                    if (ErrorHandler.Succeeded(hr))
                                    {
                                        text = Marshal.PtrToStringUni(pText);
                                    }
                                }
                                finally
                                {
                                    Marshal.FreeCoTaskMem(pText);
                                }
                            }
                            else
                            {
                                text = string.Empty;
                            }
                        }
                    }
                }
            }
            finally
            {
                if (docData != null)
                {
                    docData.Close();
                }
            }

            return(text);
        }
Beispiel #7
0
        private void InitializeInstanceGuid()
        {
            if (this.projectInstanceGuid != Guid.Empty)
            {
                return;
            }

            Guid instanceGuid = Guid.Empty;

            Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");

            // This method should be called from the open children method, then we can safely use the IsNewProject property
            if (this.ProjectMgr.IsNewProject)
            {
                instanceGuid = Guid.NewGuid();
                this.ItemNode.SetMetadata(ProjectFileConstants.InstanceGuid, instanceGuid.ToString("B"));
                ErrorHandler.ThrowOnFailure(this.nestedHierarchy.SetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, ref instanceGuid));
            }
            else
            {
                // Get a guid from the nested hiererachy.
                Guid nestedHiererachyInstanceGuid;
                ErrorHandler.ThrowOnFailure(this.nestedHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out nestedHiererachyInstanceGuid));

                // Get instance guid from the project file. If it does not exist then we create one.
                string instanceGuidAsString = this.ItemNode.GetMetadata(ProjectFileConstants.InstanceGuid);

                // 1. nestedHiererachyInstanceGuid is empty and instanceGuidAsString is empty then create a new one.
                // 2. nestedHiererachyInstanceGuid is empty and instanceGuidAsString not empty use instanceGuidAsString and update the nested project object by calling SetGuidProperty.
                // 3. nestedHiererachyInstanceGuid is not empty instanceGuidAsString is empty then use nestedHiererachyInstanceGuid and update the outer project element.
                // 4. nestedHiererachyInstanceGuid is not empty instanceGuidAsString is empty then use nestedHiererachyInstanceGuid and update the outer project element.

                if (nestedHiererachyInstanceGuid == Guid.Empty && String.IsNullOrEmpty(instanceGuidAsString))
                {
                    instanceGuid = Guid.NewGuid();
                }
                else if (nestedHiererachyInstanceGuid == Guid.Empty && !String.IsNullOrEmpty(instanceGuidAsString))
                {
                    instanceGuid = new Guid(instanceGuidAsString);

                    ErrorHandler.ThrowOnFailure(this.nestedHierarchy.SetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, ref instanceGuid));
                }
                else if (nestedHiererachyInstanceGuid != Guid.Empty)
                {
                    instanceGuid = nestedHiererachyInstanceGuid;

                    // If the instanceGuidAsString is empty then creating a guid out of it would throw an exception.
                    if (String.IsNullOrEmpty(instanceGuidAsString) || nestedHiererachyInstanceGuid != new Guid(instanceGuidAsString))
                    {
                        this.ItemNode.SetMetadata(ProjectFileConstants.InstanceGuid, instanceGuid.ToString("B"));
                    }
                }
            }

            this.projectInstanceGuid = instanceGuid;
        }
Beispiel #8
0
        /// <summary>
        /// Called by the shell when a node has been renamed from the GUI
        /// </summary>
        /// <param name="label">The name of the new label.</param>
        /// <returns>A success or failure value.</returns>
        public override int SetEditLabel(string label)
        {
            int result = this.DelegateSetPropertyToNested((int)__VSHPROPID.VSHPROPID_EditLabel, label);

            if (ErrorHandler.Succeeded(result))
            {
                this.RenameNestedProjectInParentProject(label);
            }

            return(result);
        }
Beispiel #9
0
        internal static string GetTextFromVsTextLines(IVsTextLines vsTextLines)
        {
            int lines;
            int lastLineLength;

            VSErrorHandler.ThrowOnFailure(vsTextLines.GetLineCount(out lines));
            VSErrorHandler.ThrowOnFailure(vsTextLines.GetLengthOfLine(lines - 1, out lastLineLength));

            string text;

            VSErrorHandler.ThrowOnFailure(vsTextLines.GetLineText(0, 0, lines - 1, lastLineLength, out text));
            return(text);
        }
Beispiel #10
0
        /// <summary>
        /// Delegates Getproperty calls to the inner nested.
        /// </summary>
        /// <param name="propID">The property to delegate.</param>
        /// <returns>The return of the GetProperty from nested.</returns>
        private object DelegateGetPropertyToNested(int propID)
        {
            object returnValue = null;

            if (!this.ProjectMgr.IsClosed)
            {
                Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");

                // Do not throw since some project types will return E_FAIL if they do not support a property.
                ErrorHandler.ThrowOnFailure(this.nestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, propID, out returnValue));
            }
            return(returnValue);
        }
Beispiel #11
0
        private void SetDocCookieOnNestedHier(uint itemDocCookie)
        {
            object docCookie = (int)itemDocCookie;

            try
            {
                ErrorHandler.ThrowOnFailure(this.nestedHierarchy.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ItemDocCookie, docCookie));
            }
            catch (NotImplementedException)
            {
                //we swallow this exception on purpose
            }
        }
Beispiel #12
0
        private IntPtr CreateCodeView(IVsTextLines textLines, ref string editorCaption, ref Guid cmdUI)
        {
            Type          codeWindowType = typeof(IVsCodeWindow);
            Guid          riid           = codeWindowType.GUID;
            Guid          clsid          = typeof(VsCodeWindowClass).GUID;
            IVsCodeWindow window         = (IVsCodeWindow)package.CreateInstance(ref clsid, ref riid, codeWindowType);

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));
            cmdUI = VSConstants.GUID_TextEditorFactory;
            return(Marshal.GetIUnknownForObject(window));
        }
        private static bool ShouldLoadEDMPackage(IVsHierarchy project)
        {
            var shouldLoadEDMPackage = false;

            try
            {
                if (BootstrapUtils.IsEDMSupportedInProject(project))
                {
                    // Check if project is a website project. If yes, search for edmx files under the app_code folder.
                    // Note that website project doesn't have project file and to exclude files from project you append ".exclude" in file name.
                    var dteProject = BootstrapUtils.GetProject(project);
                    if (dteProject != null &&
                        BootstrapUtils.IsWebProject(dteProject))
                    {
                        var projectFullPathProperty = dteProject.Properties.Item("FullPath");
                        var projectFullPath         = projectFullPathProperty.Value as string;

                        Debug.Assert(String.IsNullOrWhiteSpace(projectFullPath) == false, "Unable to get project full path");
                        if (String.IsNullOrWhiteSpace(projectFullPath) == false)
                        {
                            // App_Code is a special folder that will not be localized should always be under root folder.
                            var appCodePath = Path.Combine(projectFullPath, "App_Code");

                            if (Directory.Exists(appCodePath))
                            {
                                // Directory.GetFiles could potentially be an expensive operation.
                                // If the performance is not acceptable, we should look into calling Win32 API to search for files.
                                shouldLoadEDMPackage =
                                    Directory.GetFiles(appCodePath, "*" + ExtensionEdmx, SearchOption.AllDirectories).Any();
                            }
                        }
                    }
                    else
                    {
                        var fileFinder = new VSFileFinder(ExtensionEdmx);
                        shouldLoadEDMPackage = fileFinder.ExistInProject(project);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Fail("Caught exception in BootstrapPackage's ShouldLoadEDMPackage method. Message: " + ex.Message);
                // We want to continue loading the package if the exception is not critical.
                // Do not do Debug.Assert here because it could cause a lot of DDBasic failures in CHK build.
                if (VSErrorHandler.IsCriticalException(ex))
                {
                    throw;
                }
            }
            return(shouldLoadEDMPackage);
        }
        private void ShowToolWindow(Type type)
        {
            ToolWindowPane window      = this.FindToolWindow(type, 0, true);
            IVsWindowFrame windowFrame = null;

            if (window != null && window.Frame != null)
            {
                windowFrame = (IVsWindowFrame)window.Frame;
            }
            if (windowFrame != null)
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Show());
            }
        }
Beispiel #15
0
        /// <summary>
        /// Determines whether the hierarchy item changed.
        /// </summary>
        /// <param name="itemId">Item identifier of the hierarchy item contained in VSITEMID</param>
        /// <param name="punkDocData">Pointer to the IUnknown interface of the hierarchy item. </param>
        /// <param name="pfDirty">TRUE if the hierarchy item changed.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int IsItemDirty(uint itemId, IntPtr punkDocData, out int pfDirty)
        {
            Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");
            Debug.Assert(punkDocData != IntPtr.Zero, "docData intptr was zero");

            // Get an IPersistFileFormat object from docData object
            IPersistFileFormat persistFileFormat = Marshal.GetTypedObjectForIUnknown(punkDocData, typeof(IPersistFileFormat)) as IPersistFileFormat;

            Debug.Assert(persistFileFormat != null, "The docData object does not implement the IPersistFileFormat interface");

            // Call IsDirty on the IPersistFileFormat interface
            ErrorHandler.ThrowOnFailure(persistFileFormat.IsDirty(out pfDirty));

            return(VSConstants.S_OK);
        }
Beispiel #16
0
        private void InitImageHandler()
        {
            Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");

            if (null == imageHandler)
            {
                imageHandler = new ImageHandler();
            }
            object imageListAsPointer = null;

            ErrorHandler.ThrowOnFailure(this.nestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_IconImgList, out imageListAsPointer));
            if (imageListAsPointer != null)
            {
                this.imageHandler.ImageList = Utilities.GetImageList(imageListAsPointer);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Closes a nested project and releases the nested hierrachy pointer.
        /// </summary>
        internal void CloseNestedProjectNode()
        {
            if (this.isDisposed || this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return;
            }

            uint itemid = VSConstants.VSITEMID_NIL;

            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                this.DisconnectPropertyNotifySink();

                IVsUIHierarchy hier;

                IVsWindowFrame windowFrame;
                VsShellUtilities.IsDocumentOpen(this.ProjectMgr.Site, this.projectPath, Guid.Empty, out hier, out itemid, out windowFrame);


                if (itemid == VSConstants.VSITEMID_NIL)
                {
                    this.UnlockRDTEntry();
                }

                IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;
                if (solution == null)
                {
                    throw new InvalidOperationException();
                }

                ErrorHandler.ThrowOnFailure(solution.RemoveVirtualProject(this.nestedHierarchy, 0));
            }
            finally
            {
                this.StopObservingNestedProjectFile();

                // if we haven't already release the RDT cookie, do so now.
                if (itemid == VSConstants.VSITEMID_NIL)
                {
                    this.UnlockRDTEntry();
                }

                this.Dispose(true);
            }
        }
        private bool IsEDMPackageLoaded()
        {
            var vsShell = (IVsShell)GetService(typeof(SVsShell));

            Debug.Assert(vsShell != null, "unexpected null value for vsShell");
            if (vsShell != null)
            {
                var        packageGuid = guidEscherPkg;
                IVsPackage package     = null;
                var        hr          = vsShell.IsPackageLoaded(ref packageGuid, out package);
                if (VSErrorHandler.Succeeded(hr) && package != null)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #19
0
        /// <summary>
        ///     returns the IVsTextLines for the given docData object
        /// </summary>
        /// <param name="docData"></param>
        /// <returns></returns>
        internal static IVsTextLines GetVsTextLinesFromDocData(object docData)
        {
            if (docData == null)
            {
                return(null);
            }
            var buffer = docData as IVsTextLines;

            if (buffer == null)
            {
                var bp = docData as IVsTextBufferProvider;
                if (bp != null)
                {
                    VSErrorHandler.ThrowOnFailure(bp.GetTextBuffer(out buffer));
                }
            }
            return(buffer);
        }
Beispiel #20
0
        /// <summary>
        /// Notifies a sink that the [bindable] property specified by dispID has changed.
        /// If dispID is DISPID_UNKNOWN, then multiple properties have changed together.
        /// The client (owner of the sink) should then retrieve the current value of each property of interest from the object that generated the notification.
        /// In our case we will care about the  VSLangProj80.VsProjPropId.VBPROJPROPID_FileName and update the changes in the parent project file.
        /// </summary>
        /// <param name="dispid">Dispatch identifier of the property that is about to change or DISPID_UNKNOWN if multiple properties are about to change.</param>
        public virtual void OnChanged(int dispid)
        {
            if (dispid == (int)VSLangProj80.VsProjPropId.VBPROJPROPID_FileName)
            {
                // Get the filename of the nested project. Inetead of asking the label on the nested we ask the filename, since the label might not yet been set.
                IVsProject3 nestedProject = this.nestedHierarchy as IVsProject3;

                if (nestedProject != null)
                {
                    string document;
                    ErrorHandler.ThrowOnFailure(nestedProject.GetMkDocument(VSConstants.VSITEMID_ROOT, out document));
                    this.RenameNestedProjectInParentProject(Path.GetFileNameWithoutExtension(document));

                    // We need to redraw the caption since for some reason, by intervining to the OnChanged event the Caption is not updated.
                    this.ReDraw(UIHierarchyElement.Caption);
                }
            }
        }
Beispiel #21
0
        protected virtual void UnlockRDTEntry()
        {
            if (this.isDisposed || this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return;
            }
            // First we see if someone else has opened the requested view of the file.
            IVsRunningDocumentTable rdt = this.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (rdt != null && this.DocCookie != (int)ShellConstants.VSDOCCOOKIE_NIL)
            {
                _VSRDTFLAGS flags = _VSRDTFLAGS.RDT_EditLock;

                ErrorHandler.ThrowOnFailure(rdt.UnlockDocument((uint)flags, (uint)this.DocCookie));
            }

            this.DocCookie = (int)ShellConstants.VSDOCCOOKIE_NIL;
        }
        private async Task <T> ShowToolWindow <T>()
            where T : ToolWindowPane
        {
            ToolWindowPane window      = this.FindToolWindow(typeof(T), 0, true);
            IVsWindowFrame windowFrame = null;

            if (window != null && window.Frame != null)
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                windowFrame = (IVsWindowFrame)window.Frame;
            }
            if (windowFrame != null)
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Show());
                return(window as T);
            }
            return(null);
        }
Beispiel #23
0
        internal void VisitHierarchy(IVsHierarchy root)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            object pvar;
            Url    baseUri    = null;
            var    hr         = root.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out pvar);
            var    projectDir = pvar as string;

            if (VSErrorHandler.Succeeded(hr) &&
                projectDir != null)
            {
                baseUri = new Url(projectDir + Path.DirectorySeparatorChar);
            }
            VisitHierarchyItems(root, VSConstants.VSITEMID_ROOT, baseUri, _handler, true);
        }
Beispiel #24
0
        // <summary>
        //     Updates the title bar to include the item's name that we are editing
        // </summary>
        private void UpdateTitleBar(string name)
        {
            var fullName = Resources.MappingDetails_WindowTitle;

            if (!string.IsNullOrEmpty(name))
            {
                fullName = String.Format(CultureInfo.CurrentCulture, "{0} - {1}", fullName, name);
            }

            var frame = Frame;

            if (frame != null)
            {
                // set window title based on selection
                // this will return E_UNEXPECTED if the frame is disposed, ignore that as there's no need to set the title in that case.
                VsErrorHandler.ThrowOnFailure(
                    frame.SetProperty((int)VsShell.__VSFPROPID.VSFPROPID_Caption, fullName), VSConstants.E_UNEXPECTED);
            }
        }
Beispiel #25
0
        /// <summary>
        /// Delegates Getproperty calls to the inner nested.
        /// </summary>
        /// <param name="propID">The property to delegate.</param>
        /// <returns>The return of the GetProperty from nested.</returns>
        private object DelegateGetPropertyToNested(int propID)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (!this.ProjectMgr.IsClosed)
            {
                Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");

                object returnValue;

                // Do not throw since some project types will return E_FAIL if they do not support a property.
                int result = this.nestedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, propID, out returnValue);
                if (ErrorHandler.Succeeded(result))
                {
                    return(returnValue);
                }
            }

            return(null);
        }
Beispiel #26
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            // Show a Message Box to prove we were here
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            Guid       clsid   = Guid.Empty;
            int        result;

            ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                            0,
                                            ref clsid,
                                            "ShowInitialToolbar",
                                            string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.ToString()),
                                            string.Empty,
                                            0,
                                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                            OLEMSGICON.OLEMSGICON_INFO,
                                            0, // false
                                            out result));
        }
        public void Show()
        {
            var sonarLintOutputPane = VsShellUtils.GetOrCreateSonarLintOutputPane(serviceProvider);

            Debug.Assert(sonarLintOutputPane != null, "Failed to create SonarLint pane");

            if (sonarLintOutputPane == null)
            {
                return;
            }

            var hr = sonarLintOutputPane.Activate();

            Debug.Assert(ErrorHandler.Succeeded(hr), "Failed to activate SonarLint pane: " + hr);

            if (ErrorHandler.Succeeded(hr))
            {
                toolWindowService.Show(VSConstants.StandardToolWindows.Output);
            }
        }
Beispiel #28
0
 ///-------------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Creates and loads the document data
 /// (You must Close() it when done)
 /// </summary>
 ///-------------------------------------------------------------------------------------------------------------
 public IVsPersistDocData CreateDocumentData()
 {
     if (IsFile())
     {
         string fullPath = FullPath();
         if (!string.IsNullOrEmpty(fullPath))
         {
             IOleServiceProvider serviceProvider = (IOleServiceProvider)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(IOleServiceProvider));
             IVsPersistDocData   docData         = WAUtilities.CreateSitedInstance <IVsPersistDocData>(serviceProvider, typeof(VsTextBufferClass).GUID);
             if (docData != null)
             {
                 int hr = docData.LoadDocData(fullPath);
                 if (ErrorHandler.Succeeded(hr))
                 {
                     return(docData);
                 }
             }
         }
     }
     return(null);
 }
Beispiel #29
0
        /// <summary>
        /// Returns a list of solution folders projects in the solution
        /// </summary>
        public Hashtable GetSolutionFoldersEnum()
        {
            Hashtable mapHierarchies = new Hashtable();

            IVsSolution      sol = (IVsSolution)GetService(typeof(SVsSolution));
            Guid             rguidEnumOnlyThisType = guidSolutionFolderProject;
            IEnumHierarchies ppenum = null;

            ErrorHandler.ThrowOnFailure(sol.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref rguidEnumOnlyThisType, out ppenum));

            IVsHierarchy[] rgelt        = new IVsHierarchy[1];
            uint           pceltFetched = 0;

            while (ppenum.Next(1, rgelt, out pceltFetched) == VSConstants.S_OK &&
                   pceltFetched == 1)
            {
                mapHierarchies[rgelt[0]] = true;
            }

            return(mapHierarchies);
        }
Beispiel #30
0
        /// <summary>
        /// Delegates the call to the inner hierarchy.
        /// </summary>
        /// <param name="reserved">Reserved parameter defined at the IVsPersistHierarchyItem2::ReloadItem parameter.</param>
        protected internal override void ReloadItem(uint reserved)
        {
            #region precondition
            if (this.isDisposed || this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                throw new InvalidOperationException();
            }

            Debug.Assert(this.nestedHierarchy != null, "The nested hierarchy object must be created before calling this method");
            #endregion

            IVsPersistHierarchyItem2 persistHierachyItem = this.nestedHierarchy as IVsPersistHierarchyItem2;

            // We are expecting that if we get called then the nestedhierarchy supports IVsPersistHierarchyItem2, since then hierrachy should support handling its own reload.
            // There should be no errormessage to the user since this is an internal error, that it cannot be fixed at user level.
            if (persistHierachyItem == null)
            {
                throw new InvalidOperationException();
            }

            ErrorHandler.ThrowOnFailure(persistHierachyItem.ReloadItem(VSConstants.VSITEMID_ROOT, reserved));
        }