Exemplo n.º 1
0
        public void ButtonNMRSpec_Click(object sender, Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs e)
        {
            var app  = Globals.ThisAddIn.Application;
            var text = app.Selection.Text;

            text = Utility.Normalize(text);
            var query = new NMRSpectrumQuery()
            {
                Format = CurrentNMRFormat
            };
            var commands = query.MakeCommand(text);

            WordApplyer.Apply(commands);
        }
Exemplo n.º 2
0
        private void _Fire(Func <string, IEnumerable <PCommand> > makeCommand, bool normalize)
        {
            var sel = Globals.ThisAddIn.Application.Selection;

            switch (sel.Type)
            {
            case wdSelectionInlineShape:
            case wdSelectionShape:
                foreach (Word.Shape shape in sel.ChildShapeRange)
                {
                    try
                    {
                        shape.TextFrame.TextRange.Select();
                        Fire(makeCommand);
                    }
                    catch (Exception)
                    {
                    }
                }
                break;

            case wdSelectionColumn:
                var cells = sel.Cells;
                if (cells.Count == 1)
                {
                    goto default;
                }
                Word.Cell firstCell = null;
                Word.Cell lastCell  = null;
                foreach (Word.Cell cell in cells)
                {
                    if (firstCell == null)
                    {
                        firstCell = cell;
                    }
                    lastCell = cell;

                    sel.SetRange(cell.Range.Start, cell.Range.End);
                    sel.Select();
                    Fire(makeCommand);
                }
                if (firstCell != null)
                {
                    sel.SetRange(firstCell.Range.Start, lastCell.Range.End);
                }
                break;

            default:
                var text = sel.Text;
                if (text == null)
                {
                    break;
                }
                // remove cell separator, which is '\a' in MS-Word
                if (text[text.Length - 1] == '\a')
                {
                    text = text.Substring(0, text.Length - 1);
                }
                if (normalize)
                {
                    text = Utility.Normalize(text);
                }
                var commands = makeCommand(text);
                WordApplyer.Apply(commands);
                break;
            }
            ProgressDialog.Current.ReportWithCancellationCheck("");
        }