Search in sources :

Example 16 with NonFocusableCheckBox

use of com.intellij.ui.NonFocusableCheckBox in project kotlin by JetBrains.

the class KotlinInplaceVariableIntroducer method getCreateVarCheckBox.

@Nullable
protected final Function0<JComponent> getCreateVarCheckBox() {
    if (myDoNotChangeVar)
        return null;
    return new Function0<JComponent>() {

        @Override
        public JComponent invoke() {
            final JCheckBox varCheckbox = new NonFocusableCheckBox("Declare with var");
            varCheckbox.setSelected(isVar);
            varCheckbox.setMnemonic('v');
            varCheckbox.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(@NotNull ActionEvent e) {
                    new WriteCommandAction(myProject, getCommandName(), getCommandName()) {

                        @Override
                        protected void run(@NotNull Result result) throws Throwable {
                            PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
                            KtPsiFactory psiFactory = new KtPsiFactory(myProject);
                            PsiElement keyword = varCheckbox.isSelected() ? psiFactory.createVarKeyword() : psiFactory.createValKeyword();
                            PsiElement valOrVar = myDeclaration instanceof KtProperty ? ((KtProperty) myDeclaration).getValOrVarKeyword() : ((KtParameter) myDeclaration).getValOrVarKeyword();
                            valOrVar.replace(keyword);
                        }
                    }.execute();
                }
            });
            return varCheckbox;
        }
    };
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) NonFocusableCheckBox(com.intellij.ui.NonFocusableCheckBox) Function0(kotlin.jvm.functions.Function0) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

NonFocusableCheckBox (com.intellij.ui.NonFocusableCheckBox)16 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 Result (com.intellij.openapi.application.Result)3 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 Function0 (kotlin.jvm.functions.Function0)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 Balloon (com.intellij.openapi.ui.popup.Balloon)1 BalloonBuilder (com.intellij.openapi.ui.popup.BalloonBuilder)1 PsiParameter (com.intellij.psi.PsiParameter)1 JavaRefactoringSettings (com.intellij.refactoring.JavaRefactoringSettings)1 AutomaticRenamerFactory (com.intellij.refactoring.rename.naming.AutomaticRenamerFactory)1 NameSuggestionsField (com.intellij.refactoring.ui.NameSuggestionsField)1 VariableData (com.intellij.refactoring.util.VariableData)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 StateRestoringCheckBox (com.intellij.ui.StateRestoringCheckBox)1