rename file: move to java/groovy

This commit is contained in:
Anna Kozlova
2012-01-31 19:55:50 +04:00
parent f2849d7322
commit 94fc29cbb6
3 changed files with 10 additions and 7 deletions
@@ -0,0 +1,53 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.refactoring.actions;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClassOwner;
import com.intellij.psi.PsiFile;
import com.intellij.refactoring.rename.PsiElementRenameHandler;
/**
* @author ven
*/
public class RenameFileAction extends AnAction implements DumbAware {
public static final String RENAME_FILE = "Rename File";
public void actionPerformed(final AnActionEvent e) {
final PsiFile file = e.getData(LangDataKeys.PSI_FILE);
assert file != null;
final VirtualFile virtualFile = file.getVirtualFile();
assert virtualFile != null;
final Project project = e.getData(PlatformDataKeys.PROJECT);
assert project != null;
PsiElementRenameHandler.invoke(file, project, file, null);
}
public void update(AnActionEvent e) {
PsiFile file = e.getData(LangDataKeys.PSI_FILE);
Presentation presentation = e.getPresentation();
boolean enabled = file instanceof PsiClassOwner && e.getPlace() != ActionPlaces.EDITOR_POPUP && e.getData(PlatformDataKeys.PROJECT) != null;
presentation.setEnabled(enabled);
presentation.setVisible(enabled);
if (enabled) {
presentation.setText(RENAME_FILE);
presentation.setDescription(RENAME_FILE);
}
}
}