Пример #1
0
        public NoteView(string dir)
        {
            directory = dir;
            notes = new List<Note>();

            ListBox = new ListBox { Style = "ListNative" };
            TextArea = new TextArea { Style = "TextConsole" };

            var updatingNote = false;

            TextArea.TextChanged += delegate
            {
                if (ListBox.SelectedIndex < 0)
                    return;
                var note = notes[ListBox.SelectedIndex];
                bool changed = note.Changed;
                note.Content = TextArea.Text;
                if (changed != note.Changed)
                    ListBox.Invalidate();
            };

            TextArea.SelectionChanged += delegate
            {
                if (ListBox.SelectedIndex < 0 || updatingNote)
                    return;
                notes[ListBox.SelectedIndex].Selection = TextArea.Selection;
            };

            ListBox.SelectedIndexChanged += delegate
            {
                if (ListBox.SelectedIndex < 0)
                    return;
                var note = notes[ListBox.SelectedIndex];
                updatingNote = true;
                TextArea.Text = note.Content;
                TextArea.Selection = note.Selection;
                TextArea.Focus();
                updatingNote = false;
            };
        }