public int OnProjectLoadFailure(IVsHierarchy pStubHierarchy, string pszProjectName, string pszProjectMk, string pszKey)
        {
            IAnkhSccService scc = GetService <IAnkhSccService>();

            if (scc != null)
            {
                scc.ProjectLoadFailed(pszProjectMk);
            }

            return(VSErr.S_OK);
        }
示例#2
0
        static bool HandleUnmanagedOrUnversionedSolution(CommandEventArgs e, SvnItem solutionItem)
        {
            IAnkhSccService scc = e.GetService <IAnkhSccService>();
            AnkhMessageBox  mb  = new AnkhMessageBox(e.Context);

            bool shouldActivate = false;

            if (!scc.IsActive)
            {
                if (e.State.OtherSccProviderActive)
                {
                    return(false); // Can't switch in this case.. Nothing to do
                }
                // Ankh is not the active provider, we should register as active
                shouldActivate = true;
            }

            if (scc.IsSolutionManaged && solutionItem.IsVersioned)
            {
                return(true); // Projects should still be checked
            }
            bool confirmed = false;


            if (solutionItem.IsVersioned)
            { /* File is in subversion; just enable */
            }
            else if (solutionItem.IsVersionable)
            {
                if (!AddVersionableSolution(e, solutionItem, ref confirmed))
                {
                    return(false);
                }
            }
            else
            {
                if (!CheckoutWorkingCopyForSolution(e, ref confirmed))
                {
                    return(false);
                }
            }

            if (!confirmed && !e.DontPrompt && !e.IsInAutomation &&
                DialogResult.Yes != mb.Show(string.Format(CommandStrings.MarkXAsManaged,
                                                          Path.GetFileName(e.Selection.SolutionFilename)), "", MessageBoxButtons.YesNo))
            {
                return(false);
            }

            SetSolutionManaged(shouldActivate, solutionItem, scc);

            return(true);
        }
示例#3
0
        private void disconnectButton_Click(object sender, EventArgs e)
        {
            if (Context == null)
            {
                return;
            }

            IAnkhSccService scc = Context.GetService <IAnkhSccService>();

            foreach (SccProject project in SelectedProjects)
            {
                scc.SetProjectManaged(project, false);
            }

            RefreshGrid();
        }
        private void connectButton_Click(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (Context == null)
            {
                return;
            }

            IAnkhSccService scc = Context.GetService <IAnkhSccService>();

            foreach (SccProject project in SelectedProjects)
            {
                scc.SetProjectManaged(project, true);
            }

            RefreshGrid();
        }
示例#5
0
        static void SetSolutionManaged(bool shouldActivate, SvnItem item, IAnkhSccService scc)
        {
            if (shouldActivate)
                scc.RegisterAsPrimarySccProvider();

            scc.SetProjectManaged(null, true);
            item.MarkDirty(); // This clears the solution settings cache to retrieve its properties
        }
示例#6
0
        /// <summary>
        /// Returns true if <see cref="succeededProjects"/> should be set managed, false otherwise
        /// </summary>
        /// <param name="e"></param>
        /// <param name="mapper"></param>
        /// <param name="scc"></param>
        /// <param name="succeededProjects"></param>
        /// <returns></returns>
        static bool AskSetManagedSelectionProjects(CommandEventArgs e, IProjectFileMapper mapper, IAnkhSccService scc, IEnumerable<SvnProject> succeededProjects)
        {
            if (e.DontPrompt || e.IsInAutomation)
                return true;

            AnkhMessageBox mb = new AnkhMessageBox(e.Context);
            StringBuilder sb = new StringBuilder();
            bool foundOne = false;
            foreach (SvnProject project in succeededProjects)
            {
                ISvnProjectInfo info;
                if (!scc.IsProjectManaged(project) && null != (info = mapper.GetProjectInfo(project)))
                {
                    if (sb.Length > 0)
                        sb.Append("', '");

                    sb.Append(info.ProjectName);
                }

                foundOne = true;
            }

            if (!foundOne)
                return false; // No need to add when there are no projects

            string txt = sb.ToString();
            int li = txt.LastIndexOf("', '");
            if (li > 0)
                txt = txt.Substring(0, li + 1) + CommandResources.FileAnd + txt.Substring(li + 3);

            return DialogResult.Yes == mb.Show(string.Format(CommandResources.MarkXAsManaged,
                txt), AnkhId.PlkProduct, MessageBoxButtons.YesNo);
        }
        void RefreshGrid()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            ISupportInitialize init = bindingGrid;

            init.BeginInit();
            try
            {
                foreach (ChangeSourceControlRow row in bindingGrid.Rows)
                {
                    row.Refresh();
                }
            }
            finally
            {
                init.EndInit();
            }

            bool enableConnect    = false;
            bool enableDisconnect = false;

            IAnkhSccService scc = Context.GetService <IAnkhSccService>();

            bool isSolution = false;

            foreach (SccProject project in SelectedProjects)
            {
                if (project.IsSolution)
                {
                    isSolution = true;
                }

                if (scc.IsProjectManaged(project))
                {
                    enableDisconnect = true;
                }
                else if (!enableConnect)
                {
                    SvnItem item = null;
                    if (!project.IsSolution)
                    {
                        ISccProjectInfo projectInfo = ProjectMapper.GetProjectInfo(project);

                        if (projectInfo == null || string.IsNullOrEmpty(projectInfo.ProjectDirectory))
                        {
                            continue;
                        }

                        item = StatusCache[projectInfo.SccBaseDirectory];
                    }
                    else
                    {
                        item = SolutionSettings.ProjectRootSvnItem;
                    }

                    if (item != null && item.Uri != null)
                    {
                        enableConnect = true;
                    }
                }

                if (enableConnect && enableDisconnect && isSolution)
                {
                    break;
                }
            }

            EnableTab(solutionSettingsTab, isSolution);
            EnableTab(sharedSettingsTab, !isSolution);
            EnableTab(userSettingsTab, false);

            UpdateSettingTabs();

            connectButton.Enabled    = enableConnect;
            disconnectButton.Enabled = enableDisconnect;

            UpdateSettingTabs();
        }
示例#8
0
        /// <summary>
        /// Returns true if <see cref="succeededProjects"/> should be set managed, false otherwise
        /// </summary>
        /// <param name="e"></param>
        /// <param name="mapper"></param>
        /// <param name="scc"></param>
        /// <param name="succeededProjects"></param>
        /// <returns></returns>
        static bool AskSetManagedSelectionProjects(CommandEventArgs e, IProjectFileMapper mapper, IAnkhSccService scc, IEnumerable <SccProject> succeededProjects)
        {
            if (e.DontPrompt || e.IsInAutomation)
            {
                return(true);
            }

            AnkhMessageBox mb       = new AnkhMessageBox(e.Context);
            StringBuilder  sb       = new StringBuilder();
            bool           foundOne = false;

            foreach (SccProject project in succeededProjects)
            {
                ISccProjectInfo info;
                if (!scc.IsProjectManaged(project) && null != (info = mapper.GetProjectInfo(project)))
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("', '");
                    }

                    sb.Append(info.ProjectName);
                }

                foundOne = true;
            }

            if (!foundOne)
            {
                return(false); // No need to add when there are no projects
            }
            string txt = sb.ToString();
            int    li  = txt.LastIndexOf("', '");

            if (li > 0)
            {
                txt = txt.Substring(0, li + 1) + CommandStrings.FileAnd + txt.Substring(li + 3);
            }

            return(DialogResult.Yes == mb.Show(string.Format(CommandStrings.MarkXAsManaged,
                                                             txt), AnkhId.PlkProduct, MessageBoxButtons.YesNo));
        }
示例#9
0
        static void SetProjectsManaged(CommandEventArgs e)
        {
            ISvnStatusCache    cache   = e.GetService <ISvnStatusCache>();
            IFileStatusMonitor monitor = e.GetService <IFileStatusMonitor>();
            IAnkhSccService    scc     = e.GetService <IAnkhSccService>();
            IProjectFileMapper mapper  = e.GetService <IProjectFileMapper>();
            AnkhMessageBox     mb      = new AnkhMessageBox(e.Context);

            if (mapper == null)
            {
                return;
            }

            List <SccProject> projectsToBeManaged = new List <SccProject>();
            SvnItem           slnItem             = cache[e.Selection.SolutionFilename];
            Uri solutionReposRoot = null;

            if (slnItem.WorkingCopy != null)
            {
                solutionReposRoot = slnItem.WorkingCopy.RepositoryRoot;

                foreach (SccProject project in GetSelection(e.Selection))
                {
                    ISccProjectInfo projInfo = mapper.GetProjectInfo(project);

                    if (projInfo == null || projInfo.ProjectDirectory == null ||
                        !projInfo.IsSccBindable)
                    {
                        continue; // Some projects can't be managed
                    }
                    SvnItem projectDir = cache[projInfo.ProjectDirectory];

                    if (projectDir.WorkingCopy == slnItem.WorkingCopy)
                    {
                        // This is a 'normal' project, part of the solution and in the same working copy
                        projectsToBeManaged.Add(project);
                        continue;
                    }

                    bool markAsManaged;
                    bool writeReference;

                    if (projectDir.IsVersioned)
                    {
                        continue; // We don't have to add this one
                    }
                    if (projectDir.IsVersionable)
                    {
                        SvnItem parentDir = GetVersionedParent(projectDir);
                        Debug.Assert(parentDir != null);

                        DialogResult rslt = mb.Show(string.Format(CommandStrings.AddXToExistingWcY,
                                                                  projInfo.ProjectName,
                                                                  parentDir.FullPath), AnkhId.PlkProduct, MessageBoxButtons.YesNoCancel);

                        switch (rslt)
                        {
                        case DialogResult.Cancel:
                            return;

                        case DialogResult.No:
                            if (CheckoutWorkingCopyForProject(e, project, projInfo, solutionReposRoot, out markAsManaged, out writeReference))
                            {
                                if (markAsManaged)
                                {
                                    scc.SetProjectManaged(project, true);
                                }
                                if (writeReference)
                                {
                                    scc.EnsureCheckOutReference(project);
                                }

                                continue;
                            }
                            break;

                        case DialogResult.Yes:
                            projectsToBeManaged.Add(project);
                            AddPathToSubversion(e, projInfo.ProjectFile ?? projInfo.ProjectDirectory);
                            continue;
                        }
                    }
                    else
                    {
                        // We have to checkout (and create repository location)
                        if (CheckoutWorkingCopyForProject(e, project, projInfo, solutionReposRoot, out markAsManaged, out writeReference))
                        {
                            if (markAsManaged)
                            {
                                scc.SetProjectManaged(project, true);
                            }
                            if (writeReference)
                            {
                                scc.EnsureCheckOutReference(project);
                            }

                            continue;
                        }
                    }
                }
            }

            if (!AskSetManagedSelectionProjects(e, mapper, scc, projectsToBeManaged))
            {
                return;
            }

            foreach (SccProject project in projectsToBeManaged)
            {
                if (!scc.IsProjectManaged(project))
                {
                    scc.SetProjectManaged(project, true);

                    monitor.ScheduleSvnStatus(mapper.GetAllFilesOf(project)); // Update for 'New' status
                }
            }
        }
示例#10
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            if (!e.State.SolutionExists || (e.Command == AnkhCommand.FileSccAddProjectToSubversion && e.State.EmptySolution))
            {
                e.Enabled = false;
                return;
            }

            if (e.State.OtherSccProviderActive)
            {
                e.Enabled = false;
                return; // Only one scc provider can be active at a time
            }

            IAnkhSccService scc   = e.GetService <IAnkhSccService>();
            ISvnStatusCache cache = e.GetService <ISvnStatusCache>();

            if (scc == null || cache == null)
            {
                e.Enabled = false;
                return;
            }

            string solutionFilename = e.Selection.SolutionFilename;

            if (string.IsNullOrEmpty(solutionFilename) || !SvnItem.IsValidPath(solutionFilename))
            {
                solutionFilename = null;
            }

            if (e.Command == AnkhCommand.FileSccAddSolutionToSubversion)
            {
                if (solutionFilename == null || scc.IsSolutionManaged)
                {
                    e.Enabled = false; // Already handled
                    return;
                }
                SvnItem item = cache[solutionFilename];

                if (!item.Exists || !item.IsFile || item.ParentDirectory.NeedsWorkingCopyUpgrade)
                {
                    // Decide where you store the .sln first
                    e.Enabled = false;
                    return;
                }

                if (!item.IsVersioned)
                {
                    // If the .sln is ignored hide it in the context menus
                    // but don't hide it on the node itself
                    e.HideOnContextMenu = item.IsIgnored && !e.Selection.IsSolutionSelected;
                }
                return;
            }

            IProjectFileMapper pfm = e.GetService <IProjectFileMapper>();

            int  n        = 0;
            bool foundOne = false;

            foreach (IEnumerable <SccProject> projects in
                     new IEnumerable <SccProject>[]
            {
                e.Selection.GetSelectedProjects(true),
                e.Selection.GetSelectedProjects(false)
            })
            {
                foreach (SccProject p in projects)
                {
                    foundOne = true;

                    ISccProjectInfo pi = pfm.GetProjectInfo(p);

                    if (pi == null || !pi.IsSccBindable)
                    {
                        continue; // Not an SCC project
                    }
                    // A project is managed if the file says its managed
                    // and the project dir is managed
                    if (pi.ProjectDirectory != null && cache[pi.ProjectDirectory].IsVersioned &&
                        scc.IsProjectManaged(p))
                    {
                        continue; // Nothing to do here
                    }
                    string projectFile = pi.ProjectFile;

                    if (n > 1 && projectFile != null && cache[projectFile].IsIgnored)
                    {
                        e.HideOnContextMenu = true;
                    }

                    return;
                }
                n++;
                if (foundOne)
                {
                    break;
                }
            }

            e.Enabled = false;
        }