Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
        private void tw_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            TextWorker tw = sender as TextWorker;

            string newText = new TextRange(Modification.tb.Document.ContentStart, Modification.tb.Document.ContentEnd).Text;
            string textToInsert = ((string)tw.Content).Remove(0, 2);

            newText =  newText.Remove(tw.startIndex, (tw.endIndex - tw.startIndex));
            newText = newText.Insert(tw.startIndex, textToInsert);

            FlowDocument doc = new FlowDocument();

            Paragraph paragraph = new Paragraph();
            paragraph.Inlines.Add(new Run(newText));

            doc.Blocks.Add(paragraph);

            Modification.tb.Document = doc;

            Data = newText;

            FindErrors();

            Modification.sp.Children.Remove((UIElement)tw.Parent);

            Update();
        }
Exemplo n.º 3
0
        private void rtbEdit_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            timer.Interval = COUNTDOWN;

            if (e.Key == Key.V && (Keyboard.Modifiers & (ModifierKeys.Control)) == (ModifierKeys.Control))
            {
                if (Clipboard.ContainsImage())
                {
                    e.Handled = true;
                    BitmapSource bitmap = Clipboard.GetImage();
                    PngBitmapEncoder pE = new PngBitmapEncoder();
                    string tempFile = Path.GetTempFileName();
                    pE.Frames.Add(BitmapFrame.Create(bitmap));
                    using (Stream stream = File.Create(tempFile))
                    {
                        pE.Save(stream);
                    }

                    Helper.ImageHelper.InsertImg(rtbEdit, tempFile);
                    File.Delete(tempFile);
                }
            }
            else
            {
                string strText = new TextRange(rtbEdit.Document.ContentStart, rtbEdit.Document.ContentEnd).Text;
                if (strText.LastIndexOf("\r\n") > 0)
                {
                    strText = strText.Remove(strText.LastIndexOf("\r\n"));
                }
                if (strText.Length <= 0) return;
                int titleEnd = strText.IndexOf("\r\n");
                if (titleEnd > 31 || titleEnd < 0) titleEnd = 0;

                strText = strText.Remove(0, titleEnd);
                int count = Regex.Matches(strText, @"[^\s]").Count;
                if (count <= 0) return;

                tbCount.Text = count + "";

                if (count > countAll + 10 || count < countAll - 10)
                {
                    countAll = count;
                    SaveAndUpdate();
                }
            }
        }