Exemplo n.º 1
0
        public DialogText(string document)
        {
            this.HyperlinkCommand = new LambdaUICommand(Properties.Resources.CommandHyperlink,
                                                        o => {
                try {
                    DialogHyperlink dialog = new DialogHyperlink(this.editor)
                    {
                        Owner = this
                    };
                    dialog.ShowDialog();
                } catch (Exception exception) {
                    App.Mainframe.ReportException(exception);
                }
            }
                                                        );
            this.InsertImageCommand = new LambdaUICommand(Properties.Resources.CommandInsertImage, o => this.InsertImage());

            this.Document    = document;
            this.DataContext = this;
            this.InitializeComponent();
            if (!string.IsNullOrEmpty(this.Document))
            {
                FlowDocument flowDoc = TextNote.Load(this.Document);
                if (flowDoc != null)
                {
                    this.editor.Document = flowDoc;
                }
            }
        }
Exemplo n.º 2
0
        public DialogHyperlink(RichTextBox textBox)
        {
            this.textBox = textBox;
            Hyperlink link = DialogHyperlink.SelectedHyperlink(this.textBox);

            if (link != null)
            {
                TextRange range = new TextRange(link.ContentStart, link.ContentEnd);
                this.HyperlinkText = range.Text;
                this.HyperlinkUrl  = link.NavigateUri.ToString();
                textBox.Selection.Select(link.ElementStart, link.ElementEnd);
            }
            else
            {
                this.HyperlinkText = this.textBox.Selection.Text;
                string text = this.HyperlinkText.Trim();
                if (DialogHyperlink.IsUrl(text))
                {
                    this.HyperlinkUrl = text;
                }
                else
                {
                    this.HyperlinkUrl = string.Empty;
                }
            }
            this.DataContext = this;
            this.InitializeComponent();
        }
Exemplo n.º 3
0
        private void ValidateHyperlink()
        {
            bool validText = 0 < this.HyperlinkText.Trim().Length;

            this.errorInfo.Clear();
            if (!validText)
            {
                this.errorInfo["HyperlinkText"] = Properties.Resources.ErrorHyperlinkText;
            }
            bool validUrl = DialogHyperlink.IsValidUrl(this.HyperlinkUrl);

            if (!validUrl)
            {
                this.errorInfo["HyperlinkUrl"] = Properties.Resources.ErrorHyperlinkUrl;
            }
            this.IsValidHyperlink = validText && validUrl;
            if (0 < this.errorInfo.Count)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (string error in this.errorInfo.Values)
                {
                    stringBuilder.AppendLine(error);
                }
                this.Error = stringBuilder.ToString();
            }
            else
            {
                this.Error = string.Empty;
            }
        }
Exemplo n.º 4
0
 private static Hyperlink SelectedHyperlink(RichTextBox textBox)
 {
     if (textBox.Selection.IsEmpty)
     {
         return(DialogHyperlink.SelectedHyperlink(textBox.Selection.Start));
     }
     else
     {
         Hyperlink h1 = DialogHyperlink.SelectedHyperlink(textBox.Selection.Start);
         Hyperlink h2 = DialogHyperlink.SelectedHyperlink(textBox.Selection.End);
         if (h1 == h2 && h1 != null)
         {
             return(h1);
         }
         if (h1 != null)
         {
             return(h1);
         }
         if (h2 != null)
         {
             return(h2);
         }
         h1 = DialogHyperlink.FindHyperlink(textBox.Selection.Start, LogicalDirection.Forward);
         h2 = DialogHyperlink.FindHyperlink(textBox.Selection.End, LogicalDirection.Backward);
         if (h1 == h2)
         {
             return(h1);
         }
     }
     return(null);
 }
Exemplo n.º 5
0
        private static Hyperlink FindHyperlink(TextPointer textPointer, LogicalDirection logicalDirection)
        {
            TextPointer tp = textPointer.GetNextInsertionPosition(logicalDirection);

            if (tp != null)
            {
                return(DialogHyperlink.SelectedHyperlink(tp));
            }
            return(null);
        }
Exemplo n.º 6
0
 private void ButtonOkClick(object sender, RoutedEventArgs e)
 {
     try {
         if (0 < this.HyperlinkText.Length && DialogHyperlink.IsValidUrl(this.HyperlinkUrl))
         {
             this.textBox.Selection.Text = this.HyperlinkText;
             Hyperlink  h       = new Hyperlink(this.textBox.Selection.Start, this.textBox.Selection.End);
             UriBuilder builder = new UriBuilder(this.HyperlinkUrl);
             h.NavigateUri = new Uri(builder.Uri.AbsoluteUri);
             this.Close();
         }
     } catch (Exception exception) {
         App.Mainframe.ReportException(exception);
     }
 }