com.intellij.psi.util.PsiElementFilter#com.intellij.codeInsight.template.TemplateContextType源码实例Demo

下面列出了com.intellij.psi.util.PsiElementFilter#com.intellij.codeInsight.template.TemplateContextType 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


private void addContextNode(MultiMap<TemplateContextType, TemplateContextType> hierarchy,
                            CheckedTreeNode parent,
                            TemplateContextType type) {
  final Collection<TemplateContextType> children = hierarchy.get(type);
  final String name = UIUtil.removeMnemonic(type.getPresentableName());
  final CheckedTreeNode node = new CheckedTreeNode(Pair.create(children.isEmpty() ? type : null, name));
  parent.add(node);

  if (children.isEmpty()) {
    node.setChecked(myContext.get(type));
  }
  else {
    for (TemplateContextType child : children) {
      addContextNode(hierarchy, node, child);
    }
    final CheckedTreeNode other = new CheckedTreeNode(Pair.create(type, "Other"));
    other.setChecked(myContext.get(type));
    node.add(other);
  }
}
 
源代码2 项目: consulo   文件: TemplateListPanel.java

private void createTemplateEditor(final TemplateImpl template,
                                  String shortcut,
                                  Map<TemplateOptionalProcessor, Boolean> options,
                                  Map<TemplateContextType, Boolean> context) {
  myCurrentTemplateEditor = new LiveTemplateSettingsEditor(template, shortcut, options, context, new Runnable() {
    @Override
    public void run() {
      DefaultMutableTreeNode node = getNode(getSingleSelectedIndex());
      if (node != null) {
        ((DefaultTreeModel)myTree.getModel()).nodeChanged(node);
        TemplateSettings.getInstance().setLastSelectedTemplate(template.getGroupName(), template.getKey());
      }
    }
  }, TemplateSettings.getInstance().getTemplate(template.getKey(), template.getGroupName()) != null);
  for (Component component : myDetailsPanel.getComponents()) {
    if (component instanceof LiveTemplateSettingsEditor) {
      myDetailsPanel.remove(component);
    }
  }

  myDetailsPanel.add(myCurrentTemplateEditor, TEMPLATE_SETTINGS);
}
 
源代码3 项目: consulo   文件: TemplateContext.java

Map<TemplateContextType, Boolean> getDifference(@Nullable TemplateContext defaultContext) {
  Map<TemplateContextType, Boolean> result = ContainerUtil.newLinkedHashMap();
  synchronized (myContextStates) {
    //noinspection NestedSynchronizedStatement
    synchronized (defaultContext == null ? myContextStates : defaultContext.myContextStates) {
      for (TemplateContextType contextType : TemplateContextType.EP_NAME.getExtensions()) {
        String context = contextType.getContextId();
        Boolean myStateInContext = myContextStates.get(context);
        if (myStateInContext != null && differsFromDefault(defaultContext, context, myStateInContext)) {
          result.put(contextType, myStateInContext);
        }
      }
    }
  }
  return result;
}
 

private List<TemplateContextType> getApplicableContexts() {
  ArrayList<TemplateContextType> result = new ArrayList<TemplateContextType>();
  for (TemplateContextType type : myContext.keySet()) {
    if (myContext.get(type).booleanValue()) {
      result.add(type);
    }
  }
  return result;
}
 

private boolean isExpandableFromEditor() {
  boolean hasNonExpandable = false;
  for (TemplateContextType type : getApplicableContexts()) {
    if (type.isExpandableFromEditor()) {
      return true;
    }
    hasNonExpandable = true;
  }
  
  return !hasNonExpandable;
}
 

private void updateHighlighter() {
  List<TemplateContextType> applicableContexts = getApplicableContexts();
  if (!applicableContexts.isEmpty()) {
    TemplateContext contextByType = new TemplateContext();
    contextByType.setEnabled(applicableContexts.get(0), true);
    TemplateEditorUtil.setHighlighter(myTemplateEditor, contextByType);
    return;
  }
  ((EditorEx) myTemplateEditor).repaint(0, myTemplateEditor.getDocument().getTextLength());
}
 
源代码7 项目: consulo   文件: TemplateListPanel.java

private boolean areContextsEqual(final TemplateImpl newTemplate, final TemplateImpl originalTemplate) {
  Map<TemplateContextType, Boolean> templateContext = getTemplateContext(newTemplate);
  for (TemplateContextType processor : templateContext.keySet()) {
    if (originalTemplate.getTemplateContext().isEnabled(processor) != templateContext.get(processor).booleanValue())
      return false;
  }
  return true;
}
 
源代码8 项目: consulo   文件: TemplateListPanel.java

private void copyRow() {
  int selected = getSingleSelectedIndex();
  if (selected < 0) return;

  TemplateImpl orTemplate = getTemplate(selected);
  LOG.assertTrue(orTemplate != null);
  TemplateImpl template = orTemplate.copy();
  template.setKey(ABBREVIATION);
  myTemplateOptions.put(getKey(template), new HashMap<TemplateOptionalProcessor, Boolean>(getTemplateOptions(orTemplate)));
  myTemplateContext.put(getKey(template), new HashMap<TemplateContextType, Boolean>(getTemplateContext(orTemplate)));
  registerTemplate(template);

  updateTemplateDetails(true);
}
 
源代码9 项目: consulo   文件: TemplateContext.java

public boolean isEnabled(TemplateContextType contextType) {
  Boolean storedValue = isEnabledBare(contextType);
  if (storedValue == null) {
    TemplateContextType baseContextType = contextType.getBaseContextType();
    if (baseContextType != null && !(baseContextType instanceof EverywhereContextType)) {
      return isEnabled(baseContextType);
    }
    return false;
  }
  return storedValue.booleanValue();
}
 
源代码10 项目: consulo   文件: TemplateContext.java

void writeTemplateContext(Element element, @Nullable TemplateContext defaultContext) throws WriteExternalException {
  Map<TemplateContextType, Boolean> diff = getDifference(defaultContext);
  for (TemplateContextType type : diff.keySet()) {
    Element optionElement = new Element("option");
    optionElement.setAttribute("name", type.getContextId());
    optionElement.setAttribute("value", diff.get(type).toString());
    element.addContent(optionElement);
  }
}
 
源代码11 项目: consulo   文件: TemplateImpl.java

public Map<TemplateContextType, Boolean> createContext(){

    Map<TemplateContextType, Boolean> context = new LinkedHashMap<TemplateContextType, Boolean>();
    for (TemplateContextType processor : TemplateContextType.EP_NAME.getExtensions()) {
      context.put(processor, getTemplateContext().isEnabled(processor));
    }
    return context;

  }
 
源代码12 项目: consulo   文件: TemplateEditorUtil.java

private static Document createDocument(CharSequence text, @Nullable Map<TemplateContextType, Boolean> context, Project project) {
  if (context != null) {
    for (Map.Entry<TemplateContextType, Boolean> entry : context.entrySet()) {
      if (entry.getValue()) {
        return entry.getKey().createDocument(text, project);
      }
    }
  }

  return EditorFactory.getInstance().createDocument(text);
}
 
源代码13 项目: consulo   文件: EditVariableDialog.java

public EditVariableDialog(Editor editor, Component parent, ArrayList<Variable> variables, List<TemplateContextType> contextTypes) {
  super(parent, true);
  myContextTypes = contextTypes;
  myVariables = variables;
  myEditor = editor;
  init();
  setTitle(CodeInsightBundle.message("templates.dialog.edit.variables.title"));
  setOKButtonText(CommonBundle.getOkButtonText());
}
 

RmlContextType(@NotNull String id, @NotNull String presentableName, @Nullable Class<? extends TemplateContextType> baseContextType) {
    super(id, presentableName, baseContextType);
}
 
源代码15 项目: intellij-xquery   文件: XQueryContextType.java

protected XQueryContextType(@NotNull @NonNls String id, @NotNull String presentableName,
                            @Nullable Class<? extends TemplateContextType> baseContextType) {
    super(id, presentableName, baseContextType);
}
 

public ANTLRLiveTemplateContext(@NotNull @NonNls String id,
								@NotNull String presentableName,
								@Nullable Class<? extends TemplateContextType> baseContextType)
{
	super(id, presentableName, baseContextType);
}
 
源代码17 项目: buck   文件: BuckCodeContexts.java

BaseTemplateContext(
    @NotNull @NonNls String id,
    @NotNull String presentableName,
    @Nullable Class<? extends TemplateContextType> baseContextType) {
  super(id, presentableName, baseContextType);
}
 

private JPanel createShortContextPanel(final boolean allowNoContexts) {
  JPanel panel = new JPanel(new BorderLayout());

  final JLabel ctxLabel = new JLabel();
  final JLabel change = new JLabel();
  change.setForeground(JBColor.BLUE);
  change.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  panel.add(ctxLabel, BorderLayout.CENTER);
  panel.add(change, BorderLayout.EAST);

  final Runnable updateLabel = new Runnable() {
    @Override
    public void run() {
      StringBuilder sb = new StringBuilder();
      String oldPrefix = "";
      for (TemplateContextType type : getApplicableContexts()) {
        final TemplateContextType base = type.getBaseContextType();
        String ownName = UIUtil.removeMnemonic(type.getPresentableName());
        String prefix = "";
        if (base != null && !(base instanceof EverywhereContextType)) {
          prefix = UIUtil.removeMnemonic(base.getPresentableName()) + ": ";
          ownName = StringUtil.decapitalize(ownName);
        }
        if (type instanceof EverywhereContextType) {
          ownName = "Other";
        }
        if (sb.length() > 0) {
          sb.append(oldPrefix.equals(prefix) ? ", " : "; ");
        }
        if (!oldPrefix.equals(prefix)) {
          sb.append(prefix);
          oldPrefix = prefix;
        }
        sb.append(ownName);
      }
      final boolean noContexts = sb.length() == 0;
      ctxLabel.setText((noContexts ? "No applicable contexts" + (allowNoContexts ? "" : " yet") : "Applicable in " + sb.toString()) + ".  ");
      ctxLabel.setForeground(noContexts ? allowNoContexts ? JBColor.GRAY : JBColor.RED : UIUtil.getLabelForeground());
      change.setText(noContexts ? "Define" : "Change");
    }
  };

  new ClickListener() {
    @Override
    public boolean onClick(MouseEvent e, int clickCount) {
      if (disposeContextPopup()) return false;

      final JPanel content = createPopupContextPanel(updateLabel);
      Dimension prefSize = content.getPreferredSize();
      if (myLastSize != null && (myLastSize.width > prefSize.width || myLastSize.height > prefSize.height)) {
        content.setPreferredSize(new Dimension(Math.max(prefSize.width, myLastSize.width), Math.max(prefSize.height, myLastSize.height)));
      }
      myContextPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null).setResizable(true).createPopup();
      myContextPopup.show(new RelativePoint(change, new Point(change.getWidth() , -content.getPreferredSize().height - 10)));
      myContextPopup.addListener(new JBPopupAdapter() {
        @Override
        public void onClosed(LightweightWindowEvent event) {
          myLastSize = content.getSize();
        }
      });
      return true;
    }
  }.installOn(change);

  updateLabel.run();

  return panel;
}
 
源代码19 项目: consulo   文件: TemplateListPanel.java

private Map<TemplateContextType, Boolean> getTemplateContext(final TemplateImpl newTemplate) {
  return myTemplateContext.get(getKey(newTemplate));
}
 
源代码20 项目: consulo   文件: TemplateContext.java

private Boolean isEnabledBare(TemplateContextType contextType) {
  synchronized (myContextStates) {
    return myContextStates.get(contextType.getContextId());
  }
}
 
源代码21 项目: consulo   文件: TemplateContext.java

public void setEnabled(TemplateContextType contextType, boolean value) {
  synchronized (myContextStates) {
    myContextStates.put(contextType.getContextId(), value);
  }
}
 
源代码22 项目: consulo   文件: TemplateImpl.java

public void applyContext(final Map<TemplateContextType, Boolean> context) {
  for (Map.Entry<TemplateContextType, Boolean> entry : context.entrySet()) {
    getTemplateContext().setEnabled(entry.getKey(), entry.getValue().booleanValue());
  }
}
 
源代码23 项目: consulo   文件: TemplateEditorUtil.java

public static Editor createEditor(boolean isReadOnly, CharSequence text, @Nullable Map<TemplateContextType, Boolean> context) {
  final Project project = DataManager.getInstance().getDataContext().getData(CommonDataKeys.PROJECT);
  return createEditor(isReadOnly, createDocument(text, context, project), project);
}
 
源代码24 项目: consulo   文件: EditVariableDialog.java

private JComponent createVariablesTable() {
  final String[] names = {
    CodeInsightBundle.message("templates.dialog.edit.variables.table.column.name"),
    CodeInsightBundle.message("templates.dialog.edit.variables.table.column.expression"),
    CodeInsightBundle.message("templates.dialog.edit.variables.table.column.default.value"),
    CodeInsightBundle.message("templates.dialog.edit.variables.table.column.skip.if.defined")
  };

  // Create a model of the data.
  TableModel dataModel = new VariablesModel(names);

  // Create the table
  myTable = new JBTable(dataModel);
  myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  myTable.setPreferredScrollableViewportSize(new Dimension(500, myTable.getRowHeight() * 8));
  myTable.getColumn(names[0]).setPreferredWidth(120);
  myTable.getColumn(names[1]).setPreferredWidth(200);
  myTable.getColumn(names[2]).setPreferredWidth(200);
  myTable.getColumn(names[3]).setPreferredWidth(100);
  if (myVariables.size() > 0) {
    myTable.getSelectionModel().setSelectionInterval(0, 0);
  }

  JComboBox comboField = new JComboBox();
  Macro[] macros = MacroFactory.getMacros();
  Arrays.sort(macros, new Comparator<Macro> () {
    @Override
    public int compare(Macro m1, Macro m2) {
      return m1.getPresentableName().compareTo(m2.getPresentableName());
    }
  });
  eachMacro:
  for (Macro macro : macros) {
    for (TemplateContextType contextType : myContextTypes) {
      if (macro.isAcceptableInContext(contextType)) {
        comboField.addItem(macro.getPresentableName());
        continue eachMacro;
      }
    }
  }
  comboField.setEditable(true);
  DefaultCellEditor cellEditor = new DefaultCellEditor(comboField);
  cellEditor.setClickCountToStart(1);
  myTable.getColumn(names[1]).setCellEditor(cellEditor);
  myTable.setRowHeight(comboField.getPreferredSize().height);

  JTextField textField = new JTextField();

  /*textField.addMouseListener(
    new PopupHandler(){
      public void invokePopup(Component comp,int x,int y){
        showCellPopup((JTextField)comp,x,y);
      }
    }
  );*/

  cellEditor = new DefaultCellEditor(textField);
  cellEditor.setClickCountToStart(1);
  myTable.setDefaultEditor(String.class, cellEditor);

  final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTable).disableAddAction().disableRemoveAction();
  return decorator.createPanel();
}