private void PlugIn1_LinkedIdentifierActivated(LinkedIdentifierEventArgs ea)
        {
            RefactoringProviderBase activeRefactoring = CodeRush.Refactoring.Active;

            insideRename = activeRefactoring != null && activeRefactoring.DisplayName == "Rename";
            if (!insideRename || !IsTypeRename(ea))
            {
                return;
            }
            string     text     = ea.LinkedIdentifier.Text;
            SourceFile file     = ea.LinkedIdentifier.File;
            string     fullPath = file.FilePath;
            string     rootName = System.IO.Path.GetFileNameWithoutExtension(fullPath);

            while (rootName.IndexOf(".") >= 0)
            {
                rootName = System.IO.Path.GetFileNameWithoutExtension(rootName);
            }
            if (rootName == text)
            {
                if (!originalClassNames.ContainsKey(fullPath))
                {
                    originalClassNames.Add(fullPath, text);
                }
            }
        }
Beispiel #2
0
 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;
                 }
             }
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// TODO Add summary
        /// </summary>
        private void moveTypesToFilesRefactoring_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            RefactoringProviderBase moveRefactoring   = CodeRush.Refactoring.Get("Move Type to File");
            RefactoringProviderBase renameRefactoring = CodeRush.Refactoring.Get("Rename File to Match Type");

            ea.Available = moveRefactoring != null && renameRefactoring != null &&
                           (ea.CodeActive.ElementType == LanguageElementType.Namespace || ea.CodeActive.ElementType == LanguageElementType.Class);
        }
Beispiel #4
0
        /// <summary>
        /// TODO Add summary
        /// </summary>
        private void moveTypesToFilesRefactoring_LanguageSupported(LanguageSupportedEventArgs ea)
        {
            RefactoringProviderBase moveRefactoring   = CodeRush.Refactoring.Get("Move Type to File");
            RefactoringProviderBase renameRefactoring = CodeRush.Refactoring.Get("Rename File to Match Type");

            ea.Handled = moveRefactoring != null && renameRefactoring != null &&
                         moveRefactoring.IsLanguageSupported(ea.LanguageID);
        }
        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;
            }
        }
        // public methods...
        #region AddRefactoring
        public void AddRefactoring(string refactoringName, string availabilityHint)
        {
            RefactoringProviderBase refactoring = CodeRush.Refactoring.Get(refactoringName);

            if (refactoring == null)
            {
                Add(new CompatibilityRedirect(refactoringName,
                                              STR_RefactorCommand,
                                              refactoringName,
                                              String.Empty,
                                              STR_ThisRefactoringWasNotFound,
                                              false));
            }
            else
            {
                AddCommand(STR_RefactorCommand, refactoring.ProviderName, refactoring.DisplayName, refactoring.Description, availabilityHint, CodeRush.Refactoring.IsAvailable(refactoringName));
            }
        }
Beispiel #7
0
        /// <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();
        }
Beispiel #8
0
 private static bool IsRefactoringAvailable(RefactoringProviderBase refactoring)
 {
     return(refactoring.GetAvailability() == RefactoringAvailability.Available);
 }
 private static bool IsRefactoringAvailable(RefactoringProviderBase refactoring)
 {
     return refactoring.GetAvailability() == RefactoringAvailability.Available;
 }