コード例 #1
0
        public Bitmap CaptureSnippet()
        {
            int minX = 0, minY = 0, maxX = 0, maxY = 0;

            foreach (var oneScreen in Screen.AllScreens)
            {
                Logger.Record("\t[CaptureSnippet]: AllScreens[]: SNIPPET" + oneScreen.Bounds.ToString(), "ScreenShot", "info");
                minX = Math.Min(minX, oneScreen.Bounds.Left);
                minY = Math.Min(minY, oneScreen.Bounds.Top);
                maxX = Math.Max(maxX, oneScreen.Bounds.Width + oneScreen.Bounds.X);
                maxY = Math.Max(maxY, oneScreen.Bounds.Height + oneScreen.Bounds.Y);
            }
            maxY = Math.Abs(maxY) + Math.Abs(minY);
            maxX = Math.Abs(maxX) + Math.Abs(minX);

            var snipForm = new SnippetForm
            {
                Top              = minY,
                Left             = minX,
                Width            = maxX,
                Height           = maxY,
                ScreenStartImage = CaptureScreenShot()
            };

            snipForm.ShowDialog();
            if (snipForm.Cancelled || snipForm.Snippet == null)
            {
                Canceled = true;
            }
            return(snipForm.Snippet ?? new Bitmap(1, 1));
        }
コード例 #2
0
        public IActionResult Create(SnippetForm form, IFormFile SnippetFile)
        {
            if (!ModelState.IsValid)
            {
                return(View(form));
            }

            if (SnippetFile != null && string.IsNullOrWhiteSpace(form.Snippet))
            {
                form.Snippet = SnippetFile.ReadString();
            }

            return(View(form));
        }
コード例 #3
0
 public IActionResult Create(SnippetForm form)
 {
     return(View(form));
 }
コード例 #4
0
        // Handles snippet-complete command
        public void Handle(string[] arguments)
        {
            if (arguments.Length < 3)
            {
                return;
            }
            var language = getLanguage(arguments[0]);

            if (language == null)
            {
                return;
            }
            var file = getLocal(arguments);

            if (!File.Exists(file))
            {
                file = getGlobal(arguments);
            }

            if (!File.Exists(file))
            {
                return;
            }
            var lines = File.ReadAllLines(file);

            if (lines.Length < 3)
            {
                return;
            }
            var placeHolders = lines[0];
            var offsetLine   = lines[1];
            var snippet      = new StringBuilder();

            for (int i = 2; i < lines.Length; i++)
            {
                snippet.AppendLine(lines[i]);
            }
            var indentation = "";

            if (arguments.Length == 4)
            {
                indentation = arguments[3].Replace("t", "\t").Replace("s", " ");
            }
            var form = new SnippetForm(
                new OpenIDE.Core.CommandBuilding.CommandStringParser(',').Parse(placeHolders).ToArray(),
                snippet.ToString());
            int lineCount      = 0;
            int lastLineLength = 0;

            form.OnRun((content) =>
            {
                try {
                    var sb           = new StringBuilder();
                    var contentLines = content.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                    for (int i = 0; i < contentLines.Length; i++)
                    {
                        var contentLine = contentLines[i];
                        if (i == 0)
                        {
                            sb.AppendLine(contentLine);
                            lastLineLength = contentLine.Length;
                            lineCount++;
                        }
                        else if (i == contentLines.Length - 1 && contentLine == "")
                        {
                            break;
                        }
                        else if (i == contentLines.Length - 1)
                        {
                            sb.Append(indentation + contentLine);
                            lastLineLength = indentation.Length + contentLine.Length;
                            lineCount++;
                        }
                        else
                        {
                            sb.AppendLine(indentation + contentLine);
                            lastLineLength = indentation.Length + contentLine.Length;
                            lineCount++;
                        }
                    }

                    form         = null;
                    var tempFile = FS.GetTempFileName();
                    File.WriteAllText(tempFile, sb.ToString());
                    var offset = new OpenIDE.Core.CommandBuilding.Position(offsetLine);
                    if (offset.Line == -1 && offset.Column == -1)
                    {
                        offset = new OpenIDE.Core.CommandBuilding.Position(lineCount - 1, lastLineLength);
                    }
                    else
                    {
                        offset.AddToColumn(indentation.Length);
                    }
                    var insertMessage = "insert \"" + tempFile + "\" \"" + arguments[2] + "\" \"" + offset.ToCommand() + "\"";
                    if (_editor != null)
                    {
                        _editor.Send(insertMessage);
                    }
                } catch (Exception ex) {
                    Logger.Write(ex);
                }
            });
            form.Show();
            form.BringToFront();
        }