private void SmartQuotesPlugInCommandExecuting(CommandExecutingEventArgs ea) { if (!ea.CancelDefault && ea.CommandName == "Edit.DeleteBackwards") { TextViewCaret caret = GetCaretInActiveFocusedView(); if (caret != null) { if (this.settings.UseSmartDoubleQuotes && this.settings.DoubleQuotesEasyDelete && caret.LeftChar == '\"' && caret.RightChar == '\"' && CanExecuteFeature("Easy delete", "Deletes empty quotes and double quotes")) { EasyDelete(caret, this.settings.DoubleQuotesUseTextFields); return; } if (this.settings.UseSmartQuotes && this.settings.QuotesEasyDelete && caret.LeftChar == '\'' && caret.RightChar == '\'' && CanExecuteFeature("Easy delete", "Deletes empty quotes and double quotes")) { EasyDelete(caret, this.settings.QuotesUseTextFields); return; } } } }
private void Refactor_SplitString_KeyPressed(KeyPressedEventArgs ea) { if (this.settings.SmartEnterSplitString && ea.IsEnter && !ea.ShiftKeyDown && !ea.AltKeyDown && !ea.CtrlKeyDown) { TextViewCaret caret = GetCaretInActiveFocusedView(); if (caret != null) { CodeRush.Source.ParseIfTextChanged(); if (CodeRush.Caret.InsideString && CaretInCodeEditor()) { CodeRush.SmartTags.UpdateContext(); RefactoringProviderBase splitString = CodeRush.Refactoring.Get("Split String"); if (splitString != null && IsRefactoringAvailable(splitString)) { splitString.Execute(); if (this.settings.LeaveConcatenationOperatorAtTheEndOfLine) { caret.MoveRight(1); } caret.Insert(CodeRush.Language.LineContinuationCharacter, true); return; } } } } }
private void SmartQuotesPlugInEditorCharacterTyping(EditorCharacterTypingEventArgs ea) { TextViewCaret caret = GetCaretInActiveFocusedView(); if (caret != null) { if (this.settings.UseSmartDoubleQuotes && this.settings.DoubleQuotesIgnoreClosingQuote && ea.Character == '\"' && CaretBeforeClosingDoubleQuote(caret)) { ea.Cancel = true; IgnoreClosingCharacter(caret, this.settings.DoubleQuotesUseTextFields); return; } if (this.settings.UseSmartQuotes && this.settings.QuotesIgnoreClosingQuote && ea.Character == '\'' && CaretBeforeClosingQuote(caret)) { ea.Cancel = true; IgnoreClosingCharacter(caret, this.settings.QuotesUseTextFields); return; } } }
private void SmartQuotesPlugInEditorCharacterTyped(EditorCharacterTypedEventArgs ea) { TextViewCaret caret = GetCaretInActiveFocusedView(); if (caret != null) { if (this.settings.UseSmartDoubleQuotes && this.settings.DoubleQuotesAutoComplete && ea.Character == '\"' && CaretInCodeEditor() && !IsLastCharacterEscaped(caret.LeftText) && CanExecuteFeature("Smart double quotes", "Auto completes closing double quotes")) { InsertClosingCharacter(caret, "\"", this.settings.DoubleQuotesUseTextFields); return; } if (this.settings.UseSmartQuotes && this.settings.QuotesAutoComplete && ea.Character == '\'' && CaretInCodeEditor() && !IsLastCharacterEscaped(caret.LeftText) && CanExecuteFeature("Smart quotes", "Auto completes closing quote")) { CodeRush.Source.ParseIfTextChanged(); if (CaretWithinNaturalLanguage()) { // to prevent double apostrophes e.g. in English phrases return; } InsertClosingCharacter(caret, "\'", this.settings.QuotesUseTextFields); return; } } }
private static void EasyDelete(TextViewCaret caret, bool useTextField) { caret.DeleteRight(1); if (useTextField && CaretInsideTextField()) { AcceptActiveTextField(); } }
private static void IgnoreClosingCharacter(TextViewCaret caret, bool useTextField) { if (useTextField && CaretInsideTextField()) { AcceptActiveTextField(); } else { caret.MoveRight(1); } }
private static void InsertClosingCharacter(TextViewCaret caret, string character, bool useTextField) { caret.Insert(character, false); if (useTextField) { if (CaretInsideTextField()) { BreakActiveTextField(); } InsertTextFieldAt(caret); } }
private static void IgnoreClosingCharacter(TextViewCaret caret, bool useTextField) { if (useTextField && CaretInsideTextField()) { AcceptActiveTextField(); } else { while (caret.RightChar != '>') { caret.MoveRight(1); } caret.MoveRight(1); } }
private static void EasyDelete(TextViewCaret caret, bool useTextField) { while (caret.RightChar != '>') { caret.DeleteRight(1); } while (caret.LeftChar != '<') { caret.DeleteLeft(1); } caret.DeleteRight(1); if (useTextField && CaretInsideTextField()) { AcceptActiveTextField(); } }
private static void EasyDelete(TextViewCaret caret, bool useTextField) { while (caret.RightChar != '>') { caret.DeleteRight(1); } while (caret.LeftChar != '<') { caret.DeleteLeft(1); } caret.DeleteRight(1); if (useTextField && CaretInsideTextField()) { AcceptActiveTextField(); } }
private static void InsertTextFieldAt(TextViewCaret caret) { TextDocument document = caret.TextDocument; EditPoint startEditPoint = CodeRush.EditPoints.New(document, caret.SourcePoint); startEditPoint.IsAnchorable = true; EditPoint endEditPoint = CodeRush.EditPoints.New(document, caret.SourcePoint); endEditPoint.IsPushable = true; TextField newField = new TextField(startEditPoint, endEditPoint, "Enter string value", TextFieldType.Normal, false); EditPoint targetPoint = endEditPoint.Clone(); targetPoint.MoveRight(1); TextFieldTarget newTarget = new TextFieldTarget(targetPoint, targetPoint); document.TextFields.Add(newField); document.TextFieldTarget = newTarget; }
private static CategorizedToken GetLeftToken(TextViewCaret caret) { TextDocument document = caret.TextDocument; if (document == null) { return(null); } TokenCollection tokens = CodeRush.Language.GetTokens(caret.LeftText); if (tokens != null && tokens.Count > 1) { Token token = tokens[tokens.Count - 2]; return(token as CategorizedToken); } return(null); }
private static bool IsNamespaceOrAlias(TextViewCaret caret, CategorizedToken token) { foreach (DictionaryEntry @namespace in caret.TextDocument.NamespaceReferences) { if (@namespace.Key.ToString() == token.Value) { return(true); } } foreach (string alias in caret.TextDocument.Aliases) { if (alias == token.Value) { return(true); } } return(false); }
private static bool IsPossibleTypeOrMethodName(TextViewCaret caret, CategorizedToken token) { if (token == null) { return(false); } if (token.Category != TokenCategory.Identifier) { return(false); } if (IsFieldOrPropertyOrVariable(token)) { return(false); } if (IsNamespaceOrAlias(caret, token)) { return(false); } return(true); }
private void CR_SmartGenerics_EditorCharacterTyping(EditorCharacterTypingEventArgs ea) { if (!CodeRush.Language.IsCSharp) { return; } TextViewCaret caret = GetCaretInActiveFocusedView(); if (caret != null && this.settings.UseSmartGenerics && this.settings.SmartGenericsIgnoreClosingGeneric && ea.Character == '>' && IsRightTextStartedWithCloseGenericOperator(caret) && IsInsideGenerics()) { ea.Cancel = true; IgnoreClosingCharacter(caret, this.settings.SmartGenericsUseTextFields); return; } }
private static void InsertClosingCharacter(TextViewCaret caret, bool useTextField, bool addSpace) { if (addSpace) { caret.Insert(" >", false); caret.MoveRight(1); } else { caret.Insert(">", false); } if (useTextField) { if (CaretInsideTextField()) { BreakActiveTextField(); } InsertTextFieldAt(caret); } }
private static void InsertClosingCharacter(TextViewCaret caret, bool useTextField, bool addSpace) { if (addSpace) { caret.Insert(" >", false); caret.MoveRight(1); } else { caret.Insert(">", false); } if (useTextField) { if (CaretInsideTextField()) { BreakActiveTextField(); } InsertTextFieldAt(caret); } }
private void CR_SmartGenerics_CommandExecuting(CommandExecutingEventArgs ea) { if (!CodeRush.Language.IsCSharp) { return; } if (!ea.CancelDefault && ea.CommandName == "Edit.DeleteBackwards") { TextViewCaret caret = GetCaretInActiveFocusedView(); if (caret != null && this.settings.UseSmartGenerics && this.settings.SmartGenericsEasyDelete && IsInsideGenerics() && IsLeftTextEndedWithOpenGenericOperator(caret) && IsRightTextStartedWithCloseGenericOperator(caret) && CanExecuteFeature("Easy delete", "Deletes empty generics characters")) { EasyDelete(caret, this.settings.SmartGenericsUseTextFields); return; } } }
private void CR_SmartGenerics_EditorCharacterTyped(EditorCharacterTypedEventArgs ea) { if (!CodeRush.Language.IsCSharp) { return; } TextViewCaret caret = GetCaretInActiveFocusedView(); if (caret != null && this.settings.UseSmartGenerics && this.settings.SmartGenericsAutoComplete && ea.Character == '<' && CaretInCodeEditor()) { CodeRush.Source.ParseIfNeeded(); if (NeedGenerics(caret) && CanExecuteFeature("Smart generics", "Auto completes closing generics char (\">\")")) { InsertClosingCharacter(caret, this.settings.SmartGenericsUseTextFields, this.settings.SmartGenericsAddSpace); return; } } }
private static bool IsPossibleTypeOrMethodName(TextViewCaret caret, CategorizedToken token) { if (token == null) { return false; } if (token.Category != TokenCategory.Identifier) { return false; } if (IsFieldOrPropertyOrVariable(token)) { return false; } if (IsNamespaceOrAlias(caret, token)) { return false; } return true; }
private static bool IsNamespaceOrAlias(TextViewCaret caret, CategorizedToken token) { foreach (DictionaryEntry @namespace in caret.TextDocument.NamespaceReferences) { if (@namespace.Key.ToString() == token.Value) { return true; } } foreach (string alias in caret.TextDocument.Aliases) { if (alias == token.Value) { return true; } } return false; }
private static void InsertTextFieldAt(TextViewCaret caret) { TextDocument document = caret.TextDocument; EditPoint startEditPoint = CodeRush.EditPoints.New(document, caret.SourcePoint); startEditPoint.IsAnchorable = true; EditPoint endEditPoint = CodeRush.EditPoints.New(document, caret.SourcePoint); endEditPoint.IsPushable = true; TextField newField = new TextField(startEditPoint, endEditPoint, "Enter generic parameter(s)", TextFieldType.Normal, false); EditPoint targetPoint = endEditPoint.Clone(); targetPoint.MoveRight(1); TextFieldTarget newTarget = new TextFieldTarget(targetPoint, targetPoint); document.TextFields.Add(newField); document.TextFieldTarget = newTarget; }
private static bool IsLeftTextEndedWithOpenGenericOperator(TextViewCaret caret) { return caret.LeftText.TrimEnd(whiteSpaces).EndsWith("<"); }
private static bool NeedGenerics(TextViewCaret caret) { CategorizedToken leftToken = GetLeftToken(caret); return(IsPossibleTypeOrMethodName(caret, leftToken)); }
private static bool IsRightTextStartedWithCloseGenericOperator(TextViewCaret caret) { return caret.RightText.TrimStart(whiteSpaces).StartsWith(">"); }
private static bool NeedGenerics(TextViewCaret caret) { CategorizedToken leftToken = GetLeftToken(caret); return IsPossibleTypeOrMethodName(caret, leftToken); }
private static bool IsRightTextStartedWithCloseGenericOperator(TextViewCaret caret) { return(caret.RightText.TrimStart(whiteSpaces).StartsWith(">")); }
private static CategorizedToken GetLeftToken(TextViewCaret caret) { TextDocument document = caret.TextDocument; if (document == null) { return null; } TokenCollection tokens = CodeRush.Language.GetTokens(caret.LeftText); if (tokens != null && tokens.Count > 1) { Token token = tokens[tokens.Count - 2]; return token as CategorizedToken; } return null; }
private static bool CaretBeforeClosingQuote(TextViewCaret caret) { return(caret.RightChar == '\'' && CodeRush.Caret.InsideString && !IsNextCharacterEscaped(caret.LeftText)); }
private static void InsertClosingCharacter(TextViewCaret caret, string character, bool useTextField) { caret.Insert(character, false); if (useTextField) { if (CaretInsideTextField()) { BreakActiveTextField(); } InsertTextFieldAt(caret); } }
private static bool CaretBeforeClosingQuote(TextViewCaret caret) { return caret.RightChar == '\'' && CodeRush.Caret.InsideString && !IsNextCharacterEscaped(caret.LeftText); }
private static bool IsLeftTextEndedWithOpenGenericOperator(TextViewCaret caret) { return(caret.LeftText.TrimEnd(whiteSpaces).EndsWith("<")); }
private static void EasyDelete(TextViewCaret caret, bool useTextField) { caret.DeleteRight(1); if (useTextField && CaretInsideTextField()) { AcceptActiveTextField(); } }