Example #1
0
        //--------------------------------------------------------------------------------------------------

        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.Key == Key.Return)
            {
                CommitTextChange();

                TraversalRequest tRequest      = new TraversalRequest(FocusNavigationDirection.Next);
                UIElement        keyboardFocus = Keyboard.FocusedElement as UIElement;

                keyboardFocus?.MoveFocus(tRequest);

                e.Handled = true;
            }
            else if ((e.Key == Key.OemPeriod) || (e.Key == Key.OemComma) || (e.Key == Key.Decimal))
            {
                if (Text.Contains(".") && !IsEvaluating)
                {
                    e.Handled = true;
                }
            }
            else if ((e.Key == Key.OemMinus) || (e.Key == Key.Subtract))
            {
                if ((CaretIndex != 0 && SelectionStart != 0 ||
                     Text.Contains("-") && !SelectedText.Contains("-")) &&
                    !IsEvaluating)
                {
                    e.Handled = true;
                }
            }

            base.OnKeyDown(e);
        }
Example #2
0
        /// <summary>
        /// clear base.SelectedText
        /// </summary>
        private void ClearSelection()
        {
            if (SelectionLength == 0)
            {
                return;
            }

            if (SelectedText.Length == base.Text.Length)
            {
                base.Text = 0.ToString(m_valueFormatStr);
                return;
            }

            var selLength = SelectedText.Length;

            if (SelectedText.IndexOf(m_decimalSeparator) > -1)
            {
                selLength--; // selected text contains dot(.), selected length minus 1
            }

            SelectionStart += SelectedText.Length; // after selected text
            SelectionLength = 0;

            for (var k = 1; k <= selLength; k++)
            {
                DeleteText(Keys.Back);
            }
        }
Example #3
0
 bool CheckKey(char _KeyChar)
 {
     if (_KeyChar == 8 || _KeyChar == 13 || _KeyChar >= 48 && _KeyChar <= 57)
     {
         //if (DataType == EnumType.Double)
         //{
         //     if (DisFormat=="0.0"&&Text.IndexOf(".") == Text.Length - 2 && _KeyChar >= 48 && _KeyChar <= 57) return false;
         //     else if (DisFormat == "0.0000" && Text.IndexOf(".") == Text.Length - 5 && _KeyChar >= 48 && _KeyChar <= 57) return false;
         //     return true;
         //}
         //else
         return(true);
     }
     if (DataType == EnumType.Double)
     {
         if (_KeyChar == '.')
         {
             return(Text.IndexOf(".") == -1 || SelectedText.IndexOf(".") != -1);
         }
     }
     if (DataType == EnumType.Double || DataType == EnumType.Integer)
     {
         if (canBeMinus == false)
         {
             return(false);
         }
         if (_KeyChar == '-')
         {
             return(SelectionStart == 0 && Text.IndexOf("-") == -1 || SelectedText.IndexOf("-") != -1);
         }
     }
     return(false);
 }
 private void adjustSelection()
 {
     while (SelectedText.EndsWith(" ") && SelectionLength > 0)
     {
         SelectionLength -= 1;
     }
 }
Example #5
0
        private void ClearSelection()
        {
            if (SelectionLength == 0)
            {
                return;
            }
            if (SelectedText.Length == base.Text.Length)
            {
                base.Text = 0.ToString(m_valueFormatStr);
                return;
            }
            int selLength = SelectedText.Length;

            if (SelectedText.IndexOf(m_decimalSeparator) >= 0)
            {
                selLength--;
            }
            SelectionStart += SelectedText.Length;
            SelectionLength = 0;

            for (int k = 1; k <= selLength; k++)
            {
                DeleteText(Keys.Back);
            }
        }
Example #6
0
        private void WalkAddingMenuItems(XmlNodeList nodes, ToolStripMenuItem parent)
        {
            if (nodes != null)
            {
                foreach (XmlNode n in nodes)
                {
                    ToolStripMenuItem curItem = null;

                    if (parent == null)
                    {
                        curItem = ContextMenuStrip.Items.Add(n.Attributes["name"].Value) as ToolStripMenuItem;
                    }
                    else
                    {
                        curItem = parent.DropDownItems.Add(n.Attributes["name"].Value) as ToolStripMenuItem;
                    }

                    curItem.Name = n.Attributes["name"].Value;

                    var snippets = n.SelectNodes("snip");
                    foreach (XmlNode snippet in snippets)
                    {
                        curItem.DropDownItems.Add(snippet.Attributes["name"].Value, null, delegate {
                            var sel      = Environment.NewLine + SelectedText.Trim() + Environment.NewLine;
                            SelectedText = string.Format(snippet.InnerText.Trim(), sel) + Environment.NewLine;
                        });
                    }

                    WalkAddingMenuItems(n.SelectNodes("node"), curItem);
                }
            }
        }
Example #7
0
        protected override bool ProcessCmdKey(ref Message msg, Keys e)
        {
            bool ctrlV    = e == (Keys.Control | Keys.V);
            bool shiftIns = e == (Keys.Shift | Keys.Insert);
            bool ctrlC    = e == (Keys.Control | Keys.C);
            bool ctrlX    = e == (Keys.Control | Keys.X);

            if (method == CopyMethod.Integers && (ctrlV || shiftIns))
            {
                var text = Clipboard.GetText();
                {
                    var split = new string[(text.Length / 2) + (text.Length % 2 == 0 ? 0 : 1)];
                    for (int i = 0; i < split.Length; i++)
                    {
                        split[i] = text.Substring(i * 2, (i * 2) + 2 > text.Length ? 1 : 2);
                    }
                    Clipboard.SetText(string.Join(" ", split));
                }
            }
            var handled = base.ProcessCmdKey(ref msg, e);

            if (method == CopyMethod.Integers)
            {
                if (ctrlC || ctrlX)
                {
                    if (string.IsNullOrWhiteSpace(SelectedText))
                    {
                        return(false);
                    }
                    Clipboard.SetText(string.Concat(SelectedText.Split(' ').Reverse()));
                    return(true);
                }
            }
            return(handled);
        }
Example #8
0
        /// <summary>
        /// Start a new search
        /// </summary>
        public string  getSearchTerm()
        {
            // If no text is selected, select the word
            if (SelectedText.Length == 0)
            {
                int wordStart = SelectionStart;
                while (wordStart > 0 && IsWordChar(Text[wordStart - 1]))
                {
                    wordStart--;
                }
                int wordEnd = SelectionStart;
                while (wordEnd < Text.Length && IsWordChar(Text[wordEnd]))
                {
                    wordEnd++;
                }


                return(Text.Substring(wordStart, wordEnd - wordStart));
            }
            else if (!SelectedText.Contains("\n")) // if selection is single line, use that as default
            {
                return(SelectedText);
            }
            else
            {
                return(null);
            }
        }
Example #9
0
        public void Render_AllowDHTMLIsTrueAndDropDownImage_RenderHTMLTextWriter(SelectedText changeToSelectedText, bool parentIsNull)
        {
            // Arrange
            var          stringWriter     = new StringWriter();
            var          outputTextWriter = new HtmlTextWriter(stringWriter);
            const string HiddenInput      = "<input type=\"hidden\"";

            _toolDropDownList.Page          = GetMockOfPage(string.Empty).Instance;
            _toolDropDownList.DropDownImage = DummyText;
            _toolDropDownList.Cellpadding   = new Unit(10);
            _toolDropDownList.Cellspacing   = new Unit(10);
            _toolDropDownList.BackImage     = DummyText;
            _toolDropDownList.Items.Add(new ToolItem(DummyText, DummyText));
            _toolDropDownList.SelectedIndex = 0;
            const string HeightValue = "height=\"100%\"";

            ShimControl.AllInstances.ParentGet = (obj) =>
            {
                return(parentIsNull ? null : stubToolbar);
            };
            _toolDropDownList.ChangeToSelectedText = changeToSelectedText;

            // Act
            _privateObject.Invoke(MethodRender, new object[] { outputTextWriter });
            var actualResult = stringWriter.ToString();

            // Assert
            actualResult.ShouldSatisfyAllConditions(
                () => actualResult.ShouldNotBeNullOrWhiteSpace(),
                () => actualResult.ShouldContain(HiddenInput),
                () => actualResult.ShouldContain(HeightValue),
                () => actualResult.ShouldContain(DummyText)
                );
        }
 void MenuActionCopy(object sender, EventArgs e)
 {
     Clipboard.Clear();
     if (!((String.IsNullOrEmpty(SelectedText) || SelectedText.Trim().Length == 0)))
     {
         Clipboard.SetText(base.SelectedText);
     }
 }
        private void SaveSelection()
        {
            string strSelectionData = string.Format("{{ \"selectedIndex\": \"{0}\", \"selectedValue\": \"{1}\", \"selectedText\": \"{2}\", \"selectedValues\": \"{3}\" }}",
                                                    SelectedIndex,
                                                    SelectedValue.Replace("\"", "\\\""),
                                                    SelectedText.Replace("\"", "\\\""),
                                                    ToString(GetSelectedValues(), ":"));

            hidSelectedData.Value = strSelectionData;
        }
Example #12
0
        private void btnAgree_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (tb_text.GetText() == "")
            {
                return;
            }

            SelectedText?.Invoke(tb_text.GetText());
            Close();
        }
Example #13
0
 void CopyCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         string text = SelectedText.Replace(" ", "");
         Clipboard.SetText(text);
     }
     catch
     {
     }
 }
Example #14
0
        //hack - might be a better way than using OnMouseUp...
        protected override void OnMouseUp(MouseEventArgs mevent)
        {
            base.OnMouseUp(mevent);

            string trimmed = SelectedText.Trim();

            if (trimmed.Length > 1)
            {
                Clipboard.SetText(trimmed, TextDataFormat.UnicodeText);
            }
            ResetSelection();
        }
Example #15
0
 public void UncommentSelectedLines()
 {
     SelectFullLines();
     if (SelectedText.TrimStart().StartsWith(COMMENT_DELIM_SLASH))
     {
         SelectedText = rxUncommentSlashes.Replace(SelectedText, "$1");
     }
     if (SelectedText.TrimStart().StartsWith(COMMENT_DELIM_DASH))
     {
         SelectedText = rxUncommentDashes.Replace(SelectedText, "$1");
     }
 }
Example #16
0
        private void CodeEditor_SelectionChanged(object sender, RoutedEventArgs e)
        {
            TextToHighlight = null;
            //Get caret position and highlight the blocks that are needed
            int caretPosition = CaretIndex;

            //If the caret is not valid, caret reset
            if (caretPosition < 1 || caretPosition >= Text.Length)
            {
                return;
            }
            //Check if the selected text is a word and fi we can highlight it
            if (SelectedText.IndexOf(' ') == -1)
            {
                //If only accepted chars and is there more than once
                if (Regex.IsMatch(SelectedText, @"(?i)^[a-z_\-0-9]+") &&
                    Regex.Matches(Text, SelectedText).Count > 1)
                {
                    TextToHighlight = new Regex(@"\b" + SelectedText + @"\b");
                }
            }
            //if the caret is near an opening bracket, the caret can be before or after the caret
            if (Text.Substring(caretPosition, 1).Contains("{"))
            {
                openBracketPos  = caretPosition;
                closeBracketPos = CodeHelper.getAssociatedClosingBracket(Text, caretPosition);
            }
            else if (Text.Substring(caretPosition - 1, 1).Contains("{"))
            {
                caretPosition  -= 1;
                openBracketPos  = caretPosition;
                closeBracketPos = CodeHelper.getAssociatedClosingBracket(Text, caretPosition);
            }
            //else if the caret is near a closing bracket, the caret can be before or after the caret
            else if (Text.Substring(caretPosition, 1).Contains("}"))
            {
                openBracketPos  = CodeHelper.getAssociatedOpeningBracket(Text, caretPosition);
                closeBracketPos = caretPosition;
            }
            else if (Text.Substring(caretPosition - 1, 1).Contains("}"))
            {
                caretPosition  -= 1;
                openBracketPos  = CodeHelper.getAssociatedOpeningBracket(Text, caretPosition);
                closeBracketPos = caretPosition;
            }
            else
            {
                openBracketPos  = -1;
                closeBracketPos = -1;
            }
            InvalidateBlocks(caretPosition);
            InvalidateVisual();
        }
Example #17
0
        public bool DeleteSelectedText()
        {
            if (SelectedText.IsEmpty)
            {
                return(false);
            }

            TextLines.DeleteInBounds(SelectedText);
            CurrentPosition = new TextPosition(SelectedText.RealStart);
            SelectedText.Invalidate();
            return(true);
        }
Example #18
0
        public void Find(string s)
        {
            findBox.Text = s;
            findIndex    = CaretIndex;

            if (SelectedText.ToUpperInvariant() == findBox.Text.ToUpperInvariant())
            {
                findIndex = CaretIndex + 1;
            }

            FindNext();
        }
Example #19
0
 public void UncommentSelectedLines()
 {
     SelectFullLines();
     if (SelectedText.TrimStart().StartsWith(COMMENT_DELIM_SLASH, StringComparison.InvariantCultureIgnoreCase))
     {
         SelectedText = rxUncommentSlashes.Replace(SelectedText, "$1");
     }
     if (SelectedText.TrimStart().StartsWith(COMMENT_DELIM_DASH, StringComparison.InvariantCultureIgnoreCase))
     {
         SelectedText = rxUncommentDashes.Replace(SelectedText, "$1");
     }
 }
Example #20
0
        private void SaveText(object commandParameter)
        {
            string tempSelectedText = "";

            foreach (var item in BranchItemCheckedStates)
            {
                string tempBranchItemName = "[" + item.BranchItem.BranchItemName + "]";
                if (SelectedText.Contains(tempBranchItemName))
                {
                    tempSelectedText += tempBranchItemName + "; ";
                }
            }
            SelectedText = tempSelectedText;
        }
Example #21
0
 private void FilterSuggestions()
 {
     if (!string.IsNullOrEmpty(SelectedText) && SelectedText.Length > 3)
     {
         string matchText    = SelectedText.ToUpper();
         var    matchedItems = _suggestions.Where(t => t.Text.ToUpper().Contains(matchText)).ToList();
         Suggestions = matchedItems;
         RaisePropertyChanged(nameof(Suggestions));
     }
     else
     {
         Suggestions = new List <Suggestion>();
         RaisePropertyChanged(nameof(Suggestions));
     }
 }
    void ToggleSelection()
    {
        switch (selectedText)
        {
        case SelectedText.START:
            startText.fontStyle = FontStyle.Normal;
            loadText.fontStyle  = FontStyle.Bold;
            selectedText        = SelectedText.LOAD;
            break;

        case SelectedText.LOAD:
            loadText.fontStyle  = FontStyle.Normal;
            startText.fontStyle = FontStyle.Bold;
            selectedText        = SelectedText.START;
            break;
        }
    }
Example #23
0
        protected virtual void InitContextMenu()
        {
            var c = new ContextMenuStrip();

            c.Items.Add("Cut", null, delegate { Cut(); });
            c.Items.Add("Copy", null, delegate { Copy(); });
            c.Items.Add("Paste", null, delegate { Paste(); });
            c.Items.Add("Delete", null, delegate { SelectedText = ""; });
            c.Items.Add("-");
            c.Items.Add("Select All", null, delegate { SelectAll(); });
            c.Items.Add("-");
            c.Items.Add("Upcase", null, delegate { SelectedText = SelectedText.ToUpper(); });
            c.Items.Add("Downcase", null, delegate { SelectedText = SelectedText.ToLower(); });
            c.Items.Add("-");

            ContextMenuStrip = c;
        }
Example #24
0
        /*
         * /// <summary>
         * /// Overriden Undo to undo replace operations
         * /// </summary>
         * /// <remarks>
         * /// Would be a lot simpler if the framework controls gave you access to their undo stack
         * /// </remarks>
         * public new void Undo()
         * {
         *  if (Text.Equals(textAfterReplace))
         *  {
         *      Text = textBeforeReplace;
         *  }
         *  else
         *  {
         *      // Call ordinary undo
         *      base.Undo();
         *  }
         * }
         */

        /*
         * /// <summary>
         * /// Overridden CanUndo to include local undo operation
         * /// </summary>
         * public new bool CanUndo
         * {
         *  get
         *  {
         *      if (Text.Equals(textAfterReplace))
         *      {
         *          return true; // Next undo would be our replace cancel operation
         *      }
         *      else
         *      {
         *          // Call ordinary CanUndo
         *          return base.CanUndo;
         *      }
         *  }
         * }
         * */

        /*
         * /// <summary>
         * /// Redo to redo replace operations
         * /// </summary>
         * public void Redo()
         * {
         *  if (Text.Equals(textBeforeReplace))
         *  {
         *      Text = textAfterReplace;
         *  }
         *
         * }
         * */

        /// <summary>
        /// Start a new search
        /// </summary>
        private void NewSearch(bool replaceMode)
        {
            // If no text is selected, select the word
            if (SelectedText.Length == 0)
            {
                int wordStart = SelectionStart;
                while (wordStart > 0 && IsWordChar(Text[wordStart - 1]))
                {
                    wordStart--;
                }
                int wordEnd = SelectionStart;
                while (wordEnd < Text.Length && IsWordChar(Text[wordEnd]))
                {
                    wordEnd++;
                }

                // Store the selection start position on the first search so that when all searches are complete
                // this fact can be reported to the user in the find dialog.
                originalSelectionStart = wordEnd; // matching behaviour of various MS apps
                if (searchStarted != null)
                {
                    searchStarted(Text.Substring(wordStart, wordEnd - wordStart));
                }
                findDialog1.Show(Text.Substring(wordStart, wordEnd - wordStart), replaceMode);
            }
            else if (!SelectedText.Contains("\n"))       // if selection is single line, use that as default
            {
                originalSelectionStart = SelectionStart; // matching behaviour of various MS apps
                if (searchStarted != null)
                {
                    searchStarted(SelectedText);
                }
                findDialog1.Show(SelectedText, replaceMode);
            }
            else
            {
                originalSelectionStart = SelectionStart;
                if (searchStarted != null)
                {
                    searchStarted(SelectedText);
                }
                findDialog1.Show(replaceMode);
            }
        }
Example #25
0
        /// <summary>
        /// Loads top level entry list
        /// </summary>
        /// <history>
        ///     [tamttt] 20/10/2004	Created
        /// </history>
        private void BindListInfo()
        {
            string listName = SelectedText.Substring(SelectedText.IndexOf(":") + 1);
            string parent   = SelectedText.Replace(listName, "").TrimEnd(':');

            this.lblListParent.Text = parent;
            this.lblListName.Text   = listName;

            this.rowListParent.Visible = (selListInfo.Parent.Length > 0); //(parent.Length > 0)
            if (!SystemList)
            {
                this.cmdDeleteList.Visible = true;
                ClientAPI.AddButtonConfirm(cmdDeleteList, Localization.GetString("DeleteItem"));
            }
            else
            {
                this.cmdDeleteList.Visible = false;
            }
        }
Example #26
0
 public void ToggleComment()
 {
     if (Language == FastColoredTextBoxNS.Language.Custom)
     {
         Selection = GetLinesFromSelection();
         if (SelectedText.Trim().StartsWith("//"))
         {
             UncommentSelectedLines();
         }
         else
         {
             CommentSelectedLines();
         }
     }
     else
     {
         CommentSelected();
     }
     OnSyntaxHighlight(new TextChangedEventArgs(Selection));
 }
Example #27
0
        private bool EnteringDuplicateChar(char ch)
        {
            bool bResult = false;

            if (base.Text.IndexOf(ch) >= 0)
            {
                if (SelectionLength > 0)
                {
                    if (SelectedText.IndexOf(ch) >= 0)
                    {
                        bResult = true;
                    }
                }
                else
                {
                    bResult = true;
                }
            }

            return(bResult);
        }
        /// <summary>
        /// Event raised when the user right-clicks in the textbox.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _context_Popup(object sender, EventArgs e)
        {
            string word = SelectedText.Trim();

            if (word.Length > 0)
            {
                // Show the wait cursor in case the web service call takes a little while.
                System.Windows.Forms.Cursor c = Cursor;
                base.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                base.ContextMenu.MenuItems.Clear();

                _context = new System.Windows.Forms.ContextMenu();

                List <string> rhymingWords = RhymingWords.GetRhymes(word);

                // Assign the click events to the same handler and determine what was picked there.
                foreach (string rhymedWord in rhymingWords)
                {
                    _context.MenuItems.Add(new System.Windows.Forms.MenuItem(rhymedWord, _menuClickDelegate));
                }

                if (rhymingWords.Count == 0)
                {
                    System.Windows.Forms.MenuItem mi = new System.Windows.Forms.MenuItem("[No rhymes found]");
                    mi.Enabled = false;
                    _context.MenuItems.Add(mi);
                }

                // Show the menu of the rhyming words.
                base.ContextMenu = _context;
                base.Cursor      = c;
                base.ContextMenu.Show(this, _mouseLocation);

                // Seem to have to unsubscribe and resubscribe
                // or this popup menu handler isn't called.
                base.ContextMenu.Popup -= _popupDelegate;
                base.ContextMenu.Popup += _popupDelegate;
            }
        }
Example #29
0
 protected override void OnKeyPress(KeyPressEventArgs e)
 {
     if (e.KeyChar == '\t' && SelectedText.Contains(Environment.NewLine))
     {
         string start = string.Empty;
         if (SelectionStart > 0)
         {
             start = Text.Substring(0, SelectionStart);
         }
         string exchange = Text.Substring(SelectionStart, SelectionLength);
         string end      = string.Empty;
         if (SelectionStart + SelectionLength < Text.Length - 1)
         {
             end = Text.Substring(SelectionStart + SelectionLength);
         }
         Text = start + '\t' +
                exchange.Replace(Environment.NewLine, Environment.NewLine + "\t") +
                end;
         e.Handled = true;
     }
     base.OnKeyPress(e);
 }
Example #30
0
        //--------------------------------------------------------------------------------------------------

        protected override void OnTextChanged(TextChangedEventArgs e)
        {
            using (DeclareChangeBlock())
            {
                foreach (var c in e.Changes)
                {
                    if (c.AddedLength == 0)
                    {
                        continue;
                    }
                    Select(c.Offset, c.AddedLength);
                    if (SelectedText.Contains(","))
                    {
                        SelectedText = SelectedText.Replace(',', '.');
                    }
                    Select(c.Offset + c.AddedLength, 0);
                }
            }

            var text = Text;

            if (text.Length == 0)
            {
                Text = "0";
            }
            else
            {
                if (text[0] == '.')
                {
                    Text.Insert(0, "0");
                }
            }

            EvaluateExpression();

            base.OnTextChanged(e);
        }