Exemplo n.º 1
0
        private void ContextMenu_Popup(System.Object sender, System.EventArgs e)
        {
            scintilla1.ContextMenu.MenuItems.Clear();

            scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Copy", (s, ea) => scintilla1.Copy()));
            scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Select All", (s, ea) => scintilla1.SelectAll()));



            System.Drawing.Point point = System.Windows.Forms.Control.MousePosition;
            var cor = scintilla1.PointToClient(point);
            var pos = scintilla1.CharPositionFromPoint(cor.X, cor.Y);

            int startPos = ValueStartPosition(pos);
            int endPos   = ValueEndPosition(pos);

            string text = scintilla1.GetTextRange(startPos, endPos - startPos);

            if ((text.StartsWith("http://") || text.StartsWith("https://")))
            {
                scintilla1.ContextMenu.MenuItems.Add("-");
                scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Open in Browser", (s, ea) => Process.Start(text)));
                if (text.EndsWith(".jpg") || text.EndsWith(".png"))
                {
                    scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Open Image in new Window", (s, ea) =>
                    {
                        new ImageViewer(text).ShowDialog();
                    }));
                    scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Save Image", (s, ea) =>
                    {
                        SaveFileDialog saveFileDialog1   = new SaveFileDialog();
                        saveFileDialog1.RestoreDirectory = true;
                        saveFileDialog1.FileName         = text.Split('/').Last();
                        saveFileDialog1.Filter           = "Image Files|*." + text.Split('.').Last();
                        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                        {
                            using (var webClient = new WebClient())
                            {
                                webClient.DownloadFile(text, saveFileDialog1.FileName);
                            }
                        }
                    }));
                }
            }
        }