com.intellij.openapi.util.Pass Java Examples

The following examples show how to use com.intellij.openapi.util.Pass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaExtractSuperBaseDialog.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
protected JPanel createDestinationRootPanel() {
  final List<VirtualFile> sourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject);
  if (sourceRoots.size() <= 1) return super.createDestinationRootPanel();
  final JPanel panel = new JPanel(new BorderLayout());
  panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
  final JBLabel label = new JBLabel(RefactoringBundle.message("target.destination.folder"));
  panel.add(label, BorderLayout.NORTH);
  label.setLabelFor(myDestinationFolderComboBox);
  myDestinationFolderComboBox.setData(myProject, myTargetDirectory, new Pass<String>() {
    @Override
    public void pass(String s) {
    }
  }, ((PackageNameReferenceEditorCombo)myPackageNameField).getChildComponent());
  panel.add(myDestinationFolderComboBox, BorderLayout.CENTER);
  return panel;
}
 
Example #2
Source File: HaxeIntroduceHandler.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
protected void performActionOnElementOccurrences(final HaxeIntroduceOperation operation) {
  final Editor editor = operation.getEditor();
  if (editor.getSettings().isVariableInplaceRenameEnabled()) {
    ensureName(operation);
    if (operation.isReplaceAll() != null) {
      performInplaceIntroduce(operation);
    }
    else {
      OccurrencesChooser.simpleChooser(editor).showChooser(
        operation.getElement(),
        operation.getOccurrences(),
        new Pass<OccurrencesChooser.ReplaceChoice>() {
          @Override
          public void pass(OccurrencesChooser.ReplaceChoice replaceChoice) {
            operation.setReplaceAll(replaceChoice == OccurrencesChooser.ReplaceChoice.ALL);
            performInplaceIntroduce(operation);
          }
        });
    }
  }
  else {
    performIntroduceWithDialog(operation);
  }
}
 
Example #3
Source File: ExtractRuleAction.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
	PsiElement el = MyActionUtils.getSelectedPsiElement(e);
	if ( el==null ) return;

	final PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
	if ( psiFile==null ) return;

	Editor editor = e.getData(PlatformDataKeys.EDITOR);
	if ( editor==null ) return;
	SelectionModel selectionModel = editor.getSelectionModel();

	if ( !selectionModel.hasSelection() ) {
		List<PsiElement> expressions = findExtractableRules(el);

		IntroduceTargetChooser.showChooser(editor, expressions, new Pass<PsiElement>() {
			@Override
			public void pass(PsiElement element) {
				selectionModel.setSelection(element.getTextOffset(), element.getTextRange().getEndOffset());
				extractSelection(psiFile, editor, selectionModel);
			}
		}, PsiElement::getText);
	} else {
		extractSelection(psiFile, editor, selectionModel);
	}
}
 
Example #4
Source File: AbstractInplaceIntroduceTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void doTest(final Pass<AbstractInplaceIntroducer> pass)  {
  String name = getTestName(true);
  configureByFile(getBasePath() + name + getExtension());
  final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled();
  try {
    TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
    getEditor().getSettings().setVariableInplaceRenameEnabled(true);

    final AbstractInplaceIntroducer introducer = invokeRefactoring();
    pass.pass(introducer);
    TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
    assert state != null;
    state.gotoEnd(false);
    checkResultByFile(getBasePath() + name + "_after" + getExtension());
  }
  finally {
    getEditor().getSettings().setVariableInplaceRenameEnabled(enabled);
  }
}
 
Example #5
Source File: TabLabel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void setTabActions(ActionGroup group) {
  removeOldActionPanel();

  if (group == null) return;

  myActionPanel = new ActionPanel(myTabs, myInfo, new Pass<MouseEvent>() {
    @Override
    public void pass(final MouseEvent event) {
      final MouseEvent me = SwingUtilities.convertMouseEvent(event.getComponent(), event, TabLabel.this);
      processMouseEvent(me);
    }
  });

  toggleShowActions(false);

  add(myActionPanel, BorderLayout.EAST);

  myTabs.revalidateAndRepaint(false);
}
 
Example #6
Source File: InplaceButton.java    From consulo with Apache License 2.0 5 votes vote down vote up
public InplaceButton(IconButton source, final ActionListener listener, final Pass<MouseEvent> me, TimedDeadzone.Length mouseDeadzone) {
  myListener = listener;
  myBehavior = new BaseButtonBehavior(this, mouseDeadzone) {
    @Override
    protected void execute(final MouseEvent e) {
      doClick(e);
    }

    @Override
    protected void repaint(Component c) {
      doRepaintComponent(c);
    }

    @Override
    protected void pass(final MouseEvent e) {
      if (me != null) {
        me.pass(e);
      }
    }
  };

  setIcons(source);

  //setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  setToolTipText(source.getTooltip());
  setOpaque(false);
  setHoveringEnabled(true);
}
 
Example #7
Source File: IntroduceTargetChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T extends PsiElement> void showChooser(final Editor editor,
                                                      final List<T> expressions,
                                                      final Pass<T> callback,
                                                      final Function<T, String> renderer,
                                                      String title,
                                                      NotNullFunction<PsiElement, TextRange> ranger) {
  showChooser(editor, expressions, callback, renderer, title, -1, ranger);
}
 
Example #8
Source File: IntroduceTargetChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T extends PsiElement> void showChooser(final Editor editor,
                                                      final List<T> expressions,
                                                      final Pass<T> callback,
                                                      final Function<T, String> renderer,
                                                      String title) {
  showChooser(editor, expressions, callback, renderer, title, ScopeHighlighter.NATURAL_RANGER);
}
 
Example #9
Source File: OccurrencesChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void showChooser(final T selectedOccurrence, final List<T> allOccurrences, final Pass<ReplaceChoice> callback) {
  if (allOccurrences.size() == 1) {
    callback.pass(ReplaceChoice.ALL);
  }
  else {
    Map<ReplaceChoice, List<T>> occurrencesMap = ContainerUtil.newLinkedHashMap();
    occurrencesMap.put(ReplaceChoice.NO, Collections.singletonList(selectedOccurrence));
    occurrencesMap.put(ReplaceChoice.ALL, allOccurrences);
    showChooser(callback, occurrencesMap);
  }
}
 
Example #10
Source File: MemberInplaceRenameHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public InplaceRefactoring doRename(@Nonnull final PsiElement elementToRename, final Editor editor, final DataContext dataContext) {
  if (elementToRename instanceof PsiNameIdentifierOwner) {
    final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(elementToRename);
    if (processor.isInplaceRenameSupported()) {
      final StartMarkAction startMarkAction = StartMarkAction.canStart(elementToRename.getProject());
      if (startMarkAction == null || processor.substituteElementToRename(elementToRename, editor) == elementToRename) {
        processor.substituteElementToRename(elementToRename, editor, new Pass<PsiElement>() {
          @Override
          public void pass(PsiElement element) {
            final MemberInplaceRenamer renamer = createMemberRenamer(element, (PsiNameIdentifierOwner)elementToRename, editor);
            boolean startedRename = renamer.performInplaceRename();
            if (!startedRename) {
              performDialogRename(elementToRename, editor, dataContext);
            }
          }
        });
        return null;
      }
      else {
        final InplaceRefactoring inplaceRefactoring = editor.getUserData(InplaceRefactoring.INPLACE_RENAMER);
        if (inplaceRefactoring != null && inplaceRefactoring.getClass() == MemberInplaceRenamer.class) {
          final TemplateState templateState = TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(editor));
          if (templateState != null) {
            templateState.gotoEnd(true);
          }
        }
      }
    }
  }
  performDialogRename(elementToRename, editor, dataContext);
  return null;
}
 
Example #11
Source File: RenamePsiElementProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Substitutes element to be renamed and initiate rename procedure. Should be used in order to prevent modal dialogs to appear during inplace rename
 * @param element the element on which refactoring was invoked
 * @param editor the editor in which inplace refactoring was invoked
 * @param renameCallback rename procedure which should be called on the chosen substitution
 */
public void substituteElementToRename(@Nonnull final PsiElement element, @Nonnull Editor editor, @Nonnull Pass<PsiElement> renameCallback) {
  final PsiElement psiElement = substituteElementToRename(element, editor);
  if (psiElement == null) return;
  if (!PsiElementRenameHandler.canRename(psiElement.getProject(), editor, psiElement)) return;
  renameCallback.pass(psiElement);
}
 
Example #12
Source File: ActionButton.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionButton(JBTabsImpl tabs, TabInfo tabInfo, AnAction action, String place, Pass<MouseEvent> pass, TimedDeadzone.Length deadzone) {
  super(null, action.getTemplatePresentation().getIcon());
  myTabs = tabs;
  myTabInfo = tabInfo;
  myAction = action;
  myPlace = place;

  myButton = new InplaceButton(this, this, pass, deadzone) {
    @Override
    protected void doRepaintComponent(Component c) {
      repaintComponent(c);
    }
  };
  myButton.setVisible(false);
}
 
Example #13
Source File: ActionPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionPanel(JBTabsImpl tabs, TabInfo tabInfo, Pass<MouseEvent> pass) {
  myTabs = tabs;
  ActionGroup group = tabInfo.getTabLabelActions() != null ? tabInfo.getTabLabelActions() : new DefaultActionGroup();
  AnAction[] children = group.getChildren(null);

  final NonOpaquePanel wrapper = new NonOpaquePanel(new BorderLayout());
  wrapper.add(Box.createHorizontalStrut(2), BorderLayout.WEST);
  NonOpaquePanel inner = new NonOpaquePanel();
  inner.setLayout(new BoxLayout(inner, BoxLayout.X_AXIS));
  wrapper.add(inner, BorderLayout.CENTER);
  for (AnAction each : children) {
    ActionButton eachButton = new ActionButton(myTabs, tabInfo, each, tabInfo.getTabActionPlace(), pass, tabs.getTabActionsMouseDeadzone()) {
      @Override
      protected void repaintComponent(final Component c) {
        TabLabel tabLabel = (TabLabel) SwingUtilities.getAncestorOfClass(TabLabel.class, c);
        if (tabLabel != null) {
          Point point = SwingUtilities.convertPoint(c, new Point(0, 0), tabLabel);
          Dimension d = c.getSize();
          tabLabel.repaint(point.x, point.y, d.width, d.height);
        } else {
          super.repaintComponent(c);
        }
      }
    };

    myButtons.add(eachButton);
    InplaceButton component = eachButton.getComponent();
    inner.add(component);
  }

  add(wrapper);
}
 
Example #14
Source File: LSPRenameHandler.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
private InplaceRefactoring doRename(PsiElement elementToRename, Editor editor) {
    if (elementToRename instanceof PsiNameIdentifierOwner) {
        RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(elementToRename);
        if (processor.isInplaceRenameSupported()) {
            StartMarkAction startMarkAction = StartMarkAction.canStart(elementToRename.getProject());
            if (startMarkAction == null || (processor.substituteElementToRename(elementToRename, editor)
                    == elementToRename)) {
                processor.substituteElementToRename(elementToRename, editor, new Pass<PsiElement>() {
                    @Override
                    public void pass(PsiElement element) {
                        MemberInplaceRenamer renamer = createMemberRenamer(element,
                                (PsiNameIdentifierOwner) elementToRename, editor);
                        boolean startedRename = renamer.performInplaceRename();
                        if (!startedRename) {
                            performDialogRename(editor);
                        }
                    }
                });
                return null;
            }
        } else {
            InplaceRefactoring inplaceRefactoring = editor.getUserData(InplaceRefactoring.INPLACE_RENAMER);
            if ((inplaceRefactoring instanceof MemberInplaceRenamer)) {
                TemplateState templateState = TemplateManagerImpl
                        .getTemplateState(InjectedLanguageUtil.getTopLevelEditor(editor));
                if (templateState != null) {
                    templateState.gotoEnd(true);
                }
            }
        }
    }
    performDialogRename(editor);
    return null;
}
 
Example #15
Source File: CSharpIntroduceHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
protected void performActionOnElementOccurrences(final CSharpIntroduceOperation operation)
{
	final Editor editor = operation.getEditor();
	if(editor.getSettings().isVariableInplaceRenameEnabled())
	{
		ensureName(operation);
		if(operation.isReplaceAll() || operation.getOccurrences().isEmpty())
		{
			performInplaceIntroduce(operation);
		}
		else
		{
			OccurrencesChooser.simpleChooser(editor).showChooser(operation.getElement(), operation.getOccurrences(), new Pass<OccurrencesChooser.ReplaceChoice>()
			{
				@Override
				public void pass(OccurrencesChooser.ReplaceChoice replaceChoice)
				{
					operation.setReplaceAll(replaceChoice == OccurrencesChooser.ReplaceChoice.ALL);
					performInplaceIntroduce(operation);
				}
			});
		}
	}
	else
	{
		performIntroduceWithDialog(operation);
	}
}
 
Example #16
Source File: InplaceButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
public InplaceButton(IconButton source, final ActionListener listener, final Pass<MouseEvent> me) {
  this(source, listener, me, TimedDeadzone.DEFAULT);
}
 
Example #17
Source File: InplaceButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
public InplaceButton(String tooltip, final Icon icon, final ActionListener listener, final Pass<MouseEvent> me) {
  this(new IconButton(tooltip, icon, icon), listener, me);
}
 
Example #18
Source File: IntroduceTargetChooser.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static <T extends PsiElement> void showChooser(final Editor editor, final List<T> expressions, final Pass<T> callback,
                                                      final Function<T, String> renderer) {
  showChooser(editor, expressions, callback, renderer, "Expressions");
}
 
Example #19
Source File: SMTestRunnerResultsForm.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected JComponent createTestTreeView() {
  myTreeView = new SMTRunnerTestTreeView();

  myTreeView.setLargeModel(true);
  myTreeView.attachToModel(this);
  myTreeView.setTestResultsViewer(this);
  if (Registry.is("tests.view.old.statistics.panel")) {
    addTestsTreeSelectionListener(new TreeSelectionListener() {
      @Override
      public void valueChanged(TreeSelectionEvent e) {
        AbstractTestProxy selectedTest = getTreeView().getSelectedTest();
        if (selectedTest instanceof SMTestProxy) {
          myStatisticsPane.selectProxy(((SMTestProxy)selectedTest), this, false);
        }
      }
    });
  }

  final SMTRunnerTreeStructure structure = new SMTRunnerTreeStructure(myProject, myTestsRootNode);
  myTreeBuilder = new SMTRunnerTreeBuilder(myTreeView, structure);
  myTreeBuilder.setTestsComparator(TestConsoleProperties.SORT_ALPHABETICALLY.value(myProperties));
  Disposer.register(this, myTreeBuilder);

  myAnimator = new TestsProgressAnimator(myTreeBuilder);

  TrackRunningTestUtil.installStopListeners(myTreeView, myProperties, new Pass<AbstractTestProxy>() {
    @Override
    public void pass(AbstractTestProxy testProxy) {
      if (testProxy == null) return;
      final AbstractTestProxy selectedProxy = testProxy;
      //drill to the first leaf
      while (!testProxy.isLeaf()) {
        final List<? extends AbstractTestProxy> children = testProxy.getChildren();
        if (!children.isEmpty()) {
          final AbstractTestProxy firstChild = children.get(0);
          if (firstChild != null) {
            testProxy = firstChild;
            continue;
          }
        }
        break;
      }

      //pretend the selection on the first leaf
      //so if test would be run, tracking would be restarted
      myLastSelected = testProxy;

      //ensure scroll to source on explicit selection only
      if (ScrollToTestSourceAction.isScrollEnabled(SMTestRunnerResultsForm.this)) {
        final Navigatable descriptor = TestsUIUtil.getOpenFileDescriptor(selectedProxy, SMTestRunnerResultsForm.this);
        if (descriptor != null) {
          OpenSourceUtil.navigate(false, descriptor);
        }
      }
    }
  });

  //TODO always hide root node
  //myTreeView.setRootVisible(false);
  myUpdateQueue = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this);
  return myTreeView;
}