Search in sources :

Example 91 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 92 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 93 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 94 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)

Example 95 with DataContext

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

the class NlComponentTreeTest method testCopyIntoRootWhenNothingIsSelected.

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

Aggregations

DataContext (com.intellij.openapi.actionSystem.DataContext)202 Project (com.intellij.openapi.project.Project)71 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 NotNull (org.jetbrains.annotations.NotNull)23 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)23 Editor (com.intellij.openapi.editor.Editor)21 Nullable (org.jetbrains.annotations.Nullable)21 FileEditor (com.intellij.openapi.fileEditor.FileEditor)20 PsiFile (com.intellij.psi.PsiFile)16 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 DataManager (com.intellij.ide.DataManager)9 Presentation (com.intellij.openapi.actionSystem.Presentation)9 List (java.util.List)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)8 Consumer (com.intellij.util.Consumer)7 AnAction (com.intellij.openapi.actionSystem.AnAction)6 Transferable (java.awt.datatransfer.Transferable)6