示例#1
0
        public string FormatClipboard()
        {
            // WPF and Windows Forms Clipboard behavior differs when it comes
            // to DataFormats.CommaSeparatedValue.
            // WPF will always return the data as a string, no matter how it
            // was set, but Windows Forms may return a Stream or a string.
            // Use WPF Clipboard fully qualified name to ensure we don't
            // accidentally end up using the wrong clipboard implementation
            // if this code is moved.
            if (System.Windows.Clipboard.ContainsData(System.Windows.DataFormats.CommaSeparatedValue))
            {
                string data = System.Windows.Clipboard.GetData(System.Windows.DataFormats.CommaSeparatedValue) as string;
                if (data != null)
                {
                    string[]      lines = data.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                    StringBuilder res   = new StringBuilder();
                    res.AppendLine("[");
                    foreach (var line in lines)
                    {
                        string[] items = _splitLineRegex.Split(line);

                        res.Append("  [");
                        for (int i = 0; i < items.Length; i++)
                        {
                            res.Append(FormatItem(items[i]));

                            if (i != items.Length - 1)
                            {
                                res.Append(", ");
                            }
                        }
                        res.AppendLine("],");
                    }
                    res.AppendLine("]");
                    return(res.ToString());
                }
            }

            var txt = System.Windows.Clipboard.GetText();

            if (!_serviceProvider.GetPythonToolsService().AdvancedOptions.PasteRemovesReplPrompts)
            {
                return(txt);
            }


            return(ReplPromptHelpers.RemovePrompts(
                       txt,
                       _window.TextView.Options.GetNewLineCharacter()
                       ));
        }
示例#2
0
        public void RemoveReplPrompts()
        {
            Assert.AreEqual("", ReplPromptHelpers.RemovePrompts("", null));
            Assert.AreEqual("", ReplPromptHelpers.RemovePrompts(">>>", null));
            Assert.AreEqual("", ReplPromptHelpers.RemovePrompts(">>> ", null));
            Assert.AreEqual("    ", ReplPromptHelpers.RemovePrompts(">>>     ", null));
            Assert.AreEqual("pass", ReplPromptHelpers.RemovePrompts(">>> pass", null));
            Assert.AreEqual(" pass", ReplPromptHelpers.RemovePrompts(">>>  pass", null));
            Assert.AreEqual("", ReplPromptHelpers.RemovePrompts("...", null));
            Assert.AreEqual("", ReplPromptHelpers.RemovePrompts("... ", null));
            Assert.AreEqual("    ", ReplPromptHelpers.RemovePrompts("...     ", null));
            Assert.AreEqual("pass", ReplPromptHelpers.RemovePrompts("... pass", null));
            Assert.AreEqual(" pass", ReplPromptHelpers.RemovePrompts("...  pass", null));
            Assert.AreEqual("", ReplPromptHelpers.RemovePrompts("In[1]:", null));
            Assert.AreEqual("    ", ReplPromptHelpers.RemovePrompts("In [ 2 ]  :     ", null));
            Assert.AreEqual("pass", ReplPromptHelpers.RemovePrompts("In [ 2 ]  : pass", null));
            Assert.AreEqual(" pass", ReplPromptHelpers.RemovePrompts("In [ 2 ]  :  pass", null));
            Assert.AreEqual("", ReplPromptHelpers.RemovePrompts("...:", null));
            Assert.AreEqual("", ReplPromptHelpers.RemovePrompts("    ...:", null));
            Assert.AreEqual("", ReplPromptHelpers.RemovePrompts("  ...: ", null));
            Assert.AreEqual("    ", ReplPromptHelpers.RemovePrompts("  ...:     ", null));
            Assert.AreEqual("pass", ReplPromptHelpers.RemovePrompts("  ...: pass", null));
            Assert.AreEqual(" pass", ReplPromptHelpers.RemovePrompts("  ...:  pass", null));

            Assert.AreEqual(@"x = 1
print(x)
if True:
    pass


print(x)
1

if True:
    print(x)

1".Replace("\r\n", "\n"), ReplPromptHelpers.RemovePrompts(@">>> x = 1
>>> print(x)
>>> if True:
...     pass
...

In [2]: print(x)
1

In [3]: if True:
   ...:     print(x)
   ...: 
1", "\n"));
        }
示例#3
0
        public string FormatClipboard()
        {
            if (Clipboard.ContainsData(DataFormats.CommaSeparatedValue))
            {
                string data = Clipboard.GetData(DataFormats.CommaSeparatedValue) as string;
                if (data != null)
                {
                    string[]      lines = data.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                    StringBuilder res   = new StringBuilder();
                    res.AppendLine("[");
                    foreach (var line in lines)
                    {
                        string[] items = _splitLineRegex.Split(line);

                        res.Append("  [");
                        for (int i = 0; i < items.Length; i++)
                        {
                            res.Append(FormatItem(items[i]));

                            if (i != items.Length - 1)
                            {
                                res.Append(", ");
                            }
                        }
                        res.AppendLine("],");
                    }
                    res.AppendLine("]");
                    return(res.ToString());
                }
            }

            var txt = Clipboard.GetText();

            if (!_serviceProvider.GetPythonToolsService().AdvancedOptions.PasteRemovesReplPrompts)
            {
                return(txt);
            }


            return(ReplPromptHelpers.RemovePrompts(
                       txt,
                       _window.TextView.Options.GetNewLineCharacter()
                       ));
        }