예제 #1
0
        internal DocumentForm()
        {
            InitializeComponents();

            unsavedChanges = new UnsavedChanges(this, Save);
            fileName       = string.Empty;

            FormClosing += (s, e) =>
            {
                if (unsavedChanges.WereNotHandled())
                {
                    e.Cancel = true;
                }
            };

            richTextBox.TextChanged += (s, e) =>
            {
                var indicator = " *";

                if ((fileName != string.Empty) && !Text.EndsWith(fileName + indicator))
                {
                    Text += indicator;
                }

                unsavedChanges.HaveOccurred();
            };

            richTextBox.KeyPress += (s, e) =>
            {
                if ((Keys)e.KeyChar == Keys.Tab)
                {
                    InsertSpacesForTab();
                    e.Handled = true;
                }

                if ((Keys)e.KeyChar == Keys.Enter)
                {
                    IndentNewLine();
                    e.Handled = true;
                }
            };
        }
예제 #2
0
        internal DocumentForm()
        {
            InitializeComponents();

            unsavedChanges = new UnsavedChanges(this, Save);
            fileName = string.Empty;

            FormClosing += (s, e) =>
            {
                if (unsavedChanges.WereNotHandled())
                {
                    e.Cancel = true;
                }
            };

            richTextBox.TextChanged += (s, e) =>
            {
                var indicator = " *";

                if ((fileName != string.Empty) && !Text.EndsWith(fileName + indicator))
                {
                    Text += indicator;
                }

                unsavedChanges.HaveOccurred();
            };

            richTextBox.KeyPress += (s, e) =>
            {
                if ((Keys)e.KeyChar == Keys.Tab)
                {
                    InsertSpacesForTab();
                    e.Handled = true;
                }

                if ((Keys)e.KeyChar == Keys.Enter)
                {
                    IndentNewLine();
                    e.Handled = true;
                }
            };
        }