Example #1
0
        public static IEditor AddTable(IEditor editor, Point location, MemoTable table, bool useCommandExecutor)
        {
            if (table == null || table.RowCount == 0 || table.ColumnCount == 0)
            {
                return(null);
            }

            using (editor.Figure.DirtManager.BeginDirty()) {
                var req = new CreateNodeRequest();
                req.ModelFactory = new DelegatingModelFactory <MemoTable>(
                    () => {
                    return(table);
                }
                    );
                req.Bounds           = new Rectangle(location, new Size(table.ColumnCount * 50, table.RowCount * 20));
                req.AdjustSizeToGrid = false;

                var cmd = editor.GetCommand(req) as CreateNodeCommand;
                if (useCommandExecutor)
                {
                    editor.Site.CommandExecutor.Execute(cmd);
                }
                else
                {
                    cmd.Execute();
                }
                return(cmd.CreatedEditor);
            }
        }
Example #2
0
        public void CachingTest()
        {
            int        i = 0;
            Func <int> f = () => i++;
            var        t = new MemoTable();

            Assert.AreEqual(t.Memoize("x", f, 1), t.Memoize("x", f, 1), "Memoize did not return the same value for the same arguments");
            Assert.AreNotEqual(t.Memoize("x", f, 1), t.Memoize("x", f, 2), "Memoize returned the same value for the different arguments");
        }
Example #3
0
        public void CachingTest()
        {
            int i = 0;
            Func<int> f = () => i++;
            var t = new MemoTable();

            Assert.AreEqual(t.Memoize("x", f, 1), t.Memoize("x", f, 1), "Memoize did not return the same value for the same arguments");
            Assert.AreNotEqual(t.Memoize("x", f, 1), t.Memoize("x", f, 2), "Memoize returned the same value for the different arguments");
        }
Example #4
0
        private void ParseTable(HtmlNode node)
        {
            if (Logger.IsDebugEnabled)
            {
                Logger.Debug(string.Format("table: {0}, {1}", node.Name, node.InnerText));
            }

            /// 一時的に退避
            var para         = _currentParagraph;
            var stext        = _currentStyledText;
            var inBlockQuote = _indent;
            var contexts     = new Stack <ParserContext>(_contexts);

            _currentStyledText = null;
            _currentParagraph  = null;
            _indent            = false;
            _contexts          = new Stack <ParserContext>();

            var hasError = false;

            if (_currentTable == null)
            {
                _currentTable = MemoFactory.CreateTable();
                _isFirstRow   = true;

                try {
                    ParseTableContent(node);
                } catch (Exception e) {
                    Logger.Warn("Parse table error.", e);
                    MemopadApplication.Instance.Container.Remove(_currentTable);
                    _currentTable = null;

                    hasError = true;
                }
            }
            else
            {
                /// 入れ子tableはInnerTextを貼りつけておくだけ
                ParseText(GetInnerText(node), null, true);
                return;
            }

            _currentParagraph  = para;
            _currentStyledText = stext;
            _indent            = inBlockQuote;
            _contexts          = new Stack <ParserContext>(contexts);

            if (hasError)
            {
                /// 失敗したらInnerTextを貼りつけておくだけ
                ParseText(GetInnerText(node), null, true);
            }

            if (_currentTable != null && (_currentTable.RowCount == 0 || _currentTable.ColumnCount == 0))
            {
                MemopadApplication.Instance.Container.Remove(_currentTable);
                return;
            }

            if (_currentParagraph != null && !_currentParagraph.IsEmpty)
            {
                if (_currentStyledText == null)
                {
                    _currentStyledText = CreateStyledText(_currentParagraph);
                }
                else
                {
                    _currentStyledText.Add(_currentParagraph);
                }
            }
            _currentParagraph = null;

            if (_currentStyledText != null)
            {
                _result.Add(_currentStyledText);
                _currentStyledText = null;
            }

            if (_currentTable != null)
            {
                _result.Add(_currentTable);
                _currentTable = null;
            }
        }
 // ========================================
 // constructor
 // ========================================
 public InsertTableColumnCommand(MemoTable target, int columnIndex)
 {
     _target      = target;
     _columnIndex = columnIndex;
 }
Example #6
0
 public void ReadExternal(IMemento memento, ExternalizeContext context)
 {
     _restoredParent      = context.ExtendedData[EditorConsts.RestoreEditorStructureParentModel] as MemoTable;
     _restoredRowIndex    = memento.ReadInt("RowIndex");
     _restoredColumnIndex = memento.ReadInt("ColumnIndex");
 }
 // ========================================
 // constructor
 // ========================================
 public InsertTableRowCommand(MemoTable target, int rowIndex)
 {
     _target   = target;
     _rowIndex = rowIndex;
 }