Esempio n. 1
0
        public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken)
        {
            var span      = new SnapshotSpan(_view.Selection.Start.Position, _view.Selection.End.Position);
            var startLine = span.Start.GetContainingLine().Extent;
            var endLine   = span.End.GetContainingLine().Extent;

            var selectionStart = _view.Selection.Start.Position.Position;
            var selectionEnd   = _view.Selection.End.Position.Position;
            var SelectedSpan   = new SnapshotSpan(span.Snapshot, selectionStart, selectionEnd - selectionStart);

            var list = new List <SuggestedActionSet>();

            //AddMissingFile
            var addMissingFileAction = AddMissingFileAction.Create(GetErrorTags(_view, SelectedSpan), _file, _view);

            if (addMissingFileAction != null)
            {
                list.AddRange(CreateActionSet(addMissingFileAction));
            }

            if (!_view.Selection.IsEmpty && startLine == endLine)
            {
                var convertToLink  = new ConvertToLinkAction(SelectedSpan, _view);
                var convertToImage = new ConvertToImageAction(SelectedSpan, _file);
                list.AddRange(CreateActionSet(convertToLink, convertToImage));
            }

            // Blocks
            var convertToQuote     = new ConvertToQuoteAction(SelectedSpan, _view);
            var convertToCodeBlock = new ConvertToCodeBlockAction(SelectedSpan, _view);

            list.AddRange(CreateActionSet(convertToQuote, convertToCodeBlock));

            // Lists
            var convertToUnorderedList = new ConvertToUnorderedList(SelectedSpan, _view);
            var convertToOrderedList   = new ConvertToOrderedList(SelectedSpan, _view);
            var convertToTaskList      = new ConvertToTaskList(SelectedSpan, _view);

            list.AddRange(CreateActionSet(convertToUnorderedList, convertToOrderedList, convertToTaskList));

            return(list);
        }
Esempio n. 2
0
        public static AddMissingFileAction Create(IEnumerable <IMappingTagSpan <IErrorTag> > errorTags, string file, ITextView view)
        {
            var errorTag = errorTags
                           .Select(m => m.Tag as LinkErrorTag)
                           .Where(tag => tag != null)
                           .FirstOrDefault();

            if (errorTag == null)
            {
                return(null);
            }
            var result = new AddMissingFileAction
            {
                linkUrl = errorTag.Url,
                file    = file,
                view    = view
            };

            return(result);
        }