예제 #1
0
        private Stream LoadFile()
        {
            MemoryStream stream = new MemoryStream();

            if (!_saved && _hexView != null && _hexView.Edits.Count > 0)
            {
                if (MessageBox.ErrorQuery("Save", "The changes were not saved. Want to open without saving?", "Yes", "No") == 1)
                {
                    return(_hexView.Source);
                }
                _hexView.DiscardEdits();
                _saved = true;
            }

            if (_fileName != null)
            {
                var bin = System.IO.File.ReadAllBytes(_fileName);
                stream.Write(bin);
                Win.Title = this.GetName() + "-" + _fileName;
                _saved    = true;
            }
            else
            {
                Win.Title = this.GetName() + "-" + (_fileName ?? "Untitled");
            }
            return(stream);
        }
예제 #2
0
        public void DiscardEdits_Method()
        {
            var hv = new HexView(LoadStream(true))
            {
                Width = 20, Height = 20
            };

            Assert.True(hv.ProcessKey(new KeyEvent(Key.D4, new KeyModifiers())));
            Assert.True(hv.ProcessKey(new KeyEvent(Key.D1, new KeyModifiers())));
            Assert.Single(hv.Edits);
            Assert.Equal(65, hv.Edits.ToList() [0].Value);
            Assert.Equal('A', (char)hv.Edits.ToList() [0].Value);
            Assert.Equal(126, hv.Source.Length);

            hv.DiscardEdits();
            Assert.Empty(hv.Edits);
        }