private void reloadPreview(object sender) { try { LMD_Document lmdDoc = new LMD_Document(MathBox.getDocument(mbox.Document)); pwindow.loadHTMLToPreview(lmdDoc.toHTML(LMD_Document.RenderingMode.LOCAL)); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static String uploadProcedure(FlowDocument toBeUploaded) { try { String ptext = MathBox.getDocumentUni(toBeUploaded); String htmlBody = new LMD_Document(ptext).getHTMLBody(); return(NetworkManager.uploadData(ptext, htmlBody)); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return(""); } }
/// <returns>Whether the current action should continue</returns> public static String saveAsProcedure(FlowDocument document) { try { SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "Document"; sfd.DefaultExt = ".txt"; sfd.Filter = "TXT (editable)|*.txt|HTML (read-only)|*.html"; Nullable <bool> result = sfd.ShowDialog(); if (result != true) { return(""); } DataStream ds = null; int br = sfd.FilterIndex; String documentString = MathBox.getDocumentUni(document); if (br == 1) { ds = new DataStream(documentString, DataStream.Type.TXT); lastRegistered = cloneFlowDocument(document); fullPath = sfd.FileName; name = sfd.SafeFileName; } else { documentString = new LMD_Document(documentString).toHTML(LMD_Document.RenderingMode.WEB); ds = new DataStream(documentString, DataStream.Type.HTML); } FileManager.WriteDataToFile(ds, sfd.FileName); return(name); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return(""); } }
private void PreviewKeyDownHandler(object sender, KeyEventArgs e) { AutocompleteManager.handleKeyDown(e); if (e.Handled || Keyboard.IsKeyDown(Key.RightAlt)) { return; } Char c = KeyDecoder.GetCharFromKey(e.Key); if (e.Key == Key.Enter) { if (!Selection.IsEmpty) { Selection.Text = ""; } TextPointer inserted = Selection.Start.InsertLineBreak(); Selection.Select(inserted, inserted); e.Handled = true; } else if ((c == '?' || c == '#') && Selection.IsEmpty) { Selection.Text = c.ToString(); LMD_Document lmdDoc = new LMD_Document(getDocument(Document)); String result = lmdDoc.getCommandResult(); Selection.Text = (result == "") ? c.ToString() : result; Selection.Select(Selection.End, Selection.End); e.Handled = true; } else if (e.Key == Key.Space) { BeginChange(); CaretPosition = CaretPosition.GetPositionAtOffset(0, LogicalDirection.Backward); CaretPosition.InsertTextInRun(c.ToString()); CaretPosition = CaretPosition.GetNextInsertionPosition(LogicalDirection.Forward); e.Handled = true; EndChange(); } }
private void InitiatePreview() { if (PreviewIsOpen) { reloadPreview(null); return; } try { pwindow = new PreviewWindow(); pwindow.ReloadRequested += new ReloadRequestedHandler(reloadPreview); pwindow.Closed += new EventHandler(optimizator); LMD_Document lmdDoc = new LMD_Document(MathBox.getDocument(mbox.Document)); pwindow.loadHTMLToPreview(lmdDoc.toHTML(LMD_Document.RenderingMode.LOCAL)); pwindow.Show(); PreviewIsOpen = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); } }