private void EditMode_End(bool saveChanges) { // end edit mode without storing the changes if (EditMode_Enabled == true) { EditMode_Enabled = false; // unhide the normal controls QuoteLabel.Hidden = false; Citation.Hidden = false; BorderView.Hidden = false; UrlGlyph.Hidden = false; // exit enable mode. We know the parent is a canvas because of the design (EditMode_TextBox_Quote.Parent as System.Windows.Controls.Canvas).Children.Remove(EditMode_TextBox_Quote); (EditMode_TextBox_Citation.Parent as System.Windows.Controls.Canvas).Children.Remove(EditMode_TextBox_Citation); (EditMode_TextBox_Url.Parent as System.Windows.Controls.Canvas).Children.Remove(EditMode_TextBox_Url); // save changes only if they wanted to AND there's valid text to save // editing can end as long as ONE of the two has text if (saveChanges) { if (string.IsNullOrWhiteSpace(EditMode_TextBox_Quote.Text) == false || string.IsNullOrWhiteSpace(EditMode_TextBox_Citation.Text) == false) { // if they press return, commit the changed text. QuoteLabel.Text = EditMode_TextBox_Quote.Text; Citation.Text = EditMode_TextBox_Citation.Text; // try to set the URL string activeUrl = EditMode_TextBox_Url.Text; if (activeUrl.Trim( ) != EditableConfig.sPlaceholderUrlText && string.IsNullOrWhiteSpace(activeUrl) == false) { // help them out by adding 'https://' if it isn't there. if (activeUrl.StartsWith("https") == false && BibleRenderer.IsBiblePrefix(activeUrl) == false) { activeUrl = activeUrl.Insert(0, "https://"); } ActiveUrl = activeUrl; } else { ActiveUrl = null; } // update the position, which also effects layout SetPosition(Frame.Left, Frame.Top); } } } }
// Takes a string and replaces the content of the paragraph with it. private void SetText(string text, string activeUrl) { foreach (IUIControl control in ChildControls) { control.RemoveFromView(ParentEditingCanvas); } ChildControls.Clear( ); // give the text a style that doesn't include things it shouldn't inherit Styles.Style textStyle = mStyle; textStyle.mBorderColor = null; textStyle.mBorderRadius = null; textStyle.mBorderWidth = null; // now break it into words so we can do word wrapping string[] words = text.Split(' '); foreach (string word in words) { // create labels out of each one if (string.IsNullOrEmpty(word) == false) { // if the last thing we added was a special control like a reveal box, we // need the first label after that to have a leading space so it doesn't bunch up against // the control string nextWord = word; NoteText wordLabel = Parser.CreateNoteText(new CreateParams(this, Frame.Width, Frame.Height, ref textStyle), nextWord + " "); ChildControls.Add(wordLabel); } } if (activeUrl.Trim( ) != EditableConfig.sPlaceholderUrlText && string.IsNullOrWhiteSpace(activeUrl) == false) { // help them out by adding 'https://' if it isn't there. if (activeUrl.StartsWith("https") == false && BibleRenderer.IsBiblePrefix(activeUrl) == false) { activeUrl = activeUrl.Insert(0, "https://"); } ActiveUrl = activeUrl; } else { ActiveUrl = null; } TryAddUrlGlyph(Frame.Width, Frame.Height); }