Example #1
0
 private void Copy()
 {
     if (_textView != null)
     {
         _textView.Copy();
     }
 }
Example #2
0
 private void CopyMenuBarItem_Click(object sender, EventArgs e)
 {
     TextView.Copy();
 }
Example #3
0
    //
    static void Editor()
    {
        Application.Init();
        Application.HeightAsBuffer = heightAsBuffer;

        var ntop = Application.Top;

        var text = new TextView()
        {
            X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill()
        };

        string fname = GetFileName();

        var win = new Window(fname ?? "Untitled")
        {
            X      = 0,
            Y      = 1,
            Width  = Dim.Fill(),
            Height = Dim.Fill()
        };

        ntop.Add(win);

        if (fname != null)
        {
            text.Text = System.IO.File.ReadAllText(fname);
        }
        win.Add(text);

        void Paste()
        {
            if (text != null)
            {
                text.Paste();
            }
        }

        void Cut()
        {
            if (text != null)
            {
                text.Cut();
            }
        }

        void Copy()
        {
            if (text != null)
            {
                text.Copy();
            }
        }

        var menu = new MenuBar(new MenuBarItem [] {
            new MenuBarItem("_File", new MenuItem [] {
                new MenuItem("_Close", "", () => { if (Quit())
                                                   {
                                                       running = MainApp; Application.RequestStop();
                                                   }
                             }, null, null, Key.AltMask | Key.Q),
            }),
            new MenuBarItem("_Edit", new MenuItem [] {
                new MenuItem("_Copy", "", Copy, null, null, Key.C | Key.CtrlMask),
                new MenuItem("C_ut", "", Cut, null, null, Key.X | Key.CtrlMask),
                new MenuItem("_Paste", "", Paste, null, null, Key.Y | Key.CtrlMask)
            }),
        });

        ntop.Add(menu);

        Application.Run(ntop);
    }
Example #4
0
        private void Format(string option)
        {
            switch (option.ToUpper())
            {
            case "B":
                try
                {
                    SelectCurrentLine();
                    FontStyle style = new FontStyle();
                    if (TextView.SelectionFont.Bold)
                    {
                        style = style | FontStyle.Regular;
                    }
                    else
                    {
                        style = style | FontStyle.Bold;
                    }
                    if (TextView.SelectionFont.Italic)
                    {
                        style = style | FontStyle.Italic;
                    }
                    if (TextView.SelectionFont.Underline)
                    {
                        style = style | FontStyle.Underline;
                    }
                    TextView.SelectionFont = new Font(TextView.SelectionFont, style);
                    TextView.DeselectAll();
                }
                catch { };
                break;

            case "I":
                try
                {
                    SelectCurrentLine();
                    FontStyle style = new FontStyle();
                    if (TextView.SelectionFont.Italic)
                    {
                        style = style | FontStyle.Regular;
                    }
                    else
                    {
                        style = style | FontStyle.Italic;
                    }
                    if (TextView.SelectionFont.Bold)
                    {
                        style = style | FontStyle.Bold;
                    }
                    if (TextView.SelectionFont.Underline)
                    {
                        style = style | FontStyle.Underline;
                    }

                    TextView.SelectionFont = new Font(TextView.SelectionFont, style);
                    TextView.DeselectAll();
                }
                catch { };
                break;

            case "U":
                try
                {
                    SelectCurrentLine();
                    FontStyle style = new FontStyle();
                    if (TextView.SelectionFont.Underline)
                    {
                        style = style | FontStyle.Regular;
                    }
                    else
                    {
                        style = style | FontStyle.Underline;
                    }
                    if (TextView.SelectionFont.Italic)
                    {
                        style = style | FontStyle.Italic;
                    }
                    if (TextView.SelectionFont.Bold)
                    {
                        style = style | FontStyle.Bold;
                    }

                    TextView.SelectionFont = new Font(TextView.SelectionFont, style);
                    TextView.DeselectAll();
                }
                catch { };
                break;

            case "T":
                try
                {
                    SelectCurrentLine();
                    FontDialog fd = new FontDialog();
                    fd.Font = TextView.SelectionFont;
                    if (fd.ShowDialog() == DialogResult.OK)
                    {
                        TextView.SelectionFont = fd.Font;
                    }
                    TextView.DeselectAll();
                }
                catch { };
                break;

            case "UP":
                TextView.SelectionAlignment = HorizontalAlignment.Center;
                break;

            case "RIGHT":
                TextView.SelectionAlignment = HorizontalAlignment.Right;
                break;

            case "LEFT":
                TextView.SelectionAlignment = HorizontalAlignment.Left;
                break;

            case "A":
                TextView.SelectAll();
                break;

            case "C":
                TextView.Copy();
                break;

            case "V":
                TextView.Paste();
                break;

            case "X":
                TextView.Cut();
                break;

            case "Z":
                TextView.Undo();
                break;

            case "Y":
                TextView.Redo();
                break;

            case "P":
                SelectCurrentLine();
                if (TextView.SelectionProtected)
                {
                    TextView.SelectionColor = Color.FromArgb(
                        (TextView.SelectionColor.R + 70 > 255) ? 255 : TextView.SelectionColor.R + 70,
                        (TextView.SelectionColor.G + 70 > 255) ? 255 : TextView.SelectionColor.G + 70,
                        (TextView.SelectionColor.B + 70 > 255) ? 255 : TextView.SelectionColor.B + 70
                        );

                    TextView.SelectionProtected = false;
                }
                else
                {
                    TextView.SelectionColor = Color.FromArgb(
                        (TextView.SelectionColor.R - 70 < 0) ? 0 : TextView.SelectionColor.R - 70,
                        (TextView.SelectionColor.G - 70 < 0) ? 0 : TextView.SelectionColor.G - 70,
                        (TextView.SelectionColor.B - 70 < 0) ? 0 : TextView.SelectionColor.B - 70
                        );

                    TextView.SelectionProtected = true;
                }
                TextView.DeselectAll();
                break;

            case "R":
                SelectCurrentLine();
                ColorDialog CD = new ColorDialog();
                if (CD.ShowDialog() == DialogResult.OK)
                {
                    TextView.SelectionColor = CD.Color;
                }
                TextView.DeselectAll();
                break;

            case "S":
                save(true);
                break;

            case "N":
                if (MessageBox.Show("Do you want to create a new file?", "New File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    CurrentFile = "";
                    TextView.Clear();
                    TextView.ForeColor = txt_color.ForeColor;
                    TextView.BackColor = bg_color.BackColor;
                }
                break;

            case "O":
                OpenFileDialog OFD = new OpenFileDialog();
                OFD.Title = "Select a file to open";
                if (OFD.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        TextView.LoadFile(OFD.FileName);
                    }
                    catch
                    {
                        try
                        {
                            TextView.Text = System.IO.File.ReadAllText(OFD.FileName);
                        }
                        catch { }
                    }
                    CurrentFile = OFD.FileName;
                    Properties.Settings.Default.last_opened_file = CurrentFile;
                    Properties.Settings.Default.Save();
                }
                break;

            case "Q":
                if (MessageBox.Show("Do you want to delete all?", "Delete All", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    TextView.SelectionProtected = false;
                    TextView.Clear();
                    TextView.ForeColor = txt_color.ForeColor;
                    TextView.BackColor = bg_color.BackColor;
                }
                break;

            case "D":
                DuplicateLine();
                break;

            case "E":
                CheckForFunctions();
                break;
            }
        }