Search in sources :

Example 6 with DataManager

use of com.intellij.ide.DataManager in project intellij-community by JetBrains.

the class ConfigurationContext method getFromContext.

@NotNull
public static ConfigurationContext getFromContext(DataContext dataContext) {
    final ConfigurationContext context = new ConfigurationContext(dataContext);
    final DataManager dataManager = DataManager.getInstance();
    ConfigurationContext sharedContext = dataManager.loadFromDataContext(dataContext, SHARED_CONTEXT);
    if (sharedContext == null || sharedContext.getLocation() == null || context.getLocation() == null || !Comparing.equal(sharedContext.getLocation().getPsiElement(), context.getLocation().getPsiElement())) {
        sharedContext = context;
        dataManager.saveInDataContext(dataContext, SHARED_CONTEXT, sharedContext);
    }
    return sharedContext;
}
Also used : DataManager(com.intellij.ide.DataManager) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with DataManager

use of com.intellij.ide.DataManager in project intellij-community by JetBrains.

the class IdeKeyEventDispatcher method dispatchKeyEvent.

/**
   * @return {@code true} if and only if the passed event is already dispatched by the
   * {@code IdeKeyEventDispatcher} and there is no need for any other processing of the event.
   */
public boolean dispatchKeyEvent(final KeyEvent e) {
    if (myDisposed)
        return false;
    KeyboardLayoutUtil.storeAsciiForChar(e);
    if (e.isConsumed()) {
        return false;
    }
    if (isSpeedSearchEditing(e)) {
        return false;
    }
    // http://www.jetbrains.net/jira/browse/IDEADEV-12372
    if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
        if (e.getID() == KeyEvent.KEY_PRESSED) {
            myLeftCtrlPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT;
        } else if (e.getID() == KeyEvent.KEY_RELEASED) {
            myLeftCtrlPressed = false;
        }
    } else if (e.getKeyCode() == KeyEvent.VK_ALT) {
        if (e.getID() == KeyEvent.KEY_PRESSED) {
            myRightAltPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT;
        } else if (e.getID() == KeyEvent.KEY_RELEASED) {
            myRightAltPressed = false;
        }
    }
    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focusOwner = focusManager.getFocusOwner();
    // shortcuts should not work in shortcut setup fields
    if (focusOwner instanceof ShortcutTextField) {
        return false;
    }
    if (focusOwner instanceof JTextComponent && ((JTextComponent) focusOwner).isEditable()) {
        if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && e.getKeyCode() != KeyEvent.VK_ESCAPE) {
            MacUIUtil.hideCursor();
        }
    }
    MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager();
    MenuElement[] selectedPath = menuSelectionManager.getSelectedPath();
    if (selectedPath.length > 0) {
        if (!(selectedPath[0] instanceof ComboPopup)) {
            // The following couple of lines of code is a PATCH!!!
            // It is needed to ignore ENTER KEY_TYPED events which sometimes can reach editor when an action
            // is invoked from main menu via Enter key.
            setState(KeyState.STATE_PROCESSED);
            setPressedWasProcessed(true);
            return false;
        }
    }
    // Keymap shortcuts (i.e. not local shortcuts) should work only in:
    // - main frame
    // - floating focusedWindow
    // - when there's an editor in contexts
    Window focusedWindow = focusManager.getFocusedWindow();
    boolean isModalContext = focusedWindow != null && isModalContext(focusedWindow);
    //EA-39114
    if (ApplicationManager.getApplication() == null)
        return false;
    final DataManager dataManager = DataManager.getInstance();
    if (dataManager == null)
        return false;
    DataContext dataContext = dataManager.getDataContext();
    myContext.setDataContext(dataContext);
    myContext.setFocusOwner(focusOwner);
    myContext.setModalContext(isModalContext);
    myContext.setInputEvent(e);
    try {
        if (getState() == KeyState.STATE_INIT) {
            return inInitState();
        } else if (getState() == KeyState.STATE_PROCESSED) {
            return inProcessedState();
        } else if (getState() == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) {
            return inWaitForSecondStrokeState();
        } else if (getState() == KeyState.STATE_SECOND_STROKE_IN_PROGRESS) {
            return inSecondStrokeInProgressState();
        } else if (getState() == KeyState.STATE_KEY_GESTURE_PROCESSOR) {
            return myKeyGestureProcessor.process();
        } else {
            throw new IllegalStateException("state = " + getState());
        }
    } finally {
        myContext.clear();
    }
}
Also used : ShortcutTextField(com.intellij.openapi.keymap.impl.ui.ShortcutTextField) JTextComponent(javax.swing.text.JTextComponent) DataManager(com.intellij.ide.DataManager) ComboPopup(javax.swing.plaf.basic.ComboPopup) JTextComponent(javax.swing.text.JTextComponent)

Example 8 with DataManager

use of com.intellij.ide.DataManager in project android by JetBrains.

the class TreeGridTest method setUp.

@Before
public void setUp() {
    myDisposable = Disposer.newDisposable();
    Application application = mock(Application.class);
    DataManager dataManager = mock(DataManager.class);
    DataContext dataContext = mock(DataContext.class);
    ActionManager actionManager = mock(ActionManager.class);
    ApplicationManager.setApplication(application, myDisposable);
    when(application.getAnyModalityState()).thenReturn(ModalityState.NON_MODAL);
    when(application.getComponent(eq(DataManager.class))).thenReturn(dataManager);
    when(dataManager.getDataContext(any(Component.class))).thenReturn(dataContext);
    when(application.getComponent(eq(ActionManager.class))).thenReturn(actionManager);
    myGrid = new TreeGrid<>();
    myGrid.setSize(140, 800);
    myGrid.setModel(createTree());
    myGrid.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    myGrid.setFixedCellWidth(40);
    myGrid.setFixedCellHeight(40);
    myGrid.doLayout();
    BufferedImage image = UIUtil.createImage(1000, 1000, TYPE_INT_ARGB);
    myGrid.paint(image.getGraphics());
    List<JList<String>> lists = myGrid.getLists();
    myGroup1 = lists.get(0);
    myGroup2 = lists.get(1);
    myGroup3 = lists.get(2);
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) DataContext(com.intellij.openapi.actionSystem.DataContext) DataManager(com.intellij.ide.DataManager) Application(com.intellij.openapi.application.Application) BufferedImage(java.awt.image.BufferedImage) Before(org.junit.Before)

Aggregations

DataManager (com.intellij.ide.DataManager)8 DataContext (com.intellij.openapi.actionSystem.DataContext)4 Project (com.intellij.openapi.project.Project)2 AddImportAction (com.intellij.codeInsight.daemon.impl.actions.AddImportAction)1 QuestionAction (com.intellij.codeInsight.hint.QuestionAction)1 Executor (com.intellij.execution.Executor)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ChooseRunConfigurationPopup (com.intellij.execution.actions.ChooseRunConfigurationPopup)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 OptionsTopHitProvider (com.intellij.ide.ui.OptionsTopHitProvider)1 BooleanOptionDescription (com.intellij.ide.ui.search.BooleanOptionDescription)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 GotoActionModel (com.intellij.ide.util.gotoByName.GotoActionModel)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Application (com.intellij.openapi.application.Application)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ShortcutTextField (com.intellij.openapi.keymap.impl.ui.ShortcutTextField)1