Search in sources :

Example 51 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class AbstractPopup method installProjectDisposer.

private void installProjectDisposer() {
    final Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (c != null) {
        final DataContext context = DataManager.getInstance().getDataContext(c);
        final Project project = CommonDataKeys.PROJECT.getData(context);
        if (project != null) {
            myProjectDisposable = new Disposable() {

                @Override
                public void dispose() {
                    if (!AbstractPopup.this.isDisposed()) {
                        Disposer.dispose(AbstractPopup.this);
                    }
                }
            };
            Disposer.register(project, myProjectDisposable);
        }
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) JTextComponent(javax.swing.text.JTextComponent)

Example 52 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project android by JetBrains.

the class NlPalettePanelTest method testCopy.

public void testCopy() throws Exception {
    myPanel.requestFocus();
    DataContext context = mock(DataContext.class);
    CopyProvider provider = (CopyProvider) myPanel.getData(PlatformDataKeys.COPY_PROVIDER.getName());
    assertThat(provider).isNotNull();
    assertThat(provider.isCopyVisible(context)).isTrue();
    assertThat(provider.isCopyEnabled(context)).isTrue();
    provider.performCopy(context);
    ArgumentCaptor<Transferable> captor = ArgumentCaptor.forClass(Transferable.class);
    verify(myCopyPasteManager).setContents(captor.capture());
    Transferable transferable = captor.getValue();
    assertThat(transferable).isNotNull();
    assertThat(transferable.isDataFlavorSupported(ItemTransferable.DESIGNER_FLAVOR)).isTrue();
    Object item = transferable.getTransferData(ItemTransferable.DESIGNER_FLAVOR);
    assertThat(item).isInstanceOf(DnDTransferItem.class);
    DnDTransferItem dndItem = (DnDTransferItem) item;
    assertThat(dndItem.getComponents().size()).isEqualTo(1);
    DnDTransferComponent component = dndItem.getComponents().get(0);
    assertThat(component.getRepresentation()).startsWith(("<TextView"));
}
Also used : DnDTransferComponent(com.android.tools.idea.uibuilder.model.DnDTransferComponent) DataContext(com.intellij.openapi.actionSystem.DataContext) CopyProvider(com.intellij.ide.CopyProvider) Transferable(java.awt.datatransfer.Transferable) ItemTransferable(com.android.tools.idea.uibuilder.model.ItemTransferable) DnDTransferItem(com.android.tools.idea.uibuilder.model.DnDTransferItem)

Example 53 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project android by JetBrains.

the class ProjectsTest method testGetSelectedModules.

public void testGetSelectedModules() {
    createAndAddGradleFacet(myModule);
    DataContext dataContext = createMock(DataContext.class);
    Module[] data = { myModule };
    expect(dataContext.getData(LangDataKeys.MODULE_CONTEXT_ARRAY.getName())).andReturn(data);
    replay(dataContext);
    Module[] selectedModules = Projects.getModulesToBuildFromSelection(myProject, dataContext);
    assertSame(data, selectedModules);
    verify(dataContext);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) Module(com.intellij.openapi.module.Module)

Example 54 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project android by JetBrains.

the class NlComponentTreeTest method testPasteIsNotPossibleWhenMultipleComponentsAreSelected.

public void testPasteIsNotPossibleWhenMultipleComponentsAreSelected() {
    copy(myTextView);
    DataContext context = mock(DataContext.class);
    myModel.getSelectionModel().toggle(myLinearLayout);
    myModel.getSelectionModel().toggle(myAbsoluteLayout);
    assertThat(myTree.isPasteEnabled(context)).isTrue();
    assertThat(myTree.isPastePossible(context)).isFalse();
    myTree.performPaste(context);
    assertThat(toTree()).isEqualTo("<RelativeLayout>  [expanded]\n" + "    <LinearLayout>  [expanded]  [selected]\n" + "        <Button>\n" + "    <TextView>\n" + "    <AbsoluteLayout>  [selected]\n");
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext)

Example 55 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project android by JetBrains.

the class NlComponentTreeTest method testPasteAfterCut.

public void testPasteAfterCut() {
    cut(myTextView);
    DataContext context = mock(DataContext.class);
    myModel.getSelectionModel().clear();
    myModel.getSelectionModel().toggle(myButton);
    assertThat(myTree.isPasteEnabled(context)).isTrue();
    assertThat(myTree.isPastePossible(context)).isTrue();
    myTree.performPaste(context);
    assertThat(toTree()).isEqualTo("<RelativeLayout>  [expanded]\n" + "    <LinearLayout>  [expanded]\n" + "        <Button>  [selected]\n" + "        <TextView>\n" + "    <AbsoluteLayout>\n");
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext)

Aggregations

DataContext (com.intellij.openapi.actionSystem.DataContext)204 Project (com.intellij.openapi.project.Project)73 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 NotNull (org.jetbrains.annotations.NotNull)23 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)23 Editor (com.intellij.openapi.editor.Editor)22 Nullable (org.jetbrains.annotations.Nullable)21 FileEditor (com.intellij.openapi.fileEditor.FileEditor)20 PsiFile (com.intellij.psi.PsiFile)17 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)16 Module (com.intellij.openapi.module.Module)13 PsiElement (com.intellij.psi.PsiElement)13 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 DataManager (com.intellij.ide.DataManager)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)9 List (java.util.List)9 Consumer (com.intellij.util.Consumer)7 AnAction (com.intellij.openapi.actionSystem.AnAction)6 Transferable (java.awt.datatransfer.Transferable)6