Example #1
0
 /**
  * @param context
  * @return all CodeFragmentFactoryProviders that provide code fragment factories suitable in the
  *     context given
  */
 public static List<CodeFragmentFactory> getCodeFragmentFactories(@Nullable PsiElement context) {
   final DefaultCodeFragmentFactory defaultFactory = DefaultCodeFragmentFactory.getInstance();
   final CodeFragmentFactory[] providers =
       ApplicationManager.getApplication().getExtensions(CodeFragmentFactory.EXTENSION_POINT_NAME);
   final List<CodeFragmentFactory> suitableFactories =
       new ArrayList<CodeFragmentFactory>(providers.length);
   if (providers.length > 0) {
     for (CodeFragmentFactory factory : providers) {
       if (factory != defaultFactory && factory.isContextAccepted(context)) {
         suitableFactories.add(factory);
       }
     }
   }
   suitableFactories.add(defaultFactory); // let default factory be the last one
   return suitableFactories;
 }
Example #2
0
  public EvaluationDialog(Project project, TextWithImports text) {
    super(project, true);
    myProject = project;
    setModal(false);
    setCancelButtonText(CommonBundle.message("button.close"));
    setOKButtonText(DebuggerBundle.message("button.evaluate"));

    myEvaluationPanel = new MyEvaluationPanel(myProject);

    myEditor = createEditor(DefaultCodeFragmentFactory.getInstance());

    setDebuggerContext(getDebuggerContext());
    initDialogData(text);

    myContextListener =
        new DebuggerContextListener() {
          public void changeEvent(DebuggerContextImpl newContext, int event) {
            boolean close = true;
            for (DebuggerSession session :
                DebuggerManagerEx.getInstanceEx(myProject).getSessions()) {
              if (!session.isStopped()) {
                close = false;
                break;
              }
            }

            if (close) {
              close(CANCEL_EXIT_CODE);
            } else {
              setDebuggerContext(newContext);
            }
          }
        };
    DebuggerManagerEx.getInstanceEx(myProject).getContextManager().addListener(myContextListener);

    setHorizontalStretch(1f);
    setVerticalStretch(1f);
  }
  public void editNode(final DebuggerTreeNodeImpl node) {
    final DebuggerContextImpl context = getContext();
    final DebuggerExpressionComboBox comboBox =
        new DebuggerExpressionComboBox(
            getProject(),
            PositionUtil.getContextElement(context),
            "evaluation",
            DefaultCodeFragmentFactory.getInstance());
    comboBox.setText(((WatchItemDescriptor) node.getDescriptor()).getEvaluationText());
    comboBox.selectAll();

    DebuggerTreeInplaceEditor editor =
        new DebuggerTreeInplaceEditor(node) {
          public JComponent createInplaceEditorComponent() {
            return comboBox;
          }

          public JComponent getPreferredFocusedComponent() {
            return comboBox.getPreferredFocusedComponent();
          }

          public Editor getEditor() {
            return comboBox.getEditor();
          }

          public JComponent getEditorComponent() {
            return comboBox.getEditorComponent();
          }

          public void doOKAction() {
            if (comboBox.isPopupVisible()) {
              comboBox.selectPopupValue();
            }

            TextWithImports text = comboBox.getText();
            if (!text.isEmpty()) {
              WatchDebuggerTree.setWatchNodeText(node, text);
              comboBox.addRecent(text);
            } else {
              getWatchTree().removeWatch(node);
            }
            try {
              super.doOKAction();
            } finally {
              comboBox.dispose();
            }
          }

          public void cancelEditing() {
            comboBox.setPopupVisible(false);
            if (((WatchItemDescriptor) node.getDescriptor()).getEvaluationText().isEmpty()) {
              getWatchTree().removeWatch(node);
            }

            try {
              super.cancelEditing();
            } finally {
              comboBox.dispose();
            }
          }
        };
    editor.show();
  }