/// <summary>
        /// Gets the "project root"
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private static SvnItem GetRoot(BaseCommandEventArgs e)
        {
            SvnItem item = null;

            switch (e.Command)
            {
            case AnkhCommand.SolutionIssueTrackerSetup:
                IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();
                if (ss == null)
                {
                    return(null);
                }

                string root = ss.ProjectRoot;

                if (string.IsNullOrEmpty(root))
                {
                    return(null);
                }

                item = e.GetService <ISvnStatusCache>()[root];
                break;
            }

            return(item);
        }
        private static GitItem GetRoot(BaseCommandEventArgs e)
        {
            GitItem item = null;
            switch (e.Command)
            {
                case VisualGitCommand.SolutionBranch:
                case VisualGitCommand.SolutionTag:
                    IVisualGitSolutionSettings ss = e.GetService<IVisualGitSolutionSettings>();
                    if (ss == null)
                        return null;

                    string root = ss.ProjectRoot;

                    if (string.IsNullOrEmpty(root))
                        return null;

                    item = e.GetService<IFileStatusCache>()[root];
                    break;
                case VisualGitCommand.ProjectBranch:
                case VisualGitCommand.ProjectTag:
                    GitProject p = EnumTools.GetSingle(e.Selection.GetSelectedProjects(false));
                    if(p == null)
                        break;

                    IGitProjectInfo info = e.GetService<IProjectFileMapper>().GetProjectInfo(p);

                    if (info == null || info.ProjectDirectory == null)
                        break;

                    item = e.GetService<IFileStatusCache>()[info.ProjectDirectory];
                    break;
            }

            return item;
        }
        static IEnumerable<PendingChange> GetChanges(BaseCommandEventArgs e)
        {
            IPendingChangesManager pcm = e.GetService<IPendingChangesManager>();
            if (e.Command == VisualGitCommand.SolutionCommit)
            {
                foreach (PendingChange pc in pcm.GetAll())
                {
                    yield return pc;
                }
            }
            else
            {
                ProjectListFilter plf = new ProjectListFilter(e.Context, e.Selection.GetSelectedProjects(false));

                foreach (PendingChange pc in pcm.GetAll())
                {
                    if (plf.ShowChange(pc))
                        yield return pc;
                }
            }
        }
Example #4
0
        bool TryGetIssue(BaseCommandEventArgs e, out IssueMarker value)
        {
            value = null;
            IVsTextView tv = ((ISelectionContextEx)e.Selection).ActiveFrameTextView;

            if (tv == null)
            {
                LogMessageEditor editor = e.Selection.GetActiveControl<LogMessageEditor>();

                if (editor == null)
                    return false;

                tv = ((IAnkhHasVsTextView)editor).TextView;
            }

            int x, y;
            if (!ErrorHandler.Succeeded(tv.GetCaretPos(out y, out x)))
                return false;

            IVsTextLines lines;
            if (!ErrorHandler.Succeeded(tv.GetBuffer(out lines)))
                return false;

            string text, pre = null, post = null;

            text = GetLine(lines, y);

            if (string.IsNullOrEmpty(text))
                return false;

            string combined = null;
            int start = 0;
            if (y > 0)
            {
                pre = GetLine(lines, y - 1);
                combined = pre + '\n';
                start = combined.Length;
            }

            combined += text;

            post = GetLine(lines, y + 1);

            if (!string.IsNullOrEmpty(post))
                combined += '\n' + post;
            if ((y > 0) && !ErrorHandler.Succeeded(tv.GetTextStream(y - 1, 0, y, 0, out pre)))
                return false;

            if (!ErrorHandler.Succeeded(tv.GetTextStream(y + 1, 0, y + 2, 0, out post)))
                post = null;

            if (!string.IsNullOrEmpty(pre))
            {
                combined = pre.TrimEnd('\r', '\n') + '\n';
                start = combined.Length;
            }

            combined += text;

            if (!string.IsNullOrEmpty(post))
            {
                post = post.TrimEnd('\r', '\n');
                combined += '\n' + post;
            }

            if (_issueService == null)
                _issueService = e.GetService<IAnkhIssueService>();

            IEnumerable<IssueMarker> markers;

            int posToCheck = x + start;

            if (!_issueService.TryGetIssues(combined, out markers))
                return false;

            foreach (IssueMarker im in markers)
            {
                if (im.Index > posToCheck)
                    break;

                if (im.Index + im.Length >= posToCheck)
                {
                    value = im;
                    return true;
                }
            }

            return false;
        }
Example #5
0
        private static List<string> GetRecentNames(BaseCommandEventArgs e)
        {
            List<string> names = (List<string>)e.Selection.Cache[typeof(ItemMoveToChangeList)];

            if (names != null)
                return names;

            names = new List<string>();

            foreach (string cl in e.GetService<IPendingChangesManager>().GetSuggestedChangeLists())
            {
                names.Add(cl);

                if (names.Count >= 10)
                    break;
            }

            e.Selection.Cache[typeof(ItemMoveToChangeList)] = names;

            return names;
        }
        /// <summary>
        /// Gets the "project root"
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private static SvnItem GetRoot(BaseCommandEventArgs e)
        {
            SvnItem item = null;
            switch (e.Command)
            {
                case AnkhCommand.SolutionIssueTrackerSetup:
                    IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>();
                    if (ss == null)
                        return null;

                    string root = ss.ProjectRoot;

                    if (string.IsNullOrEmpty(root))
                        return null;

                    item = e.GetService<IFileStatusCache>()[root];
                    break;
            }

            return item;
        }
Example #7
0
        bool TryGetMarker(BaseCommandEventArgs e, bool issue, out TextMarker value)
        {
            value = null;
            IVsTextView tv = ((ISelectionContextEx)e.Selection).ActiveFrameTextView;

            if (tv == null)
            {
                LogMessageEditor editor = e.Selection.GetActiveControl <LogMessageEditor>();

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

                tv = ((IAnkhHasVsTextView)editor).TextView;
            }

            int x, y;

            if (!VSErr.Succeeded(tv.GetCaretPos(out y, out x)))
            {
                return(false);
            }

            IVsTextLines lines;

            if (!VSErr.Succeeded(tv.GetBuffer(out lines)))
            {
                return(false);
            }

            string text, pre = null, post = null;

            text = GetLine(lines, y);

            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            string combined = null;
            int    start    = 0;

            if (y > 0)
            {
                pre      = GetLine(lines, y - 1);
                combined = pre + '\n';
                start    = combined.Length;
            }

            combined += text;

            post = GetLine(lines, y + 1);

            if (!string.IsNullOrEmpty(post))
            {
                combined += '\n' + post;
            }

            if (_issueService == null)
            {
                _issueService = e.GetService <IAnkhIssueService>();
            }

            IEnumerable <TextMarker> markers;

            int posToCheck = x + start;

            if (issue)
            {
                if (!_issueService.TryGetIssues(combined, out markers))
                {
                    return(false);
                }
            }
            else
            {
                if (!_issueService.TryGetRevisions(combined, out markers))
                {
                    return(false);
                }
            }

            foreach (TextMarker im in markers)
            {
                if (im.Index > posToCheck)
                {
                    break;
                }

                if (im.Index + im.Length >= posToCheck)
                {
                    value = im;
                    return(true);
                }
            }

            return(false);
        }
        private IEnumerable<GitItem> GetAllRoots(BaseCommandEventArgs e)
        {
            IVisualGitProjectLayoutService pls = e.GetService<IVisualGitProjectLayoutService>();

            var result = new Dictionary<string, GitItem>(FileSystemUtil.StringComparer);

            foreach (var gitItem in pls.GetUpdateRoots(null))
            {
                if (gitItem.IsVersioned)
                    result[gitItem.FullPath] = gitItem;
            }

            return result.Values;
        }