Esempio n. 1
0
        /// <summary>
        /// Re-Formats a Markdown table to nicely formatted output (size permitting)
        /// </summary>
        /// <param name="tableMarkdown"></param>
        /// <returns>formatted markdown, if it can't be formatted original is returned</returns>
        public string FormatMarkdownTable(string tableMarkdown)
        {
            var parser = new TableParser();
            var type   = parser.DetectTableType(tableMarkdown);

            if (type == MarkdownTableType.None)
            {
                return(null);
            }

            var tableData = ParseMarkdownToData(tableMarkdown);

            if (tableData == null)
            {
                return(tableMarkdown);
            }

            string output = null;

            switch (type)
            {
            case MarkdownTableType.Pipe:
                output = parser.ToPipeTableMarkdown(tableData);
                break;

            case MarkdownTableType.Grid:
                output = parser.ToGridTableMarkdown(tableData);
                break;

            case MarkdownTableType.Html:
                output = parser.ToTableHtml(tableData);
                break;
            }

            return(output);
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var name = (sender as Control).Name;

            if (sender == ButtonOk)
            {
                var parser = new TableParser();

                if (TableMode == "Grid Table")
                {
                    TableHtml = parser.ToGridTableMarkdown(TableData);
                }
                else if (TableMode == "HTML Table")
                {
                    TableHtml = parser.ToTableHtml(TableData);
                }
                else
                {
                    TableHtml = parser.ToPipeTableMarkdown(TableData);
                }

                Cancelled    = false;
                DialogResult = true;
                Close();
            }
            else if (sender == ButtonCancel)
            {
                Cancelled = true;
                Close();
            }
            else if (sender == ButtonPasteHtml)
            {
                CreateTableFromClipboardHtml();
            }
            else if (sender == ButtonImportCsv)
            {
                var form = new TableEditorCsvImport();
                form.Owner = this;
                form.ShowDialog();

                if (form.IsCancelled)
                {
                    return;
                }

                var parser = new TableParser();

                bool   deleteCsvFile = false;
                string csvFile       = form.CsvFilename;

                if (form.ImportFromClipboard)
                {
                    string csvText = ClipboardHelper.GetText();
                    csvFile = Path.GetTempFileName();
                    csvFile = Path.ChangeExtension(csvFile, "csv");
                    File.WriteAllText(csvFile, csvText);
                    deleteCsvFile = true;
                }


                var data = parser.ParseCsvFileToData(csvFile, form.CsvSeparator);
                if (data == null || data.Count < 1)
                {
                    AppModel.Window.ShowStatusError($"Couldn\'t open file {csvFile} or the file is empty.");
                    return;
                }

                TableData = data;
                DataGridTableEditor.TableSource = TableData;

                if (deleteCsvFile)
                {
                    File.Delete(csvFile);
                }
            }

            var focusedTextBox = FocusManager.GetFocusedElement(this) as TextBox;

            if (focusedTextBox == null)
            {
                return;
            }

            if ("MenuInsertColumnRight" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddColumn(pos.Row, pos.Column, ColumnInsertLocation.Right);
            }
            else if ("MenuInsertColumnLeft" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddColumn(pos.Row, pos.Column, ColumnInsertLocation.Left);
            }
            else if ("MenuDeleteColumn" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.DeleteColumn(pos.Row, pos.Column);
            }
            else if ("MenuInsertRowBelow" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddRow(pos.Row, pos.Column, RowInsertLocation.Below);
            }
            else if ("MenuInsertRowAbove" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddRow(pos.Row, pos.Column, RowInsertLocation.Above);
            }
            else if ("MenuDeleteRow" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.DeleteRow(pos.Row, pos.Column);
            }
        }
Esempio n. 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var name = (sender as Control).Name;

            if (sender == ButtonOk)
            {
                var parser = new TableParser();

                if (TableMode == "Grid Table")
                {
                    TableHtml = parser.ToGridTableMarkdown(TableData);
                }
                else if (TableMode == "HTML Table")
                {
                    TableHtml = parser.ToTableHtml(TableData);
                }
                else
                {
                    TableHtml = parser.ToPipeTableMarkdown(TableData);
                }

                Cancelled    = false;
                DialogResult = true;
                Close();
            }
            else if (sender == ButtonCancel)
            {
                Cancelled = true;
                Close();
            }
            else if (sender == ButtonPasteHtml)
            {
                CreateTableFromClipboardHtml();
            }
            else if (sender == ButtonImportCsv)
            {
                var fd = new OpenFileDialog
                {
                    DefaultExt = ".csv",
                    Filter     = "Csv files (*.csv)|*.csv|" +
                                 "All files (*.*)|*.*",
                    CheckFileExists  = true,
                    RestoreDirectory = true,
                    Multiselect      = false,
                    Title            = "Open CsvFile"
                };
                if (!string.IsNullOrEmpty(mmApp.Configuration.LastFolder))
                {
                    fd.InitialDirectory = mmApp.Configuration.LastFolder;
                }

                var res = fd.ShowDialog();
                if (res == null || !res.Value)
                {
                    return;
                }

                var parser = new TableParser();
                var data   = parser.ParseCsvFileToData(fd.FileName);
                if (data == null || data.Count < 1)
                {
                    AppModel.Window.ShowStatusError($"Couldn\'t open file {fd.FileName} or the file is empty.");
                    return;
                }

                TableData = data;
                DataGridTableEditor.TableSource = TableData;
            }

            var focusedTextBox = FocusManager.GetFocusedElement(this) as TextBox;

            if (focusedTextBox == null)
            {
                return;
            }

            if ("MenuInsertColumnRight" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddColumn(pos.Row, pos.Column, ColumnInsertLocation.Right);
            }
            else if ("MenuInsertColumnLeft" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddColumn(pos.Row, pos.Column, ColumnInsertLocation.Left);
            }
            else if ("MenuDeleteColumn" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.DeleteColumn(pos.Row, pos.Column);
            }
            else if ("MenuInsertRowBelow" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddRow(pos.Row, pos.Column, RowInsertLocation.Below);
            }
            else if ("MenuInsertRowAbove" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddRow(pos.Row, pos.Column, RowInsertLocation.Above);
            }
            else if ("MenuDeleteRow" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.DeleteRow(pos.Row, pos.Column);
            }
        }
Esempio n. 4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var name = (sender as Control).Name;

            if (sender == ButtonOk)
            {
                var parser = new TableParser();

                if (TableMode == "Grid Table")
                {
                    TableHtml = parser.ToGridTableMarkdown(TableData);
                }
                else if (TableMode == "HTML Table")
                {
                    TableHtml = parser.ToTableHtml(TableData);
                }
                else
                {
                    TableHtml = parser.ToPipeTableMarkdown(TableData);
                }

                Cancelled    = false;
                DialogResult = true;
                Close();
            }
            else if (sender == ButtonCancel)
            {
                Cancelled = true;
                Close();
            }
            else if (sender == ButtonPasteHtml)
            {
                CreateTableFromClipboardHtml();
            }



            var focusedTextBox = FocusManager.GetFocusedElement(this) as TextBox;

            if (focusedTextBox == null)
            {
                return;
            }

            if (sender == ButtonInsertColumnRight || "MenuInsertColumnRight" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddColumn(pos.Row, pos.Column, ColumnInsertLocation.Right);
            }
            else if (sender == ButtonInsertColumnLeft || "MenuInsertColumnLeft" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddColumn(pos.Row, pos.Column, ColumnInsertLocation.Left);
            }
            else if (sender == ButtonDeleteColumn || "MenuDeleteColumn" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.DeleteColumn(pos.Row, pos.Column);
            }
            else if (sender == ButtonInsertRowBelow || "MenuInsertRowBelow" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddRow(pos.Row, pos.Column, RowInsertLocation.Below);
            }
            else if (sender == ButtonInsertRowAbove || "MenuInsertRowAbove" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.AddRow(pos.Row, pos.Column, RowInsertLocation.Above);
            }
            else if (sender == ButtonDeleteRow || "MenuDeleteRow" == name)
            {
                var pos = focusedTextBox.Tag as TablePosition;
                DataGridTableEditor.DeleteRow(pos.Row, pos.Column);
            }
        }