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; } } } } }
void RenameFile(SourceFile file, string newName) { CodeRush.Language.ParseActiveDocument(); RefactoringProviderBase renameFile = CodeRush.Refactoring.Get("Rename File to Match Type"); if (renameFile != null) { if (renameFile.IsAvailable) { renameFile.Execute(); } return; } }
/// <summary> /// TODO Add summary /// </summary> private void moveTypesToFilesRefactoring_Apply(object sender, ApplyContentEventArgs ea) { SourceFile sourceFile = CodeRush.Source.ActiveSourceFile; // Get all types var allTypes = sourceFile.AllTypes; // Filter to classes var allClassesDesc = allTypes.Cast <TypeDeclaration>() .Where(td => td.ElementType == LanguageElementType.Class) .OrderByDescending(td => td.NameRange.Start); // Move to files RefactoringProviderBase moveRefactoring = CodeRush.Refactoring.Get("Move Type to File"); foreach (TypeDeclaration classDecl in allClassesDesc) { // Skip last class if (allClassesDesc.Count() == 1) { continue; } // Move to files CodeRush.Caret.MoveTo(classDecl.NameRange.Start); CodeRush.SmartTags.UpdateContext(); moveRefactoring.Execute(); CodeRush.Documents.Activate((Document)sourceFile.Document); } // Rename the file to match last type RefactoringProviderBase renameRefactoring = CodeRush.Refactoring.Get("Rename File to Match Type"); CodeRush.SmartTags.UpdateContext(); renameRefactoring.Execute(); }