// Loads the selected assignment up in the workspace void LoadWorkspace(string completed) { List <MetaType> metaTypeList = ImEx.Import.DeserializeString <List <MetaType> >(completed); this.textviews.castextviews.Clear(); foreach (var metaItem in metaTypeList) { if (metaItem.type == typeof(MovableCasCalcView)) { textviews.InsertCalcView(metaItem.metastring, metaItem.locked); } else if (metaItem.type == typeof(MovableCasCalcMulitlineView)) { textviews.InsertCalcMultilineView(metaItem.metastring, metaItem.locked); } else if (metaItem.type == typeof(MovableCasResult)) { CasResult.FacitContainer facitcontainer = Import.DeserializeString <CasResult.FacitContainer>(metaItem.metastring); textviews.InsertResult(facitcontainer.answer, facitcontainer.facit); } else if (metaItem.type == typeof(MovableCasTextView)) { textviews.InsertTextView(metaItem.metastring, metaItem.locked, -1); } } this.textviews.castextviews.Reverse(); this.textviews.Clear(); this.textviews.Redraw(); this.textviews.Reevaluate(); this.textviews.ShowAll(); Destroy(); }
// When clicked, inserts a new textview at the buttom of the screen. void OnActivated() { textviews.InsertTextView("", false, -1); }
// Opens the file when clicked public void OpenFile() { OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; string file = String.Empty; bool hasOpenedAnything = false; switch (pid) { case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: case PlatformID.Win32NT: // <- if one, this is the one we really need { var filechooser = new System.Windows.Forms.OpenFileDialog(); filechooser.InitialDirectory = "c:\\"; filechooser.Filter = "cas files (*.cas)|*.cas"; filechooser.FilterIndex = 2; filechooser.RestoreDirectory = true; if (filechooser.ShowDialog() == System.Windows.Forms.DialogResult.OK) { file = System.IO.File.ReadAllText(filechooser.FileName); hasOpenedAnything = true; } break; } case PlatformID.Unix: case PlatformID.MacOSX: { Object[] parameters = { "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept }; FileChooserDialog filechooser = new FileChooserDialog("Open file...", null, FileChooserAction.Open, parameters); filechooser.Filter = new FileFilter(); filechooser.Filter.AddPattern("*.cas"); if (filechooser.Run() == (int)ResponseType.Accept) { file = System.IO.File.ReadAllText(filechooser.Filename); hasOpenedAnything = true; } filechooser.Destroy(); break; } default: break; } // If anything has been opened, deserializes the content, and rebuilds the workspace with the opened widgets if (hasOpenedAnything == true) { List <MetaType> metaTypeList = new List <MetaType>(); metaTypeList = ImEx.Import.DeserializeString <List <MetaType> >(file); textviews.castextviews.Clear(); foreach (var item in metaTypeList) { if (item.type == typeof(MovableCasTextView) && user.privilege == 1) { textviews.InsertTextView(item.metastring, item.locked, -1); } else if (item.type == typeof(MovableCasCalcView)) { textviews.InsertCalcView(item.metastring, item.locked); } else if (item.type == typeof(MovableCasResult)) { CasResult.FacitContainer container = new CasResult.FacitContainer(); container = Import.DeserializeString <CasResult.FacitContainer>(item.metastring); textviews.InsertResult(container.answer, container.facit); } else if (item.type == typeof(MovableCasCalcMulitlineView)) { textviews.InsertCalcMultilineView(item.metastring, item.locked); } else if (item.type == typeof(MovableCasTextView)) { textviews.InsertTextView(item.metastring, item.locked, -1); } } textviews.castextviews.Reverse(); textviews.Clear(); textviews.Redraw(); textviews.Reevaluate(); textviews.ShowAll(); } }