Example #1
0
        public static void Serialize(DocumentBuffer buffer, Stream stream)
        {
            var sw = new BinaryWriter(stream, Encoding.UTF8);

            sw.Write(BIN_VERSION);

            //Main
            sw.Write(buffer.ReadOnly);
            sw.Write(buffer.Encoding.CodePage);
            sw.Write(buffer.File.FullName);
            sw.Write(buffer.GrammarKey.ToString());
            sw.Write((int)buffer.Flags);

            //ScrollPosition
            sw.Write(buffer.ScrollPosition.X);
            sw.Write(buffer.ScrollPosition.Y);

            //Selections
            sw.Write(buffer.Selections.Count);

            foreach (var sel in buffer.Selections)
            {
                sw.Write(sel.Start.Line);
                sw.Write(sel.Start.Col);
                sw.Write(sel.End.Line);
                sw.Write(sel.End.Col);
            }

            //Collapsed lines
            var lines = new List <int>();

            for (var i = 0; i < buffer.Document.Lines.Count; i++)
            {
                var ln = buffer.Document.Lines[i];
                if (ln.Folding.Has(FoldingStates.Invisible))
                {
                    lines.Add(i);
                }
            }

            sw.Write(lines.Count);

            foreach (var i in lines)
            {
                sw.Write(i);
            }

            //Properties
            sw.Write(buffer.WordWrap);
            sw.Write(buffer.Overtype);
            sw.Write(buffer.UseTabs);
            sw.Write(buffer.IndentSize);
            sw.Write(buffer.ShowEol);
            sw.Write(buffer.ShowWhitespace);
            sw.Write(buffer.ShowLineLength);
            sw.Write(buffer.CurrentLineIndicator);
            sw.Write((int)buffer.Eol);
        }
Example #2
0
        public static void Deserialize(DocumentBuffer buffer, Stream stream)
        {
            var sr = new BinaryReader(stream, Encoding.UTF8);

            if (sr.ReadInt32() != BIN_VERSION)
            {
                App.Ext.Log($"Invalid version of document state. Expected: {BIN_VERSION}.", EntryType.Error);
                return;
            }

            var @lock = buffer.ObtainLock();

            try
            {
                //Main
                buffer.ReadOnly = sr.ReadBoolean();
                var cp = sr.ReadInt32();
                buffer.Encoding   = Encoding.GetEncoding(cp);
                buffer.File       = new FileInfo(sr.ReadString());
                buffer.GrammarKey = (Identifier)sr.ReadString();
                buffer.Flags      = (BufferDisplayFlags)sr.ReadInt32();

                //ScrollPosition
                buffer.ScrollPosition = new Point(sr.ReadInt32(), sr.ReadInt32());

                //Selections
                var count = sr.ReadInt32();
                buffer.Selections.Clear();

                for (var i = 0; i < count; i++)
                {
                    var sel = new Selection(
                        new Pos(sr.ReadInt32(), sr.ReadInt32()),
                        new Pos(sr.ReadInt32(), sr.ReadInt32())
                        );
                    buffer.Selections.AddFast(sel);
                }

                //Collapsed lines
                count = sr.ReadInt32();

                for (var i = 0; i < count; i++)
                {
                    buffer.Document.Lines[sr.ReadInt32()].Folding |= FoldingStates.Invisible;
                }

                //Properties
                buffer.WordWrap             = sr.ReadNullableBool();
                buffer.Overtype             = sr.ReadBoolean();
                buffer.UseTabs              = sr.ReadNullableBool();
                buffer.IndentSize           = sr.ReadNullableInt32();
                buffer.ShowEol              = sr.ReadNullableBool();
                buffer.ShowWhitespace       = sr.ReadNullableShowWhitespace();
                buffer.ShowLineLength       = sr.ReadNullableBool();
                buffer.CurrentLineIndicator = sr.ReadNullableBool();
                buffer.Eol = (Eol)sr.ReadInt32();
            }
            finally
            {
                @lock.Release();
            }
        }
Example #3
0
 internal EditorLock(DocumentBuffer man)
 {
     this.man = man;
 }