package com.intellij.sh.rename;

import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.openapi.actionSystem.CommonShortcuts;
import com.intellij.openapi.actionSystem.ShortcutProvider;
import com.intellij.openapi.actionSystem.ShortcutSet;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ShRenameIntention extends BaseIntentionAction implements ShortcutProvider {
  @NotNull
  @Override
  public String getFamilyName() {
    return getText();
  }

  @NotNull
  @Override
  public String getText() {
    return "Rename all occurrences";
  }

  @Override
  public boolean startInWriteAction() {
    return false;
  }

  @Override
  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    return ShSelectAllOccurrencesHandler.INSTANCE.isEnabled(editor, editor.getCaretModel().getPrimaryCaret(), null);
  }

  @Override
  public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    ShSelectAllOccurrencesHandler.INSTANCE.execute(editor, editor.getCaretModel().getPrimaryCaret(), null);
  }

  @Nullable
  @Override
  public ShortcutSet getShortcut() {
    return CommonShortcuts.getRename();
  }
}

@@ -386,16 +386,51 @@
 siFile;%0A
+import com.intellij.sh.psi.ShFile;%0A
 import c
@@ -1010,16 +1010,42 @@
   return
+ file instanceof ShFile &&
  ShSelec
@@ -1273,16 +1273,52 @@
 ption %7B%0A
+    if (file instanceof ShFile) %7B%0A  
     ShSe
@@ -1409,32 +1409,38 @@
 Caret(), null);%0A
+    %7D%0A
   %7D%0A%0A  @Nullable

rename all occurrences intention: check for sh file