Exemplo n.º 1
0
        public int FilesChanged(uint cChanges, string[] rgpszFile, uint[] rggrfChange)
        {
            if (rgpszFile == null || cChanges == 0)
            {
                return(VSErr.S_OK);
            }

            try
            {
                string[] nFiles = new string[cChanges];

                for (int i = 0; i < cChanges; i++)
                {
                    nFiles[i] = SvnTools.GetNormalizedFullPath(rgpszFile[i]);
                }

                IFileStatusMonitor monitor = GetService <IFileStatusMonitor>();

                monitor.ScheduleSvnStatus(nFiles);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();
                if (eh != null && eh.IsEnabled(ex))
                {
                    eh.OnError(ex);
                }
                else
                {
                    throw;
                }
            }

            return(VSErr.S_OK);
        }
        public bool ForceLoadUserSettings(string streamName)
        {
            IVsSolutionPersistence persistence = GetService <IVsSolutionPersistence>(typeof(SVsSolutionPersistence));

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

            try
            {
                int hr = persistence.LoadPackageUserOpts(this, streamName);

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

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

                return(false);
            }
        }
Exemplo n.º 3
0
        public void RunHelp(IAnkhControlWithHelp control)
        {
            UriBuilder ub = new UriBuilder("http://svc.ankhsvn.net/svc/go/");

            ub.Query = string.Format("t=ctrlHelp&v={0}&l={1}&dt={2}", GetService <IAnkhPackage>().UIVersion, CultureInfo.CurrentUICulture.LCID, Uri.EscapeUriString(control.DialogHelpTypeName));

            try
            {
                bool          showHelpInBrowser = true;
                IVsHelpSystem help = GetService <IVsHelpSystem>(typeof(SVsHelpService));
                if (help != null)
                {
                    showHelpInBrowser = !VSErr.Succeeded(help.DisplayTopicFromURL(ub.Uri.AbsoluteUri, (uint)VHS_COMMAND.VHS_Default));
                }

                if (showHelpInBrowser)
                {
                    Help.ShowHelp(control.Control, ub.Uri.AbsoluteUri);
                }
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                if (eh != null && eh.IsEnabled(ex))
                {
                    eh.OnError(ex);
                }
                else
                {
                    throw;
                }
            }
        }
        public int LoadUserOptions(IVsSolutionPersistence pPersistence, uint grfLoadOpts)
        {
            if ((grfLoadOpts & (uint)__VSLOADUSEROPTS.LUO_OPENEDDSW) != 0)
            {
                return(VSErr.S_OK); // We only know .suo; let's ignore old style projects
            }

            try
            {
                pPersistence.LoadPackageUserOpts(this, SccPendingChangeStream);
                pPersistence.LoadPackageUserOpts(this, SccExcludedStream);
                pPersistence.LoadPackageUserOpts(this, SccTranslateStream);

                return(VSErr.S_OK);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();

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

                return(Marshal.GetHRForException(ex));
            }
            finally
            {
                if (Marshal.IsComObject(pPersistence))
                {
                    Marshal.ReleaseComObject(pPersistence); // See Package.cs from MPF for reason
                }
            }
        }
        // Global note:
        // The same trick we do here for the solution (loading the package when encountering a solution property)
        // can be done on several project types using IVsProjectStartupServices
        public int QuerySaveSolutionProps(IVsHierarchy pHierarchy, VSQUERYSAVESLNPROPS[] pqsspSave)
        {
            if (pqsspSave == null)
            {
                return(VSErr.E_POINTER);
            }

            try
            {
                // This function is called by the IDE to determine if something needs to be saved in the solution.
                // If the package returns that it has dirty properties, the shell will callback on SaveSolutionProps

                if (Scc == null || !Scc.IsSolutionManaged)
                {
                    pqsspSave[0] = VSQUERYSAVESLNPROPS.QSP_HasNoProps;
                    return(VSErr.S_OK);
                }

                if (pHierarchy == null)
                {
                    if (Scc.IsSolutionDirty)
                    {
                        pqsspSave[0] = VSQUERYSAVESLNPROPS.QSP_HasDirtyProps;
                    }
                    else
                    {
                        pqsspSave[0] = VSQUERYSAVESLNPROPS.QSP_HasNoDirtyProps;
                    }
                }
                else
                {
                    if (!Scc.HasProjectProperties(pHierarchy))
                    {
                        pqsspSave[0] = VSQUERYSAVESLNPROPS.QSP_HasNoProps;
                    }
                    else if (Scc.IsSolutionDirty)
                    {
                        pqsspSave[0] = VSQUERYSAVESLNPROPS.QSP_HasDirtyProps;
                    }
                    else
                    {
                        pqsspSave[0] = VSQUERYSAVESLNPROPS.QSP_HasNoDirtyProps;
                    }
                }
                return(VSErr.S_OK);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();

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

                return(Marshal.GetHRForException(ex));
            }
        }
Exemplo n.º 6
0
        public void OnIdle(AnkhIdleArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_delayed)
            {
                TryReleaseDelayed();
            }
            else
            if (e.Periodic)
            {
                for (int i = 0; i < _tickCount; i++)
                {
                    if (_ticks[i] != 0)
                    {
                        Debug.WriteLine(string.Format("AnkhSVN: Tocking {0}", AnkhCommand.TickFirst + i));
                        PostExecCommand(AnkhCommand.TickFirst + i);
                    }
                }
            }

            if (e.NonPeriodic)
            {
                AnkhAction action;

                while (null != (action = GetIdleAction()))
                {
                    try
                    {
                        if (action != null)
                        {
                            action();
                        }
                    }
                    catch (Exception ex)
                    {
                        IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();
                        if (handler != null && handler.IsEnabled(ex))
                        {
                            handler.OnError(ex);
                        }
                        else
                        {
                            throw;
                        }
                    }

                    if (!e.ContinueIdle())
                    {
                        break;
                    }
                }
            }
        }
        public int ReadSolutionProps(IVsHierarchy pHierarchy, string pszProjectName, string pszProjectMk, string pszKey, int fPreLoad, IPropertyBag pPropBag)
        {
            try
            {
                using (IPropertyMap map = new PropertyBag(pPropBag))
                {
                    bool preload = (fPreLoad != 0);

                    switch (pszKey)
                    {
                    case SubversionPropertyCategory:
                        if (preload && pHierarchy == null)
                        {
                            string value;
                            bool   register;

                            if (!map.TryGetValue(ManagedPropertyName, out value))
                            {
                                register = false;
                            }
                            else if (string.IsNullOrEmpty(value) || !bool.TryParse(value, out register))
                            {
                                register = false;
                            }

                            if (register)
                            {
                                Scc.RegisterAsPrimarySccProvider();

                                Scc.LoadingManagedSolution(true);
                            }
                        }
                        break;

                    case AnkhId.SvnOriginName:
                        Scc.ReadProjectProperties(pHierarchy, pszProjectName, pszProjectMk, map);
                        break;
                    }
                }
                return(VSErr.S_OK);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();

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

                return(Marshal.GetHRForException(ex));
            }
        }
        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));
            }
        }
        int IVsPersistSolutionProps.WriteSolutionProps(IVsHierarchy pHierarchy, string pszKey, IPropertyBag pPropBag)
        {
            if (Scc == null)
            {
                return(VSErr.S_OK);
            }
            else if (pPropBag == null)
            {
                return(VSErr.E_POINTER);
            }

            try
            {
                // This method is called from the VS implementation after a request from SaveSolutionProps
                using (IPropertyMap map = new PropertyBag(pPropBag))
                {
                    switch (pszKey)
                    {
                    case SubversionPropertyCategory:
                        map.SetRawValue(ManagedPropertyName, true.ToString());
                        // BH: Don't localize this text! Changing it will change all solutions marked as managed by Ankh
                        map.SetRawValue(ManagerPropertyName, "AnkhSVN - Subversion Support for Visual Studio");
                        break;

                    case AnkhId.SvnOriginName:
                        Scc.StoreProjectProperties(pHierarchy, map);
                        break;
                    }
                }

                return(VSErr.S_OK);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();

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

                return(Marshal.GetHRForException(ex));
            }
        }
Exemplo n.º 10
0
 public override void RefreshList()
 {
     try
     {
         DoRefresh(true);
     }
     catch (Exception ex)
     {
         IAnkhErrorHandler eh = Context.GetService <IAnkhErrorHandler>();
         if (eh != null && eh.IsEnabled(ex))
         {
             eh.OnError(ex);
         }
         else
         {
             throw;
         }
     }
 }
Exemplo n.º 11
0
        void IAnkhServiceEvents.OnLastChanged(LastChangedEventArgs e)
        {
            try
            {
                OnLastChanged(e);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                if (eh != null && eh.IsEnabled(ex))
                {
                    eh.OnError(ex);
                }
                else
                {
                    throw;
                }
            }
        }
Exemplo n.º 12
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            // Exit as quickly as possible without creating exceptions. This function is performance critical!

            if (GuidRefIsNull(ref pguidCmdGroup))
            {
                return(VSErr.OLECMDERR_E_NOTSUPPORTED);
            }

            Dictionary <int, EventHandler> cmdMap;

            if (!_commandMap.TryGetValue(pguidCmdGroup, out cmdMap))
            {
                return(VSErr.OLECMDERR_E_UNKNOWNGROUP);
            }

            EventHandler handler;

            if (cmdMap.TryGetValue(unchecked ((int)nCmdID), out handler))
            {
                try
                {
                    handler(this, EventArgs.Empty);
                }
                catch (Exception ex)
                {
                    IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                    if (eh != null && eh.IsEnabled(ex))
                    {
                        eh.OnError(ex);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(VSErr.OLECMDERR_E_NOTSUPPORTED);
        }
Exemplo n.º 13
0
        public bool Execute(AnkhCommand command, CommandEventArgs e)
        {
            EnsureLoaded();
            CommandMapItem item;

            if (_map.TryGetValue(command, out item))
            {
                try
                {
                    e.Prepare(item);

                    CommandUpdateEventArgs u = new CommandUpdateEventArgs(command, e.Context);
                    item.OnUpdate(u);
                    if (u.Enabled)
                    {
                        item.OnExecute(e);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                    if (eh != null && eh.IsEnabled(ex))
                    {
                        eh.OnError(ex, e);
                        return(true); // If we return false VS shows another error box!
                    }

                    throw;
                }

                return(item.IsHandled);
            }

            return(false);
        }
Exemplo n.º 14
0
        public virtual void OnThemeChange(IAnkhServiceProvider sender, CancelEventArgs e)
        {
            ShowSelectAllCheckBox = false; // Not supported by VS theming. Disable to avoid problems and unnecessary work :(

            _isThemed = !e.Cancel;
            try
            {
                base.OnParentChanged(EventArgs.Empty); // Recreate handle, keeping state
            }
            catch (Exception ee)
            {
                IAnkhErrorHandler handler = sender.GetService <IAnkhErrorHandler>();

                if (handler != null && handler.IsEnabled(ee))
                {
                    handler.OnError(ee);
                }
                else
                {
                    throw;
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Saves the settings.
        /// </summary>
        public void SaveSettings()
        {
            // Load in case something changed in the mean time, other page/other VS instance
            ConfigSvc.LoadConfig();

            SaveSettingsCore();

            try
            {
                ConfigSvc.SaveConfig(Config);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = Context.GetService <IAnkhErrorHandler>();

                if (eh != null && eh.IsEnabled(ex))
                {
                    eh.OnError(ex);
                    return;
                }

                throw;
            }
        }
Exemplo n.º 16
0
        private void PostCommit_IssueTracker(PendingCommitState state, SvnCommitResult result)
        {
            IssueRepository iRepo = IssueService.CurrentIssueRepository;

            if (iRepo == null)
            {
                return;
            }

            List <Uri> uris = new List <Uri>();

            foreach (PendingChange pc in state.Changes)
            {
                uris.Add(pc.Uri);
            }

            PostCommitArgs pca = new PostCommitArgs(uris.ToArray(), result.Revision, state.LogMessage);

            try
            {
                iRepo.PostCommit(pca);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                if (eh != null && eh.IsEnabled(ex))
                {
                    eh.OnError(ex);
                }
                else
                {
                    throw;
                }
            }
        }
Exemplo n.º 17
0
        public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            _solutionLoaded = true;
            SccEvents.OnSolutionOpened(true);

            GetService <IAnkhServiceEvents>().OnSolutionOpened(EventArgs.Empty);

            if (!SccProvider.IsActive)
            {
                return(VSErr.S_OK);
            }
            try
            {
                VerifySolutionNaming();

                IAnkhSolutionSettings ss = GetService <IAnkhSolutionSettings>();

                if (ss != null && ss.ProjectRoot != null)
                {
                    string rootDir = Path.GetPathRoot(ss.ProjectRoot);
                    if (rootDir.Length == 3 && rootDir.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
                    {
                        DriveInfo di    = new DriveInfo(rootDir);
                        bool      oldFs = false;

                        switch ((di.DriveFormat ?? "").ToUpperInvariant())
                        {
                        case "FAT32":
                        case "FAT":
                            oldFs = true;
                            break;
                        }

                        if (oldFs)
                        {
                            IAnkhConfigurationService cs = GetService <IAnkhConfigurationService>();

                            if (!cs.GetWarningBool(AnkhWarningBool.FatFsFound))
                            {
                                using (SccFilesystemWarningDialog dlg = new SccFilesystemWarningDialog())
                                {
                                    dlg.Text = Path.GetFileName(ss.SolutionFilename);
                                    if (DialogResult.OK == dlg.ShowDialog(Context))
                                    {
                                        cs.SetWarningBool(AnkhWarningBool.FatFsFound, true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();

                if (handler.IsEnabled(ex))
                {
                    handler.OnError(ex);
                }
                else
                {
                    throw;
                }
            }

            return(VSErr.S_OK);
        }
        public int ReadUserOptions([In] IStream pOptionsStream, [In] string pszKey)
        {
            try
            {
                using (ComStreamWrapper wrapper = new ComStreamWrapper(pOptionsStream, true))
                {
                    IAnkhSccService scc;
                    switch (pszKey)
                    {
                    case SccPendingChangeStream:
                        LoadPendingChanges(wrapper);
                        break;

                    case SccTranslateStream:
                        scc = GetService <IAnkhSccService>();
                        if (scc != null)
                        {
                            scc.SerializeSccTranslateData(wrapper, false);
                        }
                        break;

                    case SccExcludedStream:
                        scc = GetService <IAnkhSccService>();
                        if (scc != null)
                        {
                            scc.SerializeSccExcludeData(wrapper, false);
                        }
                        break;

                    default:
                        // TODO: Add support for some service api for our services
                        break;
                    }
                }
                return(VSErr.S_OK); // Our data is in subversion properties
            }
            catch (EndOfStreamException)
            {
                // Ignore: Old version? Broken Solution File? (Common error)
                return(VSErr.S_OK);;
            }
            catch (Exception ex)
            {
#if DEBUG
                IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();

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

                return(VSErr.S_OK);
            }
            finally
            {
                if (Marshal.IsComObject(pOptionsStream))
                {
                    Marshal.ReleaseComObject(pOptionsStream); // See Package.cs from MPF for reason
                }
            }
        }
Exemplo n.º 19
0
        public bool PerformUpdate(AnkhCommand command, CommandUpdateEventArgs e)
        {
            EnsureLoaded();
            CommandMapItem item;

            if (_map.TryGetValue(command, out item))
            {
                bool skip;
                if ((item.Availability & CommandAvailability.AlwaysFlag) != 0)
                {
                    skip = false;
                }
                else if (((item.Availability & CommandAvailability.SvnActive) != 0) && States.SccProviderActive)
                {
                    skip = false;
                }
                else if (((item.Availability & CommandAvailability.GitActive) != 0) && States.GitSccProviderActive)
                {
                    skip = false;
                }
                else
                {
                    skip = true;
                }

                if (skip)
                {
                    e.Enabled = false;
                }
                else
                {
                    try
                    {
                        e.Prepare(item);

                        item.OnUpdate(e);
                    }
                    catch (Exception ex)
                    {
                        IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                        if (eh != null && eh.IsEnabled(ex))
                        {
                            eh.OnError(ex, e);
                            return(false);
                        }

                        throw;
                    }
                }

                if (item.HiddenWhenDisabled && !e.Enabled)
                {
                    e.Visible = false;
                }

                if (item.DynamicMenuEnd)
                {
                    e.DynamicMenuEnd = true;
                }

                return(item.IsHandled);
            }
            else if (_defined.Contains(command))
            {
                e.Enabled = e.Visible = false;
                return(true);
            }

            return(false);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Called by projects and editors before modifying a file
        /// The function allows the source control systems to take the necessary actions (checkout, flip attributes)
        /// to make the file writable in order to allow the edit to continue
        ///
        /// There are a lot of cases to deal with during QueryEdit/QuerySave.
        /// - called in commmand line mode, when UI cannot be displayed
        /// - called during builds, when save shoudn't probably be allowed
        /// - called during projects migration, when projects are not open and not registered yet with source control
        /// - checking out files may bring new versions from vss database which may be reloaded and the user may lose in-memory changes; some other files may not be reloadable
        /// - not all editors call QueryEdit when they modify the file the first time (buggy editors!), and the files may be already dirty in memory when QueryEdit is called
        /// - files on disk may be modified outside IDE and may have attributes incorrect for their scc status
        /// - checkouts may fail
        /// </summary>
        /// <param name="rgfQueryEdit">The RGF query edit.</param>
        /// <param name="cFiles">The c files.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgrgf">The RGRGF.</param>
        /// <param name="rgFileInfo">The rg file info.</param>
        /// <param name="pfEditVerdict">The pf edit verdict.</param>
        /// <param name="prgfMoreInfo">The PRGF more info.</param>
        /// <returns></returns>
        public int QueryEditFiles(uint rgfQueryEdit, int cFiles, string[] rgpszMkDocuments, uint[] rgrgf, VSQEQS_FILE_ATTRIBUTE_DATA[] rgFileInfo, out uint pfEditVerdict, out uint prgfMoreInfo)
        {
            tagVSQueryEditFlags queryFlags = (tagVSQueryEditFlags)rgfQueryEdit;

            pfEditVerdict = (uint)tagVSQueryEditResult.QER_EditOK;
            prgfMoreInfo  = (uint)(tagVSQueryEditResultFlags)0; // Must be 0 when verdict is QER_EditOK or you see failures like issue #624

            bool allowUI = (queryFlags & (tagVSQueryEditFlags.QEF_SilentMode | tagVSQueryEditFlags.QEF_ReportOnly | tagVSQueryEditFlags.QEF_ForceEdit_NoPrompting)) == 0;

            bool?allowReadOnlyNonSccWrites = null;

            if (rgpszMkDocuments == null)
            {
                return(VSErr.E_POINTER);
            }

            try
            {
                // If the editor asks us to do anything in our power to make it editable
                // without prompting, just make those files writable.
                if ((queryFlags & tagVSQueryEditFlags.QEF_ForceEdit_NoPrompting) != 0)
                {
                    return(QueryEditForceWritable(rgpszMkDocuments));
                }

                HybridCollection <string> mustLockFiles     = null;
                HybridCollection <string> readOnlyEditFiles = null;
                List <SvnItem>            mustLockItems     = null;
                List <SvnItem>            readOnlyItems     = null;

                for (int i = 0; i < cFiles; i++)
                {
                    SvnItem item;
                    {
                        string file = rgpszMkDocuments[i];

                        if (!IsSafeSccPath(file))
                        {
                            continue; // Skip non scc paths (Includes %TEMP%\*)
                        }
                        item = StatusCache[file];
                    }

                    Monitor.ScheduleDirtyCheck(item);

                    if (item.IsReadOnlyMustLock && !item.IsDirectory)
                    {
                        if (!allowUI)
                        {
                            pfEditVerdict = (uint)tagVSQueryEditResult.QER_EditNotOK;
                            prgfMoreInfo  = (uint)(tagVSQueryEditResultFlags.QER_ReadOnlyUnderScc
                                                   | tagVSQueryEditResultFlags.QER_NoisyCheckoutRequired);

                            return(VSErr.S_OK);
                        }

                        if (mustLockItems == null)
                        {
                            mustLockFiles = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);
                            mustLockItems = new List <SvnItem>();
                        }

                        if (!mustLockFiles.Contains(item.FullPath))
                        {
                            mustLockFiles.Add(item.FullPath);
                            mustLockItems.Add(item);
                        }
                    }
                    else if (item.IsReadOnly)
                    {
                        if (!allowReadOnlyNonSccWrites.HasValue)
                        {
                            allowReadOnlyNonSccWrites = AllowReadOnlyNonSccWrites();
                        }

                        if (!allowReadOnlyNonSccWrites.Value)
                        {
                            if (!allowUI)
                            {
                                pfEditVerdict = (uint)tagVSQueryEditResult.QER_EditNotOK;
                                prgfMoreInfo  = (uint)(tagVSQueryEditResultFlags.QER_InMemoryEditNotAllowed
                                                       | tagVSQueryEditResultFlags.QER_ReadOnlyNotUnderScc
                                                       | tagVSQueryEditResultFlags.QER_NoisyPromptRequired);

                                return(VSErr.S_OK);
                            }

                            if (readOnlyEditFiles == null)
                            {
                                readOnlyEditFiles = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);
                                readOnlyItems     = new List <SvnItem>();
                            }

                            if (!readOnlyEditFiles.Contains(item.FullPath))
                            {
                                readOnlyEditFiles.Add(item.FullPath);
                                readOnlyItems.Add(item);
                            }
                        }
                        // else // allow editting
                    }
                }
                if (mustLockItems != null)
                {
                    List <SvnItem> mustBeLocked = new List <SvnItem>(mustLockItems);

                    // Look at all subfiles of the must be locked document and add these to the dialog
                    // to make it easier to lock them too
                    foreach (string lockFile in new List <string>(mustLockFiles))
                    {
                        foreach (string file in GetAllDocumentFiles(lockFile))
                        {
                            if (!mustLockFiles.Contains(file))
                            {
                                mustLockFiles.Add(file);
                                mustLockItems.Add(StatusCache[file]);
                            }
                        }
                    }

                    CommandService.DirectlyExecCommand(AnkhCommand.SccLock, mustLockItems, CommandPrompt.DoDefault);
                    // Only check the original list; the rest of the items in mustLockItems is optional
                    foreach (SvnItem i in mustBeLocked)
                    {
                        if (i.IsReadOnlyMustLock)
                        {
                            // User has probably canceled the lock operation, or it failed.
                            pfEditVerdict = (uint)tagVSQueryEditResult.QER_EditNotOK;
                            prgfMoreInfo  = (uint)(tagVSQueryEditResultFlags.QER_CheckoutCanceledOrFailed
                                                   | tagVSQueryEditResultFlags.QER_ReadOnlyUnderScc);
                            break;
                        }
                    }
                }
                if (readOnlyItems != null)
                {
                    // TODO: Handle multiple items correctly
                    // Is this only for non-scc items or also for scc items that are readonly for other reasons?
                    CommandResult result =
                        CommandService.DirectlyExecCommand(AnkhCommand.MakeNonSccFileWriteable, readOnlyItems[0], CommandPrompt.DoDefault);

                    bool allowed = result.Result is bool?(bool)result.Result : false;

                    if (!allowed)
                    {
                        pfEditVerdict = (uint)tagVSQueryEditResult.QER_EditNotOK;
                        prgfMoreInfo  = (uint)(tagVSQueryEditResultFlags.QER_InMemoryEditNotAllowed
                                               | tagVSQueryEditResultFlags.QER_ReadOnlyNotUnderScc // TODO: Specialize to SCC?
                                               );
                    }
                }
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                if (eh != null && eh.IsEnabled(ex))
                {
                    eh.OnError(ex);
                }
                else
                {
                    throw;
                }
            }

            return(VSErr.S_OK);
        }
Exemplo n.º 21
0
        private void ReleaseExternalWrites()
        {
            Dictionary <string, DocumentLock> modified;

            lock (_externallyChanged)
            {
                if (_externallyChanged.Count == 0)
                {
                    return;
                }

                modified = new Dictionary <string, DocumentLock>(_externallyChanged, StringComparer.OrdinalIgnoreCase);
                _externallyChanged.Clear();
            }

            try
            {
                ScheduleSvnStatus(modified.Keys);
                foreach (KeyValuePair <string, DocumentLock> file in modified)
                {
                    SvnItem item = SvnCache[file.Key];

                    if (item.IsConflicted)
                    {
                        AnkhMessageBox mb = new AnkhMessageBox(Context);

                        DialogResult dr = mb.Show(string.Format(Resources.YourMergeToolSavedXWouldYouLikeItMarkedAsResolved, file.Key),
                                                  Resources.MergeCompleted, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);

                        switch (dr)
                        {
                        case DialogResult.Yes:
                            using (SvnClient c = Context.GetService <ISvnClientPool>().GetNoUIClient())
                            {
                                SvnResolveArgs ra = new SvnResolveArgs();
                                ra.ThrowOnError = false;

                                c.Resolve(file.Key, SvnAccept.Merged, ra);
                            }
                            goto case DialogResult.No;

                        case DialogResult.No:
                            if (!item.IsModified)
                            {
                                // Reload?
                            }
                            break;

                        default:
                            // Let VS handle the file
                            return;     // No reload
                        }
                    }

                    if (!item.IsDocumentDirty)
                    {
                        if (file.Value != null)
                        {
                            file.Value.Reload(file.Key);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                if (eh != null && eh.IsEnabled(ex))
                {
                    eh.OnError(ex);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                foreach (DocumentLock dl in modified.Values)
                {
                    if (dl != null)
                    {
                        dl.Dispose();
                    }
                }
            }
        }