//creates new ObservableCollection with new return block and set returnBox item source to new OC list public void CreateMethodReturnBlock() { Block newReturnBlock = MainPage.createReservedBlock("RETURN"); ComboBoxItem ci = (ComboBoxItem)returnType.SelectedItem; TextBlock tb = (TextBlock)ci.Content; //get the TextBlock aka return type //newReturnBlock.metadataList[1] = tb.Text; newReturnBlock.returnType = tb.Text; newReturnBlock = newReturnBlock.cloneSelf(false); newReturnBlock.LayoutRoot.Width = returnBox.Width - 20; newReturnBlock.LayoutRoot.Height = returnBox.Height - 15; ObservableCollection <Block> returnList = new ObservableCollection <Block>(); if (!tb.Text.Equals("VOID")) { returnList.Add(newReturnBlock); } returnBox.ItemsSource = returnList; //UpdateMethodBlocks(); foreach (EditorDragDropTarget EDDT in MainPage.editorLists) { //replace based on block name ((ListBox)EDDT.Content).ItemsSource = EDDT.switchBlocks(newReturnBlock.cloneSelf(true), false); } }
//finds each method and updates that method in the editor windows of all tabs private void UpdateMethodBlocks(Block methodBlock) { foreach (EditorDragDropTarget EDDT in MainPage.editorLists) { //replace based on block user generated name //((ListBox)EDDT.Content).ItemsSource = EDDT.switchBlocks(methodBlock.cloneSelf(true), true); EDDT.switchBlocks(EDDT.Content as ListBox, methodBlock.cloneSelf(true), true); ObservableCollection <Block> collection = ((ListBox)EDDT.Content).ItemsSource as ObservableCollection <Block>; Parsing.SocketReader.ReplaceMethodBlocks(collection, methodBlock.cloneSelf(true)); } }
public static void SaveToXML() { IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); if (!iso.FileExists("save.xml")) { using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("save.xml", FileMode.CreateNew, iso)) { // Write to the Isolated Storage for the user. XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; // Create an XmlWriter. using (XmlWriter writer = XmlWriter.Create(isoStream, settings)) { writer.WriteStartElement("SaveFile"); #region Variables writer.WriteComment("Variables?"); // Write the Variable root writer.WriteStartElement("GROUP"); writer.WriteAttributeString("name", "VARIABLES"); // Write all Variables foreach (Block b in MainPage.variableList) { writer.WriteStartElement("VARIABLE"); writer.WriteStartElement("name"); writer.WriteString(b.metadataList[1]); //name of variable writer.WriteEndElement(); writer.WriteStartElement("return"); writer.WriteString(b.metadataList[0]); //return type writer.WriteEndElement(); writer.WriteEndElement(); } // Write the close tag for Variables writer.WriteEndElement(); #endregion #region Methods writer.WriteComment("Methods?"); // Write the Method root writer.WriteStartElement("GROUP"); writer.WriteAttributeString("name", "METHODS"); // Write all Methods foreach (Block b in MainPage.methodList) { writer.WriteStartElement("METHOD"); writer.WriteStartElement("name"); writer.WriteString(b.metadataList[1]); //name of method writer.WriteEndElement(); writer.WriteStartElement("return"); writer.WriteString(b.returnType); //return type writer.WriteEndElement(); writer.WriteStartElement("PARAMETERS"); TabPage methodCode = (TabPage)MainPage.tabList[MainPage.methodList.IndexOf(b)].Content; for (int i = 0; i < methodCode.parameterBox.Items.Count; i++) { writer.WriteStartElement("PARAMETER"); Block param = methodCode.getParamAtIndex(i); writer.WriteStartElement("name"); writer.WriteString(param.metadataList[1]); //name of parameter writer.WriteEndElement(); writer.WriteStartElement("return"); writer.WriteString(param.metadataList[0]); //return type writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); } // Write the close tag for Methods writer.WriteEndElement(); #endregion #region Editors writer.WriteComment("Editors?"); // Write the EDITOR root writer.WriteStartElement("GROUP"); writer.WriteAttributeString("name", "EDITORS"); // Write all EDDT's foreach (EditorDragDropTarget EDDT in MainPage.editorLists) { ReadOnlyObservableCollection <Block> collection = EDDT.getTreeList(); //get tree list writer.WriteStartElement("EDITOR"); writer.WriteAttributeString("name", EDDT.Name); foreach (Block b in collection) { writer.WriteStartElement("BLOCK"); writer.WriteAttributeString("type", b.Text); //type of block writer.WriteStartElement("LINE"); writer.WriteString(collection.IndexOf(b).ToString()); //line number of block writer.WriteEndElement(); if (b.Text.Equals("METHOD")) { writer.WriteStartElement("name"); writer.WriteString(b.metadataList[1]); //name of method writer.WriteEndElement(); } if (b.flag_hasSocks) //if there are sockets we need to dive in { WriteSockets(writer, b); } writer.WriteEndElement(); } writer.WriteEndElement(); } // Write the close tag for Variables writer.WriteEndElement(); #endregion writer.WriteEndElement(); // Write the XML to the file. writer.Flush(); } } } }