private void ApplyAutocomplete(AutocompleteItem item, Range fragment)
        {
            var newText = item.GetTextForReplace();
            //replace text of fragment


            var index = fragment.Text.IndexOfAny(SpecialSymbols.SuperscriptsWithoutSpace.ToCharArray());

            if (index == 0)
            {
                newText = SpecialSymbols.AsciiToSuperscript(newText);
            }
            else if (index > 0)
            {
                newText = fragment.Text.Substring(0, index) + SpecialSymbols.AsciiToSuperscript(newText);
            }
            else if (SharedViewState.Instance.IsExponent)
            {
                newText = fragment.Text + SpecialSymbols.AsciiToSuperscript(newText);
            }


            fragment.Text = newText;
            fragment.TargetWrapper.TargetControl.Focus();
        }
Esempio n. 2
0
        private void ExpressionTextBox_KeyPress(object s, KeyPressEventArgs e)
        {
            if (_sharedViewState.IsExponent)
            {
                if (SpecialSymbols.AsciiForSuperscripts.Contains(e.KeyChar))
                {
                    e.KeyChar = SpecialSymbols.AsciiToSuperscript(e.KeyChar);
                }
            }

            if (IsOperator(e.KeyChar))
            {
                if (e.KeyChar == SpecialSymbols.ExponentModeSymbol)
                {
                    _sharedViewState.IsExponent = !_sharedViewState.IsExponent;
                    _showCaret();
                    // EventAggregator.Instance.Publish<ExponentModeChangedEvent>(new ExponentModeChangedEvent(_sharedViewState.IsExponent));
                    e.Handled = true;
                    //return;
                }

                if (e.KeyChar == '*')
                {
                    e.KeyChar = SpecialSymbols.DotSymbol;
                    //for (int i = 0; i < this.AutoCompleteCustomSource.Count; i++)
                    // this.AutoCompleteCustomSource[i] += Text + e.KeyChar;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Takes folder name and returns a cleaned up version, with alternate names swapped out
        /// </summary>
        /// <param name="foldername">name of folder as it is on file system</param>
        /// <returns>resulting command name</returns>
        private string ResolveName(string foldername)
        {
            // allow for ordering of folders, multiple folders with same command
            foldername = GetRegex(foldername, @"\d+ (.*)");     // remove leading number
            foldername = GetRegex(foldername, @"(.*) \(\d+\)"); // remove parentheses & number from end
            foldername = GetRegex(foldername, @"(.*) - Copy");  // remove Copy

            foldername = SpecialSymbols.Decode(foldername);

            // if we have a command using an alternate name, match it here
            if (SpecialSymbols.AltCommandNames.Keys.Contains(foldername.Trim()))
            {
                foldername = SpecialSymbols.AltCommandNames[foldername];
            }
            return(foldername.Trim());
        }
Esempio n. 4
0
        private static string NormalizeString(string str)
        {
            var index = str.IndexOfAny(SpecialSymbols.SuperscriptsWithoutSpace.ToCharArray());


            var normalizedFragmentText = str;

            if (index != -1)
            {
                normalizedFragmentText = str.Substring(index);
            }


            normalizedFragmentText = SpecialSymbols.SuperscriptsToAscii(normalizedFragmentText).ToLowerInvariant();
            return(normalizedFragmentText);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.Key == Key.D6 &&
                (Keyboard.Modifiers & ModifierKeys.Shift) ==
                ModifierKeys.Shift)
            {
                _sharedViewState.IsExponent = !_sharedViewState.IsExponent;

                e.Handled = true;
                return;
            }

            if (_sharedViewState.IsExponent)
            {
                var ch = GetCharFromKey(e.Key);
                if (SpecialSymbols.IsAscii(ch))
                {
                    var str = SpecialSymbols.AsciiToSuperscript(ch.ToString());
                    if (string.IsNullOrWhiteSpace(str))
                    {
                    }
                    else
                    {
                        TextArea.PerformTextInput(str);
                    }
                }
                e.Handled = true;
            }
            else
            {
                if (e.Key == Key.Multiply)
                //     e = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, GlobalConfig.dotSymbol);
                {
                    TextArea.PerformTextInput(SpecialSymbols.DotSymbol + "");
                    e.Handled = true;
                }
                else
                {
                    base.OnKeyDown(e);
                }
            }
        }
Esempio n. 6
0
        private string ReplacePow(string input) //OK
        {
            var nativeCompilerCompatiblePowerNotation = @"pow($1,$2)$3";

            var result = input;

            while (expressionInParenthesesRaisedToAnyPowerRegex.IsMatch(result))
            {
                result = expressionInParenthesesRaisedToAnyPowerRegex.Replace(result,
                                                                              //http://stackoverflow.com/questions/7898310/using-regex-to-balance-match-parenthesis
                                                                              nativeCompilerCompatiblePowerNotation);
            }

            result = numberRaisedToAnyPowerRegex.Replace(result, nativeCompilerCompatiblePowerNotation);

            result = variableRaisedToAnyPowerRegex.Replace(result, nativeCompilerCompatiblePowerNotation);

            result = SpecialSymbols.SuperscriptsToAscii(result);

            return(result);
        }
Esempio n. 7
0
        public ModeDeterminer(ITslCompiler tslCompiler)
        {
            _tslCompiler = tslCompiler;
            //  FindX = new Regex(pre + "x" + post, RegexOptions.Compiled);
            FindY =
                new Regex(
                    mergePatterns(pre + "y" + post,
                                  preExponent + SpecialSymbols.AsciiToSuperscript("y") + postExponent),
                    RegexOptions.Compiled);

            FindZ =
                new Regex(
                    mergePatterns(pre + "z" + post,
                                  preExponent + SpecialSymbols.AsciiToSuperscript("z") + postExponent),
                    RegexOptions.Compiled);

            FindI =
                new Regex(
                    mergePatterns(pre + "i" + post,
                                  preExponent + SpecialSymbols.AsciiToSuperscript("i") + postExponent),
                    RegexOptions.Compiled);
        }
Esempio n. 8
0
        private void ParseExpression(string path, StringBuilder program)
        {
            DirectoryInfo baseDir = new DirectoryInfo(path);

            string commandtext = ResolveName(baseDir.Name);

            switch (commandtext)
            {
            case "string":     // if it's a string, grab the content and put quotes around it
                program.Append("\"" + SpecialSymbols.Decode(baseDir.GetDirectories()[0].Name) + "\"");
                break;

            case "int":
            case "float":
            case "char":
                program.Append(SpecialSymbols.Decode(baseDir.GetDirectories()[0].Name));
                break;

            default:     // if we don't know what it is, treat as a literal
                program.Append(ResolveName(baseDir.Name));
                break;
            }
        }
Esempio n. 9
0
        private void ApplyAutocomplete(AutocompleteItem item, Range fragment)
        {
            var newText = item.GetTextForReplace();
            //replace text of fragment

            var expressionTextBox = (TargetControlWrapper.TargetControl as ExpressionTextBox);
            var scintillaEditor   =
                (TargetControlWrapper.TargetControl as ScintillaCodeEditorControl);

            var isExponent = false;

            if (expressionTextBox != null)
            {
                isExponent = expressionTextBox.ExponentMode;
            }
            else if (scintillaEditor != null)
            {
                isExponent = scintillaEditor.ExponentMode;
            }


            fragment.Text = isExponent ? SpecialSymbols.AsciiToSuperscript(newText) : newText;
            fragment.TargetWrapper.TargetControl.Focus();
        }
Esempio n. 10
0
        private void NumericTextBox_TextChanged(object sender, EventArgs e)
        {
            if (!Text.Contains('E') && !Text.Contains('e'))
            {
                return;
            }

            var chunks = Text.Split('E', 'e', 'i');

            if (!Text.Contains('i'))
            {
                Text = chunks[0] + SpecialSymbols.DotSymbol + "10" +
                       SpecialSymbols.AsciiToSuperscript(chunks[1]);
            }
            else
            {
                //1. -1E-11 + 5E-11i
                if (Text.Count(c => c == 'E') >= 2)
                {
                    var midChunk = chunks[1].Insert(chunks[1].LastIndexOfAny(new[] { '+', '-' }) + 1, "(");

                    var midChunks = midChunk.Split(new[] { "+(", "-(", "+ (", "- (" },
                                                   StringSplitOptions.RemoveEmptyEntries);

                    Text = chunks[0] + SpecialSymbols.DotSymbol + "10" +
                           SpecialSymbols.AsciiToSuperscript(midChunks[0]) +
                           midChunk.Substring(midChunk.LastIndexOfAny(new[] { '+', '-' })) +
                           SpecialSymbols.DotSymbol + "10" +
                           SpecialSymbols.AsciiToSuperscript(chunks[2]) + ")" +
                           SpecialSymbols.DotSymbol + "i";
                }
                else
                {
                    if (chunks[0].Count(c => c == '+') == 0 &&
                        Regex.IsMatch(chunks[1], @"^[+\-]?(\d+)$") &&
                        Regex.IsMatch(chunks[0], @"^-?(\d+\.?\d*)$"))
                    {
                        //2.      5E-11i//-5·16²²·i
                        Text = "(" + chunks[0] + SpecialSymbols.DotSymbol + "10" +
                               SpecialSymbols.AsciiToSuperscript(chunks[1]) + ")" +
                               SpecialSymbols.DotSymbol + "i";
                    }


                    //3. -1 + 5E-11i//-5·16²²·i+22
                    else if (Regex.IsMatch(chunks[0], @"^-?(\d+\.?\d*)[\+\-](\d+\.?\d*)$"))
                    {
                        Text = chunks[0].Insert(chunks[0].LastIndexOfAny(new[] { '+', '-' }) + 1, "(") +
                               SpecialSymbols.DotSymbol + "10" +
                               SpecialSymbols.AsciiToSuperscript(chunks[1]) + ")" +
                               SpecialSymbols.DotSymbol + "i";
                    }


                    //4. -1E-11 + 5i
                    else if (Regex.IsMatch(chunks[1],
                                           @"^[+\-]?(\d+)[\+\-](\d+\.?\d*)$"))
                    {
                        var chunk11 = chunks[1].Substring(0, chunks[1].LastIndexOfAny(new[] { '+', '-' }));

                        var chunk12 = chunks[1].Substring(chunks[1].LastIndexOfAny(new[] { '+', '-' }));


                        Text = chunks[0] +
                               SpecialSymbols.DotSymbol + "10" +
                               SpecialSymbols.AsciiToSuperscript(chunk11) +
                               chunk12 + SpecialSymbols.DotSymbol + "i";
                    }
                }
            }
        }
        private void SciriptingRichTextBox_KeyPress(object s, KeyPressEventArgs e)
        {
            if (e.KeyChar < 32)
            {
                // Prevent control characters from getting inserted into the text buffer
                e.Handled = true;
                return;
            }

            if (_sharedViewState.IsExponent)
            {
                if (SpecialSymbols.AsciiForSuperscripts.Contains(e.KeyChar))
                {
                    e.KeyChar = SpecialSymbols.AsciiToSuperscript(e.KeyChar);
                }
            }

            if (IsOperator(e.KeyChar))
            {
                if (e.KeyChar == SpecialSymbols.ExponentModeSymbol)
                {
                    _sharedViewState.IsExponent = !_sharedViewState.IsExponent;
                    //_showCaret();
                    e.Handled = true;
                    //return;
                    //this.Refresh();
                }

                if (e.KeyChar == '*')
                {
                    e.KeyChar = SpecialSymbols.DotSymbol;
                    //for (int i = 0; i < this.AutoCompleteCustomSource.Count; i++)
                    // this.AutoCompleteCustomSource[i] += Text + e.KeyChar;
                }
            }


            /*
             * if (e.KeyChar == '^')
             * {
             *  ExponentMode = !ExponentMode;
             *  e.Handled = true;
             *  return;
             * }
             *
             * if (ExponentMode)
             * {
             *  e.Handled = true;
             *
             *  if (SpecialSymbols.AsciiForSuperscripts.Contains(e.KeyChar))
             *  {
             *      var str = SpecialSymbols.AsciiToSuperscript(e.KeyChar + "");
             *
             *      var byteOffset = CurrentPosition;
             *
             *      var range = GetTextRange(0, byteOffset);
             *      var charOffset = range.Length;
             *
             *      var positionInDocument = charOffset;
             *
             *      var caretPos = AnchorPosition; //Caret.Position;
             *      if (!string.IsNullOrEmpty(str) && !string.IsNullOrWhiteSpace(str))
             *      {
             *          Text = Text.Insert(positionInDocument, str);
             *          GotoPosition(caretPos + 1);
             *          Focus();
             *      }
             *  }
             * }
             * else if (e.KeyChar == '*')
             * {
             *  e.KeyChar = SpecialSymbols.DotSymbol;
             * }*/
        }
Esempio n. 12
0
 private static string ReplaceMatchWithPow(Match match)
 {
     return(match.Result(NativeCompilerCompatiblePowerNotation.Replace("$2",
                                                                       SpecialSymbols.SuperscriptsToAscii(match.Groups[2].Value))));
 }