Search in sources :

Example 1 with RenameDialog

use of com.intellij.refactoring.rename.RenameDialog in project intellij-community by JetBrains.

the class PyMagicLiteralRenameHandler method invoke.

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    PsiElement element = getElement(file, editor);
    if (element == null) {
        return;
    }
    RenameDialog.showRenameDialog(dataContext, new RenameDialog(project, element, null, editor));
}
Also used : RenameDialog(com.intellij.refactoring.rename.RenameDialog) PsiElement(com.intellij.psi.PsiElement)

Example 2 with RenameDialog

use of com.intellij.refactoring.rename.RenameDialog in project android by JetBrains.

the class AndroidRenameHandler method performApplicationPackageRenaming.

private static void performApplicationPackageRenaming(@NotNull Project project, @NotNull Editor editor, @NotNull DataContext context) {
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
    if (!(element instanceof XmlAttributeValue)) {
        return;
    }
    final Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (module == null) {
        return;
    }
    RenameDialog.showRenameDialog(context, new RenameDialog(project, element, null, editor) {

        @NotNull
        @Override
        protected String getLabelText() {
            return "Rename Android application package of module '" + module.getName() + "' to:";
        }

        @Override
        protected void canRun() throws ConfigurationException {
            final String name = getNewName();
            if (name.length() == 0) {
                throw new ConfigurationException(AndroidBundle.message("specify.package.name.error"));
            }
            if (!AndroidUtils.isValidAndroidPackageName(name)) {
                throw new ConfigurationException(AndroidBundle.message("not.valid.package.name.error", name));
            }
            if (!AndroidCommonUtils.contains2Identifiers(name)) {
                throw new ConfigurationException(AndroidBundle.message("package.name.must.contain.2.ids.error"));
            }
            super.canRun();
        }
    });
}
Also used : RenameDialog(com.intellij.refactoring.rename.RenameDialog) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement)

Example 3 with RenameDialog

use of com.intellij.refactoring.rename.RenameDialog in project android by JetBrains.

the class AndroidRenameHandler method performValueResourceRenaming.

private static void performValueResourceRenaming(Project project, Editor editor, DataContext dataContext, XmlTag tag) {
    final XmlAttribute nameAttribute = tag.getAttribute("name");
    if (nameAttribute == null) {
        return;
    }
    final XmlAttributeValue attributeValue = nameAttribute.getValueElement();
    if (attributeValue == null) {
        return;
    }
    RenameDialog.showRenameDialog(dataContext, new RenameDialog(project, new ValueResourceElementWrapper(attributeValue), null, editor));
}
Also used : RenameDialog(com.intellij.refactoring.rename.RenameDialog) ValueResourceElementWrapper(org.jetbrains.android.dom.wrappers.ValueResourceElementWrapper)

Example 4 with RenameDialog

use of com.intellij.refactoring.rename.RenameDialog in project intellij by bazelbuild.

the class RenameRefactoringTest method testRenameSuggestionForBuildFile.

@Test
public void testRenameSuggestionForBuildFile() {
    BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"));
    RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(buildFile);
    RenameDialog dialog = processor.createRenameDialog(getProject(), buildFile, buildFile, null);
    String[] suggestions = dialog.getSuggestedNames();
    assertThat(suggestions[0]).isEqualTo("BUILD");
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) RenamePsiElementProcessor(com.intellij.refactoring.rename.RenamePsiElementProcessor) RenameDialog(com.intellij.refactoring.rename.RenameDialog) Test(org.junit.Test)

Example 5 with RenameDialog

use of com.intellij.refactoring.rename.RenameDialog in project android by JetBrains.

the class ThemeEditorComponent method renameTheme.

/**
   * Uses Android Studio refactoring to rename the current theme
   */
private void renameTheme() {
    ConfiguredThemeEditorStyle selectedTheme = getSelectedTheme();
    assert selectedTheme != null;
    assert selectedTheme.isProjectStyle();
    PsiElement namePsiElement = selectedTheme.getNamePsiElement();
    if (namePsiElement == null) {
        return;
    }
    RenameDialog renameDialog = new RenameDialog(myThemeEditorContext.getProject(), namePsiElement, null, null);
    renameDialog.show();
    if (renameDialog.isOK()) {
        String newName = renameDialog.getNewName();
        // We don't need to call reload here, because myResourceChangeListener will take care of it
        myThemeName = selectedTheme.getQualifiedName().replace(selectedTheme.getName(), newName);
        mySubStyleName = null;
    }
}
Also used : RenameDialog(com.intellij.refactoring.rename.RenameDialog) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) PsiElement(com.intellij.psi.PsiElement)

Aggregations

RenameDialog (com.intellij.refactoring.rename.RenameDialog)7 PsiElement (com.intellij.psi.PsiElement)4 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)2 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)2 RenamePsiElementProcessor (com.intellij.refactoring.rename.RenamePsiElementProcessor)2 Test (org.junit.Test)2 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)1 Module (com.intellij.openapi.module.Module)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 ValueResourceElementWrapper (org.jetbrains.android.dom.wrappers.ValueResourceElementWrapper)1 NotNull (org.jetbrains.annotations.NotNull)1