Exemple #1
0
        public void TestToggleBoldness1()
        {
            _textBox.EnableMarkdownShortcuts = true;
            _textBox.Text = "Foobar";
            _textBox.Select(0, 6);

            _keyboard.Click(_textBox, Key.B, ModifierKeys.Control);

            _textBox.Text.Should().Be("**Foobar**");
            _textBox.SelectedText.Should().Be("**Foobar**");
        }
Exemple #2
0
        /// <summary>Save file method</summary>
        /// <param name="strFileName">string - file name</param>
        private void SaveDocument(string strFileName)
        {
            this.Text = "Simple Text Editor" + strFileName;
            EditorTextBox.Select(0, 0);

            FileStream fileStream = null;

            try
            {
                fileStream = new FileStream(strFileName, FileMode.Create, FileAccess.Write);
                Byte[] dataByte;

                dataByte = new Byte[EditorTextBox.Text.Length];
                dataByte.Initialize();
                dataByte = m_Encoder.GetBytes(EditorTextBox.Text.ToString());
                fileStream.Write(dataByte, 0, dataByte.Length);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error :" + ex, "Simple Text Editor", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
            this.Text = "Simple Text Editor" + strFileName;
            return;
        }
Exemple #3
0
        /// <summary>Open menu implementation</summary>
        /// <param name="sender">object</param>
        /// <param name="e">EventArgs</param>
        private void mnuOpen_Click(object sender, EventArgs e)
        {
            string strFileName = "";
            string strTemp     = "";

            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                //If the document is not saved then prompt the user to save
                if (m_IsContentModified && (
                        m_Features.CheckStatus(LicenseFeatures.Save.ToString()) ||
                        m_Features.CheckStatus(LicenseFeatures.SaveAs.ToString())))
                {
                    switch (MessageBox.Show(this, "The document is not saved. Do you wish to save now ?", "Simple Text Editor", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation))
                    {
                    case DialogResult.Yes:
                        if (!SaveFile())
                        {
                            return;
                        }
                        EditorTextBox.Text = "";
                        this.Text          = "Simple Text Editor";
                        break;

                    case DialogResult.No:
                        EditorTextBox.Text = "";
                        this.Text          = "Simple Text Editor";
                        break;

                    case DialogResult.Cancel:
                        return;
                    }
                }
                strFileName    = openFileDialog.FileName;
                m_DocumentName = strFileName;
            }
            else
            {
                return;
            }

            //Read the file
            FileStream fileStream      = null;
            string     strFileContents = "";

            try
            {
                strTemp = "";
                int iRetval = 1;

                fileStream = new FileStream(strFileName, FileMode.Open, FileAccess.Read);
                Byte[] dataByte = new Byte[1024];
                dataByte.Initialize();
                for (; iRetval != 0;)
                {
                    dataByte.Initialize();
                    strTemp          = "";
                    iRetval          = fileStream.Read(dataByte, 0, 1024);
                    strTemp          = m_Encoder.GetString(dataByte, 0, 1024);
                    strFileContents += strTemp;
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show(this, "File not found or permission denied", "Simple Text Editor", MessageBoxButtons.OK);
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error : " + ex.ToString(), "Simple Text Editor", MessageBoxButtons.OK);
                return;
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }

            strTemp            = strFileName.ToLower();
            EditorTextBox.Text = strFileContents;
            this.Text          = "Simple Text Editor" + strFileName;
            EditorTextBox.Select(0, 0);
            m_IsContentModified = false;
        }
Exemple #4
0
 private void toolUnderline_Click(object sender, EventArgs e)
 {
     if (EditorTextBox.SelectionFont != null)
     {
         if (EditorTextBox.SelectionFont.Underline)
         {
             EditorTextBox.SelectionFont = new Font(EditorTextBox.SelectionFont, EditorTextBox.SelectionFont.Style & ~FontStyle.Underline);
             toolUnderline.Checked       = false;
         }
         else
         {
             EditorTextBox.SelectionFont = new Font(EditorTextBox.SelectionFont, EditorTextBox.SelectionFont.Style | FontStyle.Underline);
             toolUnderline.Checked       = true;
         }
     }
     else
     {
         int selectionStart  = EditorTextBox.SelectionStart;
         int selectionLength = EditorTextBox.SelectionLength;
         int selectionEnd    = selectionStart + EditorTextBox.SelectionLength;
         int j = 0;
         while (true)
         {
             int i = 0;
             int sectionSelectionStart = selectionStart + j;
             if (sectionSelectionStart < selectionEnd)
             {
                 while (true)
                 {
                     EditorTextBox.Select(sectionSelectionStart, i);
                     if (EditorTextBox.SelectionFont != null)
                     {
                         if (selectionEnd > sectionSelectionStart + i)
                         {
                             i++;
                         }
                         else
                         {
                             EditorTextBox.SelectionFont = new Font(EditorTextBox.SelectionFont, EditorTextBox.SelectionFont.Style | FontStyle.Underline);
                             j += i;
                             break;
                         }
                     }
                     if (EditorTextBox.SelectionFont == null)
                     {
                         i--;
                         EditorTextBox.Select(sectionSelectionStart, i);
                         EditorTextBox.SelectionFont = new Font(EditorTextBox.SelectionFont, EditorTextBox.SelectionFont.Style | FontStyle.Underline);
                         j += i;
                         EditorTextBox.Select(selectionStart, selectionLength);
                         break;
                     }
                 }
             }
             else
             {
                 EditorTextBox.Select(selectionStart, selectionLength);
                 break;
             }
         }
     }
 }