Esempio n. 1
0
        /// <summary>
        /// Handles context-click to create a row below the current row.
        /// </summary>
        /// <param name="sender"><c><see cref="rowit_CreateBelow"/></c></param>
        /// <param name="e"></param>
        void rowclick_CreateBelow(object sender, EventArgs e)
        {
            var fields = new string[Table.ColCount];

            for (int c = 0; c != Table.ColCount; ++c)
            {
                fields[c] = gs.Stars;
            }

            Table.Insert(_r + 1, fields);


            Restorable rest = UndoRedo.createRow(Table.Rows[_r + 1], UndoRedo.UrType.rt_Delete);

            if (!Table.Changed)
            {
                Table.Changed = true;
                rest.isSaved  = UndoRedo.IsSavedType.is_Undo;
            }
            Table._ur.Push(rest);

            if (Settings._autorder && order() != 0)
            {
                layout();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes a single or multiple <c><see cref="Row">Rows</see></c>.
        /// </summary>
        /// <remarks>Called by
        /// <c><see cref="Yata"/>.editrowsclick_DeleteRange()</c>.</remarks>
        internal void DeleteRows()
        {
            _f.Obfuscate();
            DrawRegulator.SuspendDrawing(this);


            int selr = getSelectedRow();

            int        range = Math.Abs(RangeSelect);
            Restorable rest  = UndoRedo.createArray(range + 1, UndoRedo.UrType.rt_ArrayInsert);

            int rFirst, rLast;

            if (RangeSelect > 0)
            {
                rFirst = selr;
                rLast  = selr + RangeSelect;
            }
            else
            {
                rFirst = selr + RangeSelect;
                rLast  = selr;
            }

            while (rLast >= rFirst)             // reverse delete.
            {
                rest.array[range--] = Rows[rLast].Clone() as Row;
                Delete(rLast, false);

                --rLast;
            }

            if (RowCount == 1 && rLast == -1)             // ie. if grid was blanked -> ID #0 was auto-inserted.
            {
                rLast = 0;
            }
            else
            {
                rLast = -1;               // calibrate all extant rows.
            }
            Calibrate(rLast);             // delete key

            if (selr < RowCount)
            {
                EnsureDisplayedRow(selr);
            }


            if (!Changed)
            {
                Changed      = true;
                rest.isSaved = UndoRedo.IsSavedType.is_Undo;
            }
            _ur.Push(rest);


            DrawRegulator.ResumeDrawing(this);
            _f.Obfuscate(false);
        }
Esempio n. 3
0
        /// <summary>
        /// User's current state is pushed onto <c><see cref="Undoables"/></c>
        /// on any regular state-change. The stack of
        /// <c><see cref="Redoables"/></c> is cleared.
        /// </summary>
        /// <param name="it">a <c><see cref="Restorable"/></c> object to push
        /// onto the top of the <c>Undoables</c> stack</param>
        internal void Push(Restorable it)
        {
            Undoables.Push(it);
            Redoables.Clear();

            _grid._f.EnableUndo(true);
            _grid._f.EnableRedo(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Handles context-click to paste into the current row.
        /// </summary>
        /// <param name="sender"><c><see cref="rowit_Paste"/></c></param>
        /// <param name="e"></param>
        void rowclick_Paste(object sender, EventArgs e)
        {
            // - store the row's current state to 'rPre' in the Restorable
            Restorable rest = UndoRedo.createRow(Table.Rows[_r]);


            YataGrid._init = true;             // bypass EnableGotoLoadchanged() in Cell.setter_loadchanged

            Row row = Table.Rows[_r];

            int c = 0;

            if (Settings._autorder)
            {
                row[c].text            = _r.ToString(CultureInfo.InvariantCulture);
                row[c].diff            =
                    row[c].loadchanged = false;

                ++c;
            }

            for (; c != Table.ColCount; ++c)
            {
                if (c < _copyr[0].Length)
                {
                    row[c].text = _copyr[0][c];
                }
                else
                {
                    row[c].text = gs.Stars;                     // TODO: perhaps keep any remaining cells as they are.
                }
                row[c].diff            =
                    row[c].loadchanged = false;
            }
            row._brush = Brushes.Created;

            YataGrid._init = false;
            EnableGotoLoadchanged(Table.anyLoadchanged());

            Table.Calibrate(_r);

            Table.Invalidator(YataGrid.INVALID_GRID);


            if (!Table.Changed)
            {
                Table.Changed = true;
                rest.isSaved  = UndoRedo.IsSavedType.is_Undo;
            }

            // - store the row's changed state to 'rPos' in the Restorable
            rest.rPos = Table.Rows[_r].Clone() as Row;
            Table._ur.Push(rest);
        }
Esempio n. 5
0
        /// <summary>
        /// Pastes a range of rows.
        /// </summary>
        /// <param name="sender"><c><see cref="it_PasteRange"/></c></param>
        /// <param name="e"></param>
        /// <remarks>Fired by
        /// <list type="bullet">
        /// <item>Rows|Paste <c>[Ctrl+Shift+v]</c></item>
        /// </list></remarks>
        void editrowsclick_PasteRange(object sender, EventArgs e)
        {
            Obfuscate();
            DrawRegulator.SuspendDrawing(Table);


            Restorable rest = UndoRedo.createArray(_copyr.Count, UndoRedo.UrType.rt_ArrayDelete);

            int selr = Table.getSelectedRow();

            if (selr == -1)
            {
                selr = Table.RowCount;
            }

            int r = selr;

            for (int i = 0; i != _copyr.Count; ++i, ++r)
            {
                Table.Insert(r, _copyr[i], false);
                rest.array[i] = Table.Rows[r].Clone() as Row;
            }

            Table.Calibrate(selr, _copyr.Count - 1);             // paste range

            Table.ClearSelects(false, true);
            Table.Rows[selr].selected = true;
            Table.RangeSelect         = _copyr.Count - 1;
            Table.EnsureDisplayedRow(selr);


            if (!Table.Changed)
            {
                Table.Changed = true;
                rest.isSaved  = UndoRedo.IsSavedType.is_Undo;
            }
            Table._ur.Push(rest);


            DrawRegulator.ResumeDrawing(Table);
            Obfuscate(false);

            if (Settings._autorder && order() != 0)
            {
                layout();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Handles context-click to paste below the current row.
        /// </summary>
        /// <param name="sender"><c><see cref="rowit_PasteBelow"/></c></param>
        /// <param name="e"></param>
        void rowclick_PasteBelow(object sender, EventArgs e)
        {
            Table.Insert(_r + 1, _copyr[0]);


            Restorable rest = UndoRedo.createRow(Table.Rows[_r + 1], UndoRedo.UrType.rt_Delete);

            if (!Table.Changed)
            {
                Table.Changed = true;
                rest.isSaved  = UndoRedo.IsSavedType.is_Undo;
            }
            Table._ur.Push(rest);

            if (Settings._autorder && order() != 0)
            {
                layout();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Redo's a cell-text change or a row-insert/delete/overwrite or a
        /// row-array insert/delete.
        /// </summary>
        public void Redo()
        {
            _it = Redoables.Pop();

            _grid.Changed = (_it.isSaved != UndoRedo.IsSavedType.is_Redo);

            switch (_it.RestoreType)
            {
            case UrType.rt_Cell:
                _it.cell.text = _it.postext;
                RestoreCell();
                break;

            case UrType.rt_Insert:
                InsertRow();
                _it.RestoreType = UrType.rt_Delete;
                break;

            case UrType.rt_Delete:
                DeleteRow();
                _it.RestoreType = UrType.rt_Insert;
                break;

            case UrType.rt_Overwrite:
                _it.r = _it.rPos;
                Overwrite();
                break;

            case UrType.rt_ArrayInsert:
                InsertArray();
                _it.RestoreType = UrType.rt_ArrayDelete;
                break;

            case UrType.rt_ArrayDelete:
                DeleteArray();
                _it.RestoreType = UrType.rt_ArrayInsert;
                break;
            }

            Undoables.Push(_it);
        }
Esempio n. 8
0
        /// <summary>
        /// Handles context-click to delete the current row.
        /// </summary>
        /// <param name="sender">
        /// <list type="bullet">
        /// <item><c><see cref="rowit_Delete"/></c></item>
        /// <item><c><see cref="rowit_Cut"/></c></item>
        /// </list></param>
        /// <param name="e"></param>
        void rowclick_Delete(object sender, EventArgs e)
        {
            Restorable rest = UndoRedo.createRow(Table.Rows[_r], UndoRedo.UrType.rt_Insert);


            Table.Delete(_r);

            EnableRoweditOperations();


            if (!Table.Changed)
            {
                Table.Changed = true;
                rest.isSaved  = UndoRedo.IsSavedType.is_Undo;
            }
            Table._ur.Push(rest);

            if (Settings._autorder && order() != 0)
            {
                layout();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Handles a single-row merge operation.
        /// </summary>
        /// <param name="sender"><c><see cref="cellit_MergeRo"/></c></param>
        /// <param name="e"></param>
        void cellclick_MergeRo(object sender, EventArgs e)
        {
            YataGrid table;

            if (Table == _diff1)
            {
                table = _diff2;
            }
            else
            {
                table = _diff1;
            }

            int r = _sel.y;

            // - store the row's current state to 'rPre' in the Restorable
            Restorable rest = UndoRedo.createRow(table.Rows[r]);


            int c = 0;

            for (; c != table.ColCount && c != Table.ColCount; ++c)
            {
                table[r, c].text = Table[r, c].text;
                table[r, c].diff = false;

                Table[r, c].diff = false;
            }

            if (Settings._autorder)
            {
                table[r, 0].text = table[r, 0].y.ToString(CultureInfo.InvariantCulture);                // not likely to happen. user'd have to load a table w/
            }
            // an out of order id then merge that row to another table.
            if (table.ColCount > Table.ColCount)
            {
                for (; c != table.ColCount; ++c)
                {
                    table[r, c].text = gs.Stars;
                    table[r, c].diff = false;
                }
            }
            else if (table.ColCount < Table.ColCount)
            {
                for (; c != Table.ColCount; ++c)
                {
                    Table[r, c].diff = false;
                }
            }

            Table.Invalidator(YataGrid.INVALID_GRID | YataGrid.INVALID_FROZ);

            // TODO: test if this funct needs to re-width a bunch of stuff


            if (!table.Changed)
            {
                table.Changed = true;
                rest.isSaved  = UndoRedo.IsSavedType.is_Undo;
            }

            // - store the row's changed state to 'rPos' in the Restorable
            rest.rPos = table.Rows[r].Clone() as Row;
            table._ur.Push(rest);
        }
Esempio n. 10
0
        /// <summary>
        /// Instantiates <c><see cref="RowCreatorDialog"/></c> for
        /// inserting/creating multiple rows.
        /// </summary>
        /// <param name="sender"><c><see cref="it_CreateRows"/></c></param>
        /// <param name="e"></param>
        /// <remarks>Fired by
        /// <list type="bullet">
        /// <item>Rows|Create ... <c>[F2]</c></item>
        /// </list></remarks>
        void editrowsclick_CreateRows(object sender, EventArgs e)
        {
            int selr = Table.getSelectedRowOrCells();

            using (var rcd = new RowCreatorDialog(this, selr, _copyr.Count != 0))
            {
                if (rcd.ShowDialog(this) == DialogResult.OK)
                {
                    Obfuscate();
                    DrawRegulator.SuspendDrawing(Table);


                    Restorable rest = UndoRedo.createArray(_lengthCr, UndoRedo.UrType.rt_ArrayDelete);

                    var cells = new string[Table.ColCount];
                    switch (_fillCr)
                    {
                    case CrFillType.Stars:
                        for (int i = 0; i != Table.ColCount; ++i)
                        {
                            cells[i] = gs.Stars;
                        }
                        break;

                    case CrFillType.Selected:
                        for (int i = 0; i != Table.ColCount; ++i)
                        {
                            cells[i] = Table[selr, i].text;
                        }
                        break;

                    case CrFillType.Copied:
                        for (int i = 0; i != Table.ColCount; ++i)
                        {
                            if (i < _copyr[0].Length)
                            {
                                cells[i] = _copyr[0][i];
                            }
                            else
                            {
                                cells[i] = gs.Stars;
                            }
                        }
                        break;
                    }

                    int r = _startCr;
                    for (int i = 0; i != _lengthCr; ++i, ++r)
                    {
                        cells[0] = r.ToString(CultureInfo.InvariantCulture);

                        Table.Insert(r, cells, false);
                        rest.array[i] = Table.Rows[r].Clone() as Row;
                    }

                    Table.Calibrate(_startCr, _lengthCr - 1);                     // insert range

                    Table.ClearSelects(false, true);
                    Table.Rows[_startCr].selected = true;
                    Table.RangeSelect             = _lengthCr - 1;
                    Table.EnsureDisplayedRow(_startCr);


                    if (!Table.Changed)
                    {
                        Table.Changed = true;
                        rest.isSaved  = UndoRedo.IsSavedType.is_Undo;
                    }
                    Table._ur.Push(rest);


                    DrawRegulator.ResumeDrawing(Table);
                    Obfuscate(false);

                    if (Settings._autorder && order() != 0)
                    {
                        layout();
                    }
                }
            }
        }