示例#1
0
        private async void PasteAsync()
        {
            var text = await((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))).GetTextAsync();

            if (text is null)
            {
                return;
            }

            var coords = CoordsParser.ExtractCoords(text);

            if (coords.HasValue)
            {
                var nextTextBox         = FindNext <ParameterTextBox>(this);
                var nextNextTextBox     = FindNext <ParameterTextBox>(nextTextBox);
                var nextNextNextTextBox = FindNext <ParameterTextBox>(nextNextTextBox);

                this.Text = coords.Value.x.ToString(CultureInfo.InvariantCulture);
                if (nextTextBox != null)
                {
                    nextTextBox.Text = coords.Value.y.ToString(CultureInfo.InvariantCulture);
                }
                if (nextNextTextBox != null)
                {
                    nextNextTextBox.Text = coords.Value.z.ToString(CultureInfo.InvariantCulture);
                }
                if (nextNextNextTextBox != null && coords.Value.o.HasValue)
                {
                    nextNextNextTextBox.Text = coords.Value.o.Value.ToString(CultureInfo.InvariantCulture);
                }
            }
            else
            {
                Paste();
            }
        }
 public void TestRandomSuffix()
 {
     Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("1, 2, 3, 4[random]"));
 }
 public void TestRandomPrefix()
 {
     Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("[1] position: 1, 2, 3, 4"));
 }
 public void TestMixedXyz()
 {
     Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("1 2, 3; 4"));
 }
 public void TestLettersColonXyzo()
 {
     Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("X: 1 Y: 2 Z: 3 O: 4"));
 }
 public void TestLettersXyzo()
 {
     Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("X 1 Y 2 Z 3 O 4"));
 }
 public void TestSemicolonXyz()
 {
     Assert.AreEqual((1f, 2f, 3f, O), CoordsParser.ExtractCoords("1; 2; 3"));
 }
 public void TestCommaXyz()
 {
     Assert.AreEqual((1f, 2f, 3f, O), CoordsParser.ExtractCoords("1, 2, 3"));
 }
 public void TestSpaceXyz()
 {
     Assert.AreEqual((1f, 2f, 3f, O), CoordsParser.ExtractCoords("1 2 3"));
     Assert.AreEqual((1.5f, 2.5f, 3.5f, O), CoordsParser.ExtractCoords("1.5 2.5 3.5"));
     Assert.AreEqual((-1.5f, -2.5f, -3.5f, O), CoordsParser.ExtractCoords("-1.5 -2.5 -3.5"));
 }