Exemple #1
0
 int IVsSccControlNewSolution.AddNewSolutionToSourceControl()
 {
     try
     {
         OnAddNewSolutionToSourceControl(EventArgs.Empty);
         return(VSErr.S_OK);
     }
     catch (Exception e)
     {
         return(VSErr.GetHRForException(e));
     }
 }
        private bool TryGetDocumentInfo(uint cookie, out string name, out uint flags, out IVsHierarchy hier, out uint itemId, out object document)
        {
            if (!_documentInfo_init)
            {
                _documentInfo_init = true;
                DocumentInfoInit();
            }

            if (GetDocumentMoniker_cb != null)
            {
                // Allow VS2013 to delayload windows
                try
                {
                    name  = GetDocumentMoniker_cb(cookie);
                    flags = GetDocumentFlags_cb(cookie);

                    hier     = null;
                    itemId   = VSItemId.Nil;
                    document = null;
                    return(true);
                }
                catch
                { }
            }

            IntPtr ppunkDocData;
            uint   locks;
            uint   editLocks;

            if (VSErr.Succeeded(RunningDocumentTable.GetDocumentInfo(cookie,
                                                                     out flags, out locks, out editLocks, out name, out hier, out itemId, out ppunkDocData)))
            {
                if (ppunkDocData != IntPtr.Zero)
                {
                    document = Marshal.GetUniqueObjectForIUnknown(ppunkDocData);
                    Marshal.Release(ppunkDocData);
                }
                else
                {
                    document = null;
                }

                return(true);
            }
            else
            {
                hier     = null;
                itemId   = VSItemId.Nil;
                document = null;
                return(false);
            }
        }
        public DiffMergeInstance(IAnkhServiceProvider context, IVsWindowFrame frame)
            : base(context)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            _frame  = frame;
            _frame2 = frame as IVsWindowFrame2;

            if (_frame2 != null && VSErr.Succeeded(_frame2.Advise(this, out _frameCookie)))
            {
                _frameHooked = true;
            }
        }
Exemple #4
0
        public void RegisterAsPrimarySccProvider()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsRegisterScciProvider rscp = GetService <IVsRegisterScciProvider>();

            if (rscp == null)
            {
                return;
            }

            VSErr.ThrowOnFailure(rscp.RegisterSourceControlProvider(ProviderGuid));
        }
        private Guid GetGuid(__VSFPROPID id)
        {
            Guid gResult;

            if (VSErr.Succeeded(Frame.GetGuidProperty((int)id, out gResult)))
            {
                return(gResult);
            }
            else
            {
                return(Guid.Empty);
            }
        }
        public UnifiedDiffDropDownBar(UnifiedDiffLanguage language, AnkhCodeWindowManager manager)
            : base(language, manager)
        {
            IVsTextView view = EnumTools.GetFirst(manager.GetViews());

            if (VSErr.Succeeded(view.GetBuffer(out _buffer)))
            {
                if (!TryHookConnectionPoint <IVsTextLinesEvents>(_buffer, this, out _linesCookie))
                {
                    _linesCookie = 0;
                }
            }
        }
Exemple #7
0
        int IVsSccProvider.SetInactive()
        {
            try
            {
                SetActive(false);
            }
            catch (Exception e)
            {
                return(VSErr.GetHRForException(e));
            }

            return(VSErr.S_OK);
        }
Exemple #8
0
 int IVsSccControlNewSolution.GetDisplayStringForAction(out string pbstrActionName)
 {
     try
     {
         pbstrActionName = GetDisplayStringForAddNewSolutionToSourceControl();
         return(VSErr.S_OK);
     }
     catch (Exception e)
     {
         pbstrActionName = null;
         return(VSErr.GetHRForException(e));
     }
 }
Exemple #9
0
        public bool TryGetColor(__VSSYSCOLOREX vsColor, out Color color)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            uint rgb;

            if (VSErr.Succeeded(UIShell.GetVSSysColorEx((int)vsColor, out rgb)))
            {
                color = ColorTranslator.FromWin32(unchecked ((int)rgb));
                return(true);
            }
            color = Color.Empty;
            return(false);
        }
Exemple #10
0
        private void LoadInitial()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsSolution solution = GetService <IVsSolution>(typeof(SVsSolution));

            if (solution == null)
            {
                return;
            }

            string dir, file, user;

            if (!VSErr.Succeeded(solution.GetSolutionInfo(out dir, out file, out user)) ||
                string.IsNullOrEmpty(file))
            {
                return; // No solution loaded, nothing to load
            }

            Guid             none = Guid.Empty;
            IEnumHierarchies hierEnum;

            if (!VSErr.Succeeded(solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref none, out hierEnum)))
            {
                return;
            }

            IVsHierarchy[] hiers = new IVsHierarchy[32];
            uint           nFetched;

            while (VSErr.Succeeded(hierEnum.Next((uint)hiers.Length, hiers, out nFetched)))
            {
                if (nFetched == 0)
                {
                    break;
                }
                for (int i = 0; i < nFetched; i++)
                {
                    IVsSccProject2 p2 = hiers[i] as IVsSccProject2;

                    if (p2 != null)
                    {
                        SccEvents.OnProjectOpened(p2, false);
                    }
                }
            }

            _solutionLoaded = true;
            SccEvents.OnSolutionOpened(false);
        }
        public int SaveSolutionProps(IVsHierarchy pHierarchy, IVsSolutionPersistence pPersistence)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try
            {
                int hr = VSErr.S_OK;

                // This function gets called by the shell after QuerySaveSolutionProps returned QSP_HasDirtyProps

                // The package will pass in the key under which it wants to save its properties,
                // and the IDE will call back on WriteSolutionProps

                // The properties will be saved in the Pre-Load section
                // When the solution will be reopened, the IDE will call our package to load them back before the projects in the solution are actually open
                // This could help if the source control package needs to persist information like projects translation tables, that should be read from the suo file
                // and should be available by the time projects are opened and the shell start calling IVsSccEnlistmentPathTranslation functions.
                if (Scc != null && Scc.IsSolutionManaged)
                {
                    if (pHierarchy == null)
                    {
                        hr = pPersistence.SavePackageSolutionProps(1 /* fPreLoad */, pHierarchy, this, SubversionPropertyCategory);
                    }
                    else if (Scc.HasProjectProperties(pHierarchy))
                    {
                        hr = pPersistence.SavePackageSolutionProps(1 /* fPreLoad */, pHierarchy, this, AnkhId.SvnOriginName);
                    }

                    // Once we saved our props, the solution is not dirty anymore
                    if (VSErr.Succeeded(hr))
                    {
                        Scc.IsSolutionDirty = false;
                    }
                }

                return(hr);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();

                if (handler != null)
                {
                    handler.OnError(ex);
                }

                return(Marshal.GetHRForException(ex));
            }
        }
        /// <include file='doc\PropertySheet.uex' path='docs/doc[@for="LanguagePreferences.Apply"]/*' />
        public virtual void Apply()
        {
            IVsTextManager2 textMgr2 = GetService <IVsTextManager2>(typeof(SVsTextManager));

            if (textMgr2 != null)
            {
                this.prefs.guidLang = langSvc;
                LANGPREFERENCES2[] langPrefs2 = new LANGPREFERENCES2[1];
                langPrefs2[0] = this.prefs;
                if (!VSErr.Succeeded(textMgr2.SetUserPreferences2(null, null, langPrefs2, null)))
                {
                    Debug.Assert(false, "textMgr2.SetUserPreferences2");
                }
            }
        }
Exemple #13
0
        public bool SaveDocument(IVsRunningDocumentTable rdt)
        {
            if (!IsDocumentInitialized || (_flags & _VSRDTFLAGS.RDT_DontSave) != 0)
            {
                return(true);
            }

            if (VSErr.Succeeded(rdt.SaveDocuments(0, Hierarchy, ItemId, Cookie)))
            {
                SetDirty(false);
                return(true);
            }

            return(false);
        }
Exemple #14
0
        int IVsSccProvider.SetInactive()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try
            {
                SetActive(false);
            }
            catch (Exception e)
            {
                return(VSErr.GetHRForException(e));
            }

            return(VSErr.S_OK);
        }
            public ThreadedWaitWrapper(IVsThreadedWaitDialogFactory factory, string caption, string message)
            {
                if (factory == null)
                {
                    return;
                }

                if (!VSErr.Succeeded(factory.CreateInstance(out _dlg2)))
                {
                    _dlg2 = null;
                    return;
                }

                _dlg2.StartWaitDialog(caption, message, null, null, null, 2, false, true);
            }
Exemple #16
0
        private Guid GetGuid(__VSFPROPID id)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Guid gResult;

            if (VSErr.Succeeded(Frame.GetGuidProperty((int)id, out gResult)))
            {
                return(gResult);
            }
            else
            {
                return(Guid.Empty);
            }
        }
Exemple #17
0
        [CLSCompliant(false)] // Implements 2 interfaces
        public int RegisterSccProject(IVsSccProject2 pscp2Project, string pszSccProjectName, string pszSccAuxPath, string pszSccLocalPath, string pszProvider)
        {
            try
            {
                SccProjectData data;
                ProjectMap.EnsureSccProject(pscp2Project, out data);

                OnRegisterSccProject(data, pszProvider);
                return(VSErr.S_OK);
            }
            catch (Exception e)
            {
                return(VSErr.GetHRForException(e));
            }
        }
Exemple #18
0
        static string AppIdLocalServerSearch(string appId)
        {
            if (string.IsNullOrEmpty(appId))
            {
                throw new ArgumentNullException("appId");
            }

            Guid clsid;

            if (!VSErr.Succeeded(NativeMethods.CLSIDFromProgID(appId, out clsid)))
            {
                return(null);
            }

            return(ClsIdServerSearch(clsid));
        }
Exemple #19
0
        public void InitializeEditor(VSEditorControl form, IVsUIHierarchy hier, IVsWindowFrame frame, uint docid)
        {
            VSDocumentFormPane pane = null;
            object             value;

            if (VSErr.Succeeded(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out value)))
            {
                pane = value as VSDocumentFormPane;
            }


            if (pane != null)
            {
                ((IVSEditorControlInit)form).InitializedForm(hier, docid, frame, pane.Host);
            }
        }
Exemple #20
0
        public int OnItemDeleted(uint itemid)
        {
            SetPreCreatedItem(VSItemId.Nil);

            object var;

            if (VSErr.Succeeded(ProjectHierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out var)) &&
                (bool)var)
            {
                return(VSErr.S_OK); // Extra item for show all files
            }

            SetDirty();

            return(VSErr.S_OK);
        }
Exemple #21
0
        bool MapProject(IVsHierarchy pHierarchy, out string slnLocation, out SccProjectData data)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IVsSccProject2 sccProject = pHierarchy as IVsSccProject2;

            if (sccProject != null && ProjectMap.TryGetSccProject(sccProject, out data))
            {
                // data valid
            }
            else if (sccProject != null)
            {
                data = new SccProjectData(ProjectMap, sccProject);
            }
            else
            {
                data = null;
            }

            string projectLocation = null;

            try
            {
                if (data != null && !string.IsNullOrEmpty(data.ProjectLocation))
                {
                    projectLocation = data.ProjectLocation;
                    return(true);
                }

                IVsSolution2 sln = GetService <IVsSolution2>(typeof(SVsSolution));

                if (sln != null &&
                    VSErr.Succeeded(pHierarchy.GetCanonicalName(VSItemId.Root, out projectLocation)))
                {
                    return(!string.IsNullOrEmpty(projectLocation));
                }

                projectLocation = null;
                return(false);
            }
            finally
            {
                if (projectLocation == null || !_trueNameMap.TryGetValue(projectLocation, out slnLocation))
                {
                    slnLocation = projectLocation;
                }
            }
        }
        public SolutionSettings(IAnkhServiceProvider context)
            : base(context)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsShell shell = GetService <IVsShell>(typeof(SVsShell));

            if (shell == null)
            {
                throw new InvalidOperationException("IVsShell not available");
            }

            object r;

            if (VSErr.Succeeded(shell.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out r)))
            {
                _vsUserRoot = (string)r;
            }
            else
            {
                _vsUserRoot = @"SOFTWARE\Microsoft\VisualStudio\8.0";
            }

            string baseName = _vsUserRoot;

            if (_vsUserRoot.EndsWith(@"\UserSettings", StringComparison.OrdinalIgnoreCase))
            {
                _inRanu    = true;
                baseName   = _vsUserRoot.Substring(0, _vsUserRoot.Length - 13);
                _vsAppRoot = baseName + @"\Configuration";
            }
            else
            {
                _vsAppRoot = _vsUserRoot;
            }

            if (baseName.StartsWith(@"SOFTWARE\", StringComparison.OrdinalIgnoreCase))
            {
                baseName = baseName.Substring(9); // Should always trigger
            }
            if (baseName.StartsWith(@"Microsoft\", StringComparison.OrdinalIgnoreCase))
            {
                baseName = baseName.Substring(10); // Give non-ms hives a prefix
            }
            _hiveSuffix = baseName;
        }
Exemple #23
0
        private CmdStateCacheItem GetCache(Guid cmdContextId)
        {
            uint cookie;

            if (!VSErr.Succeeded(Monitor.GetCmdUIContextCookie(ref cmdContextId, out cookie)))
            {
                return(new CmdStateCacheItem(Monitor, 0));
            }

            CmdStateCacheItem item;

            if (!_cookieMap.TryGetValue(cookie, out item))
            {
                _cookieMap[cookie] = item = new CmdStateCacheItem(Monitor, cookie);
            }

            return(item);
        }
Exemple #24
0
        public bool EnsureProjectLoaded(Guid project, bool recursive)
        {
            IVsSolution4 sln = GetService <IVsSolution4>(typeof(SVsSolution));

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

            if (recursive)
            {
                return(VSErr.Succeeded(sln.EnsureProjectIsLoaded(ref project, (uint)__VSBSLFLAGS.VSBSLFLAGS_None)));
            }
            else
            {
                return(VSErr.Succeeded(sln.ReloadProject(ref project)));
            }
        }
        private object FetchDocument()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if ((_flags & RDT_PendingInitialization) != 0)
            {
                return(null);
            }

            _fetchedRaw = true;

            // Normally when a document is open we get a handle via the opendocument tracker; but we might be to soon
            IVsRunningDocumentTable rd = GetService <IVsRunningDocumentTable>(typeof(SVsRunningDocumentTable));

            if (rd == null)
            {
                return(null);
            }

            uint         id;
            IVsHierarchy hier;
            IntPtr       data;
            uint         cookie; // We can't store the cookie, as that would mean it is in the lookup table

            if (VSErr.Succeeded(rd.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, Name, out hier, out id, out data, out cookie)))
            {
                if (hier != null)
                {
                    Hierarchy = hier;
                }
                if ((id != 0) && id != VSItemId.Nil)
                {
                    ItemId = id;
                }

                if (data != IntPtr.Zero)
                {
                    _rawDocument = Marshal.GetUniqueObjectForIUnknown(data);
                    Marshal.Release(data);
                }
            }

            return(_rawDocument);
        }
Exemple #26
0
        protected internal virtual void Initialize()
        {
            IVsDropdownBarManager dbm = Manager.CodeWindow as IVsDropdownBarManager;

            if (dbm == null)
            {
                return;
            }

            int combos = NumberOfCombos;

            _combos.Clear();
            for (int i = 0; i < combos; i++)
            {
                _combos.Add(new ComboMemberCollection(this, i));
            }

            if (!VSErr.Succeeded(dbm.AddDropdownBar(combos, this)))
            {
                return;
            }

            IVsDropdownBar bar;

            if (!VSErr.Succeeded(dbm.GetDropdownBar(out bar)))
            {
                return;
            }

            _added = true;
            GetService <IAnkhPackage>().RegisterIdleProcessor(this);

            foreach (IVsTextView v in Manager.GetViews())
            {
                _comboViews.Add(v, new ComboTextView(this, v));

                if (_activeView == null)
                {
                    _activeView = v;
                }
            }

            ScheduleSynchronize();
        }
        private bool RecurseInto(SelectionItem si, ProjectWalkDepth depth)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            object value;

            if (VSErr.Succeeded(si.Hierarchy.GetProperty(si.Id,
                                                         (int)__VSHPROPID.VSHPROPID_HasEnumerationSideEffects, out value)))
            {
                if (value != null)
                {
                    bool hasSideEffects = (bool)value;

                    // Unless we are walking SCC projects, don't go deeper
                    // because we don't want side effects!

                    if (hasSideEffects)
                    {
                        if (depth == ProjectWalkDepth.AllDescendantsInHierarchy && IgnoreSideEffects(si.SccProject))
                        {
                            return(true);
                        }

                        return(false);
                    }
                }
            }

            if (si.SccProject == null && VSErr.Succeeded(si.Hierarchy.GetProperty(si.Id,
                                                                                  (int)__VSHPROPID2.VSHPROPID_ChildrenEnumerated, out value)))
            {
                if (value != null)
                {
                    bool childrenEnumerated = (bool)value;

                    if (!childrenEnumerated)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        //[CLSCompliant(false)]
        static bool GetSccFiles(IVsHierarchy hierarchy, IVsSccProject2 sccProject, uint id, out string[] files, bool includeSpecial, bool includeNoScc, IDictionary <string, uint> map)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            int[] flags;
            files = null;

            if (!GetSccFiles(hierarchy, sccProject, id, out files, out flags, includeNoScc, map))
            {
                return(false);
            }
            else if (flags == null || sccProject == null || !includeSpecial)
            {
                return(true);
            }

            int n = Math.Min(files.Length, flags.Length);

            List <string> allFiles = new List <string>(files);

            for (int i = 0; i < n; i++)
            {
                if (0 != (flags[i] & (int)tagVsSccFilesFlags.SFF_HasSpecialFiles))
                {
                    CALPOLESTR[] str = new CALPOLESTR[1];
                    CADWORD[]    dw  = new CADWORD[1];

                    if (VSErr.Succeeded(sccProject.GetSccSpecialFiles(id, allFiles[i], str, dw)))
                    {
                        files = GetFileNamesFromOleBuffer(str, true);
                        GetFlagsFromOleBuffer(dw, true); // Free the flags (No need to parse at this time)

                        if (files != null && files.Length > 0)
                        {
                            allFiles.AddRange(files);
                        }
                    }
                }
            }

            files = allFiles.ToArray();
            return(true);
        }
        public void OpenOrAddProjectFile(string projectFile, bool add)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (string.IsNullOrEmpty(projectFile))
            {
                throw new ArgumentNullException("projectFile");
            }

            string ext        = Path.GetExtension(projectFile);
            bool   isSolution = false;

            foreach (string x in SolutionFilter.Split(';'))
            {
                if (string.Equals(ext, Path.GetExtension(x), StringComparison.OrdinalIgnoreCase))
                {
                    isSolution = true;
                    break;
                }
            }

            IVsSolution solution = GetService <IVsSolution>(typeof(SVsSolution));

            int hr;

            if (isSolution && !add)
            {
                hr = solution.OpenSolutionFile(0, projectFile);
            }
            else
            {
                Guid   gnull      = Guid.Empty;
                Guid   gInterface = Guid.Empty;
                IntPtr pProj      = IntPtr.Zero;

                hr = solution.CreateProject(ref gnull, projectFile, null, null, (uint)__VSCREATEPROJFLAGS.CPF_OPENFILE, ref gInterface, out pProj);
            }

            if (!VSErr.Succeeded(hr))
            {
                new AnkhMessageBox(this).Show(Marshal.GetExceptionForHR(hr).Message, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
        private void HookFileChanges(bool reHook)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsFileChangeEx fileChange = null;

            if (_fileChangeCookies != null)
            {
                fileChange = GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx));
                uint[] list = _fileChangeCookies;
                _fileChangeCookies = null;

                foreach (uint u in list)
                {
                    if (u != 0)
                    {
                        fileChange.UnadviseFileChange(u);
                    }
                }
            }

            if (reHook && _isFileDocument)
            {
                if (fileChange == null)
                {
                    fileChange = GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx));
                }

                List <string> items = new List <string>(GetService <IProjectFileMapper>().GetAllDocumentFiles(_name));

                uint[] cookies = new uint[items.Count];
                _fileChangeCookies = cookies;

                for (int i = 0; i < items.Count; i++)
                {
                    uint ck;
                    if (VSErr.Succeeded(fileChange.AdviseFileChange(items[i], (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Time), this, out ck)))
                    {
                        cookies[i] = ck;
                    }
                }
            }
        }