Java Code Examples for com.intellij.openapi.util.registry.Registry#is()

The following examples show how to use com.intellij.openapi.util.registry.Registry#is() . 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: GotoClassAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  if (project == null) return;

  boolean dumb = DumbService.isDumb(project);
  if (Registry.is("new.search.everywhere")) {
    if (!dumb || new ClassSearchEverywhereContributor(project, null).isDumbAware()) {
      showInSearchEverywherePopup(ClassSearchEverywhereContributor.class.getSimpleName(), e, true, true);
    }
    else {
      invokeGoToFile(project, e);
    }
  }
  else {
    if (!dumb) {
      super.actionPerformed(e);
    }
    else {
      invokeGoToFile(project, e);
    }
  }
}
 
Example 2
Source File: GradientViewport.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void paintGradient(Graphics g) {
  g = g.create();
  try {
    Color background = getViewColor();
    Component header = getHeader();
    if (header != null) {
      header.setBounds(0, 0, getWidth(), header.getPreferredSize().height);
      if (background != null) {
        g.setColor(background);
        g.fillRect(header.getX(), header.getY(), header.getWidth(), header.getHeight());
      }
    }
    if (g instanceof Graphics2D && background != null && !Registry.is("ui.no.bangs.and.whistles")) {
      paintGradient((Graphics2D)g, background, 0, header == null ? 0 : header.getHeight());
    }
    if (header != null) {
      header.paint(g);
    }
  }
  finally {
    g.dispose();
  }
}
 
Example 3
Source File: DesktopEditorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * {@link #stopDumbLater} or {@link #stopDumb} must be performed in finally
 */
public void startDumb() {
  if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;
  if (!Registry.is("editor.dumb.mode.available")) return;
  putUserData(BUFFER, null);
  Rectangle rect = ((JViewport)myEditorComponent.getParent()).getViewRect();
  // The LCD text loop is enabled only for opaque images
  BufferedImage image = UIUtil.createImage(myEditorComponent, rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
  Graphics imageGraphics = image.createGraphics();
  imageGraphics.translate(-rect.x, -rect.y);
  Graphics2D graphics = JBSwingUtilities.runGlobalCGTransform(myEditorComponent, imageGraphics);
  graphics.setClip(rect.x, rect.y, rect.width, rect.height);
  myEditorComponent.paintComponent(graphics);
  graphics.dispose();
  putUserData(BUFFER, image);
}
 
Example 4
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Context createContext(Editor editor, int offset) {
  Project project = Objects.requireNonNull(editor.getProject());

  HighlightInfo info = null;
  if (!Registry.is("ide.disable.editor.tooltips")) {
    info = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).findHighlightByOffset(editor.getDocument(), offset, false);
  }

  PsiElement elementForQuickDoc = null;
  if (EditorSettingsExternalizable.getInstance().isShowQuickDocOnMouseOverElement()) {
    PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (psiFile != null) {
      elementForQuickDoc = psiFile.findElementAt(offset);
      if (elementForQuickDoc instanceof PsiWhiteSpace || elementForQuickDoc instanceof PsiPlainText) {
        elementForQuickDoc = null;
      }
    }
  }

  return info == null && elementForQuickDoc == null ? null : new Context(offset, info, elementForQuickDoc);
}
 
Example 5
Source File: ShowGraphHistoryAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  if (!Registry.is("vcs.log.graph.history")) {
    presentation.setEnabledAndVisible(false);
  }
  else {
    VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
    Project project = e.getProject();
    if (file == null || project == null) {
      presentation.setEnabledAndVisible(false);
    }
    else {
      VirtualFile root = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(file);
      VcsLogData dataManager = VcsProjectLog.getInstance(project).getDataManager();
      if (root == null || dataManager == null) {
        presentation.setEnabledAndVisible(false);
      }
      else {
        presentation.setVisible(dataManager.getRoots().contains(root));
        presentation.setEnabled(dataManager.getIndex().isIndexed(root));
      }
    }
  }
}
 
Example 6
Source File: IdeEventQueue.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void fixStickyAlt(@Nonnull AWTEvent e) {
  if (Registry.is("actionSystem.win.suppressAlt.new")) {
    if (UIUtil.isUnderWindowsLookAndFeel() &&
        e instanceof InputEvent &&
        (((InputEvent)e).getModifiers() & (InputEvent.ALT_MASK | InputEvent.ALT_DOWN_MASK)) != 0 &&
        !(e instanceof KeyEvent && ((KeyEvent)e).getKeyCode() == KeyEvent.VK_ALT)) {
      try {
        if (FieldHolder.ourStickyAltField != null) {
          FieldHolder.ourStickyAltField.set(null, true);
        }
      }
      catch (Exception exception) {
        LOG.error(exception);
      }
    }
  }
  else if (SystemInfo.isWinXpOrNewer && !SystemInfo.isWinVistaOrNewer && e instanceof KeyEvent && ((KeyEvent)e).getKeyCode() == KeyEvent.VK_ALT) {
    ((KeyEvent)e).consume();  // IDEA-17359
  }
}
 
Example 7
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private float getEditorScaleFactor() {
  if (Registry.is("editor.scale.gutter.icons")) {
    float scale = myEditor.getScale();
    if (Math.abs(1f - scale) > 0.10f) {
      return scale;
    }
  }
  return 1f;
}
 
Example 8
Source File: MacIntelliJTextBorder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void paint(Component c, Graphics2D g2, int width, int height, int arc) {
  clipForBorder(c, g2, width, height);

  Object eop = ((JComponent)c).getClientProperty("JComponent.error.outline");
  if (Registry.is("ide.inplace.errors.outline") && Boolean.parseBoolean(String.valueOf(eop))) {
    DarculaUIUtilPart.paintErrorBorder(g2, width, height, arc, isSymmetric(), isFocused(c));
  } else if (isFocused(c)) {
    DarculaUIUtilPart.paintFocusBorder(g2, width, height, arc, isSymmetric());
  }
}
 
Example 9
Source File: CertificateManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void initComponent() {
  try {
    // Don't do this: protocol created this way will ignore SSL tunnels. See IDEA-115708.
    // Protocol.registerProtocol("https", CertificateManager.createDefault().createProtocol());
    if (Registry.is("ide.certificate.manager")) {
      SSLContext.setDefault(getSslContext());
      LOG.debug("Default SSL context initialized");
    }
  }
  catch (Exception e) {
    LOG.error(e);
  }
}
 
Example 10
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeEditorTyping(char c, @Nonnull DataContext dataContext) {
  if (!Registry.is("editor.new.mouse.hover.popups")) {
    return;
  }
  getInstance().cancelProcessingAndCloseHint();
}
 
Example 11
Source File: DaemonListeners.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseDragged(@Nonnull EditorMouseEvent e) {
  if (Registry.is("editor.new.mouse.hover.popups")) {
    return;
  }
  TooltipController.getInstance().cancelTooltips();
}
 
Example 12
Source File: UIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void suppressFocusStealing(Window window) {
  // Focus stealing is not a problem on Mac
  if (SystemInfo.isMac) return;
  if (Registry.is("suppress.focus.stealing")) {
    setAutoRequestFocus(window, false);
  }
}
 
Example 13
Source File: ToolkitBugsProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean process(Throwable e) {
  if (!Registry.is("ide.consumeKnownToolkitBugs")) return false;

  StackTraceElement[] stack = e.getStackTrace();
  for (Handler each : myHandlers) {
    if (each.process(e, stack)) {
      LOG.info("Ignored exception by toolkit bug processor, bug id=" + each.toString() + " desc=" + each.getDetails());
      return true;
    }
  }
  return false;
}
 
Example 14
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseEntered(@Nonnull EditorMouseEvent event) {
  if (!Registry.is("editor.new.mouse.hover.popups")) {
    return;
  }
  // we receive MOUSE_MOVED event after MOUSE_ENTERED even if mouse wasn't physically moved,
  // e.g. if a popup overlapping editor has been closed
  getInstance().skipNextMovement();
}
 
Example 15
Source File: UIUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static Paint getGradientPaint(float x1, float y1, @Nonnull Color c1, float x2, float y2, @Nonnull Color c2) {
  return (Registry.is("ui.no.bangs.and.whistles", false)) ? ColorUtil.mix(c1, c2, .5) : new GradientPaint(x1, y1, c1, x2, y2, c2);
}
 
Example 16
Source File: BaseRefactoringProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void doRefactoring(@Nonnull final Collection<UsageInfo> usageInfoSet) {
  for (Iterator<UsageInfo> iterator = usageInfoSet.iterator(); iterator.hasNext(); ) {
    UsageInfo usageInfo = iterator.next();
    final PsiElement element = usageInfo.getElement();
    if (element == null || !isToBeChanged(usageInfo)) {
      iterator.remove();
    }
  }

  String commandName = getCommandName();
  LocalHistoryAction action = LocalHistory.getInstance().startAction(commandName);

  final UsageInfo[] writableUsageInfos = usageInfoSet.toArray(UsageInfo.EMPTY_ARRAY);
  try {
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    RefactoringListenerManagerImpl listenerManager = (RefactoringListenerManagerImpl)RefactoringListenerManager.getInstance(myProject);
    myTransaction = listenerManager.startTransaction();
    final Map<RefactoringHelper, Object> preparedData = new LinkedHashMap<>();
    final Runnable prepareHelpersRunnable = () -> {
      for (final RefactoringHelper helper : RefactoringHelper.EP_NAME.getExtensionList()) {
        Object operation = ReadAction.compute(() -> helper.prepareOperation(writableUsageInfos));
        preparedData.put(helper, operation);
      }
    };

    ProgressManager.getInstance().runProcessWithProgressSynchronously(prepareHelpersRunnable, "Prepare ...", false, myProject);

    Runnable performRefactoringRunnable = () -> {
      final String refactoringId = getRefactoringId();
      if (refactoringId != null) {
        RefactoringEventData data = getBeforeData();
        if (data != null) {
          data.addUsages(usageInfoSet);
        }
        myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(refactoringId, data);
      }

      try {
        if (refactoringId != null) {
          UndoableAction action1 = new UndoRefactoringAction(myProject, refactoringId);
          UndoManager.getInstance(myProject).undoableActionPerformed(action1);
        }

        performRefactoring(writableUsageInfos);
      }
      finally {
        if (refactoringId != null) {
          myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, getAfterData(writableUsageInfos));
        }
      }
    };
    ApplicationEx2 app = (ApplicationEx2)Application.get();
    if (Registry.is("run.refactorings.under.progress")) {
      app.runWriteActionWithNonCancellableProgressInDispatchThread(commandName, myProject, null, indicator -> performRefactoringRunnable.run());
    }
    else {
      app.runWriteAction(performRefactoringRunnable);
    }

    DumbService.getInstance(myProject).completeJustSubmittedTasks();

    for (Map.Entry<RefactoringHelper, Object> e : preparedData.entrySet()) {
      //noinspection unchecked
      e.getKey().performOperation(myProject, e.getValue());
    }
    myTransaction.commit();
    if (Registry.is("run.refactorings.under.progress")) {
      app.runWriteActionWithNonCancellableProgressInDispatchThread(commandName, myProject, null, indicator -> performPsiSpoilingRefactoring());
    }
    else {
      app.runWriteAction(this::performPsiSpoilingRefactoring);
    }
  }
  finally {
    action.finish();
  }

  int count = writableUsageInfos.length;
  if (count > 0) {
    StatusBarUtil.setStatusBarInfo(myProject, RefactoringBundle.message("statusBar.refactoring.result", count));
  }
  else {
    if (!isPreviewUsages(writableUsageInfos)) {
      StatusBarUtil.setStatusBarInfo(myProject, RefactoringBundle.message("statusBar.noUsages"));
    }
  }
}
 
Example 17
Source File: MacMessagesImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static Window getForemostWindow(final Window window) {
  Window _window = null;
  IdeFocusManager ideFocusManager = IdeFocusManager.getGlobalInstance();

  Component focusOwner = IdeFocusManager.findInstance().getFocusOwner();
  // Let's ask for a focused component first
  if (focusOwner != null) {
    _window = SwingUtilities.getWindowAncestor(focusOwner);
  }

  if (_window == null) {
    // Looks like ide lost focus, let's ask about the last focused component
    focusOwner = ideFocusManager.getLastFocusedFor(ideFocusManager.getLastFocusedFrame());
    if (focusOwner != null) {
      _window = SwingUtilities.getWindowAncestor(focusOwner);
    }
  }

  if (_window == null) {
    _window = WindowManager.getInstance().findVisibleFrame();
  }

  if (_window == null && window != null) {
    // It might be we just has not opened a frame yet.
    // So let's ask AWT
    focusOwner = window.getMostRecentFocusOwner();
    if (focusOwner != null) {
      _window = SwingUtilities.getWindowAncestor(focusOwner);
    }
  }

  if (_window != null) {
    // We have successfully found the window
    // Let's check that we have not missed a blocker
    if (ModalityHelper.isModalBlocked(_window)) {
      _window = ModalityHelper.getModalBlockerFor(_window);
    }
  }

  if (SystemInfo.isAppleJvm && MacUtil.getWindowTitle(_window) == null) {
    // With Apple JDK we cannot find a window if it does not have a title
    // Let's show a dialog instead of the message.
    throw new MacMessageException("MacMessage parent does not have a title.");
  }
  while (_window != null && MacUtil.getWindowTitle(_window) == null) {
    _window = _window.getOwner();
    //At least our frame should have a title
  }

  while (Registry.is("skip.untitled.windows.for.mac.messages") && _window != null && _window instanceof JDialog && !((JDialog)_window).isModal()) {
    _window = _window.getOwner();
  }

  return _window;
}
 
Example 18
Source File: FocusManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void assertDispatchThread() {
  if (Registry.is("actionSystem.assertFocusAccessFromEdt")) {
    ApplicationManager.getApplication().assertIsDispatchThread();
  }
}
 
Example 19
Source File: Messages.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isMacSheetEmulation() {
  return SystemInfo.isMac && Registry.is("ide.mac.message.dialogs.as.sheets") && Registry.is("ide.mac.message.sheets.java.emulation");
}
 
Example 20
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void onActivity() {
  if (!Registry.is("editor.new.mouse.hover.popups")) return;

  cancelCurrentProcessing();
}