예제 #1
0
        public void SplitEmptyString()
        {
            var t = new TaggedText("");
            var result = t.SplitByClicks();

            Assert.IsNotNull(result, "Returned a null list.");
            Assert.IsFalse(result.Any(), "List contained results.");
        }
예제 #2
0
        public void TestToString()
        {
            var expected = SentenceWithTags;

            var t = new TaggedText(SentenceWithTags);
            var actual = t.ToString();

            Assert.AreEqual(expected, actual, "Didn't produce the original sentence.");
        }
예제 #3
0
        public void RemoveTagsFromText()
        {
            const string expected = "This has some tags in it.";

            var t = new TaggedText(SentenceWithTags);
            var actual = t.ToPrettyString();

            Assert.AreEqual(expected, actual, "Didn't remove tags properly.");
        }
예제 #4
0
        public void LeaveStringIntactWhenNoSplit()
        {
            const string sentence = "This has no clicks to split by.";

            var t = new TaggedText(sentence);
            var split = t.SplitByClicks();

            Assert.IsTrue(split.Count == 1, "Split when there wasn't a click.");
            Assert.IsTrue(split[0].Equals("This has no clicks to split by."), "Didn't leave original string intact.");
        }
예제 #5
0
        public void SplitStringsByClick()
        {
            const string sentence = "This is separated by a click.[afterclick]This is the next part.";

            var t = new TaggedText(sentence);

            var split = t.SplitByClicks();
            Assert.IsTrue(split.Count == 2, "Split into incorrect amount of strings.");
            Assert.IsTrue(split[0].Equals("This is separated by a click."), "First split incorrect.");
            Assert.IsTrue(split[1].Equals("This is the next part."), "Second split incorrect.");
        }
예제 #6
0
        public static string ToVisibleDisplayString(this TaggedText part, bool includeLeftToRightMarker)
        {
            var text = part.ToString();

            if (includeLeftToRightMarker)
            {
                if (part.Tag == TextTags.Punctuation ||
                    part.Tag == TextTags.Space ||
                    part.Tag == TextTags.LineBreak)
                {
                    text = LeftToRightMarkerPrefix + text;
                }
            }

            return(text);
        }
예제 #7
0
        /////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Updates the contents of the item, based on the Tag.
        /// </summary>
        ///
        public void UpdateItemWithTag(TaggedText tag, bool move = false)
        {
            int position = FindTag(tag.Tag);

            if (position >= 0)
            {
                Items[position] = tag;

                if (move)
                {
                    CurrentItem = position;
                }

                Invalidate();
            }
        }
예제 #8
0
            public static Run GetRun(TaggedText part, IClassificationFormatMap formatMap, ClassificationTypeMap typeMap)
            {
                var text = GetVisibleDisplayString(part, includeLeftToRightMarker: true);

                var run = new Run(text);

                var taggedTextMappingService = PrimaryWorkspace.Workspace.Services
                                               .GetLanguageServices(LanguageNames.Hlsl) // TODO: Shouldn't hardcode HLSL here
                                               .GetService <ITaggedTextMappingService>();

                var format = formatMap.GetTextProperties(typeMap.GetClassificationType(taggedTextMappingService.GetClassificationTypeName(part.Tag)));

                run.SetTextProperties(format);

                return(run);
            }
예제 #9
0
            private static string GetVisibleDisplayString(TaggedText part, bool includeLeftToRightMarker)
            {
                var text = part.Text;

                if (includeLeftToRightMarker)
                {
                    var classificationTypeName = ClassificationTags.GetClassificationTypeName(part.Tag);
                    if (classificationTypeName == ClassificationTypeNames.Punctuation ||
                        classificationTypeName == ClassificationTypeNames.WhiteSpace)
                    {
                        text = LeftToRightMarkerPrefix + text;
                    }
                }

                return(text);
            }
예제 #10
0
        /// <summary>
        /// Adds new line at current character position (splitting line in two).
        /// </summary>
        ///
        public void InsertNewLine(bool inPlace = true)
        {
            if (ReadOnly || !Multiline)
            {
                return;
            }

            if (!inPlace)
            {
                CurrentColumn = 0;
            }

            if (CurrentRow >= RowCount)
            {
                // Current position is after the last line, so simply add an empty line.
                //
                this.Items.Add((TaggedText)string.Empty);

                if (inPlace)
                {
                    ++CurrentRow;
                }
            }
            else
            {
                // Split current line in two.
                //
                string line = Current.Text;
                Current = Current.Replace(line.Substring(0, CurrentColumn));

                this.Items.Insert(CurrentRow + 1,
                                  new TaggedText(line.Substring(CurrentColumn), Current.Tag)
                                  );

                if (inPlace)
                {
                    ++CurrentRow;
                    CurrentColumn = 0;
                }
            }

            ContentsChanged = true;
            OnTextChanged();
        }
예제 #11
0
        /// <summary>
        /// Overwrites characters starting at current position.
        /// </summary>
        ///
        public void ReplaceString(string str)
        {
            if (ReadOnly)
            {
                return;
            }

            if (CurrentRow >= RowCount)
            {
                // Current position is after the last line, simply add a new line
                // containing string to be replaced.
                //
                this.Items.Add((TaggedText)str);

                CurrentColumn += str.Length;
            }
            else
            {
                // Replace string at current position.
                //
                int count = Math.Min(str.Length, Current.Text.Length - CurrentColumn);

                string newText = Current.Text.Remove(CurrentColumn, count)
                                 .Insert(CurrentColumn, str);

                Current = Current.Replace(newText);

                CurrentColumn += str.Length;
            }

            // If cursor hits right edge, shift view 10 positions to the left
            //
            if (CurrentColumn >= ViewFromColumn + ClientWidth - 1)
            {
                if (Current.Text.Length > CurrentColumn)
                {
                    ViewFromColumn += 10;
                }
            }

            ContentsChanged = true;
            OnTextChanged();
        }
예제 #12
0
    /////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Draws MdiClient background and application version info.
    /// </summary>
    ///
    private void DrawMdiClientWindow()
    {
        MdiClient.BorderBackColor      = Color.Black;
        MdiClient.BorderBackColorInact = Color.Black;
        MdiClient.BorderForeColor      = Color.DarkCyan;
        MdiClient.BorderForeColorInact = Color.DarkCyan;
        MdiClient.BackColor            = Color.Black;
        MdiClient.ForeColor            = Color.DarkCyan;

        MdiClient.FillRectangle(0, 0, MdiClient.Width, MdiClient.Height, ' ');

        /////////////////////////////////////////////////////////////////////////////////

        // Display application version info.
        //
        string info = GetVerboseVersionInfo();
        TaggedTextCollection lines = TaggedText.SplitTextInLines(info);

        int left = MdiClient.Width - 2 - lines.MaxTextLength;
        int top  = MdiClient.Height - 1 - lines.Count;

        for (int i = 0; i < lines.Count; ++i)
        {
            MdiClient.At(left, top + i).Write(lines[i].Text);
        }

        // Display information about tracing, if any.
        //
        Debug.IfTracingExecute(() =>
        {
            MdiClient.ForeColor = Color.DarkMagenta;

            MdiClient.At(2, MdiClient.Height - 3);

            MdiClient.Write("Tracing to: ");
            MdiClient.Write(System.IO.Path.GetFileName(Debug.TraceFile.Name));

            MdiClient.At(2, MdiClient.Height - 2);

            MdiClient.Write("Trace flags: ");
            MdiClient.Write(Debug.TraceFlags.Verbose());
        });
    }
예제 #13
0
        public static void SaveStringToWaveFiles(string notesText, string folderPath, string fileNameFormat)
        {
            TaggedText    taggedNotes   = new TaggedText(notesText);
            List <String> stringsToSave = taggedNotes.SplitByClicks();

            //MD5 md5 = MD5.Create();

            for (int i = 0; i < stringsToSave.Count; i++)
            {
                String textToSave   = stringsToSave[i];
                String baseFileName = String.Format(fileNameFormat, i + 1);

                // The first item will autoplay; everything else is triggered by a click.
                String fileName = i > 0 ? baseFileName + " (OnClick)" : baseFileName;

                String filePath = folderPath + "\\" + fileName + ".wav";

                SaveStringToWaveFile(textToSave, filePath);
            }
        }
예제 #14
0
        public TaggedText getMOSReport(string appPwd, string EDIPI)
        {
            TaggedText result = new TaggedText();

            if (String.IsNullOrEmpty(appPwd))
            {
                result.fault = new FaultTO("Missing appPwd");
            }
            else if (String.IsNullOrEmpty(EDIPI))
            {
                result.fault = new FaultTO("Missing EDIPI");
            }

            if (result.fault != null)
            {
                return(result);
            }

            try
            {
                AbstractConnection cxn = new MdoOracleConnection(new DataSource()
                {
                    ConnectionString = mySession.MdwsConfiguration.MosConnectionString
                });
                PatientApi api = new PatientApi();
                Patient    p   = new Patient()
                {
                    EDIPI = EDIPI
                };
                TextReport rpt = api.getMOSReport(cxn, p);
                result.text = rpt.Text;
                result.tag  = "VADIR";
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }
            return(result);
        }
예제 #15
0
        public static void SaveStringToWaveFiles(string notesText, string folderPath, string fileNameFormat)
        {
            TaggedText    taggedNotes   = new TaggedText(notesText);
            List <string> stringsToSave = taggedNotes.SplitByClicks();

            //MD5 md5 = MD5.Create();

            for (int i = 0; i < stringsToSave.Count; i++)
            {
                string textToSave   = stringsToSave[i];
                string baseFileName = string.Format(fileNameFormat, i + 1);

                // The first item will autoplay; everything else is triggered by a click.
                string fileName = i > 0 ? baseFileName + " (OnClick)" : baseFileName;
                string filePath = folderPath + "\\" + fileName + ".wav";

                switch (AudioSettingService.selectedVoiceType)
                {
                case VoiceType.ComputerVoice:
                    ComputerVoiceRuntimeService.SaveStringToWaveFile(textToSave, filePath,
                                                                     AudioSettingService.selectedVoice as ComputerVoice);
                    break;

                case VoiceType.AzureVoice:
                    AzureRuntimeService.SaveStringToWaveFileWithAzureVoice(textToSave, filePath,
                                                                           AudioSettingService.selectedVoice as AzureVoice);
                    break;

                case VoiceType.WatsonVoice:
                    WatsonRuntimeService.SaveStringToWaveFile(textToSave, filePath,
                                                              AudioSettingService.selectedVoice as WatsonVoice);
                    break;

                default:
                    break;
                }
            }
        }
예제 #16
0
        public static Run ToRun(this TaggedText text)
        {
            var s = text.ToVisibleDisplayString(includeLeftToRightMarker: true);

            var run = new Run(s)
            {
                FontSize   = 12,
                FontWeight = FontWeights.Normal,
                Foreground = text.Tag switch
                {
                    TextTags.Keyword => Caches.GetSolidColorBrush(new ByteColor(0xFF, 0xF9, 0x26, 0x72)),
                    TextTags.Struct => Caches.GetSolidColorBrush(new ByteColor(0xFF, 0x56, 0xD9, 0xEF)),
                    TextTags.Enum => Caches.GetSolidColorBrush(new ByteColor(0xFF, 0x56, 0xD9, 0xEF)),
                    TextTags.TypeParameter => Caches.GetSolidColorBrush(new ByteColor(0xFF, 0x56, 0xD9, 0xEF)),
                    TextTags.Class => Caches.GetSolidColorBrush(new ByteColor(0xFF, 0x56, 0xD9, 0xEF)),
                    TextTags.Delegate => Caches.GetSolidColorBrush(new ByteColor(0xFF, 0x56, 0xD9, 0xEF)),
                    TextTags.Interface => Caches.GetSolidColorBrush(new ByteColor(0xFF, 0x56, 0xD9, 0xEF)),
                    _ => Caches.GetSolidColorBrush(ByteColor.White)
                }
            };

            return(run);
        }
예제 #17
0
 static void appendSectionAsCsharp(QuickInfoSection section, StringBuilder builder, FormattingOptions formattingOptions, int startingIndex = 0, bool includeSpaceAtStart = true)
 {
     if (includeSpaceAtStart)
     {
         builder.Append(formattingOptions.NewLine);
     }
     builder.Append("```csharp");
     builder.Append(formattingOptions.NewLine);
     for (int i = startingIndex; i < section.TaggedParts.Length; i++)
     {
         TaggedText part = section.TaggedParts[i];
         if (part.Tag == TextTags.LineBreak && i + 1 != section.TaggedParts.Length)
         {
             builder.Append(formattingOptions.NewLine);
         }
         else
         {
             builder.Append(part.Text);
         }
     }
     builder.Append(formattingOptions.NewLine);
     builder.Append("```");
 }
예제 #18
0
        /////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Appends text from string collection.
        /// </summary>
        ///
        public void AppendText(List <string> array)
        {
            if (this.Items == null)
            {
                // Reset text position and lines collection to defaults

                CursorLeft     = 0;
                CursorTop      = 0;
                CurrentRow     = 0;
                CurrentColumn  = 0;
                ViewFromRow    = 0;
                ViewFromColumn = 0;

                this.Items = new TaggedTextCollection();
            }

            if (array == null)
            {
                return;
            }

            if (Multiline)
            {
                foreach (string line in array)
                {
                    this.Items.Add(TaggedText.ClearFromControlCharacters(line));
                }
            }
            else // append current line
            {
                Current += TaggedText.ClearFromControlCharacters(
                    string.Join(" ", array.ToArray()));
            }

            Invalidate();
        }
예제 #19
0
        public TextNode ExtractAndConsume(ref string phraseString)
        {
            phraseString = phraseString.Trim();
            var tagStart = 0;
            var tagEnd   = phraseString.Substring(tagStart).IndexOf(" (", StringComparison.Ordinal);

            if (tagEnd == -1 || tagEnd < tagStart)
            {
                var tt         = phraseString.SplitRemoveEmpty(' ');
                var taggedPair = new TaggedText(text: tt[1], tag: tt[0]);
                phraseString = string.Empty;
                return(new TextNode(taggedPair.Tag + ":  " + taggedPair.Text));
            }
            var tagLength    = tagEnd;
            var tag          = phraseString.Substring(tagStart + 1, tagLength - 1);
            var innerTextEnd = phraseString.IndexOf("))", StringComparison.Ordinal);
            var innerTextLen = innerTextEnd - tagEnd + 1;
            var innerText    = phraseString.Substring(tagEnd + 1, innerTextLen);

            if (innerText.Count(c => c == '(') > 0)
            {
                phraseString = phraseString.Substring(tagLength + innerText.Length).Trim();
                var taggedPair = new TaggedText(tag: tag, text: innerText);
                var result     = new TextNode(taggedPair.Tag + ":  " + taggedPair.Text);
                result.AppentChild(ExtractAndConsume(ref innerText));
                return(result);
            }
            else
            {
                phraseString = phraseString.Substring(innerTextEnd + 1).Trim();
                var tagged = new TaggedText(tag: "X", text: string.Format("({0} {1})", tag, innerText));
                var result = new TextNode(tagged.Tag + ":  " + tagged.Text);
                result.AppentChild(ExtractAndConsume(ref innerText));
                return(result);
            }
        }
예제 #20
0
        public static Run ToRun(this TaggedText text)
        {
            var s = text.ToVisibleDisplayString(includeLeftToRightMarker: true);

            var run = new Run(s);

            switch (text.Tag)
            {
            case TextTags.Keyword:
                run.Foreground = Brushes.Blue;
                break;

            case TextTags.Struct:
            case TextTags.Enum:
            case TextTags.TypeParameter:
            case TextTags.Class:
            case TextTags.Delegate:
            case TextTags.Interface:
                run.Foreground = Brushes.Teal;
                break;
            }

            return(run);
        }
        public override Task <CompletionDescription> GetDescriptionAsync(Document document, CompletionItem item, CancellationToken cancellationToken)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var descriptionContent = new List <TaggedText>();

            if (item.Properties.TryGetValue(DescriptionKey, out var directiveDescription))
            {
                var descriptionText = new TaggedText(TextTags.Text, directiveDescription);
                descriptionContent.Add(descriptionText);
            }

            var completionDescription = CompletionDescription.Create(descriptionContent.ToImmutableArray());

            return(Task.FromResult(completionDescription));
        }
예제 #22
0
        public TaggedText isSurgeryNote(string sitecode, string noteDefinitionIEN)
        {
            TaggedText result = new TaggedText();
            string     msg    = MdwsUtils.isAuthorizedConnection(_mySession, sitecode);

            if (msg != "OK")
            {
                result.fault = new FaultTO(msg);
            }
            else if (noteDefinitionIEN == "")
            {
                result.fault = new FaultTO("Missing noteDefinitionIEN");
            }
            if (result.fault != null)
            {
                return(result);
            }

            if (sitecode == null)
            {
                sitecode = _mySession.ConnectionSet.BaseSiteId;
            }

            try
            {
                AbstractConnection cxn = _mySession.ConnectionSet.getConnection(sitecode);
                bool f = _api.isSurgeryNote(cxn, noteDefinitionIEN);
                result.tag  = (f ? "Y" : "N");
                result.text = (f ? "Cannot create new surgery note at this time" : "");
            }
            catch (Exception e)
            {
                result.fault = new FaultTO(e.Message);
            }
            return(result);
        }
예제 #23
0
    void scanText()
    {
        taggedTexts = new List <TaggedText>();

        int    wordIndex = 0;
        string currentText = "";
        bool   scanningCard = deck.BracketedText[0] == '{', atStart = true;

        Action addWord = () => {
            Card   card = null;
            string word = currentText;

            if (scanningCard)
            {
                card = deck.Cards[wordIndex++];
                word = currentText.Split(':')[0];
            }

            TaggedText next = new TaggedText
                              (
                word,
                scanningCard ? TextStatus.InDrawPile : TextStatus.NotACard,
                card
                              );
            taggedTexts.Add(next);

            currentText = "";
        };

        foreach (char c in deck.BracketedText)
        {
            switch (c)
            {
            case '{':
                if (scanningCard)
                {
                    throw new Exception("unexpected {");
                }
                if (!atStart)
                {
                    addWord();
                }
                scanningCard = true;
                break;

            case '}':
                if (!scanningCard)
                {
                    throw new Exception("unexpected }");
                }
                addWord();
                scanningCard = false;
                break;

            default:
                currentText += c;
                break;
            }
            atStart = false;
        }

        addWord();
    }
예제 #24
0
 public static TextBlock ToTextBlock(this TaggedText part, IClassificationFormatMap formatMap, ClassificationTypeMap typeMap)
 {
     return(SpecializedCollections.SingletonEnumerable(part).ToTextBlock(formatMap, typeMap));
 }
예제 #25
0
 void Add(TaggedText taggedText)
 {
     content.Append(taggedText.Text);
     contentTagged.Add(taggedText);
 }
예제 #26
0
    /////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Adds a TaggedText item to the list of items for a ComboBox.
    /// </summary>
    ///
    public int AddItem(TaggedText t)
    {
        return(this.Items.Add(t));
    }
예제 #27
0
 public async Task TagText(CommandContext ctx, [RemainingText] string text)
 {
     TaggedText tt = new TaggedText(text);
     await ctx.ReplyAsync("**Content Tagged:**\n```\n" + tt.Content + "\n```\n**Breakdown:**\n```\n" + string.Join('\n', tt.Tags.Select(t => t.color + ": " + t.text + "")) + "\n```");
 }
예제 #28
0
 public static SerializableTaggedText Dehydrate(TaggedText taggedText)
 {
     return new SerializableTaggedText { Tag = taggedText.Tag, Text = taggedText.Text };
 }
예제 #29
0
        private void Initialize()
        {
            var content = new StringBuilder();
            var prettyPrintedContent = new StringBuilder();

            var parts = new List <TaggedText>();
            var prettyPrintedParts = new List <TaggedText>();

            var parameters = new List <IParameter>();

            var signaturePrefixParts   = _signatureHelpItem.PrefixDisplayParts;
            var signaturePrefixContent = _signatureHelpItem.PrefixDisplayParts.GetFullText();

            AddRange(signaturePrefixParts, parts, prettyPrintedParts);
            Append(signaturePrefixContent, content, prettyPrintedContent);

            var separatorParts   = _signatureHelpItem.SeparatorDisplayParts;
            var separatorContent = separatorParts.GetFullText();

            var newLinePart    = new TaggedText(TextTags.LineBreak, "\r\n");
            var newLineContent = newLinePart.ToString();
            var spacerPart     = new TaggedText(TextTags.Space, new string(' ', signaturePrefixContent.Length));
            var spacerContent  = spacerPart.ToString();

            var paramColumnCount = 0;

            for (var i = 0; i < _signatureHelpItem.Parameters.Length; i++)
            {
                var sigHelpParameter = _signatureHelpItem.Parameters[i];

                var parameterPrefixParts   = sigHelpParameter.PrefixDisplayParts;
                var parameterPrefixContext = sigHelpParameter.PrefixDisplayParts.GetFullText();

                var parameterParts = AddOptionalBrackets(
                    sigHelpParameter.IsOptional, sigHelpParameter.DisplayParts);
                var parameterContent = parameterParts.GetFullText();

                var parameterSuffixParts   = sigHelpParameter.SuffixDisplayParts;
                var parameterSuffixContext = sigHelpParameter.SuffixDisplayParts.GetFullText();

                paramColumnCount += separatorContent.Length + parameterPrefixContext.Length + parameterContent.Length + parameterSuffixContext.Length;

                if (i > 0)
                {
                    AddRange(separatorParts, parts, prettyPrintedParts);
                    Append(separatorContent, content, prettyPrintedContent);

                    if (paramColumnCount > MaxParamColumnCount)
                    {
                        prettyPrintedParts.Add(newLinePart);
                        prettyPrintedParts.Add(spacerPart);
                        prettyPrintedContent.Append(newLineContent);
                        prettyPrintedContent.Append(spacerContent);

                        paramColumnCount = 0;
                    }
                }

                AddRange(parameterPrefixParts, parts, prettyPrintedParts);
                Append(parameterPrefixContext, content, prettyPrintedContent);

                parameters.Add(new Parameter(this, sigHelpParameter, parameterContent, content.Length, prettyPrintedContent.Length));

                AddRange(parameterParts, parts, prettyPrintedParts);
                Append(parameterContent, content, prettyPrintedContent);

                AddRange(parameterSuffixParts, parts, prettyPrintedParts);
                Append(parameterSuffixContext, content, prettyPrintedContent);
            }

            AddRange(_signatureHelpItem.SuffixDisplayParts, parts, prettyPrintedParts);
            Append(_signatureHelpItem.SuffixDisplayParts.GetFullText(), content, prettyPrintedContent);

            if (_parameterIndex >= 0)
            {
                var sigHelpParameter = _signatureHelpItem.Parameters[_parameterIndex];

                AddRange(sigHelpParameter.SelectedDisplayParts, parts, prettyPrintedParts);
                Append(sigHelpParameter.SelectedDisplayParts.GetFullText(), content, prettyPrintedContent);
            }

            AddRange(_signatureHelpItem.DescriptionParts, parts, prettyPrintedParts);
            Append(_signatureHelpItem.DescriptionParts.GetFullText(), content, prettyPrintedContent);

            var documentation = _signatureHelpItem.DocumentationFactory(CancellationToken.None).ToList();

            if (documentation.Count > 0)
            {
                AddRange(new[] { newLinePart }, parts, prettyPrintedParts);
                Append(newLineContent, content, prettyPrintedContent);

                AddRange(documentation, parts, prettyPrintedParts);
                Append(documentation.GetFullText(), content, prettyPrintedContent);
            }

            _content = content.ToString();
            _prettyPrintedContent      = prettyPrintedContent.ToString();
            _displayParts              = parts.ToImmutableArrayOrEmpty();
            _prettyPrintedDisplayParts = prettyPrintedParts.ToImmutableArrayOrEmpty();
            _parameters = parameters.ToReadOnlyCollection();
        }
예제 #30
0
 public static TextBlock ToTextBlock(this TaggedText part, ClassificationTypeMap typeMap, ITaggedTextMappingService mappingService)
 {
     return(SpecializedCollections.SingletonEnumerable(part).ToTextBlock(typeMap, mappingService));
 }
예제 #31
0
        private void Initialize()
        {
            var content = new StringBuilder();
            var prettyPrintedContent = new StringBuilder();

            var parts = new List<TaggedText>();
            var prettyPrintedParts = new List<TaggedText>();

            var parameters = new List<IParameter>();

            var signaturePrefixParts = _signatureHelpItem.PrefixDisplayParts;
            var signaturePrefixContent = _signatureHelpItem.PrefixDisplayParts.GetFullText();

            AddRange(signaturePrefixParts, parts, prettyPrintedParts);
            Append(signaturePrefixContent, content, prettyPrintedContent);

            var separatorParts = _signatureHelpItem.SeparatorDisplayParts;
            var separatorContent = separatorParts.GetFullText();

            var newLinePart = new TaggedText(TextTags.LineBreak, "\r\n");
            var newLineContent = newLinePart.ToString();
            var spacerPart = new TaggedText(TextTags.Space, new string(' ', signaturePrefixContent.Length));
            var spacerContent = spacerPart.ToString();

            var paramColumnCount = 0;

            for (int i = 0; i < _signatureHelpItem.Parameters.Length; i++)
            {
                var sigHelpParameter = _signatureHelpItem.Parameters[i];

                var parameterPrefixParts = sigHelpParameter.PrefixDisplayParts;
                var parameterPrefixContext = sigHelpParameter.PrefixDisplayParts.GetFullText();

                var parameterParts = AddOptionalBrackets(
                    sigHelpParameter.IsOptional, sigHelpParameter.DisplayParts);
                var parameterContent = parameterParts.GetFullText();

                var parameterSuffixParts = sigHelpParameter.SuffixDisplayParts;
                var parameterSuffixContext = sigHelpParameter.SuffixDisplayParts.GetFullText();

                paramColumnCount += separatorContent.Length + parameterPrefixContext.Length + parameterContent.Length + parameterSuffixContext.Length;

                if (i > 0)
                {
                    AddRange(separatorParts, parts, prettyPrintedParts);
                    Append(separatorContent, content, prettyPrintedContent);

                    if (paramColumnCount > MaxParamColumnCount)
                    {
                        prettyPrintedParts.Add(newLinePart);
                        prettyPrintedParts.Add(spacerPart);
                        prettyPrintedContent.Append(newLineContent);
                        prettyPrintedContent.Append(spacerContent);

                        paramColumnCount = 0;
                    }
                }

                AddRange(parameterPrefixParts, parts, prettyPrintedParts);
                Append(parameterPrefixContext, content, prettyPrintedContent);

                parameters.Add(new Parameter(this, sigHelpParameter, parameterContent, content.Length, prettyPrintedContent.Length));

                AddRange(parameterParts, parts, prettyPrintedParts);
                Append(parameterContent, content, prettyPrintedContent);

                AddRange(parameterSuffixParts, parts, prettyPrintedParts);
                Append(parameterSuffixContext, content, prettyPrintedContent);
            }

            AddRange(_signatureHelpItem.SuffixDisplayParts, parts, prettyPrintedParts);
            Append(_signatureHelpItem.SuffixDisplayParts.GetFullText(), content, prettyPrintedContent);

            if (_parameterIndex >= 0)
            {
                var sigHelpParameter = _signatureHelpItem.Parameters[_parameterIndex];

                AddRange(sigHelpParameter.SelectedDisplayParts, parts, prettyPrintedParts);
                Append(sigHelpParameter.SelectedDisplayParts.GetFullText(), content, prettyPrintedContent);
            }

            AddRange(_signatureHelpItem.DescriptionParts, parts, prettyPrintedParts);
            Append(_signatureHelpItem.DescriptionParts.GetFullText(), content, prettyPrintedContent);

            var documentation = _signatureHelpItem.DocumentationFactory(CancellationToken.None).ToList();
            if (documentation.Count > 0)
            {
                AddRange(new[] { newLinePart }, parts, prettyPrintedParts);
                Append(newLineContent, content, prettyPrintedContent);

                AddRange(documentation, parts, prettyPrintedParts);
                Append(documentation.GetFullText(), content, prettyPrintedContent);
            }

            _content = content.ToString();
            _prettyPrintedContent = prettyPrintedContent.ToString();
            _displayParts = parts.ToImmutableArrayOrEmpty();
            _prettyPrintedDisplayParts = prettyPrintedParts.ToImmutableArrayOrEmpty();
            _parameters = parameters.ToReadOnlyCollection();
        }
예제 #32
0
 private static bool CompareParts(TaggedText p1, TaggedText p2)
 {
     return(p1.ToString() == p2.ToString());
 }
예제 #33
0
        /// <summary>
        /// Raises the DrawContents event.
        /// </summary>
        /// <param name="screen">screen where the window is redrawn</param>
        /// <param name="hasFocus">true if the window is in application focus</param>
        ///
        protected override void OnDrawContents(Screen screen, bool hasFocus)
        {
            if (screen == null)
            {
                return;
            }

            // Setup item colors for header
            //
            if (hasFocus)
            {
                screen.BackColor = HeaderBackColor;
                screen.ForeColor = HeaderForeColor;
            }
            else
            {
                screen.BackColor = HeaderBackColorInact;
                screen.ForeColor = HeaderForeColorInact;
            }

            // Draw header
            //
            for (int row = 0; row < HeaderHeight; ++row)
            {
                string text = Header[row];

                if (text == WideDivider)   // 'wide'-divider drawn in border
                {
                    continue;
                }
                else if (text == ShortDivider)   // 'short'-divider
                {
                    text = string.Empty.PadRight(ClientWidth, '─');
                }

                text = TaggedText.AlignedText(text, ClientWidth,
                                              TextAlign.Left, HorizontalPadding, HorizontalPadding);

                screen.CursorTop  = row;
                screen.CursorLeft = 0;
                screen.Write(text);
            }

            // Visible rows belongs to half-open range [ startRow, lastRow )
            //
            int startRow = Math.Max(0, ViewFrom);
            int lastRow  = Math.Min(ItemCount, ViewFrom + ViewHeight);

            for (int row = startRow; row < lastRow; ++row)
            {
                string text = row >= Items.Count ? string.Empty : Items[row].Text;

                text = TaggedText.AlignedText(text, ClientWidth,
                                              TextAlign.Left, HorizontalPadding, HorizontalPadding);

                // Setup item colors
                //
                if (hasFocus)
                {
                    if (row == CurrentItem)
                    {
                        screen.BackColor = CurrentRowBackColor;
                        screen.ForeColor = CurrentRowForeColor;
                    }
                    else
                    {
                        screen.BackColor = BackColor;
                        screen.ForeColor = ForeColor;
                    }
                }
                else if (row == CurrentItem)
                {
                    screen.BackColor = CurrentRowBackColorInact;
                    screen.ForeColor = CurrentRowForeColorInact;
                }
                else
                {
                    screen.BackColor = BackColorInact;
                    screen.ForeColor = ForeColorInact;
                }

                screen.CursorTop  = HeaderHeight + row - ViewFrom;
                screen.CursorLeft = 0;
                screen.Write(text);
            }

            // Setup item colors for footer
            //
            if (hasFocus)
            {
                screen.BackColor = FooterBackColor;
                screen.ForeColor = FooterForeColor;
            }
            else
            {
                screen.BackColor = FooterBackColorInact;
                screen.ForeColor = FooterForeColorInact;
            }

            // Draw footer
            //
            for (int row = 0; row < FooterHeight; ++row)
            {
                string text = Footer[row];

                if (text == WideDivider)   // 'wide'-divider drawn in border
                {
                    continue;
                }
                else if (text == ShortDivider)   // 'short'-divider
                {
                    text = string.Empty.PadRight(ClientWidth, '─');
                }

                text = TaggedText.AlignedText(text, ClientWidth,
                                              TextAlign.Left, HorizontalPadding, HorizontalPadding);

                screen.CursorTop  = ClientHeight - FooterHeight + row;
                screen.CursorLeft = 0;
                screen.Write(text);
            }

            base.OnDrawContents(screen, hasFocus);
        }
예제 #34
0
 public static SerializableTaggedText Dehydrate(TaggedText taggedText)
 {
     return(new SerializableTaggedText {
         Tag = taggedText.Tag, Text = taggedText.Text
     });
 }
 private static bool CompareParts(TaggedText p1, TaggedText p2)
 {
     return p1.ToString() == p2.ToString();
 }
 private static bool CompareParts(TaggedText p1, TaggedText p2)
 => p1.ToString() == p2.ToString();
예제 #37
0
        /////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Draws default border, caption and scroll bar for the window.
        /// </summary>
        /// <remarks>
        /// Border is drawn depending on Border, Caption and VerticalScrollBar flags:
        /// <pre>
        ///              No Border           With Border           With Border
        ///                                                        and Caption
        ///
        ///          Without Scrollbar:                           ┌──────────────┐
        ///                                                       │██████████████│
        ///                                 ┌──────────────┐      ├──────────────┤
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒▒▒     │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│      │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒▒▒     │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│      │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒▒▒     │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│      │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
        ///                                 └──────────────┘      └──────────────┘
        ///
        ///          With Scrollbar:                              ┌──────────────┐
        ///                                                       │██████████████│
        ///                                 ┌────────────┬─┐      ├────────────┬─┤
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒│▲     │▒▒▒▒▒▒▒▒▒▒▒▒│▲│      │▒▒▒▒▒▒▒▒▒▒▒▒│▲│
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒│█     │▒▒▒▒▒▒▒▒▒▒▒▒│█│      │▒▒▒▒▒▒▒▒▒▒▒▒│█│
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒│▼     │▒▒▒▒▒▒▒▒▒▒▒▒│▼│      │▒▒▒▒▒▒▒▒▒▒▒▒│▼│
        ///                                 └────────────┴─┘      └────────────┴─┘
        /// </pre>
        ///
        /// 3D-shadow of the border might be drawn using:
        /// <code>
        ///
        /// screen.SetColors( Left + 1, Top + Height + 1, Width + 2, 1,
        ///     Color.Black, Color.Black );
        ///
        /// screen.SetColors( Left + Width + 1, Top + 1, 2, Height,
        ///     Color.Black, Color.Black );
        ///
        /// </code>
        ///
        /// </remarks>
        ///
        public void DefaultDrawBorder(Screen screen, bool hasFocus)
        {
            ColorContext savedColors = new ColorContext(screen);

            bool hasScrollbar = VerticalScrollBar && Height >= 2 && Width >= 3;

            if (Border && !CaptionVisible)
            {
                // Draw normal window border without caption but with optional
                // border margin
                //
                screen.DrawRectangle(-1, -1, Width + 2, Height + 2);
            }
            else if (Border)
            {
                // Draw expanded window border for caption
                //
                screen.DrawRectangle(-1, -3, Width + 2, Height + 4);

                // Draw separator between window contents and caption
                //
                screen.Put(-1, -1, Box._UDsR);
                screen.Put(Width, -1, Box._UDLs);
                screen.DrawRectangle(0, -1, Width, 1);
            }

            // Draw vertical scrollbar with optional frame
            //
            if (hasScrollbar)
            {
                int reducedWidth = Width - 2;

                // Draw separator between window contents and scroll bar
                //
                if (Border)
                {
                    screen.DrawRectangle(reducedWidth, 0, 1, Height);
                    screen.Put(reducedWidth, -1, Box._sDLR);
                    screen.Put(reducedWidth, Height, Box._UsLR);
                }
                else
                {
                    screen.DrawRectangle(reducedWidth, 0, 1, Height);
                    screen.DrawRectangle(reducedWidth + 2, 0, 1, Height);
                }

                // Draw vertical scroll bar

                if (hasFocus)
                {
                    screen.ForeColor = ScrollBarForeColor;
                }
                else
                {
                    screen.ForeColor = ScrollBarForeColorInact;
                }

                screen.DrawVerticalScrollBar(reducedWidth + 1, 0, Height,
                                             VerticalScrollBarFirstItem, VerticalScrollBarLastItem,
                                             VerticalScrollBarItemCount);
            }

            // Write caption
            //
            if (Border & CaptionVisible & Caption != null)
            {
                if (hasFocus)
                {
                    screen.BackColor = CaptionBackColor;
                    screen.ForeColor = CaptionForeColor;
                }
                else
                {
                    screen.BackColor = CaptionBackColorInact;
                    screen.ForeColor = CaptionForeColorInact;
                }

                string text = TaggedText.AlignedText(Caption, Width,
                                                     CaptionTextAlign, CaptionIndent, CaptionIndent);

                screen.CursorTop  = -2;
                screen.CursorLeft = 0;
                screen.Write(text);
            }

            savedColors.Restore();
        }