Esempio n. 1
0
        internal void MakePrivateCopyOfUndoRedo()
        {
            // Data in the actions may reference a file buffer that
            // can become invalid (eg after saving a file)
            // Copy the data to private in-memory buffers to avoid data corruption
            // and crashes...
            //

            if (Preferences.Instance["Undo.KeepAfterSave"] == "Never")
            {
                undoDeque.Clear();
                redoDeque.Clear();
                return;
            }

            if (Preferences.Instance["Undo.KeepAfterSave"] == "Always")
            {
                foreach (ByteBufferAction action in undoDeque)
                {
                    action.MakePrivateCopyOfData();
                }

                foreach (ByteBufferAction action in redoDeque)
                {
                    action.MakePrivateCopyOfData();
                }

                return;
            }

            // if Preferences.Instance["Undo.KeepAfterSave"] == "Memory"
            // drop the undo and redo actions that don't fit into memory (and all actions
            // after them in the Deques).
            Deque <ByteBufferAction> newUndoDeque = new Deque <ByteBufferAction>();
            Deque <ByteBufferAction> newRedoDeque = new Deque <ByteBufferAction>();

            foreach (ByteBufferAction action in undoDeque)
            {
                long freeMem = long.MaxValue;
                try {
                    freeMem = Portable.GetAvailableMemory();
                }
                catch (NotImplementedException) {}

                if (freeMem < action.GetPrivateCopySize())
                {
                    break;
                }

                action.MakePrivateCopyOfData();
                newUndoDeque.AddEnd(action);
            }


            foreach (ByteBufferAction action in redoDeque)
            {
                long freeMem = long.MaxValue;
                try {
                    freeMem = Portable.GetAvailableMemory();
                }
                catch (NotImplementedException) {}

                if (freeMem < action.GetPrivateCopySize())
                {
                    break;
                }

                action.MakePrivateCopyOfData();
                newRedoDeque.AddEnd(action);
            }

            undoDeque.Clear();
            redoDeque.Clear();

            undoDeque = newUndoDeque;
            redoDeque = newRedoDeque;
        }