Exemple #1
0
        private void SaveAs_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Rich text format (*.rtf)|*.rtf|Text document (*.txt)|*.txt|HTML document (*.html)|*.html";


            if (ExportAsRTF.IsSelected)
            {
                sfd.FilterIndex = 1;
            }
            else if (ExportAsText.IsSelected)
            {
                sfd.FilterIndex = 2;
            }
            else if (ExportAsHtml.IsSelected)
            {
                sfd.FilterIndex = 3;
            }

            if (sfd.ShowDialog() == true)
            {
                try
                {
                    string extension = System.IO.Path.GetExtension(sfd.FileName).ToLower();
                    if (extension == ".txt")
                    {
                        OpenSave.ExportAsTXT(Document, sfd.FileName);
                    }
                    else
                    if (extension == ".html" || extension == ".htm")
                    {
                        if (!IsExportAsList())
                        {
                            SaveImageFiles(System.IO.Path.GetDirectoryName(sfd.FileName));
                        }
                        OpenSave.ExportAsHtml(Document, __MainWindow, sfd.FileName, IsExportAsList());
                    }
                    else
                    if (extension == ".rtf")
                    {
                        OpenSave.ExportAsRtf(Document, __MainWindow, sfd.FileName, IsExportAsList());
                    }
                    else
                    if (extension == ".xaml")
                    {
                        OpenSave.ExportAsXAML(Document, __MainWindow, sfd.FileName, IsExportAsList());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while exporting document: " + ex.Message, "Error Exporting Document", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Exemple #2
0
        private void UpdateExportAsText()
        {
            if (__DocumentAsText == null)
            {
                __DocumentAsText = OpenSave.ExportAsTXT(Document, __MainWindow);
            }

            ExportedText.Text       = __DocumentAsText;
            ExportedText.Visibility = Visibility.Visible;
            Browser.Visibility      = Visibility.Hidden;
            ExportedRtf.Visibility  = Visibility.Hidden;
            PleaseWait.Visibility   = Visibility.Hidden;
        }
Exemple #3
0
        private void UpdateExportAsHtml()
        {
            string data = "";

            if (IsExportAsList() == false)
            {
                if (__DocumentAsHtml == null)
                {
                    __DocumentAsHtml = OpenSave.ExportAsHtml(Document, __MainWindow);
                }

                data = __DocumentAsHtml;
            }
            else if (IsExportAsList() == true)
            {
                if (__DocumentAsHtml_List == null)
                {
                    __DocumentAsHtml_List = OpenSave.ExportAsHtml_List(Document);
                }

                data = __DocumentAsHtml_List;
            }

            var files = SaveImageFiles(System.IO.Path.GetTempPath());

            __FilesToDelete.AddRange(files);

            string tmp      = System.IO.Path.GetTempFileName();
            string tempFile = tmp + ".html";

            __FilesToDelete.Add(tmp);
            __FilesToDelete.Add(tempFile);

            StreamWriter writer = new StreamWriter(tempFile);

            writer.Write(data);
            writer.Close();

            ExportedText.Text = data;

            Browser.Navigate("file:///" + tempFile);
            Browser.Visibility      = Visibility.Visible;
            ExportedText.Visibility = Visibility.Hidden;
            ExportedRtf.Visibility  = Visibility.Hidden;
            PleaseWait.Visibility   = Visibility.Hidden;
        }
Exemple #4
0
        public void UpdateExportAsRtf()
        {
            if (IsExportAsList() == false && __DocumentAsXaml == null)
            {
                __DocumentAsXaml = ExportToXaml_WordFriendly.ExportToXaml(Document, __MainWindow);
            }
            else if (IsExportAsList() && __DocumentAsXaml_List == null)
            {
                __DocumentAsXaml_List = OpenSave.ExportAsXAML_List(Document);
            }


            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);

            if (IsExportAsList())
            {
                writer.Write(__DocumentAsXaml_List);
            }
            else
            {
                writer.Write(__DocumentAsXaml);
            }

            writer.Flush();
            stream.Seek(0, SeekOrigin.Begin);

            FlowDocument document = XamlReader.Load(stream) as FlowDocument;

            if (document != null)
            {
                ExportedRtf.Document = document;
            }

            Browser.Visibility      = Visibility.Hidden;
            ExportedText.Visibility = Visibility.Hidden;
            ExportedRtf.Visibility  = Visibility.Visible;
            PleaseWait.Visibility   = Visibility.Hidden;
        }
Exemple #5
0
 private void button2_Click(object sender, EventArgs e)
 {
     OpenSave     = OpenSave.Save;
     DialogResult = DialogResult.OK;
     this.Close();
 }
Exemple #6
0
        public static string Export(OutlinerDocument Document, MainWindow wnd)
        {
            StringBuilder writer = new StringBuilder();

            writer.AppendLine("<html>");
            writer.AppendLine("<head>");
            writer.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />");
            writer.AppendLine(String.Format("<title>{0}</title>", System.IO.Path.GetFileName(Document.FileName)));
            writer.AppendLine("<style>p {{margin:0px;}}");
            writer.AppendLine("  td {padding:0px;}");
            writer.AppendLine("  th {font-size:12px; align:right; font-family: Helvetica,Arial,sans-serif;}");
            writer.AppendLine("  td#column{padding-left:4px;}");
            writer.AppendLine("  td#note{padding-left:4px;}");
            writer.AppendLine("  img#exp {padding-right:1px;}");
            writer.AppendLine("  img#checkbox {padding-right:1px;}");
            writer.AppendLine("  img#bul {padding-right:1px;}");
            writer.AppendLine("</style>");
            writer.AppendLine("</head>");
            writer.AppendLine("<body topmargin=0>\n");

            FlowDocument wholeDocument = new FlowDocument();

            wholeDocument.FontFamily = UVOutliner.Settings.DefaultFontFamily;
            wholeDocument.FontSize   = UVOutliner.Settings.DefaultFontSize;

            List <OutlinerNote> linearList = new List <OutlinerNote>();

            DocumentHelpers.GetLinearNotesList(Document.RootNode, linearList, false);

            double totalWidth = 0;

            for (int i = 0; i < Document.ColumnDefinitions.Count; i++)
            {
                totalWidth += Document.ColumnDefinitions[i].Width;
            }

            writer.AppendLine("<table width='100%'>");
            int[] columnWidths = new int[wnd.OutlinerTreeColumns.Count];

            for (int i = 0; i < wnd.OutlinerTreeColumns.Count; i++)
            {
                columnWidths[i] = (int)((Document.ColumnDefinitions[wnd.GetColumnIdByView(i)].Width / totalWidth) * 100);
            }

            // add column headers
            if (Document.ColumnDefinitions.Count > 1)
            {
                writer.AppendLine("<tr>");

                for (int i = 0; i < wnd.OutlinerTreeColumns.Count; i++)
                {
                    int columnId = wnd.GetColumnIdByView(i);
                    writer.Append(String.Format("<th width='{0}%'>", columnWidths[i]));
                    writer.Append(Document.ColumnDefinitions[columnId].ColumnName);
                    writer.AppendLine("</th>");
                }
                writer.AppendLine("</tr>");
            }

            // add all other columns
            for (int i = 0; i < linearList.Count; i++)
            {
                OutlinerNote note       = linearList[i];
                double       indent     = (Math.Max(0, note.Level - 1)) * 20;
                string       indent_str = ""; for (int t = 0; t < indent / 10; t++)
                {
                    indent_str += " ";
                }

                if (note.IsEmpty)
                {
                    writer.AppendLine(indent_str + "<tr><td>&nbsp;</td></tr>");
                    continue;
                }

                writer.AppendLine(indent_str + "<tr>");
                for (int c = 0; c < wnd.OutlinerTreeColumns.Count; c++)
                {
                    int columnId = wnd.GetColumnIdByView(c);

                    FlowDocument flowDocument = linearList[i].Columns[columnId].ColumnData as FlowDocument;
                    if (flowDocument == null)
                    {
                        writer.AppendLine(indent_str + "<td></td>");
                        continue;
                    }

                    if (columnId != 0)
                    {
                        string style;
                        var    html = OpenSave.HtmlFromReport(flowDocument, out style);
                        writer.AppendLine(String.Format(indent_str + "<td id=column style='{0}'>{1}</td>", style, html));
                    }
                    else
                    {
                        writer.AppendLine(indent_str + "<td>");
                        writer.AppendLine(indent_str + "  <table width='100%'>");
                        writer.AppendLine(indent_str + "  <tr><td>");
                        writer.Append(String.Format(indent_str + "      <nobr><div style='margin-left: {0}px;'>", indent));

                        if (note.SubNotes.Count == 0)
                        {
                            writer.Append("<img src='uvbul.png' id=bul width=14 height=14 alt='&bull;'>");
                        }
                        else
                        {
                            if (note.IsExpanded)
                            {
                                writer.Append("<img src='uvndexpa.png' id=exp width=14 height=14>");
                            }
                            else
                            {
                                writer.Append("<img src='uvndcol.png' id=exp width=14 height=14>");
                            }
                        }

                        if (Document.CheckboxesVisble)
                        {
                            if (note.IsChecked == true)
                            {
                                writer.Append("<img src='uvchboxch.png' id=checkbox width=14 height=14>");
                            }
                            else
                            {
                                writer.Append("<img src='uvchboxunch.png' id=checkbox width=14 height=14>");
                            }
                        }
                        writer.AppendLine("</div></nobr>");
                        string style;
                        var    html = OpenSave.HtmlFromReport(flowDocument, out style);

                        writer.AppendLine(indent_str + String.Format("  </td><td width='100%' id=column style='{0}'>", style));
                        writer.AppendLine(indent_str + String.Format("    {0}", html));

                        writer.AppendLine(indent_str + "  </td></tr>");
                        if (note.HasInlineNote)
                        {
                            html = OpenSave.HtmlFromReport(note.InlineNoteDocument, out style);

                            writer.AppendLine(indent_str + "  <tr><td></td>");
                            writer.AppendLine(indent_str + string.Format("      <td id=note style='{0}'>", style));
                            writer.AppendLine(indent_str + String.Format("        {0}", html));
                            writer.AppendLine(indent_str + "      </td></tr>");
                        }

                        writer.AppendLine(indent_str + "  </table>");
                        writer.AppendLine(indent_str + "</td>");
                    }
                }
                writer.AppendLine(indent_str + "</tr>");
            }
            writer.AppendLine("</table></body></html>");

            return(writer.ToString());
        }