Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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
            }
        }
        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());
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 14
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);
                }
            }
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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;
        }
Ejemplo n.º 17
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);
            }
        }
        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);
        }
Ejemplo n.º 19
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));
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Display the SCC Provider Toolwindow if it is not already visible
        /// </summary>
        private void ShowSccProviderToolWindow()
        {
            IVsWindowFrame windowFrame = null;

            try
            {
                // This function is called when the package is auto-loaded (as result of our command UI context
                // guidSccProvider being set active). This can happen on startup, if this scc provider was active
                // last time the shell was started.
                // However, at that time we cannot create the toolwindow because the shell is not fully initialized
                // and the window profile is not yet loaded. We need to protect
                MsVsShell.ToolWindowPane window = FindToolWindow(typeof(SccProviderToolWindow), 0, true);
                if (window != null && window.Frame != null)
                {
                    windowFrame = (IVsWindowFrame)window.Frame;
                }
            }
            catch (COMException e)
            {
                if (e.ErrorCode != VSConstants.E_UNEXPECTED)
                {
                    throw;
                }
            }

            if (windowFrame == null)
            {
                return;
            }

            if (sccService.Active)
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Show());
            }
            else
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Hide());
            }
        }
Ejemplo n.º 22
0
        private void ShowSccProviderToolWindow()
        {
            MsVsShell.ToolWindowPane window      = this.FindToolWindow(typeof(SccProviderToolWindow), 0, true);
            IVsWindowFrame           windowFrame = null;

            if (window != null && window.Frame != null)
            {
                windowFrame = (IVsWindowFrame)window.Frame;
            }
            if (windowFrame == null)
            {
                throw new InvalidOperationException("No valid window frame object was returned from Toolwindow pane");
            }
            if (sccService.Active)
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Show());
            }
            else
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Hide());
            }
        }
Ejemplo n.º 23
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));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Flag indicating that changes to a file can be ignored when item is saved or reloaded.
        /// </summary>
        /// <param name="ignoreFlag">Flag indicating whether or not to ignore changes (1 to ignore, 0 to stop ignoring).</param>
        protected internal override void IgnoreItemFileChanges(bool ignoreFlag)
        {
            #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

            this.IgnoreNestedProjectFile(ignoreFlag);

            IVsPersistHierarchyItem2 persistHierachyItem = this.nestedHierarchy as IVsPersistHierarchyItem2;

            // If the IVsPersistHierarchyItem2 is not implemented by the nested just return
            if (persistHierachyItem == null)
            {
                return;
            }

            ErrorHandler.ThrowOnFailure(persistHierachyItem.IgnoreItemFileChanges(VSConstants.VSITEMID_ROOT, ignoreFlag ? 1 : 0));
        }
Ejemplo n.º 25
0
        private IntPtr CreateDocumentView(string physicalView, IVsHierarchy hierarchy, uint itemid, IVsTextLines textLines, out string editorCaption, out Guid cmdUI)
        {
            //Init out params
            editorCaption = string.Empty;
            cmdUI         = Guid.Empty;

            if (string.IsNullOrEmpty(physicalView))
            {
                // create code window as default physical view
                return(CreateCodeView(textLines, ref editorCaption, ref cmdUI));
            }
            else if (string.Compare(physicalView, "design", true, CultureInfo.InvariantCulture) == 0)
            {
                // Create Form view
                return(CreateFormView(hierarchy, itemid, textLines, ref editorCaption, ref cmdUI));
            }

            // We couldn't create the view
            // Return special error code so VS can try another editor factory.
            ErrorHandler.ThrowOnFailure((int)VSConstants.VS_E_UNSUPPORTEDFORMAT);

            return(IntPtr.Zero);
        }
Ejemplo n.º 26
0
        public static object GetDocData(IServiceProvider site, string documentPath, _VSRDTFLAGS lockFlags, out uint docCookie)
        {
            if (site == null)
            {
                VSErrorHandler.ThrowOnFailure(VSConstants.E_UNEXPECTED);
            }

            var rdtService = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            IVsHierarchy hierarchy;
            uint         itemId;
            var          docDataPtr = IntPtr.Zero;

            docCookie = VSConstants.VSCOOKIE_NIL;
            object ret = null;

            try
            {
                if (
                    ErrorHandler.Succeeded(
                        rdtService.FindAndLockDocument(
                            (uint)lockFlags, documentPath, out hierarchy, out itemId, out docDataPtr, out docCookie)) &&
                    docDataPtr != IntPtr.Zero)
                {
                    ret = Marshal.GetObjectForIUnknown(docDataPtr);
                }
            }
            finally
            {
                if (docDataPtr != IntPtr.Zero)
                {
                    Marshal.Release(docDataPtr);
                }
            }

            return(ret);
        }
Ejemplo n.º 27
0
        private IVsTextLines GetTextBuffer(System.IntPtr docDataExisting)
        {
            IVsTextLines textLines;

            if (docDataExisting == IntPtr.Zero)
            {
                // Create a new IVsTextLines buffer.
                Type textLinesType = typeof(IVsTextLines);
                Guid riid          = textLinesType.GUID;
                Guid clsid         = typeof(VsTextBufferClass).GUID;
                textLines = package.CreateInstance(ref clsid, ref riid, textLinesType) as IVsTextLines;

                // set the buffer's site
                ((IObjectWithSite)textLines).SetSite(serviceProvider.GetService(typeof(IOleServiceProvider)));
            }
            else
            {
                // Use the existing text buffer
                Object dataObject = Marshal.GetObjectForIUnknown(docDataExisting);
                textLines = dataObject as IVsTextLines;
                if (textLines == null)
                {
                    // Try get the text buffer from textbuffer provider
                    IVsTextBufferProvider textBufferProvider = dataObject as IVsTextBufferProvider;
                    if (textBufferProvider != null)
                    {
                        textBufferProvider.GetTextBuffer(out textLines);
                    }
                }
                if (textLines == null)
                {
                    // Unknown docData type then, so we have to force VS to close the other editor.
                    ErrorHandler.ThrowOnFailure((int)VSConstants.VS_E_INCOMPATIBLEDOCDATA);
                }
            }
            return(textLines);
        }
Ejemplo n.º 28
0
        public bool CreateAndLoadBuffer()
        {
            DestroyBuffer();

            var pkg = PackageManager.Package as Package;
            IServiceProvider serviceProvider = pkg;

            var textLinesType = typeof(VSTextManagerInterop.IVsTextLines);
            var riid          = textLinesType.GUID;
            var clsid         = typeof(VSTextManagerInterop.VsTextBufferClass).GUID;

            _underlyingBuffer = pkg.CreateInstance(ref clsid, ref riid, textLinesType);
            Debug.Assert(_underlyingBuffer != null, "Failure while creating buffer.");

            var buffer = _underlyingBuffer as VSTextManagerInterop.IVsTextLines;

            Debug.Assert(buffer != null, "Why does buffer not implement IVsTextLines?");

            var ows = buffer as IObjectWithSite;

            if (ows != null)
            {
                ows.SetSite(serviceProvider.GetService(typeof(IOleServiceProvider)));
            }

            // We want to set the LanguageService SID explicitly to the XML Language Service.
            // We need turn off GUID_VsBufferDetectLangSID before calling LoadDocData so that the
            // TextBuffer does not do the work to detect the LanguageService SID from the file extension.
            var userData = buffer as VSTextManagerInterop.IVsUserData;

            if (userData != null)
            {
                var VsBufferDetectLangSID = new Guid("{17F375AC-C814-11d1-88AD-0000F87579D2}"); //GUID_VsBufferDetectLangSID;
                VSErrorHandler.ThrowOnFailure(userData.SetData(ref VsBufferDetectLangSID, false));
            }

            var langSid = CommonPackageConstants.xmlEditorLanguageService;

            VSErrorHandler.ThrowOnFailure(buffer.SetLanguageServiceID(ref langSid));

            var persistDocData = buffer as IVsPersistDocData;

            if (persistDocData != null)
            {
                persistDocData.LoadDocData(FileName);
                var artifactUri = new Uri(FileName);

                var artifact = PackageManager.Package.ModelManager.GetArtifact(artifactUri);
                if (artifact != null &&
                    artifact.IsCodeGenArtifact)
                {
                    var standaloneProvider = artifact.XmlModelProvider as StandaloneXmlModelProvider;
                    if (standaloneProvider.ExtensionErrors == null ||
                        standaloneProvider.ExtensionErrors.Count == 0)
                    {
                        // If there is a cached code gen artifact, it will have loaded its text buffer using extensions already.
                        // Therefore we can grab the text buffer from that artifact for our docdata buffer, and dispose the
                        // code gen artifact since it's using a XmlProvider that is standalone and won't be supported by the
                        // designer.
                        var projectItem = VsUtils.GetProjectItem(Hierarchy, ItemId);
                        if (projectItem != null)
                        {
                            if (VSHelpers.CheckOutFilesIfEditable(ServiceProvider, new[] { FileName }))
                            {
                                string artifactText = null;
                                using (var writer = new Utf8StringWriter())
                                {
                                    artifact.XDocument.Save(writer, SaveOptions.None);
                                    artifactText = writer.ToString();
                                }

                                if (!String.IsNullOrWhiteSpace(artifactText))
                                {
                                    VsUtils.SetTextForVsTextLines(VsBuffer, artifactText);
                                }
                            }
                            else
                            {
                                ErrorListHelper.LogExtensionErrors(
                                    new List <ExtensionError>
                                {
                                    new ExtensionError(
                                        string.Format(
                                            CultureInfo.CurrentCulture, Resources.ExtensionError_SourceControlLock,
                                            Path.GetFileName(FileName)),
                                        ErrorCodes.ExtensionsError_BufferNotEditable,
                                        ExtensionErrorSeverity.Error)
                                },
                                    projectItem);
                            }
                        }

                        PackageManager.Package.ModelManager.ClearArtifact(artifactUri);
                    }
                    else
                    {
                        // If the extensions ran into errors whilst loading, we'll need to re-run extensions anyway so we ignore the cache
                        PackageManager.Package.ModelManager.ClearArtifact(artifactUri);
                        DispatchLoadToExtensions();
                    }
                }
                else
                {
                    DispatchLoadToExtensions();
                }
            }

            // DSL exposes the FileNameChanged event which we subscribe to so we can update the moniker inside
            // the text buffer, which is required to update our model as well as keep the XmlModel in sync.
            FileNameChanged += OnFileNameChanged;
            RegisterUndoTracking();
            return(true);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Initialize the nested hierarhy node.
        /// </summary>
        /// <param name="fileName">The file name of the nested project.</param>
        /// <param name="destination">The location of the nested project.</param>
        /// <param name="projectName">The name of the project.</param>
        /// <param name="createFlags">The nested project creation flags </param>
        /// <remarks>This methos should be called just after a NestedProjectNode object is created.</remarks>
        public virtual void Init(string fileName, string destination, string projectName, __VSCREATEPROJFLAGS createFlags)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "fileName");
            }

            if (String.IsNullOrEmpty(destination))
            {
                throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "destination");
            }

            this.projectName = Path.GetFileName(fileName);
            this.projectPath = Path.Combine(destination, this.projectName);

            // 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();
            }

            // Get the project type guid from project element
            string typeGuidString     = this.ItemNode.GetMetadataAndThrow(ProjectFileConstants.TypeGuid, new InvalidOperationException());
            Guid   projectFactoryGuid = Guid.Empty;

            if (!String.IsNullOrEmpty(typeGuidString))
            {
                projectFactoryGuid = new Guid(typeGuidString);
            }

            // Get the project factory.
            IVsProjectFactory projectFactory;

            ErrorHandler.ThrowOnFailure(solution.GetProjectFactory((uint)0, new Guid[] { projectFactoryGuid }, fileName, out projectFactory));

            this.CreateProjectDirectory();

            //Create new project using factory
            int    cancelled;
            Guid   refiid     = NativeMethods.IID_IUnknown;
            IntPtr projectPtr = IntPtr.Zero;

            try
            {
                ErrorHandler.ThrowOnFailure(projectFactory.CreateProject(fileName, destination, projectName, (uint)createFlags, ref refiid, out projectPtr, out cancelled));

                if (projectPtr != IntPtr.Zero)
                {
                    this.nestedHierarchy = Marshal.GetTypedObjectForIUnknown(projectPtr, typeof(IVsHierarchy)) as IVsHierarchy;
                    Debug.Assert(this.nestedHierarchy != null, "Nested hierarchy could not be created");
                    Debug.Assert(cancelled == 0);
                }
            }
            finally
            {
                if (projectPtr != IntPtr.Zero)
                {
                    // We created a new instance of the project, we need to call release to decrement the ref count
                    // the RCW (this.nestedHierarchy) still has a reference to it which will keep it alive
                    Marshal.Release(projectPtr);
                }
            }

            if (cancelled != 0 && this.nestedHierarchy == null)
            {
                ErrorHandler.ThrowOnFailure(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            // Link into the nested VS hierarchy.
            ErrorHandler.ThrowOnFailure(this.nestedHierarchy.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ParentHierarchy, this.ProjectMgr));
            ErrorHandler.ThrowOnFailure(this.nestedHierarchy.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ParentHierarchyItemid, (object)(int)this.ID));

            this.LockRDTEntry();

            this.ConnectPropertyNotifySink();
        }
Ejemplo n.º 30
0
        protected override void Initialize()
        {
            try
            {
                // load the local settings
                Preferences.Initialize();
                Preferences.LocalSettings.Load(null);

                logger.Trace("Entering Initialize() of: {0}", this.ToString());
                base.Initialize();

                // Proffer the source control service implemented by the provider
                // The service provider implemented by the package
                SccService = new P4VsProviderService(this);
                ((IServiceContainer)this).AddService(typeof(P4VsProviderService), SccService, true);

                // Initilise Glyphs
                IVsHierarchy solHier = (IVsHierarchy)GetService(typeof(SVsSolution));
                Glyphs = new NodeGlyphs(SccService, solHier);

                // Add our command handlers for menu (commands must exist in the .vsct file)
                OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
                if (mcs != null)
                {
                    // View Menu commands
                    #region View Menu commands
                    // Workspaces ToolWindow Command
                    CommandID   cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewWorkspaceToolWindow);
                    MenuCommand menuCmd = new MenuCommand(new EventHandler(P4VsViewWorkspaceToolWindow), cmd);
                    mcs.AddCommand(menuCmd);

                    // History ToolWindow
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewHistoryToolWindow);
                    menuCmd = new MenuCommand(new EventHandler(P4VsViewHistoryToolWindow), cmd);
                    mcs.AddCommand(menuCmd);

                    // Jobs ToolWindow
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewJobsToolWindow);
                    menuCmd = new MenuCommand(new EventHandler(P4VsViewJobsToolWindow), cmd);
                    mcs.AddCommand(menuCmd);

                    // P4 ToolWindow
                    //cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewP4ToolWindow);
                    //menuCmd = new MenuCommand(new EventHandler(P4VsViewP4ToolWindow), cmd);
                    //mcs.AddCommand(menuCmd);

                    // SubmittedChangelists ToolWindow
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewSubmittedChangelistsToolWindow);
                    menuCmd = new MenuCommand(new EventHandler(P4VsViewSubmittedChangelistsToolWindow), cmd);
                    mcs.AddCommand(menuCmd);

                    // PendingChangelists ToolWindow
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewPendingChangelistsToolWindow);
                    menuCmd = new MenuCommand(new EventHandler(P4VsViewPendingChangelistsToolWindow), cmd);
                    mcs.AddCommand(menuCmd);

                    // Labels ToolWindow
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewLabelsToolWindow);
                    menuCmd = new MenuCommand(new EventHandler(P4VsViewLabelsToolWindow), cmd);
                    mcs.AddCommand(menuCmd);

                    // Swarm ToolWindow
                    //cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewSwarmToolWindow);
                    //menuCmd = new MenuCommand(new EventHandler(P4VsViewSwarmToolWindow), cmd);
                    //mcs.AddCommand(menuCmd);

                    // Streams ToolWindow
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewStreamsToolWindow);
                    menuCmd = new MenuCommand(new EventHandler(P4VsViewStreamsToolWindow), cmd);
                    mcs.AddCommand(menuCmd);

                    // Reviews ToolWindow
                    //cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdViewReviewsToolWindow);
                    //menuCmd = new MenuCommand(new EventHandler(P4VsViewReviewsToolWindow), cmd);
                    //mcs.AddCommand(menuCmd);
                    #endregion

                    // Help Menu commands
                    #region Help Menu commands
                    // Help/P4VS Help
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdP4VSHelp);
                    menuCmd = new MenuCommand(new EventHandler(P4VsP4VSHelp), cmd);
                    mcs.AddCommand(menuCmd);

                    // Help/P4VS SystemInfo
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdP4VSSystemInfo);
                    menuCmd = new MenuCommand(new EventHandler(P4VsP4VSSystemInfo), cmd);
                    mcs.AddCommand(menuCmd);

                    #endregion

                    // File Menu commands
                    #region File Menu commands
                    // File/Open Solution in Perforce Depot
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdFileOpenInDepot);
                    menuCmd = new MenuCommand(new EventHandler(P4VsFileOpenInDepot), cmd);
                    mcs.AddCommand(menuCmd);

                    // File/Open Connection to a Perforce Depot
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdOpenConnection);
                    menuCmd = new MenuCommand(new EventHandler(P4VsOpenConnection), cmd);
                    mcs.AddCommand(menuCmd);

                    // File/Close Connection to the Perforce Depot
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdCloseConnection);
                    menuCmd = new MenuCommand(new EventHandler(P4VsCloseConnection), cmd);
                    mcs.AddCommand(menuCmd);

                    // Workspaces ToolWindow's ToolBar Command
                    //cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdToolWindowToolbarCommand);
                    //menuCmd = new MenuCommand(new EventHandler(P4VsWorkspaceToolWindowToolbarCommand), cmd);
                    //mcs.AddCommand(menuCmd);
                    #endregion

                    // Source control menu commands
                    #region File Menu commands
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdScmRefresh);
                    menuCmd = new MenuCommand(new EventHandler(P4VsScmRefresh), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdAddToSourceControl);
                    menuCmd = new MenuCommand(new EventHandler(P4VsAddToSourceControl), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdCheckin);
                    menuCmd = new MenuCommand(new EventHandler(P4VsCheckin), cmd);
                    mcs.AddCommand(menuCmd);

                    //cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdCheckout);
                    //menuCmd = new MenuCommand(new EventHandler(P4VsCheckout), cmd);
                    //mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdCheckout);
                    menuCmd = new OleMenuCommand(new EventHandler(P4VsCheckout), cmd);
                    //queryStatusMenuCommand.BeforeQueryStatus +=new EventHandler(OnBeforeQueryStatus);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdCheckoutProject);
                    menuCmd = new MenuCommand(new EventHandler(P4VsCheckoutEntireProjectOrSolution), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdCheckoutSolution);
                    menuCmd = new MenuCommand(new EventHandler(P4VsCheckoutEntireProjectOrSolution), cmd);
                    mcs.AddCommand(menuCmd);

                    //cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdUseSccOffline);
                    //menuCmd = new MenuCommand(new EventHandler(P4VsUseSccOffline), cmd);
                    //mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdReconcile);
                    menuCmd = new MenuCommand(new EventHandler(P4VsReconcileFiles), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdRevert);
                    menuCmd = new MenuCommand(new EventHandler(P4VsRevert), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdRevertUnchanged);
                    menuCmd = new MenuCommand(new EventHandler(P4VsRevertUnchanged), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdLock);
                    menuCmd = new MenuCommand(new EventHandler(P4VsLock), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdUnlock);
                    menuCmd = new MenuCommand(new EventHandler(P4VsUnlock), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdChangeFileType);
                    menuCmd = new MenuCommand(new EventHandler(P4VsChangeFileType), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdMoveToChangelist);
                    menuCmd = new MenuCommand(new EventHandler(P4VsMoveToChangelist), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdAddToIgnoreList);
                    menuCmd = new MenuCommand(new EventHandler(P4VsAddToIgnoreList), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdRemoveFromIgnoreList);
                    menuCmd = new MenuCommand(new EventHandler(P4VsRemoveFromIgnoreList), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdEditIgnoreList);
                    menuCmd = new MenuCommand(new EventHandler(P4VsEditIgnoreList), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdResolve);
                    menuCmd = new MenuCommand(new EventHandler(P4VsResolve), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdSync);
                    menuCmd = new MenuCommand(new EventHandler(P4VsSync), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdSyncHead);
                    menuCmd = new MenuCommand(new EventHandler(P4VsSyncHead), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdDiffVsHave);
                    menuCmd = new MenuCommand(new EventHandler(P4VsDiffVsHave), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdDiffVsAny);
                    menuCmd = new MenuCommand(new EventHandler(P4VsDiffVsAny), cmd);
                    mcs.AddCommand(menuCmd);

                    //cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdAddProjectToSCC);
                    //menuCmd = new MenuCommand(new EventHandler(P4VsAddProjectToSCC), cmd);
                    //mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdShowHistory);
                    menuCmd = new MenuCommand(new EventHandler(P4VsShowHistory), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdShelve);
                    menuCmd = new MenuCommand(new EventHandler(P4VsShelve), cmd);
                    mcs.AddCommand(menuCmd);

                    //cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdScmAttributes);
                    //menuCmd = new MenuCommand(new EventHandler(P4VsScmAttributes), cmd);
                    //mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdScmMerge);
                    menuCmd = new MenuCommand(new EventHandler(P4VsScmMerge), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdScmCopy);
                    menuCmd = new MenuCommand(new EventHandler(P4VsScmCopy), cmd);
                    mcs.AddCommand(menuCmd);
                    #endregion

                    // P4V commands
                    #region P4V Menu commands
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdP4V);
                    menuCmd = new MenuCommand(new EventHandler(P4VsP4V), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdTimeLapse);
                    menuCmd = new MenuCommand(new EventHandler(P4VsTimeLapse), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdRevGraph);
                    menuCmd = new MenuCommand(new EventHandler(P4VsRevGraph), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdStreamGraph);
                    menuCmd = new MenuCommand(new EventHandler(P4VsStreamGraph), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.cmdidCancelActiveCommand);
                    menuCmd = new MenuCommand(new EventHandler(Exec_CancelActiveCommand), cmd);
                    mcs.AddCommand(menuCmd);

                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.cmdidCurrentStream);
                    menuCmd = new MenuCommand(new EventHandler(Exec_CurrentStream), cmd);
                    mcs.AddCommand(menuCmd);
                    #endregion

                    // Status Bar commands
                    #region Status Bar commands
                    // Add to Source Control/Publish
                    cmd     = new CommandID(GuidList.guidP4VsProviderCmdSet, CommandId.icmdPublish);
                    menuCmd = new MenuCommand(new EventHandler(P4VsScmPublish), cmd);
                    mcs.AddCommand(menuCmd);
                    #endregion

                    // DropDownCombo
                    //	 a DROPDOWNCOMBO does not let the user type into the combo box; they can only pick from the list.
                    //   The string value of the element selected is returned.
                    //	 For example, this type of combo could be used for the "Solution Configurations" on the "Standard" toolbar.
                    //
                    //   A DropDownCombo box requires two commands:
                    //     One command (cmdidMyCombo) is used to ask for the current value of the combo box and to
                    //     set the new value when the user makes a choice in the combo box.
                    //
                    //     The second command (cmdidMyComboGetList) is used to retrieve this list of choices for the combo box.
                    //
                    // Normally IOleCommandTarget::QueryStatus is used to determine the state of a command, e.g.
                    // enable vs. disable, shown vs. hidden, etc. The QueryStatus method does not have any way to
                    // control the statue of a combo box, e.g. what list of items should be shown and what is the
                    // current value. In order to communicate this information actually IOleCommandTarget::Exec
                    // is used with a non-NULL varOut parameter. You can think of these Exec calls as extended
                    // QueryStatus calls. There are two pieces of information needed for a combo, thus it takes
                    // two commands to retrieve this information. The main command id for the command is used to
                    // retrieve the current value and the second command is used to retrieve the full list of
                    // choices to be displayed as an array of strings.
                    cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, (int)CommandId.cmdidConnectionDropDownCombo);
                    omcConnectionComboSelChanged = new OleMenuCommand(new EventHandler(P4VsConnectionDropDownCombo), cmd);
                    omcConnectionComboSelChanged.ParametersDescription = "$"; // accept any argument string
                    mcs.AddCommand(omcConnectionComboSelChanged);

                    cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, (int)CommandId.cmdidConnectionDropDownComboGetList);
                    omcConnectionComboGetList = new OleMenuCommand(new EventHandler(P4VsConnectionDropDownComboGetList), cmd);
                    mcs.AddCommand(omcConnectionComboGetList);

                    cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, (int)CommandId.cmdidActiveChangelistDropDownCombo);
                    omcActiveChangelistComboSelChanged = new OleMenuCommand(new EventHandler(P4VsActiveChangelistDropDownCombo), cmd);
                    omcActiveChangelistComboSelChanged.ParametersDescription = "$"; // accept any argument string
                    mcs.AddCommand(omcActiveChangelistComboSelChanged);

                    cmd = new CommandID(GuidList.guidP4VsProviderCmdSet, (int)CommandId.cmdidActiveChangelistDropDownComboGetList);
                    omcActiveChangelistComboGetList = new OleMenuCommand(new EventHandler(P4VsActiveChangelistDropDownComboGetList), cmd);
                    mcs.AddCommand(omcActiveChangelistComboGetList);
                }

                // -- Set an eventlistener for shell property changes
                var shellService = GetService(typeof(SVsShell)) as IVsShell;
                if (shellService != null)
                {
                    ErrorHandler.ThrowOnFailure(shellService.AdviseShellPropertyChanges(this, out _EventSinkCookie));
                }

                // Register the provider with the source control manager
                // If the package is to become active, this will also callback on OnActiveStateChange and the menu commands will be enabled
                IVsRegisterScciProvider rscp = (IVsRegisterScciProvider)GetService(typeof(IVsRegisterScciProvider));
                rscp.RegisterSourceControlProvider(GuidList.guidP4VsProvider);

                instance = this;
            } catch (Exception ex)
            {
                logger.Error(ex, "Initialize failed");
                logger.Error("Error: {0}", ex.Message);
                logger.Error("Stacktrace: {0}", ex.StackTrace);
            }
        }