com.intellij.ide.DataManager Java Examples

The following examples show how to use com.intellij.ide.DataManager. 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: NavBarUpdateQueue.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void requestModelUpdateFromContextOrObject(DataContext dataContext, Object object) {
  try {
    final NavBarModel model = myPanel.getModel();
    if (dataContext != null) {
      if (dataContext.getData(CommonDataKeys.PROJECT) != myPanel.getProject() || myPanel.isNodePopupActive()) {
        requestModelUpdate(null, myPanel.getContextObject(), true);
        return;
      }
      final Window window = SwingUtilities.getWindowAncestor(myPanel);
      if (window != null && !window.isFocused()) {
        model.updateModel(DataManager.getInstance().getDataContext(myPanel));
      }
      else {
        model.updateModel(dataContext);
      }
    }
    else {
      model.updateModel(object);
    }

    queueRebuildUi();
  }
  finally {
    myModelUpdating.set(false);
  }
}
 
Example #2
Source File: MacOSDefaultMenuInitializer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
@ReviewAfterMigrationToJRE(9)
public MacOSDefaultMenuInitializer(AboutManager aboutManager, DataManager dataManager, WindowManager windowManager) {
  myAboutManager = aboutManager;
  myDataManager = dataManager;
  myWindowManager = windowManager;
  if (SystemInfo.isMac) {
    try {
      ThrowableRunnable<Throwable> task = SystemInfo.isJavaVersionAtLeast(9) ? new Java9Worker(this::showAbout) : new PreJava9Worker(this::showAbout);

      task.run();

      installAutoUpdateMenu();
    }
    catch (Throwable t) {
      LOGGER.warn(t);
    }
  }
}
 
Example #3
Source File: PathEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private VirtualFile[] doAdd() {
  VirtualFile baseDir = myAddBaseDir;
  Project project = DataManager.getInstance().getDataContext(myComponent).getData(CommonDataKeys.PROJECT);
  if (baseDir == null && project != null) {
    baseDir = project.getBaseDir();
  }
  VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myComponent, project, baseDir);
  files = adjustAddedFileSet(myComponent, files);
  List<VirtualFile> added = new ArrayList<VirtualFile>(files.length);
  for (VirtualFile vFile : files) {
    if (addElement(vFile)) {
      added.add(vFile);
    }
  }
  return VfsUtil.toVirtualFileArray(added);
}
 
Example #4
Source File: CloseActiveTabAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(e.getDataContext(), true);
  boolean processed = false;
  if (contentManager != null && contentManager.canCloseContents()) {
    final Content selectedContent = contentManager.getSelectedContent();
    if (selectedContent != null && selectedContent.isCloseable()) {
      contentManager.removeContent(selectedContent, true);
      processed = true;
    }
  }

  if (!processed && contentManager != null) {
    final DataContext context = DataManager.getInstance().getDataContext(contentManager.getComponent());
    final ToolWindow tw = context.getData(PlatformDataKeys.TOOL_WINDOW);
    if (tw != null) {
      tw.hide(null);
    }
  }
}
 
Example #5
Source File: XDebuggerEditorBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
private ListPopup createLanguagePopup() {
  DefaultActionGroup actions = new DefaultActionGroup();
  for (Language language : getSupportedLanguages()) {
    //noinspection ConstantConditions
    actions.add(new AnAction(language.getDisplayName(), null, language.getAssociatedFileType().getIcon()) {
      @RequiredUIAccess
      @Override
      public void actionPerformed(@Nonnull AnActionEvent e) {
        XExpression currentExpression = getExpression();
        setExpression(new XExpressionImpl(currentExpression.getExpression(), language, currentExpression.getCustomInfo()));
        requestFocusInEditor();
      }
    });
  }

  DataContext dataContext = DataManager.getInstance().getDataContext(getComponent());
  return JBPopupFactory.getInstance().createActionGroupPopup("Choose Language", actions, dataContext,
                                                             JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
                                                             false);
}
 
Example #6
Source File: LightPlatformCodeInsightTestCase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected static DataContext getCurrentEditorDataContext() {
  final DataContext defaultContext = DataManager.getInstance().getDataContext();
  return new DataContext() {
    @Override
    @javax.annotation.Nullable
    public Object getData(@NonNls Key dataId) {
      if (PlatformDataKeys.EDITOR == dataId) {
        return getEditor();
      }
      if (CommonDataKeys.PROJECT == dataId) {
        return getProject();
      }
      if (LangDataKeys.PSI_FILE == dataId) {
        return getFile();
      }
      if (LangDataKeys.PSI_ELEMENT == dataId) {
        PsiFile file = getFile();
        if (file == null) return null;
        Editor editor = getEditor();
        if (editor == null) return null;
        return file.findElementAt(editor.getCaretModel().getOffset());
      }
      return defaultContext.getData(dataId);
    }
  };
}
 
Example #7
Source File: WidgetEditToolbar.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final AnAction action = ActionManager.getInstance().getAction("Flutter.ExtractWidget");
  if (action != null) {
    TransactionGuard.submitTransaction(project, () -> {
      final Editor editor = getCurrentEditor();
      if (editor == null) {
        // It is a race condition if we hit this. Gracefully assume
        // the action has just been canceled.
        return;
      }
      final JComponent editorComponent = editor.getComponent();
      final DataContext editorContext = DataManager.getInstance().getDataContext(editorComponent);
      final AnActionEvent editorEvent = AnActionEvent.createFromDataContext(ActionPlaces.UNKNOWN, null, editorContext);

      action.actionPerformed(editorEvent);
    });
  }
}
 
Example #8
Source File: ButtonToolbarImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
ActionJButton(final AnAction action) {
  super(action.getTemplatePresentation().getText());
  myAction = action;
  setMnemonic(action.getTemplatePresentation().getMnemonic());
  setDisplayedMnemonicIndex(action.getTemplatePresentation().getDisplayedMnemonicIndex());

  addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      AnActionEvent event = new AnActionEvent(null, ((BaseDataManager)DataManager.getInstance()).getDataContextTest(ButtonToolbarImpl.this), myPlace, myPresentationFactory.getPresentation(action),
                                              ActionManager.getInstance(), e.getModifiers());
      if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) {
        ActionUtil.performActionDumbAware(action, event);
      }
    }
  });

}
 
Example #9
Source File: ActionsTree.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void reset(final Keymap keymap, final QuickList[] allQuickLists, String filter, @Nullable KeyboardShortcut shortcut) {
  myKeymap = keymap;

  final PathsKeeper pathsKeeper = new PathsKeeper();
  pathsKeeper.storePaths();

  myRoot.removeAllChildren();

  ActionManager actionManager = ActionManager.getInstance();
  Project project = DataManager.getInstance().getDataContext(myComponent).getData(CommonDataKeys.PROJECT);
  Group mainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, allQuickLists, filter, true, filter != null && filter.length() > 0 ?
                                                                                                    ActionsTreeUtil.isActionFiltered(filter, true) :
                                                                                                    (shortcut != null ? ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut) : null));
  if ((filter != null && filter.length() > 0 || shortcut != null) && mainGroup.initIds().isEmpty()){
    mainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, allQuickLists, filter, false, filter != null && filter.length() > 0 ?
                                                                                                 ActionsTreeUtil.isActionFiltered(filter, false) :
                                                                                                 ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut));
  }
  myRoot = ActionsTreeUtil.createNode(mainGroup);
  myMainGroup = mainGroup;
  MyModel model = (MyModel)myTree.getModel();
  model.setRoot(myRoot);
  model.nodeStructureChanged(myRoot);

  pathsKeeper.restorePaths();
}
 
Example #10
Source File: BranchActionGroupPopup.java    From consulo with Apache License 2.0 6 votes vote down vote up
public BranchActionGroupPopup(@Nonnull String title, @Nonnull Project project, @Nonnull Condition<AnAction> preselectActionCondition, @Nonnull ActionGroup actions, @Nullable String dimensionKey) {
  super(title, createBranchSpeedSearchActionGroup(actions), SimpleDataContext.getProjectContext(project), preselectActionCondition, true);
  myProject = project;
  DataManager.registerDataProvider(getList(), dataId -> POPUP_MODEL == dataId ? getListModel() : null);
  myKey = dimensionKey;
  if (myKey != null) {
    Dimension storedSize = WindowStateService.getInstance(myProject).getSizeFor(myProject, myKey);
    if (storedSize != null) {
      //set forced size before component is shown
      setSize(storedSize);
      myUserSizeChanged = true;
    }
    createTitlePanelToolbar(myKey);
  }
  myMeanRowHeight = getList().getCellBounds(0, 0).height + UIUtil.getListCellVPadding() * 2;
}
 
Example #11
Source File: DesktopContentManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (PlatformDataKeys.CONTENT_MANAGER == dataId || PlatformDataKeys.NONEMPTY_CONTENT_MANAGER == dataId && getContentCount() > 1) {
    return DesktopContentManagerImpl.this;
  }

  for (DataProvider dataProvider : myDataProviders) {
    Object data = dataProvider.getData(dataId);
    if (data != null) {
      return data;
    }
  }

  if (myUI instanceof DataProvider) {
    return ((DataProvider)myUI).getData(dataId);
  }

  DataProvider provider = DataManager.getDataProvider(this);
  return provider == null ? null : provider.getData(dataId);
}
 
Example #12
Source File: LanguageConsoleImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setupEditor(@Nonnull EditorEx editor) {
  ConsoleViewUtil.setupConsoleEditor(editor, false, false);
  editor.getContentComponent().setFocusCycleRoot(false);
  editor.setHorizontalScrollbarVisible(true);
  editor.setVerticalScrollbarVisible(true);
  editor.setBorder(null);

  EditorSettings editorSettings = editor.getSettings();
  editorSettings.setAdditionalLinesCount(1);
  editorSettings.setAdditionalColumnsCount(1);

  DataManager.registerDataProvider(editor.getComponent(), (dataId) -> getEditorData(editor, dataId));
}
 
Example #13
Source File: EditSourceOnEnterKeyHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void install(@Nullable final Runnable before, final JComponent component,
                           @Nullable final Runnable whenPerformed) {
  component.registerKeyboardAction(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      DataContext dataContext = DataManager.getInstance().getDataContext(component);
      if (before != null) before.run();
      OpenSourceUtil.openSourcesFrom(dataContext, true);
      if (whenPerformed != null) whenPerformed.run();
    }
  }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
}
 
Example #14
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void startFindUsages(@Nonnull PsiElement element, @Nonnull RelativePoint popupPosition, Editor editor, int maxUsages) {
  Project project = element.getProject();
  FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager();
  FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(element, false);
  if (handler == null) return;
  if (myShowSettingsDialogBefore) {
    showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
    return;
  }
  showElementUsages(editor, popupPosition, handler, maxUsages, handler.getFindUsagesOptions(DataManager.getInstance().getDataContext()));
}
 
Example #15
Source File: ActionManagerEx.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void fireBeforeActionPerformed(String actionId, InputEvent event) {
  final AnAction action = getAction(actionId);
  if (action != null) {
    final DataContext context = DataManager.getInstance().getDataContext();
    final AnActionEvent e = new AnActionEvent(event, context, ActionPlaces.UNKNOWN, action.getTemplatePresentation(), this, 0);
    fireBeforeActionPerformed(action, context, e);
  }
}
 
Example #16
Source File: FindInProjectUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void showSettings() {
  Content selectedContent = UsageViewContentManager.getInstance(myProject).getSelectedContent(true);
  JComponent component = selectedContent == null ? null : selectedContent.getComponent();
  FindInProjectManager findInProjectManager = FindInProjectManager.getInstance(myProject);
  findInProjectManager.findInProject(DataManager.getInstance().getDataContext(component), myFindModel);
}
 
Example #17
Source File: AutoScrollToSourceHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void scrollToSource(final Component tree) {
  DataContext dataContext=DataManager.getInstance().getDataContext(tree);
  getReady(dataContext).doWhenDone(new Runnable() {
    @Override
    public void run() {
      DataContext context = DataManager.getInstance().getDataContext(tree);
      final VirtualFile vFile = context.getData(PlatformDataKeys.VIRTUAL_FILE);
      if (vFile != null) {
        // Attempt to navigate to the virtual file with unknown file type will show a modal dialog
        // asking to register some file type for this file. This behaviour is undesirable when autoscrolling.
        if (vFile.getFileType() == UnknownFileType.INSTANCE || vFile.getFileType() instanceof INativeFileType) return;

        //IDEA-84881 Don't autoscroll to very large files
        if (vFile.getLength() > PersistentFSConstants.getMaxIntellisenseFileSize()) return;
      }
      Navigatable[] navigatables = context.getData(PlatformDataKeys.NAVIGATABLE_ARRAY);
      if (navigatables != null) {
        if (navigatables.length > 1) {
          return;
        }
        for (Navigatable navigatable : navigatables) {
          // we are not going to open modal dialog during autoscrolling
          if (!navigatable.canNavigateToSource()) return;
        }
      }
      OpenSourceUtil.openSourcesFrom(context, false);
    }
  });
}
 
Example #18
Source File: DiffSideView.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setEditorSource(final Project project, final EditorSource source) {
  MyState state = new MyState();
  myEditorSource = source;
  myLineMarker.attach(myEditorSource);
  Editor editor = myEditorSource.getEditor();
  final FileEditor fileEditor = myEditorSource.getFileEditor();
  if (editor == null) {
    insertComponent(fileEditor == null ? MOCK_COMPONENT : fileEditor.getComponent());
    DataManager.registerDataProvider(myPanel, new DataProvider() {
      @Override
      public Object getData(@Nonnull @NonNls Key<?> dataId) {
        if (CommonDataKeys.PROJECT == dataId) {
          return project;
        }
        if (PlatformDataKeys.FILE_EDITOR == dataId) {
          return fileEditor;
        }
        return null;
      }
    });
    if (fileEditor != null) {
      ScrollUtil.scrollVertically(fileEditor.getComponent(), 0);
      ScrollUtil.scrollHorizontally(fileEditor.getComponent(), 0);

    }
  }
  else {
    DataManager.removeDataProvider(myPanel);
    editor.getScrollingModel().scrollHorizontally(0);
    insertComponent(editor.getComponent());
    applyHighlighter();
    setMouseListeners(source);
    MyEditorFocusListener.install(this);

    state.restore();
  }
}
 
Example #19
Source File: XDebugView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static <T> T getData(Key<T> key, @Nonnull Component component) {
  DataContext dataContext = DataManager.getInstance().getDataContext(component);
  ViewContext viewContext = dataContext.getData(ViewContext.CONTEXT_KEY);
  ContentManager contentManager = viewContext == null ? null : viewContext.getContentManager();
  if (contentManager != null) {
    T data = DataManager.getInstance().getDataContext(contentManager.getComponent()).getData(key);
    if (data != null) {
      return data;
    }
  }
  return dataContext.getData(key);
}
 
Example #20
Source File: RerunFailedTestsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean getAction(@Nonnull AnActionEvent e, boolean execute) {
  Project project = e.getProject();
  if (project == null) {
    return false;
  }

  RunContentDescriptor contentDescriptor = ExecutionManager.getInstance(project).getContentManager().getSelectedContent();
  if (contentDescriptor == null) {
    return false;
  }

  JComponent component = contentDescriptor.getComponent();
  if (component == null) {
    return false;
  }

  ExecutionEnvironment environment = DataManager.getInstance().getDataContext(component).getData(LangDataKeys.EXECUTION_ENVIRONMENT);
  if (environment == null) {
    return false;
  }

  AnAction[] actions = contentDescriptor.getRestartActions();
  if (actions.length == 0) {
    return false;
  }

  for (AnAction action : actions) {
    if (action instanceof AbstractRerunFailedTestsAction) {
      if (execute) {
        ((AbstractRerunFailedTestsAction)action).execute(e, environment);
      }
      return true;
    }
  }
  return false;
}
 
Example #21
Source File: EditSourceOnDoubleClickHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void install(final JList list, final Runnable whenPerformed) {
  new DoubleClickListener() {
    @Override
    protected boolean onDoubleClick(MouseEvent e) {
      Point point = e.getPoint();
      int index = list.locationToIndex(point);
      if (index == -1) return false;
      if (!list.getCellBounds(index, index).contains(point)) return false;
      DataContext dataContext = DataManager.getInstance().getDataContext(list);
      OpenSourceUtil.openSourcesFrom(dataContext, true);
      whenPerformed.run();
      return true;
    }
  }.installOn(list);
}
 
Example #22
Source File: CodeCompletionHandlerBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void addCompletionChar(InsertionContext context, LookupElement item) {
  if (!context.getOffsetMap().containsOffset(InsertionContext.TAIL_OFFSET)) {
    String message = "tailOffset<0 after inserting " + item + " of " + item.getClass();
    if (context instanceof WatchingInsertionContext) {
      message += "; invalidated at: " + ((WatchingInsertionContext)context).invalidateTrace + "\n--------";
    }
    LOG.info(message);
  }
  else if (!CompletionAssertions.isEditorValid(context.getEditor())) {
    LOG.info("Injected editor invalidated " + context.getEditor());
  }
  else {
    context.getEditor().getCaretModel().moveToOffset(context.getTailOffset());
  }
  if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
    Language language = PsiUtilBase.getLanguageInEditor(context.getEditor(), context.getFile().getProject());
    if (language != null) {
      for (SmartEnterProcessor processor : SmartEnterProcessors.INSTANCE.allForLanguage(language)) {
        if (processor.processAfterCompletion(context.getEditor(), context.getFile())) break;
      }
    }
  }
  else {
    DataContext dataContext = DataManager.getInstance().getDataContext(context.getEditor().getContentComponent());
    EditorActionManager.getInstance().getTypedAction().getHandler().execute(context.getEditor(), context.getCompletionChar(), dataContext);
  }
}
 
Example #23
Source File: LanguageConsoleImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void initComponents() {
  setupComponents();

  myPanel.add(myHistoryViewer.getComponent());
  myPanel.add(myConsoleExecutionEditor.getComponent());
  myPanel.add(myScrollBar);
  myPanel.setBackground(myConsoleExecutionEditor.getEditor().getBackgroundColor());
  DataManager.registerDataProvider(myPanel, this);
}
 
Example #24
Source File: MergeRequestProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public Object getData(@Nonnull Key<?> dataId) {
  Object data;

  DataProvider contentProvider = ((BaseDataManager)DataManager.getInstance()).getDataProviderEx(myContentPanel.getTargetComponent());
  if (contentProvider != null) {
    data = contentProvider.getData(dataId);
    if (data != null) return data;
  }

  if (CommonDataKeys.PROJECT == dataId) {
    return myProject;
  }
  else if (PlatformDataKeys.HELP_ID == dataId) {
    if (myRequest.getUserData(DiffUserDataKeys.HELP_ID) != null) {
      return myRequest.getUserData(DiffUserDataKeys.HELP_ID);
    }
    else {
      return "procedures.vcWithIDEA.commonVcsOps.integrateDiffs.resolveConflict";
    }
  }

  DataProvider requestProvider = myRequest.getUserData(DiffUserDataKeys.DATA_PROVIDER);
  if (requestProvider != null) {
    data = requestProvider.getData(dataId);
    if (data != null) return data;
  }

  DataProvider contextProvider = myContext.getUserData(DiffUserDataKeys.DATA_PROVIDER);
  if (contextProvider != null) {
    data = contextProvider.getData(dataId);
    if (data != null) return data;
  }
  return null;
}
 
Example #25
Source File: IntroduceVariableDialog.java    From CppTools with Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
  myNewVarName = new NameSuggestionsField(
    calcVariants(),
    (Project) DataManager.getInstance().getDataContext().getData(DataConstants.PROJECT),
    CppSupportLoader.CPP_FILETYPE
  );
}
 
Example #26
Source File: StatisticsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public StatisticsPanel(final Project project, final TestFrameworkRunningModel model) {
  myProject = project;
  myTableModel = new StatisticsTableModel();
  myStatisticsTableView.setModelAndUpdateColumns(myTableModel);
  myFrameworkRunningModel = model;

  final Runnable gotoSuiteOrParentAction = createGotoSuiteOrParentAction();
  new DoubleClickListener() {
    @Override
    protected boolean onDoubleClick(MouseEvent e) {
      gotoSuiteOrParentAction.run();
      return true;
    }
  }.installOn(myStatisticsTableView);

  // Fire selection changed and move focus on SHIFT+ENTER
  final KeyStroke shiftEnterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK);
  SMRunnerUtil.registerAsAction(shiftEnterKey, "select-test-proxy-in-test-view",
                          new Runnable() {
                            public void run() {
                              showSelectedProxyInTestsTree();
                            }
                          },
                          myStatisticsTableView);

  // Expand selected or go to parent on ENTER
  final KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
  SMRunnerUtil.registerAsAction(enterKey, "go-to-selected-suite-or-parent",
                          gotoSuiteOrParentAction,
                          myStatisticsTableView);
  // Contex menu in Table
  PopupHandler.installPopupHandler(myStatisticsTableView, IdeActions.GROUP_TESTTREE_POPUP, ActionPlaces.TESTTREE_VIEW_POPUP);
  // set this statistic tab as dataprovider for test's table view
  DataManager.registerDataProvider(myStatisticsTableView, this);
}
 
Example #27
Source File: BuckDependencyOptimizerTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private void doTest() {
  myFixture.configureByFile("dependencyOptimizer/" + getTestName(false) + "/before.BUCK");

  OptimizeImportsAction.actionPerformedImpl(
      DataManager.getInstance().getDataContext(myFixture.getEditor().getContentComponent()));

  myFixture.checkResultByFile("dependencyOptimizer/" + getTestName(true) + "/after.BUCK");
}
 
Example #28
Source File: IdeErrorsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
  final DataContext dataContext = ((BaseDataManager)DataManager.getInstance()).getDataContextTest((Component)e.getSource());

  AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, myAnalyze.getTemplatePresentation(), ActionManager.getInstance(), e.getModifiers());

  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project != null) {
    myAnalyze.actionPerformed(event);
    doOKAction();
  }
}
 
Example #29
Source File: ActionUpdater.java    From consulo with Apache License 2.0 5 votes vote down vote up
private DataContext getDataContext(@Nonnull AnAction action) {
  if (myVisitor == null) return myDataContext;
  if (myDataContext instanceof AsyncDataContext)  // it's very expensive to create async-context for each custom component
    return myDataContext;                         // and such actions (with custom components, i.e. buttons from dialogs) updates synchronously now
  final Component component = myVisitor.getCustomComponent(action);
  return component != null ? DataManager.getInstance().getDataContext(component) : myDataContext;
}
 
Example #30
Source File: ExpressionOrStatementInsertHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredWriteAction
public void handleInsert(final InsertionContext context, final T item)
{
	final Editor editor = context.getEditor();
	final Document document = editor.getDocument();
	context.commitDocument();

	handleInsertImpl(context, item, editor, document);

	if(myOpenChar == '{')
	{
		document.insertString(editor.getCaretModel().getOffset(), "\n");
	}

	context.commitDocument();

	PsiElement elementAt = context.getFile().findElementAt(context.getStartOffset());
	PsiElement parent = elementAt == null ? null : elementAt.getParent();
	if(parent != null)
	{
		CodeStyleManager.getInstance(parent.getProject()).reformat(parent);

		if(myOpenChar == '{')
		{
			EditorWriteActionHandler actionHandler = (EditorWriteActionHandler) EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
			actionHandler.executeWriteAction(editor, DataManager.getInstance().getDataContext(editor.getContentComponent()));
		}
	}
}