Exemplo n.º 1
0
 private void InsertSelectedEntry(char characterInsertion)
 {
     if (this.intellisenseListBox.SelectedIndex <= -1 || !this.intellisensePopup.IsOpen)
         return;
     string text = new TextRange(this.richTextBox.Document.ContentStart, this.richTextBox.CaretPosition).Text;
     int startIndex = text.LastIndexOf(' ');
     string currentWord = startIndex != -1 ? text.Substring(startIndex).TrimStart(new char[0]) : text.TrimStart(new char[0]);
     IntellisenseItem intellisenseItem = this.intellisenseListBox.SelectedItem as IntellisenseItem;
     bool flag = text.StartsWith("d ", StringComparison.InvariantCultureIgnoreCase) && !IntellisenseAdorner.DM_EXPRESSION_WITH_END_SPACE.IsMatch(text);
     string textData = this.IgnorePrefix || flag ? intellisenseItem.FilterValue : intellisenseItem.DisplayValue;
     if (textData.StartsWith("@") || textData.StartsWith("#"))
     {
         int charactersToDelete = IntellisenseAdorner.GetNumberOfCharactersToDelete(currentWord, textData.StartsWith("@") ? "@" : "#");
         if (currentWord.EndsWith(" "))
             this.richTextBox.CaretPosition.DeleteTextInRun(-(charactersToDelete - 1));
         else
             this.richTextBox.CaretPosition.DeleteTextInRun(-charactersToDelete);
     }
     else if (currentWord.EndsWith(" "))
         this.richTextBox.CaretPosition.DeleteTextInRun(-(currentWord.Length - 1));
     else
         this.richTextBox.CaretPosition.DeleteTextInRun(-currentWord.Length);
     if ((int)characterInsertion != 0 && !this.IgnorePrefix)
         textData = textData + (object)characterInsertion;
     this.richTextBox.CaretPosition = this.richTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward) ?? this.richTextBox.CaretPosition;
     if (!flag)
     {
         this.richTextBox.CaretPosition.InsertTextInRun(textData);
     }
     else
     {
         this.richTextBox.CaretPosition.InsertTextInRun(textData);
         Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)intellisenseItem.FilterValue), (object)CommonCommands.MultiAccountifyToken((Enum)ViewModelMessages.DirectMessage, intellisenseItem.TwitterAccountID));
     }
     this.ignoreDisplay = true;
 }
Exemplo n.º 2
0
        private void RichTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (_isLoading)
                return;
            _isLoading = true;

            RichTextBox t = sender as RichTextBox;
            if (t == null)
                return;

            BlockCollection bc = t.Document.Blocks;
            foreach (Block b in bc)
            {
                if (b is Paragraph)
                {
                    var para = b as Paragraph;
                    string text = new TextRange(para.ContentStart, para.ContentEnd).Text;

                    bool isProject = text.EndsWith(":");
                    bool isTask = text.StartsWith("-") || text.StartsWith("*");
                    bool isNote = !isProject && !isTask;
                    bool isDone = text.Contains("@done");

                    para.Foreground = isNote ? Brushes.DimGray : Brushes.Black;
                    para.FontSize = isProject ? 16 : 12;
                    para.TextDecorations = isDone ? TextDecorations.Strikethrough : null;
                }
            }
            _isLoading = false;
        }
Exemplo n.º 3
0
 private void FormatExisting()
 {
     IEnumerator<Block> paras = MainTextArea.Document.Blocks.GetEnumerator();
     string currentText;
     Paragraph newPara;
     List<Block> newBlocks = new List<Block>();
     for (int i = 0; i < MainTextArea.Document.Blocks.Count; i++)
     {
         paras.MoveNext();
         if (paras.Current.Tag == null)
         {
             currentText = new TextRange(paras.Current.ContentStart, paras.Current.ContentEnd).Text;
             newPara = new Paragraph();
             foreach (string symbol in StyleSymbol)
             {
                 if (currentText.StartsWith(symbol))
                 {
                     currentText = currentText.Remove(0, symbol.Length);
                     newPara.Tag = StyleName[Array.IndexOf(StyleSymbol, symbol)];
                     break;
                 }
             }
             newPara.Inlines.Add(new Run(currentText));
             ChangeParagraphStyle((Paragraph)newPara, newPara.Tag.ToString());
         }
         else
         {
             newPara = (Paragraph)paras.Current;
         }
         newBlocks.Add(newPara);
     }
     MainTextArea.Document.Blocks.Clear();
     MainTextArea.Document.Blocks.AddRange(newBlocks);
 }