protected NoteState LoadState(string filePath) { NoteState noteState = null; // if the file exists if (System.IO.File.Exists(filePath) == true) { // read it using (StreamReader reader = new StreamReader(filePath)) { // grab the stream that reprents a list of all their notes string json = reader.ReadLine(); if (json != null) { noteState = JsonConvert.DeserializeObject <NoteState>(json) as NoteState; } } } if (noteState != null) { // restore each user note foreach (NoteState.UserNoteContent note in noteState.UserNoteContentList) { // create the note, add it to our list, and to the view UserNote userNote = new UserNote(new BaseControl.CreateParams(this, Frame.Width, Frame.Height, ref mStyle), DeviceHeight, note, UserNoteChanged); UserNoteControls.Add(userNote); userNote.AddToView(MasterView); } // we can assume that the states are 1:1 in the same order as the controls, // because the controls are sorted right after being created, so we're guaranteed // their order is known. There's no risk they were created in a different order. // collect all the reveal boxes and restore them List <IUIControl> revealBoxes = new List <IUIControl>( ); GetControlOfType <RevealBox>(revealBoxes); // for the count, take whichever is less, the number of reveal boxes OR the state list, // because it's possible the note was changed after the last save, and a reveal box // may have been added / removed. int revealBoxCount = Math.Min(revealBoxes.Count, noteState.RevealBoxStateList.Count); for (int i = 0; i < revealBoxCount; i++) { RevealBox revealBox = revealBoxes[i] as RevealBox; revealBox.SetRevealed(noteState.RevealBoxStateList[i].Revealed); } // collect all the text inputs and restore them List <IUIControl> textInputList = new List <IUIControl>( ); GetControlOfType <TextInput>(textInputList); // for the count, take whichever is less, the number of text inputs OR the state list, // because it's possible the note was changed after the last save, and a text input // may have been added / removed. int textInputCount = Math.Min(textInputList.Count, noteState.TextInputStateList.Count); for (int i = 0; i < textInputCount; i++) { TextInput textInput = textInputList[i] as TextInput; textInput.SetText(noteState.TextInputStateList[i].Text); } } return(noteState); }
public static IUIControl TryParseControl(Notes.BaseControl.CreateParams parentParams, XmlReader reader) { // either create/parse a new control, or return null. if (Paragraph.ElementTagMatches(reader.Name)) { #if __WIN__ return(new EditableParagraph(parentParams, reader)); #else return(new Paragraph(parentParams, reader)); #endif } else if (Canvas.ElementTagMatches(reader.Name)) { return(new Canvas(parentParams, reader)); } else if (StackPanel.ElementTagMatches(reader.Name)) { return(new StackPanel(parentParams, reader)); } else if (List.ElementTagMatches(reader.Name)) { return(new List(parentParams, reader)); } else if (ListItem.ElementTagMatches(reader.Name)) { return(new ListItem(parentParams, reader)); } else if (RevealBox.ElementTagMatches(reader.Name)) { #if __WIN__ return(new EditableRevealBox(parentParams, reader)); #else return(new RevealBox(parentParams, reader)); #endif } else if (Quote.ElementTagMatches(reader.Name)) { #if __WIN__ return(new EditableQuote(parentParams, reader)); #else return(new Quote(parentParams, reader)); #endif } else if (TextInput.ElementTagMatches(reader.Name)) { #if __WIN__ return(new EditableTextInput(parentParams, reader)); #else return(new TextInput(parentParams, reader)); #endif } else if (Header.ElementTagMatches(reader.Name)) { #if __WIN__ return(new EditableHeader(parentParams, reader)); #else return(new Header(parentParams, reader)); #endif } else if (NoteText.ElementTagMatches(reader.Name)) { #if __WIN__ return(new EditableNoteText(parentParams, reader)); #else return(new NoteText(parentParams, reader)); #endif } throw new Exception(String.Format("Control of type {0} does not exist.", reader.Name)); }
public void HandleChildStyleChanged(EditStyling.Style style, IEditableUIControl childControl) { switch (style) { case EditStyling.Style.RevealBox: { // first, find the target in our list int targetIndex = 0; foreach (IUIControl child in ChildControls) { // when we find it if (child.Equals(childControl) == true) { // take its index, and remove it from the renderer and our list of children targetIndex = ChildControls.IndexOf(child); child.RemoveFromView(ParentEditingCanvas); ChildControls.RemoveAt(targetIndex); break; } } // if we received RevealBox, we're either upgrading a NoteText to BE a RevealBox, // or downgrading a RevealBox to be a normal NoteText. EditableNoteText editableNoteText = childControl as EditableNoteText; if (editableNoteText != null) { // create a new revealBox, but force the text to uppper-case and add the bold font (since this is typically what the Mobile App does) Style controlStyle = childControl.GetControlStyle( ); controlStyle.mFont = new FontParams( ); controlStyle.mFont.mName = sDefaultBoldFontName; RevealBox newRevealBox = Parser.CreateRevealBox(new CreateParams(this, Frame.Width, Frame.Height, ref controlStyle), editableNoteText.GetText( ).ToUpper( ).Trim( )); newRevealBox.AddToView(ParentEditingCanvas); // add the new revealBox into the same spot as what it's replacing ChildControls.Insert(targetIndex, newRevealBox); // make sure we add a space after the reveal box, as that's required. NoteText textLabel = Parser.CreateNoteText(new CreateParams(this, Frame.Width, Frame.Height, ref mStyle), " "); textLabel.AddToView(ParentEditingCanvas); ChildControls.Insert(targetIndex + 1, textLabel); } EditableRevealBox editableRevealBox = childControl as EditableRevealBox; if (editableRevealBox != null) { // create a new revealBox that has the styling and text of the noteText it's replacing. Style controlStyle = childControl.GetControlStyle( ); NoteText newNoteText = Parser.CreateNoteText(new CreateParams(this, Frame.Width, Frame.Height, ref controlStyle), editableRevealBox.GetText( ).Trim( )); newNoteText.AddToView(ParentEditingCanvas); // add the new revealBox into the same spot as what it's replacing ChildControls.Insert(targetIndex, newNoteText); } break; } } // for now, lets just redo our layout. SetPosition(Frame.Left, Frame.Top); }