Esempio n. 1
0
        private void UpdatePreTag(PreTag preTag)
        {
            if (preTag == null)
            {
                return;
            }

            int position = contentTextBox.SelectionStart;

            if (preTag.ComesFromFile)
            {
                if (!contentTextBox.Text.EndsWith("\r\n\r\n"))
                {
                    contentTextBox.Text += "\r\n\r\n";
                }
                contentTextBox.Text += preTag.Text;
            }
            else
            {
                contentTextBox.Text = contentTextBox.Text.Substring(0, preTag.Start) +
                                      preTag.Text +
                                      contentTextBox.Text.Substring(preTag.Start + preTag.Length);
            }

            contentTextBox.SelectionStart = position;
        }
Esempio n. 2
0
        private async void ReadFileAndAddTextBox(StorageFile file)
        {
            string fileContent = await FileIO.ReadTextAsync(file);

            PreTag preTag = new PreTag();

            preTag.ComesFromFile = true;
            preTag.Text          = fileContent;

            Frame.Navigate(typeof(PreEditorPage), preTag);
        }
Esempio n. 3
0
 /// <summary>
 /// Invoked when this page is about to be displayed in a Frame.
 /// </summary>
 /// <param name="e">Event data that describes how this page was reached.  The Parameter
 /// property is typically used to configure the page.</param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     preTag = e.Parameter as PreTag;
     if (preTag.ComesFromFile)
     {
         contentTextBox.Text = preTag.Text.Trim();
     }
     else
     {
         contentTextBox.Text = ContentBuilder.PreToText(preTag.Text);
     }
 }
 /// <summary>
 /// Invoked when this page is about to be displayed in a Frame.
 /// </summary>
 /// <param name="e">Event data that describes how this page was reached.  The Parameter
 /// property is typically used to configure the page.</param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     preTag = e.Parameter as PreTag;
     if (preTag.ComesFromFile)
     {
         contentTextBox.Text = preTag.Text.Trim();
     }
     else
     {
         contentTextBox.Text = ContentBuilder.PreToText(preTag.Text);
     }
 }
Esempio n. 5
0
        private async void TextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            PreTag  preTag  = ContentBuilder.GetPreTag(textBox);

            if (preTag != null)
            {
                e.Handled = true;

                // Create a menu and add commands specifying an id value for each instead of a delegate.
                var menu = new PopupMenu();
                menu.Commands.Add(new UICommand("Edit <pre> tag.", null, 2));
                var chosenCommand = await menu.ShowAsync(new Point(e.CursorLeft, e.CursorTop));

                if (chosenCommand != null)
                {
                    if (chosenCommand.Label.StartsWith("Edit"))
                    {
                        Frame.Navigate(typeof(PreEditorPage), preTag);
                    }
                }
            }
        }
Esempio n. 6
0
        static public PreTag GetPreTag(TextBox textBox)
        {
            PreTag preTag = new PreTag();

            preTag.ComesFromFile = false;

            Debug.WriteLine(textBox.SelectionStart);

            int lineFeeds = CountLineFeedsBeforeSelection(textBox.Text, textBox.SelectionStart);

            if (textBox.SelectedText.Length > 0)
            {
                preTag.Start = textBox.Text.IndexOf("<pre>", textBox.SelectionStart + lineFeeds);
            }

            // If TextBox.SelectedText is zero, the current cursor position is textBox.SelectionStart.
            if (preTag.Start < 0)
            {
                preTag.Start = textBox.Text.LastIndexOf("<pre>", textBox.SelectionStart + lineFeeds);
            }

            if (preTag.Start >= 0)
            {
                // If the is a <pre>, look for the next </pre>.
                preTag.End = textBox.Text.IndexOf("</pre>", preTag.Start);
            }

            if (preTag.Start < 0 || preTag.End < 0)
            {
                // <pre> or </pre> not found.
                return(null);
            }

            preTag.Text = textBox.Text.Substring(preTag.Start, preTag.Length);
            return(preTag);
        }
Esempio n. 7
0
        public static PreTag GetPreTag(TextBox textBox)
        {
            PreTag preTag = new PreTag();
            preTag.ComesFromFile = false;

            Debug.WriteLine(textBox.SelectionStart);

            int lineFeeds = CountLineFeedsBeforeSelection(textBox.Text, textBox.SelectionStart);

            if (textBox.SelectedText.Length > 0)
            {
                preTag.Start = textBox.Text.IndexOf("<pre>", textBox.SelectionStart + lineFeeds);
            }

            // If TextBox.SelectedText is zero, the current cursor position is textBox.SelectionStart.
            if (preTag.Start < 0)
            {
                preTag.Start = textBox.Text.LastIndexOf("<pre>", textBox.SelectionStart + lineFeeds);
            }

            if (preTag.Start >= 0)
            {
                // If the is a <pre>, look for the next </pre>.
                preTag.End = textBox.Text.IndexOf("</pre>", preTag.Start);
            }

            if (preTag.Start < 0 || preTag.End < 0)
            {
                // <pre> or </pre> not found.
                return null;
            }

            preTag.Text = textBox.Text.Substring(preTag.Start, preTag.Length);
            return preTag;
        }