com.intellij.openapi.util.registry.Registry Java Examples

The following examples show how to use com.intellij.openapi.util.registry.Registry. 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: MouseGestureManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void remove(IdeFrame frame) {
  if (!Registry.is("actionSystem.mouseGesturesEnabled")) return;

  if (SystemInfo.isMacOSSnowLeopard) {
    try {
      Object listener = myListeners.get(frame);
      JComponent cmp = frame.getComponent();
      myListeners.remove(frame);
      if (listener != null && cmp != null && cmp.isShowing()) {
        ((MacGestureAdapter)listener).remove(cmp);
      }
    }
    catch (Throwable e) {
      LOG.debug(e);
    }
  }

}
 
Example #2
Source File: UIUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Direct painting into component's graphics with XORMode is broken on retina-mode so we need to paint into an intermediate buffer first.
 */
public static void paintWithXorOnRetina(@Nonnull Dimension size, @Nonnull Graphics g, boolean useRetinaCondition, Consumer<Graphics2D> paintRoutine) {
  if (!useRetinaCondition || !isRetina() || Registry.is("ide.mac.retina.disableDrawingFix", false)) {
    paintRoutine.consume((Graphics2D)g);
  }
  else {
    Rectangle rect = g.getClipBounds();
    if (rect == null) rect = new Rectangle(size);

    //noinspection UndesirableClassUsage
    Image image = new BufferedImage(rect.width * 2, rect.height * 2, BufferedImage.TYPE_INT_RGB);
    Graphics2D imageGraphics = (Graphics2D)image.getGraphics();

    imageGraphics.scale(2, 2);
    imageGraphics.translate(-rect.x, -rect.y);
    imageGraphics.setClip(rect.x, rect.y, rect.width, rect.height);

    paintRoutine.consume(imageGraphics);
    image.flush();
    imageGraphics.dispose();

    ((Graphics2D)g).scale(0.5, 0.5);
    g.drawImage(image, rect.x * 2, rect.y * 2, null);
  }
}
 
Example #3
Source File: SearchEverywhereAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public JComponent createCustomComponent(Presentation presentation, String place) {
  return new ActionButton(this, presentation, place, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE) {
    @Override
    protected void updateToolTipText() {
      String shortcutText = getShortcut();

      if (Registry.is("ide.helptooltip.enabled")) {
        HelpTooltip.dispose(this);

        new HelpTooltip().setTitle(myPresentation.getText()).setShortcut(shortcutText).setDescription("Searches for:<br/> - Classes<br/> - Files<br/> - Tool Windows<br/> - Actions<br/> - Settings")
                .installOn(this);
      }
      else {
        setToolTipText("<html><body>Search Everywhere<br/>Press <b>" + shortcutText + "</b> to access<br/> - Classes<br/> - Files<br/> - Tool Windows<br/> - Actions<br/> - Settings</body></html>");
      }
    }
  };
}
 
Example #4
Source File: DefaultFileNavigationContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void processElementsWithName(@Nonnull String name, @Nonnull final Processor<NavigationItem> _processor, @Nonnull FindSymbolParameters parameters) {
  final boolean globalSearch = parameters.getSearchScope().isSearchInLibraries();
  final Processor<PsiFileSystemItem> processor = item -> {
    if (!globalSearch && ProjectCoreUtil.isProjectOrWorkspaceFile(item.getVirtualFile())) {
      return true;
    }
    return _processor.process(item);
  };

  boolean directoriesOnly = isDirectoryOnlyPattern(parameters);
  if (!directoriesOnly) {
    FilenameIndex.processFilesByName(name, false, processor, parameters.getSearchScope(), parameters.getProject(), parameters.getIdFilter());
  }

  if (directoriesOnly || Registry.is("ide.goto.file.include.directories")) {
    FilenameIndex.processFilesByName(name, true, processor, parameters.getSearchScope(), parameters.getProject(), parameters.getIdFilter());
  }
}
 
Example #5
Source File: Breadcrumbs.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
  // this custom component does not have a corresponding UI,
  // so we should care of painting its background
  if (isOpaque()) {
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
  }
  if (g instanceof Graphics2D) {
    Graphics2D g2d = (Graphics2D)g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, getKeyForCurrentScope(!Registry.is("editor.breadcrumbs.system.font")));
    for (CrumbView view : views) {
      if (view.crumb != null) view.paint(g2d);
    }
  }
}
 
Example #6
Source File: ChangesModuleGroupingPolicy.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public ChangesBrowserNode getParentNodeFor(final StaticFilePath node, final ChangesBrowserNode rootNode) {
  if (myProject.isDefault()) return null;

  ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();

  VirtualFile vFile = node.getVf();
  if (vFile == null) {
    vFile = LocalFileSystem.getInstance().findFileByIoFile(new File(node.getPath()));
  }
  boolean hideExcludedFiles = Registry.is("ide.hide.excluded.files");
  if (vFile != null && Comparing.equal(vFile, index.getContentRootForFile(vFile, hideExcludedFiles))) {
    Module module = index.getModuleForFile(vFile, hideExcludedFiles);
    return getNodeForModule(module, rootNode);
  }
  return null;
}
 
Example #7
Source File: WorkspaceCache.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Executes a cache refresh.
 */
private void refresh() {
  final Workspace workspace = Workspace.loadUncached(project);
  if (workspace == cache && !disconnected) return;
  if (cache != null && workspace == null) {
    disconnected = true;
    return;
  }

  disconnected = false;
  cache = workspace;

  // If the current workspace is a bazel workspace, update the Dart plugin
  // registry key to indicate that there are dart projects without pubspec
  // registry keys. TODO(jacobr): it would be nice if the Dart plugin was
  // instead smarter about handling Bazel projects.
  if (cache != null) {
    if (!Registry.is(dartProjectsWithoutPubspecRegistryKey, false)) {
      Registry.get(dartProjectsWithoutPubspecRegistryKey).setValue(true);
    }
  }
  notifyListeners();
}
 
Example #8
Source File: AbstractTreeUi.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static <T> T calculateYieldingToWriteAction(@RequiredReadAction @Nonnull Supplier<? extends T> producer) throws ProcessCanceledException {
  if (!Registry.is("ide.abstractTreeUi.BuildChildrenInBackgroundYieldingToWriteAction") || ApplicationManager.getApplication().isDispatchThread()) {
    return producer.get();
  }
  ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  if (indicator != null && indicator.isRunning()) {
    return producer.get();
  }

  Ref<T> result = new Ref<>();
  boolean succeeded = ProgressManager.getInstance().runInReadActionWithWriteActionPriority(() -> result.set(producer.get()), indicator);

  if (!succeeded || indicator != null && indicator.isCanceled()) {
    throw new ProcessCanceledException();
  }
  return result.get();
}
 
Example #9
Source File: FindInProjectUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static String buildStringToFindForIndicesFromRegExp(@Nonnull String stringToFind, @Nonnull Project project) {
  if (!Registry.is("idea.regexp.search.uses.indices")) return "";

  return ReadAction.compute(() -> {
    final List<PsiElement> topLevelRegExpChars = getTopLevelRegExpChars("a", project);
    if (topLevelRegExpChars.size() != 1) return "";

    // leave only top level regExpChars
    return StringUtil.join(getTopLevelRegExpChars(stringToFind, project), new Function<PsiElement, String>() {
      final Class regExpCharPsiClass = topLevelRegExpChars.get(0).getClass();

      @Override
      public String fun(PsiElement element) {
        if (regExpCharPsiClass.isInstance(element)) {
          String text = element.getText();
          if (!text.startsWith("\\")) return text;
        }
        return " ";
      }
    }, "");
  });
}
 
Example #10
Source File: RegistryValueCommand.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected ActionCallback _execute(PlaybackContext context) {
  final String[] keyValue = getText().substring(PREFIX.length()).trim().split("=");
  if (keyValue.length != 2) {
    context.error("Expected expresstion: " + PREFIX + " key=value", getLine());
    return new ActionCallback.Rejected();
  }

  final String key = keyValue[0];
  final String value = keyValue[1];

  context.storeRegistryValue(key);

  Registry.get(key).setValue(value);

  return new ActionCallback.Done();
}
 
Example #11
Source File: JBViewport.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Dimension getPreferredScrollableViewportSize(@Nonnull JTree tree) {
  if (JTree.class != getPreferredScrollableViewportSizeDeclaringClass(tree)) {
    return tree.getPreferredScrollableViewportSize(); // may be null
  }
  Dimension size = getPreferredSizeWithoutScrollBars(tree);
  if (size == null) return new Dimension();

  int fixedHeight = tree.getRowHeight();

  int modelRows = tree.getRowCount();
  if (modelRows <= 0) {
    if (fixedHeight <= 0) fixedHeight = Registry.intValue("ide.preferred.scrollable.viewport.fixed.height");
    if (fixedHeight <= 0) fixedHeight = JBUIScale.scale(16);
  }
  int visibleRows = tree.getVisibleRowCount();
  if (visibleRows <= 0) visibleRows = Registry.intValue("ide.preferred.scrollable.viewport.visible.rows");

  boolean addExtraSpace = Registry.is("ide.preferred.scrollable.viewport.extra.space");
  Insets insets = getInnerInsets(tree);
  size.height = insets != null ? insets.top + insets.bottom : 0;
  if (0 < fixedHeight) {
    size.height += fixedHeight * visibleRows;
    if (addExtraSpace) size.height += fixedHeight / 2;
  }
  else if (visibleRows > 0) {
    int lastRow = Math.min(visibleRows, modelRows - 1);
    Rectangle bounds = tree.getRowBounds(lastRow);
    if (bounds != null) {
      size.height = bounds.y + bounds.height * (visibleRows - lastRow);
      if (addExtraSpace) {
        size.height += bounds.height / 2;
      }
      else if (insets != null) {
        size.height += insets.bottom;
      }
    }
  }
  return size;
}
 
Example #12
Source File: NavBarItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean needPaintIcon() {
  if (Registry.is("navBar.show.icons") || isPopupElement || isLastElement()) {
    return true;
  }
  Object object = getObject();
  return object instanceof PsiElement && ((PsiElement)object).getContainingFile() != null;
}
 
Example #13
Source File: KeyboardSettingsExternalizable.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isSupportedKeyboardLayout(@Nonnull Component component) {
  if (Registry.is("ide.keyboard.dvorak")) return true;
  if (SystemInfo.isMac) return false;
  String keyboardLayoutLanguage = getLanguageForComponent(component);
  for (String language : supportedNonEnglishLanguages) {
    if (language.equals(keyboardLayoutLanguage)) {
      return true;
    }
  }
  return false;
}
 
Example #14
Source File: RunManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setTemporaryConfiguration(@Nullable final RunnerAndConfigurationSettings tempConfiguration) {
  if (tempConfiguration == null) return;

  tempConfiguration.setTemporary(true);

  addConfiguration(tempConfiguration, isConfigurationShared(tempConfiguration), getBeforeRunTasks(tempConfiguration.getConfiguration()), false);
  if (Registry.is("select.run.configuration.from.context")) {
    setSelectedConfiguration(tempConfiguration);
  }
}
 
Example #15
Source File: RainbowHighlighter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Color[] generateColorSequence(@Nonnull TextAttributesScheme colorsScheme) {
  String colorDump = ApplicationManager.getApplication().isUnitTestMode()
                     ? UNIT_TEST_COLORS
                     : Registry.get("rainbow.highlighter.colors").asString();

  final List<String> registryColors = StringUtil.split(colorDump, ",");
  if (!registryColors.isEmpty()) {
    return registryColors.stream().map(s -> ColorUtil.fromHex(s.trim())).toArray(Color[]::new);
  }

  List<Color> stopColors = ContainerUtil.map(RAINBOW_COLOR_KEYS, key -> colorsScheme.getAttributes(key).getForegroundColor());
  List<Color> colors = ColorGenerator.generateLinearColorSequence(stopColors, RAINBOW_COLORS_BETWEEN);
  return colors.toArray(new Color[colors.size()]);
}
 
Example #16
Source File: ModuleDefaultVcsRootPolicy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@javax.annotation.Nullable
public VirtualFile getVcsRootFor(@Nonnull VirtualFile file) {
  FileIndexFacade indexFacade = ServiceManager.getService(myProject, FileIndexFacade.class);
  if (myBaseDir != null && indexFacade.isValidAncestor(myBaseDir, file)) {
    LOG.debug("File " + file + " is under project base dir " + myBaseDir);
    return myBaseDir;
  }
  VirtualFile contentRoot = ProjectRootManager.getInstance(myProject).getFileIndex().getContentRootForFile(file, Registry.is("ide.hide.excluded.files"));
  if (contentRoot != null) {
    LOG.debug("Content root for file " + file + " is " + contentRoot);
    if (contentRoot.isDirectory()) {
      return contentRoot;
    }
    VirtualFile parent = contentRoot.getParent();
    LOG.debug("Content root is not a directory, using its parent " + parent);
    return parent;
  }
  if (ProjectKt.isDirectoryBased(myProject)) {
    VirtualFile ideaDir = ProjectKt.getDirectoryStoreFile(myProject);
    if (ideaDir != null && VfsUtilCore.isAncestor(ideaDir, file, false)) {
      LOG.debug("File " + file + " is under .idea");
      return ideaDir;
    }
  }
  LOG.debug("Couldn't find proper root for " + file);
  return null;
}
 
Example #17
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 #18
Source File: ParameterInfoComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
ParameterInfoComponent(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, boolean requestFocus, boolean allowSwitchLabel) {
  super(new BorderLayout());
  myRequestFocus = requestFocus;

  if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
    JComponent editorComponent = editor.getComponent();
    JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    myWidthLimit = layeredPane.getWidth();
  }

  NORMAL_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.PLAIN) : UIUtil.getLabelFont();
  BOLD_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.BOLD) : NORMAL_FONT.deriveFont(Font.BOLD);

  myObjects = objects;

  setBackground(BACKGROUND);

  myHandler = handler;
  myMainPanel = new JPanel(new GridBagLayout());
  setPanels();

  if (myRequestFocus) {
    AccessibleContextUtil.setName(this, "Parameter Info. Press TAB to navigate through each element. Press ESC to close.");
  }

  final JScrollPane pane = ScrollPaneFactory.createScrollPane(myMainPanel, true);
  add(pane, BorderLayout.CENTER);

  myAllowSwitchLabel = allowSwitchLabel && !(editor instanceof EditorWindow);
  setShortcutLabel();
  myCurrentParameterIndex = -1;
}
 
Example #19
Source File: RemoteExternalSystemFacadeImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
  if (args.length < 1) {
    throw new IllegalArgumentException(
            "Can't create external system facade. Reason: given arguments don't contain information about external system resolver to use");
  }
  final Class<ExternalSystemProjectResolver<?>> resolverClass = (Class<ExternalSystemProjectResolver<?>>)Class.forName(args[0]);
  if (!ExternalSystemProjectResolver.class.isAssignableFrom(resolverClass)) {
    throw new IllegalArgumentException(
            String.format("Can't create external system facade. Reason: given external system resolver class (%s) must be IS-A '%s'", resolverClass,
                          ExternalSystemProjectResolver.class));
  }

  if (args.length < 2) {
    throw new IllegalArgumentException(
            "Can't create external system facade. Reason: given arguments don't contain information about external system build manager to use");
  }
  final Class<ExternalSystemTaskManager<?>> buildManagerClass = (Class<ExternalSystemTaskManager<?>>)Class.forName(args[1]);
  if (!ExternalSystemProjectResolver.class.isAssignableFrom(resolverClass)) {
    throw new IllegalArgumentException(
            String.format("Can't create external system facade. Reason: given external system build manager (%s) must be IS-A '%s'", buildManagerClass,
                          ExternalSystemTaskManager.class));
  }

  // running the code indicates remote communication mode with external system
  Registry.get(System.getProperty(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY) + ExternalSystemConstants.USE_IN_PROCESS_COMMUNICATION_REGISTRY_KEY_SUFFIX)
          .setValue(false);

  RemoteExternalSystemFacadeImpl facade = new RemoteExternalSystemFacadeImpl(resolverClass, buildManagerClass);
  facade.init();
  start(facade);
}
 
Example #20
Source File: MouseShortcutPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
MouseShortcutPanel(boolean allowDoubleClick) {
  super(new BorderLayout());
  myClickCount = allowDoubleClick ? 2 : 1;
  addMouseListener(myMouseListener);
  addMouseWheelListener(myMouseListener);
  if (SystemInfo.isMacIntel64 && SystemInfo.isJetBrainsJvm && Registry.is("ide.mac.forceTouch")) {
    new MacGestureSupportForMouseShortcutPanel(this, () -> myMouseShortcut = null);
  }
  setBackground(BACKGROUND);
  setOpaque(true);
}
 
Example #21
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private String decorate(String text) {
  text = StringUtil.replaceIgnoreCase(text, "</html>", "");
  text = StringUtil.replaceIgnoreCase(text, "</body>", "");
  text = StringUtil.replaceIgnoreCase(text, DocumentationMarkup.SECTIONS_START + DocumentationMarkup.SECTIONS_END, "");
  text = StringUtil.replaceIgnoreCase(text, DocumentationMarkup.SECTIONS_START + "<p>" + DocumentationMarkup.SECTIONS_END, "");
  boolean hasContent = text.contains(DocumentationMarkup.CONTENT_START);
  if (!hasContent) {
    if (!text.contains(DocumentationMarkup.DEFINITION_START)) {
      int bodyStart = findContentStart(text);
      if (bodyStart > 0) {
        text = text.substring(0, bodyStart) + DocumentationMarkup.CONTENT_START + text.substring(bodyStart) + DocumentationMarkup.CONTENT_END;
      }
      else {
        text = DocumentationMarkup.CONTENT_START + text + DocumentationMarkup.CONTENT_END;
      }
      hasContent = true;
    }
    else if (!text.contains(DocumentationMarkup.SECTIONS_START)) {
      text = StringUtil.replaceIgnoreCase(text, DocumentationMarkup.DEFINITION_START, "<div class='definition-only'><pre>");
    }
  }
  if (Registry.is("editor.new.mouse.hover.popups") && !text.contains(DocumentationMarkup.DEFINITION_START)) {
    text = text.replace("class='content'", "class='content-only'");
  }
  String location = getLocationText();
  if (location != null) {
    text = text + getBottom(hasContent) + location + "</div>";
  }
  String links = getExternalText(myManager, getElement(), myExternalUrl, myProvider);
  if (links != null) {
    text = text + getBottom(location != null) + links;
  }
  //workaround for Swing html renderer not removing empty paragraphs before non-inline tags
  text = text.replaceAll("<p>\\s*(<(?:[uo]l|h\\d|p))", "$1");
  text = addExternalLinksIcon(text);
  return text;
}
 
Example #22
Source File: DesktopTransactionGuardImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean areAssertionsEnabled() {
  Application app = ApplicationManager.getApplication();
  if (app.isUnitTestMode() && !ourTestingTransactions) {
    return false;
  }
  if (app instanceof ApplicationEx && !((ApplicationEx)app).isLoaded()) {
    return false;
  }
  return Registry.is("ide.require.transaction.for.model.changes", false);
}
 
Example #23
Source File: ComponentValidator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void hidePopup(boolean now) {
  if (popup != null && popup.isVisible()) {
    if (now || hyperlinkListener == null) {
      popup.cancel();
      popup = null;
    }
    else {
      popupAlarm.addRequest(() -> {
        if (!isOverPopup || hyperlinkListener == null) {
          hidePopup(true);
        }
      }, Registry.intValue("ide.tooltip.initialDelay.highlighter"));
    }
  }
}
 
Example #24
Source File: DialogWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void resizeWithAnimation(@Nonnull final Dimension size) {
  //todo[kb]: fix this PITA
  myResizeInProgress = true;
  if (!Registry.is("enable.animation.on.dialogs")) {
    setSize(size.width, size.height);
    myResizeInProgress = false;
    return;
  }

  new Thread("DialogWrapper resizer") {
    int time = 200;
    int steps = 7;

    @Override
    public void run() {
      int step = 0;
      final Dimension cur = getSize();
      int h = (size.height - cur.height) / steps;
      int w = (size.width - cur.width) / steps;
      while (step++ < steps) {
        setSize(cur.width + w * step, cur.height + h * step);
        TimeoutUtil.sleep(time / steps);
      }
      setSize(size.width, size.height);
      //repaint();
      if (myErrorText.shouldBeVisible()) {
        myErrorText.setVisible(true);
      }
      myResizeInProgress = false;
    }
  }.start();
}
 
Example #25
Source File: MnemonicHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes mnemonics support for the specified component and for its children if needed.
 *
 * @param component the root component of the hierarchy
 */
public static void init(Component component) {
  if (Registry.is("ide.mnemonic.helper.old", false) || Registry.is("ide.checkDuplicateMnemonics", false)) {
    new MnemonicHelper().register(component);
  }
  else {
    ourMnemonicFixer.addTo(component);
  }
}
 
Example #26
Source File: AppIcon.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public final void setErrorBadge(Project project, String text) {
  if (!isAppActive() && Registry.is("ide.appIcon.badge")) {
    _setOkBadge(getIdeFrame(project), false);
    _setTextBadge(getIdeFrame(project), text);
  }
}
 
Example #27
Source File: FocusManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private FurtherRequestor(@Nonnull IdeFocusManager manager, @Nonnull Expirable expirable) {
  myManager = manager;
  myExpirable = expirable;
  if (Registry.is("ide.debugMode")) {
    myAllocation = new Exception();
  }
}
 
Example #28
Source File: RecentLocationsDataModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private TextRange getLinesRange(Document document, int line) {
  int lineCount = document.getLineCount();
  if (lineCount == 0) {
    return TextRange.EMPTY_RANGE;
  }

  int beforeAfterLinesCount = Registry.intValue("recent.locations.lines.before.and.after", 2);

  int before = Math.min(beforeAfterLinesCount, line);
  int after = Math.min(beforeAfterLinesCount, lineCount - line);

  int linesBefore = before + beforeAfterLinesCount - after;
  int linesAfter = after + beforeAfterLinesCount - before;

  int startLine = Math.max(line - linesBefore, 0);
  int endLine = Math.min(line + linesAfter, lineCount - 1);

  int startOffset = document.getLineStartOffset(startLine);
  int endOffset = document.getLineEndOffset(endLine);

  if (startOffset <= endOffset) {
    return TextRange.create(startOffset, endOffset);
  }
  else {
    return TextRange.create(DocumentUtil.getLineTextRange(document, line));
  }
}
 
Example #29
Source File: SelectionQuotingTypedHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Result beforeCharTyped(final char charTyped, final Project project, final Editor editor, final PsiFile file, final FileType fileType) {
  // TODO[oleg] remove this hack when API changes
  if (myReplacedTextRange != null) {
    if (myReplacedTextRange.getEndOffset() <= editor.getDocument().getTextLength()) {
      if (myRestoreStickySelection && editor instanceof EditorEx) {
        EditorEx editorEx = (EditorEx)editor;
        CaretModel caretModel = editorEx.getCaretModel();
        caretModel.moveToOffset(myLtrSelection ? myReplacedTextRange.getStartOffset() : myReplacedTextRange.getEndOffset());
        editorEx.setStickySelection(true);
        caretModel.moveToOffset(myLtrSelection ? myReplacedTextRange.getEndOffset() : myReplacedTextRange.getStartOffset());
      }
      else {
        if (myLtrSelection || editor instanceof EditorWindow) {
          editor.getSelectionModel().setSelection(myReplacedTextRange.getStartOffset(), myReplacedTextRange.getEndOffset());
        }
        else {
          editor.getSelectionModel().setSelection(myReplacedTextRange.getEndOffset(), myReplacedTextRange.getStartOffset());
        }
        if (Registry.is("editor.smarterSelectionQuoting")) {
          editor.getCaretModel().moveToOffset(myLtrSelection ? myReplacedTextRange.getEndOffset() : myReplacedTextRange.getStartOffset());
        }
      }
    }
    myReplacedTextRange = null;
    return Result.STOP;
  }
  return Result.CONTINUE;
}
 
Example #30
Source File: CommentByLineCommentHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void doIndentCommenting(final Block block) {
  final Document document = block.editor.getDocument();
  final CharSequence chars = document.getCharsSequence();
  final IndentData minIndent = computeMinIndent(block.editor, block.psiFile, block.startLine, block.endLine);
  final CommonCodeStyleSettings.IndentOptions indentOptions = CodeStyle.getIndentOptions(block.psiFile);

  DocumentUtil.executeInBulk(document, block.endLine - block.startLine > Registry.intValue("comment.by.line.bulk.lines.trigger"), () -> {
    for (int line = block.endLine; line >= block.startLine; line--) {
      int lineStart = document.getLineStartOffset(line);
      int offset = lineStart;
      final StringBuilder buffer = new StringBuilder();
      while (true) {
        IndentData indent = IndentData.createFrom(buffer, 0, buffer.length(), indentOptions.TAB_SIZE);
        if (indent.getTotalSpaces() >= minIndent.getTotalSpaces()) break;
        char c = chars.charAt(offset);
        if (c != ' ' && c != '\t') {
          String newSpace = minIndent.createIndentInfo().generateNewWhiteSpace(indentOptions);
          document.replaceString(lineStart, offset, newSpace);
          offset = lineStart + newSpace.length();
          break;
        }
        buffer.append(c);
        offset++;
      }
      commentLine(block, line, offset);
    }
  });
}