Пример #1
0
        private void Table_Click()
        {
            int idx = textContentEmail.SelectionStart;

            if (TableOrDoubleClick(idx))
            {
                return;                //so it was already handled with an edit table dialog
            }
            //User did not click inside a table, so they must want to add a new table.
            FormMarkupTableEdit FormMTE = new FormMarkupTableEdit();

            FormMTE.Markup = @"{|
!Width=""100""|Heading1!!Width=""100""|Heading2!!Width=""100""|Heading3
|-
|||||
|-
|||||
|}";
            FormMTE.IsNew  = true;
            FormMTE.ShowDialog();
            if (FormMTE.DialogResult != DialogResult.OK)
            {
                return;
            }
            textContentEmail.SelectionLength = 0;
            textContentEmail.SelectedText    = FormMTE.Markup;
            textContentEmail.SelectionLength = 0;
            textContentEmail.Focus();
        }
Пример #2
0
        ///<summary>This is called both when a user double clicks anywhere in the edit box, or when the click the Table button in the toolbar.  This ONLY handles popping up an edit window for an existing table.  If the cursor was not in an existing table, then this returns false.  After that, the behavior in the two areas differs.  Returns true if it popped up.</summary>
        private bool TableOrDoubleClick(int charIdx)
        {
            //there is some code clutter in this method from when we used TableViews.  It seems harmless, but can be removed whenever.
            MatchCollection matches = Regex.Matches(textContent.Text, @"\{\|\n.+?\n\|\}", RegexOptions.Singleline);
            //Tables-------------------------------------------------------------------------------
            Match matchCur = matches.OfType <Match>().ToList().FirstOrDefault(x => x.Index <= charIdx && x.Index + x.Length >= charIdx);

            //handle the clicks----------------------------------------------------------------------------
            if (matchCur == null)
            {
                return(false);               //did not click inside a table
            }
            bool isLastCharacter = matchCur.Index + matchCur.Length == textContent.Text.Length;

            textContent.SelectionLength = 0;          //otherwise we get an annoying highlight
            //==Travis 11/20/15:  If we want to fix wiki tables in the future so duplicate tables dont both get changed from a double click, we'll need to
            //   use a regular expression to find which match of strTableLoad the user clicked on, and only replace that match below.
            FormMarkupTableEdit formT = new FormMarkupTableEdit();

            formT.Markup            = matchCur.Value;
            formT.CountTablesInPage = matches.Count;
            formT.IsNew             = false;
            formT.ShowDialog();
            if (formT.DialogResult != DialogResult.OK)
            {
                return(true);
            }
            if (formT.Markup == null)           //indicates delete
            {
                textContent.Text            = textContent.Text.Remove(matchCur.Index, matchCur.Length);
                textContent.SelectionLength = 0;
                return(true);
            }
            textContent.Text = textContent.Text.Substring(0, matchCur.Index)                                            //beginning of markup
                               + formT.Markup                                                                           //replace the table
                               + (isLastCharacter ? "" : textContent.Text.Substring(matchCur.Index + matchCur.Length)); //continue to end, if any text after table markup.
            textContent.SelectionLength = 0;
            return(true);
        }