com.intellij.codeInsight.CodeInsightBundle Java Examples

The following examples show how to use com.intellij.codeInsight.CodeInsightBundle. 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: PostfixTemplatesConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
public Layout() {
  myLayout = VerticalLayout.create();

  myPostfixTemplatesEnabled = CheckBox.create("&Enable postfix templates");
  myLayout.add(myPostfixTemplatesEnabled);

  myCompletionEnabledCheckbox = CheckBox.create("&Show postfix templates in completion autopopup");
  myLayout.add(myCompletionEnabledCheckbox);

  ComboBox.Builder<Character> builder = ComboBox.<Character>builder();
  builder.add(TemplateSettings.SPACE_CHAR, CodeInsightBundle.message("template.shortcut.space"));
  builder.add(TemplateSettings.ENTER_CHAR, CodeInsightBundle.message("template.shortcut.enter"));
  builder.add(TemplateSettings.TAB_CHAR, CodeInsightBundle.message("template.shortcut.tab"));
  myShortcutComboBox = builder.build();

  myLayout.add(LabeledComponents.left("Expand templates with", myShortcutComboBox));

  myPostfixTemplatesEnabled.addValueListener(event -> updateComponents());
}
 
Example #2
Source File: TemplateManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void startTemplateWithPrefix(final Editor editor,
                                    final TemplateImpl template,
                                    final int templateStart,
                                    @Nullable final PairProcessor<String, String> processor,
                                    @Nullable final String argument) {
  final int caretOffset = editor.getCaretModel().getOffset();
  final TemplateState templateState = initTemplateState(editor);
  CommandProcessor commandProcessor = CommandProcessor.getInstance();
  commandProcessor.executeCommand(myProject, () -> {
    editor.getDocument().deleteString(templateStart, caretOffset);
    editor.getCaretModel().moveToOffset(templateStart);
    editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    editor.getSelectionModel().removeSelection();
    Map<String, String> predefinedVarValues = null;
    if (argument != null) {
      predefinedVarValues = new HashMap<>();
      predefinedVarValues.put(TemplateImpl.ARG, argument);
    }
    templateState.start(template, processor, predefinedVarValues);
  }, CodeInsightBundle.message("insert.code.template.command"), null);
}
 
Example #3
Source File: GotoImplementationHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
protected String getChooserTitle(@Nonnull PsiElement sourceElement, String name, int length, boolean finished) {
  ItemPresentation presentation = ((NavigationItem)sourceElement).getPresentation();
  String fullName;
  if (presentation == null) {
    fullName = name;
  }
  else {
    PsiElement container = getContainer(sourceElement);
    ItemPresentation containerPresentation = container == null || container instanceof PsiFile ? null : ((NavigationItem)container).getPresentation();
    String containerText = containerPresentation == null ? null : containerPresentation.getPresentableText();
    fullName = (containerText == null ? "" : containerText+".") + presentation.getPresentableText();
  }
  return CodeInsightBundle.message("goto.implementation.chooserTitle", fullName, length, finished ? "" : " so far");
}
 
Example #4
Source File: TemplateListPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private JPanel createExpandByPanel() {
  JPanel panel = new JPanel(new GridBagLayout());
  GridBagConstraints gbConstraints = new GridBagConstraints();
  gbConstraints.weighty = 0;
  gbConstraints.weightx = 0;
  gbConstraints.gridy = 0;
  panel.add(new JLabel(CodeInsightBundle.message("templates.dialog.shortcut.chooser.label")), gbConstraints);

  gbConstraints.gridx = 1;
  gbConstraints.insets = new Insets(0, 4, 0, 0);
  myExpandByCombo = new JComboBox();
  myExpandByCombo.addItem(SPACE);
  myExpandByCombo.addItem(TAB);
  myExpandByCombo.addItem(ENTER);
  panel.add(myExpandByCombo, gbConstraints);

  gbConstraints.gridx = 2;
  gbConstraints.weightx = 1;
  panel.add(new JPanel(), gbConstraints);
  panel.setBorder(new EmptyBorder(0, 0, 10, 0));
  return panel;
}
 
Example #5
Source File: GenerateAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull final AnActionEvent e) {
  DataContext dataContext = e.getDataContext();

  Project project = e.getRequiredData(CommonDataKeys.PROJECT);
  final ListPopup popup =
          JBPopupFactory.getInstance().createActionGroupPopup(
                  CodeInsightBundle.message("generate.list.popup.title"),
                  wrapGroup(getGroup(), dataContext, project),
                  dataContext,
                  JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
                  false);

  popup.showInBestPositionFor(dataContext);
}
 
Example #6
Source File: ParameterInfoComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setShortcutLabel() {
  if (myShortcutLabel != null) remove(myShortcutLabel);

  String upShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_UP);
  String downShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_DOWN);
  if (!myAllowSwitchLabel || myObjects.length <= 1 || !myHandler.supportsOverloadSwitching() || upShortcut.isEmpty() && downShortcut.isEmpty()) {
    myShortcutLabel = null;
  }
  else {
    myShortcutLabel = new JLabel(upShortcut.isEmpty() || downShortcut.isEmpty()
                                 ? CodeInsightBundle.message("parameter.info.switch.overload.shortcuts.single", upShortcut.isEmpty() ? downShortcut : upShortcut)
                                 : CodeInsightBundle.message("parameter.info.switch.overload.shortcuts", upShortcut, downShortcut));
    myShortcutLabel.setForeground(CONTEXT_HELP_FOREGROUND);
    Font labelFont = UIUtil.getLabelFont();
    myShortcutLabel.setFont(labelFont.deriveFont(labelFont.getSize2D() - (SystemInfo.isWindows ? 1 : 2)));
    myShortcutLabel.setBorder(JBUI.Borders.empty(6, 10, 0, 10));
    add(myShortcutLabel, BorderLayout.SOUTH);
  }
}
 
Example #7
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void executeUpdateParameterInfo(PsiElement elementForUpdating, MyUpdateParameterInfoContext context, Runnable continuation) {
  PsiElement parameterOwner = context.getParameterOwner();
  if (parameterOwner != null && !parameterOwner.equals(elementForUpdating)) {
    context.removeHint();
    return;
  }

  runTask(myProject, ReadAction.nonBlocking(() -> {
    try {
      myHandler.updateParameterInfo(elementForUpdating, context);
      return elementForUpdating;
    }
    catch (IndexNotReadyException e) {
      DumbService.getInstance(myProject).showDumbModeNotification(CodeInsightBundle.message("parameter.info.indexing.mode.not.supported"));
    }
    return null;
  }).withDocumentsCommitted(myProject).expireWhen(() -> !myKeepOnHintHidden && !myHint.isVisible() && !ApplicationManager.getApplication().isHeadlessEnvironment() ||
                                                        getCurrentOffset() != context.getOffset() ||
                                                        !elementForUpdating.isValid()).expireWith(this), element -> {
    if (element != null && continuation != null) {
      context.applyUIChanges();
      continuation.run();
    }
  }, null, myEditor);
}
 
Example #8
Source File: LiveTemplateSettingsEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private JComponent createNorthPanel() {
  JPanel panel = new JPanel(new GridBagLayout());

  GridBag gb = new GridBag().setDefaultInsets(4, 4, 4, 4).setDefaultWeightY(1).setDefaultFill(GridBagConstraints.BOTH);

  JLabel keyPrompt = new JLabel(CodeInsightBundle.message("dialog.edit.template.label.abbreviation"));
  keyPrompt.setLabelFor(myKeyField);
  panel.add(keyPrompt, gb.nextLine().next());

  panel.add(myKeyField, gb.next().weightx(1));

  JLabel descriptionPrompt = new JLabel(CodeInsightBundle.message("dialog.edit.template.label.description"));
  descriptionPrompt.setLabelFor(myDescription);
  panel.add(descriptionPrompt, gb.next());

  panel.add(myDescription, gb.next().weightx(3));
  return panel;
}
 
Example #9
Source File: LayoutCodeDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
public LayoutCodeDialog(@Nonnull Project project,
                        @Nonnull PsiFile file,
                        boolean textSelected,
                        final String helpId) {
  super(project, true);
  myFile = file;
  myProject = project;
  myTextSelected = textSelected;
  myHelpId = helpId;

  myLastRunOptions = new LastRunReformatCodeOptionsProvider(PropertiesComponent.getInstance());
  myRunOptions = createOptionsBundledOnDialog();

  setOKButtonText(CodeInsightBundle.message("reformat.code.accept.button.text"));
  setTitle("Reformat File: " + file.getName());

  init();
}
 
Example #10
Source File: ReformatCodeAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static DirectoryFormattingOptions getDirectoryFormattingOptions(@Nonnull Project project, @Nonnull PsiDirectory dir) {
  LayoutDirectoryDialog dialog = new LayoutDirectoryDialog(
          project,
          CodeInsightBundle.message("process.reformat.code"),
          CodeInsightBundle.message("process.scope.directory", dir.getVirtualFile().getPath()),
          FormatChangedTextUtil.hasChanges(dir)
  );

  boolean enableIncludeDirectoriesCb = dir.getSubdirectories().length > 0;
  dialog.setEnabledIncludeSubdirsCb(enableIncludeDirectoriesCb);
  dialog.setSelectedIncludeSubdirsCb(enableIncludeDirectoriesCb);

  if (dialog.showAndGet()) {
    return dialog;
  }
  return null;
}
 
Example #11
Source File: ReformatCodeAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static ReformatFilesOptions getLayoutProjectOptions(@Nonnull Project project, @Nullable Module module) {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    return myTestOptions;
  }

  final String text = module != null ? CodeInsightBundle.message("process.scope.module", module.getModuleDir())
                                     : CodeInsightBundle.message("process.scope.project", project.getPresentableUrl());

  final boolean enableOnlyVCSChangedRegions = module != null ? FormatChangedTextUtil.hasChanges(module)
                                                             : FormatChangedTextUtil.hasChanges(project);

  LayoutProjectCodeDialog dialog =
          new LayoutProjectCodeDialog(project, CodeInsightBundle.message("process.reformat.code"), text, enableOnlyVCSChangedRegions);
  if (!dialog.showAndGet()) {
    return null;
  }
  return dialog;
}
 
Example #12
Source File: LayoutProjectCodeDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  myTitle.setText(myText);
  myOptionsPanel.setBorder(IdeBorderFactory.createTitledBorder(CodeInsightBundle.message("reformat.directory.dialog.options")));
  myFiltersPanel.setBorder(IdeBorderFactory.createTitledBorder(CodeInsightBundle.message("reformat.directory.dialog.filters")));

  myMaskWarningLabel.setIcon(AllIcons.General.Warning);
  myMaskWarningLabel.setVisible(false);

  myIncludeSubdirsCb.setVisible(shouldShowIncludeSubdirsCb());

  initFileTypeFilter();
  initScopeFilter();

  restoreCbsStates();
  return myWholePanel;
}
 
Example #13
Source File: IntentionDescriptionPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void reset(IntentionActionMetaData actionMetaData, String filter)  {
  try {
    final TextDescriptor url = actionMetaData.getDescription();
    final String description = url == null ?
                               CodeInsightBundle.message("under.construction.string") :
                               SearchUtil.markup(url.getText(), filter);
    myDescriptionBrowser.setText(description);
    setupPoweredByPanel(actionMetaData);

    showUsages(myBeforePanel, myBeforeSeparator, myBeforeUsagePanels, actionMetaData.getExampleUsagesBefore());
    showUsages(myAfterPanel, myAfterSeparator, myAfterUsagePanels, actionMetaData.getExampleUsagesAfter());

    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        myPanel.revalidate();
      }
    });

  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
Example #14
Source File: HighlightUsagesHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void setStatusText(Project project, final String elementName, int refCount, boolean clearHighlights) {
  String message;
  if (clearHighlights) {
    message = "";
  }
  else if (refCount > 0) {
    message = CodeInsightBundle.message(elementName != null ?
                                        "status.bar.highlighted.usages.message" :
                                        "status.bar.highlighted.usages.no.target.message", refCount, elementName, getShortcutText());
  }
  else {
    message = CodeInsightBundle.message(elementName != null ?
                                        "status.bar.highlighted.usages.not.found.message" :
                                        "status.bar.highlighted.usages.not.found.no.target.message", elementName);
  }
  WindowManager.getInstance().getStatusBar(project).setInfo(message);
}
 
Example #15
Source File: ProblemsHolder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static String unresolvedReferenceMessage(@Nonnull PsiReference reference) {
  String message;
  if (reference instanceof EmptyResolveMessageProvider) {
    String pattern = ((EmptyResolveMessageProvider)reference).getUnresolvedMessagePattern();
    try {
      message = BundleBase.format(pattern, reference.getCanonicalText()); // avoid double formatting
    }
    catch (IllegalArgumentException ex) {
      // unresolvedMessage provided by third-party reference contains wrong format string (e.g. {}), tolerate it
      message = pattern;
      LOG.info(pattern);
    }
  }
  else {
    message = CodeInsightBundle.message("error.cannot.resolve.default.message", reference.getCanonicalText());
  }
  return message;
}
 
Example #16
Source File: OptimizeImportsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
protected JComponent createCenterPanel() {
  JPanel panel = new JPanel();
  BoxLayout layout = new BoxLayout(panel, BoxLayout.Y_AXIS);
  panel.setLayout(layout);

  panel.add(new JLabel(myText));
  myOnlyVcsCheckBox = new JCheckBox(CodeInsightBundle.message("process.scope.changed.files"));
  boolean lastRunVcsChangedTextEnabled = myLastRunOptions.getLastTextRangeType() == TextRangeType.VCS_CHANGED_TEXT;

  myOnlyVcsCheckBox.setEnabled(myContextHasChanges);
  myOnlyVcsCheckBox.setSelected(myContextHasChanges && lastRunVcsChangedTextEnabled);
  myOnlyVcsCheckBox.setBorder(new EmptyBorder(0, 10, 0, 0));
  panel.add(myOnlyVcsCheckBox);
  return panel;
}
 
Example #17
Source File: EscapeHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Editor editor, DataContext dataContext) {
  TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
  if (templateState != null && !templateState.isFinished()) {
    SelectionModel selectionModel = editor.getSelectionModel();
    LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);

    // the idea behind lookup checking is that if there is a preselected value in lookup
    // then user might want just to close lookup but not finish a template.
    // E.g. user wants to move to the next template segment by Tab without completion invocation.
    // If there is no selected value in completion that user definitely wants to finish template
    boolean lookupIsEmpty = lookup == null || lookup.getCurrentItem() == null;
    if (!selectionModel.hasSelection() && lookupIsEmpty) {
      CommandProcessor.getInstance().setCurrentCommandName(CodeInsightBundle.message("finish.template.command"));
      templateState.gotoEnd(true);
      return;
    }
  }

  if (myOriginalHandler.isEnabled(editor, dataContext)) {
    myOriginalHandler.execute(editor, dataContext);
  }
}
 
Example #18
Source File: HaxeRestoreReferencesDialog.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final JPanel panel = new JPanel(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
  myList = new JBList((Object[])myNamedElements);
  myList.setCellRenderer(new FQNameCellRenderer());
  panel.add(ScrollPaneFactory.createScrollPane(myList), BorderLayout.CENTER);

  panel.add(new JBLabel(CodeInsightBundle.message("dialog.paste.on.import.text"), SMALL, BRIGHTER), BorderLayout.NORTH);

  final JPanel buttonPanel = new JPanel(new VerticalFlowLayout());
  final JButton okButton = new JButton(CommonBundle.getOkButtonText());
  getRootPane().setDefaultButton(okButton);
  buttonPanel.add(okButton);
  final JButton cancelButton = new JButton(CommonBundle.getCancelButtonText());
  buttonPanel.add(cancelButton);

  panel.setPreferredSize(new Dimension(500, 400));

  return panel;
}
 
Example #19
Source File: HaxeRestoreReferencesDialog.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
public HaxeRestoreReferencesDialog(final Project project, final String[] elements) {
  super(project, true);
  myNamedElements = elements;
  /*
  for (Object element : elements) {
    if (!(element instanceof PsiClass)) {
      myContainsClassesOnly = false;
      break;
    }
  }
  */
  /*
  if (myContainsClassesOnly) {
    setTitle(CodeInsightBundle.message("dialog.import.on.paste.title"));
  }
  else {
    setTitle(CodeInsightBundle.message("dialog.import.on.paste.title2"));
  }
  */
  setTitle(CodeInsightBundle.message("dialog.import.on.paste.title"));
  init();

  myList.setSelectionInterval(0, myNamedElements.length - 1);
}
 
Example #20
Source File: IntentionHintComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void onMouseEnter(final boolean small) {
  myIconLabel.setIcon(myHighlightedIcon);
  myPanel.setBorder(small ? createActiveBorderSmall() : createActiveBorder());

  String acceleratorsText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
  if (!acceleratorsText.isEmpty()) {
    myIconLabel.setToolTipText(CodeInsightBundle.message("lightbulb.tooltip", acceleratorsText));
  }
}
 
Example #21
Source File: GotoTestOrCodeHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected String getChooserTitle(@Nonnull PsiElement sourceElement, String name, int length, boolean finished) {
  String suffix = finished ? "" : " so far";
  if (TestFinderHelper.isTest(sourceElement)) {
    return CodeInsightBundle.message("goto.test.chooserTitle.subject", name, length, suffix);
  }
  else {
    return CodeInsightBundle.message("goto.test.chooserTitle.test", name, length, suffix);
  }
}
 
Example #22
Source File: IntentionManagerSettings.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void processOptions(@Nonnull SearchableOptionProcessor processor) {
  for (IntentionActionBean bean : IntentionManager.EP_INTENTION_ACTIONS.getExtensionList()) {
    String[] categories = bean.getCategories();

    if (categories == null) {
      continue;
    }
    String descriptionDirectoryName = bean.getDescriptionDirectoryName();

    IntentionActionWrapper intentionAction = new IntentionActionWrapper(bean);
    if (descriptionDirectoryName == null) {
      descriptionDirectoryName = IntentionManagerImpl.getDescriptionDirectoryName(intentionAction);
    }

    IntentionActionMetaData data = new IntentionActionMetaData(intentionAction, getClassLoader(intentionAction), categories, descriptionDirectoryName);

    final TextDescriptor description = data.getDescription();

    try {
      String descriptionText = description.getText().toLowerCase();
      descriptionText = HTML_PATTERN.matcher(descriptionText).replaceAll(" ");
      final Set<String> words = processor.getProcessedWordsWithoutStemming(descriptionText);
      words.addAll(processor.getProcessedWords(data.getFamily()));
      for (String word : words) {
        processor.addOption(word, data.getFamily(), data.getFamily(), IntentionSettingsConfigurable.HELP_ID, CodeInsightBundle.message("intention.settings"));
      }
    }
    catch (IOException e) {
      LOG.error(e);
    }
  }
}
 
Example #23
Source File: ReformatFilesDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ReformatFilesDialog(@Nonnull Project project, @Nonnull VirtualFile[] files) {
  super(project, true);
  myLastRunSettings = new LastRunReformatCodeOptionsProvider(PropertiesComponent.getInstance());

  boolean canTargetVcsChanges = FormatChangedTextUtil.hasChanges(files, project);
  myOnlyChangedText.setEnabled(canTargetVcsChanges);
  myOnlyChangedText.setSelected(canTargetVcsChanges && myLastRunSettings.getLastTextRangeType() == VCS_CHANGED_TEXT);
  myOptimizeImports.setSelected(myLastRunSettings.getLastOptimizeImports());
  myRearrangeEntriesCb.setSelected(myLastRunSettings.getLastRearrangeCode());

  setTitle(CodeInsightBundle.message("dialog.reformat.files.title"));
  init();
}
 
Example #24
Source File: HighlightUsagesHandlerBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void buildStatusText(@Nullable String elementName, int refCount) {
  if (refCount > 0) {
    myStatusText = CodeInsightBundle.message(elementName != null ?
                                             "status.bar.highlighted.usages.message" :
                                             "status.bar.highlighted.usages.no.target.message", refCount, elementName,
                                             HighlightUsagesHandler.getShortcutText());
  }
  else {
    myHintText = CodeInsightBundle.message(elementName != null ?
                                           "status.bar.highlighted.usages.not.found.message" :
                                           "status.bar.highlighted.usages.not.found.no.target.message", elementName);
  }
}
 
Example #25
Source File: SurroundWithTemplateHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void invoke(@Nonnull final Project project, @Nonnull final Editor editor, @Nonnull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  DefaultActionGroup group = createActionGroup(project, editor, file);
  if (group == null) return;

  final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(CodeInsightBundle.message("templates.select.template.chooser.title"), group,
                                                                              DataManager.getInstance().getDataContext(editor.getContentComponent()),
                                                                              JBPopupFactory.ActionSelectionAid.MNEMONICS, false);

  popup.showInBestPositionFor(editor);
}
 
Example #26
Source File: GotoTypeDeclarationAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public void invoke(@Nonnull final Project project, @Nonnull Editor editor, @Nonnull PsiFile file) {
  PsiDocumentManager.getInstance(project).commitAllDocuments();

  int offset = editor.getCaretModel().getOffset();
  PsiElement[] symbolTypes = findSymbolTypes(editor, offset);
  if (symbolTypes == null || symbolTypes.length == 0) return;
  if (symbolTypes.length == 1) {
    navigate(project, symbolTypes[0]);
  }
  else {
    NavigationUtil.getPsiElementPopup(symbolTypes, CodeInsightBundle.message("choose.type.popup.title")).showInBestPositionFor(editor);
  }
}
 
Example #27
Source File: TemplateManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void startTemplate(final Editor editor,
                           final String selectionString,
                           final Template template,
                           boolean inSeparateCommand,
                           TemplateEditingListener listener,
                           final PairProcessor<String, String> processor,
                           final Map<String, String> predefinedVarValues) {
  final TemplateState templateState = initTemplateState(editor);

  //noinspection unchecked
  templateState.getProperties().put(ExpressionContext.SELECTION, selectionString);

  if (listener != null) {
    templateState.addTemplateStateListener(listener);
  }
  Runnable r = () -> {
    if (selectionString != null) {
      ApplicationManager.getApplication().runWriteAction(() -> EditorModificationUtil.deleteSelectedText(editor));
    }
    else {
      editor.getSelectionModel().removeSelection();
    }
    templateState.start((TemplateImpl)template, processor, predefinedVarValues);
  };
  if (inSeparateCommand) {
    CommandProcessor.getInstance().executeCommand(myProject, r, CodeInsightBundle.message("insert.code.template.command"), null);
  }
  else {
    r.run();
  }

  if (shouldSkipInTests()) {
    if (!templateState.isFinished()) templateState.gotoEnd(false);
  }
}
 
Example #28
Source File: LayoutProjectCodeDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LayoutProjectCodeDialog(@Nonnull Project project,
                               @Nonnull String title,
                               @Nonnull String text,
                               boolean enableOnlyVCSChangedTextCb)
{
  super(project, false);
  myText = text;
  myProject = project;
  myEnableOnlyVCSChangedTextCb = enableOnlyVCSChangedTextCb;
  myLastRunOptions = new LastRunReformatCodeOptionsProvider(PropertiesComponent.getInstance());

  setOKButtonText(CodeInsightBundle.message("reformat.code.accept.button.text"));
  setTitle(title);
  init();
}
 
Example #29
Source File: OptimizeImportsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
OptimizeImportsDialog(Project project, String text, boolean hasChanges) {
  super(project, false);
  myText = text;
  myContextHasChanges = hasChanges;
  myLastRunOptions = new LastRunReformatCodeOptionsProvider(PropertiesComponent.getInstance());
  setOKButtonText(CodeInsightBundle.message("reformat.code.accept.button.text"));
  setTitle(CodeInsightBundle.message("process.optimize.imports"));
  init();
}
 
Example #30
Source File: AbstractLayoutCodeProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean checkFileWritable(final PsiFile file) {
  if (!file.isWritable()) {
    MessagesEx.fileIsReadOnly(myProject, file.getVirtualFile()).setTitle(CodeInsightBundle.message("error.dialog.readonly.file.title")).showLater();
    return false;
  }
  else {
    return true;
  }
}