Search in sources :

Example 1 with SelectionModel

use of com.android.tools.idea.uibuilder.model.SelectionModel in project android by JetBrains.

the class InteractionManagerTest method testDragAndDrop.

public void testDragAndDrop() throws Exception {
    // Drops a fragment (xmlFragment below) into the design surface (via drag & drop events) and verifies that
    // the resulting document ends up modified as expected.
    @Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    android:layout_width=\"0dp\"\n" + "    android:layout_height=\"0dp\"\n" + "    android:orientation=\"vertical\">\n" + "\n" + "</LinearLayout>\n";
    XmlFile xmlFile = (XmlFile) myFixture.addFileToProject("res/layout/layout.xml", source);
    DesignSurface surface = createSurface();
    NlModel model = createModel(surface, myFacet, xmlFile);
    ScreenView screenView = createScreen(surface, model, new SelectionModel());
    DesignSurface designSurface = screenView.getSurface();
    InteractionManager manager = createManager(designSurface);
    @Language("XML") String xmlFragment = "" + "<TextView xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "     android:layout_width=\"wrap_content\"\n" + "     android:layout_height=\"wrap_content\"\n" + "     android:text=\"Hello World\"\n" + "/>";
    Transferable transferable = createTransferable(DataFlavor.stringFlavor, xmlFragment);
    dragDrop(manager, 0, 0, 100, 100, transferable);
    Disposer.dispose(model);
    @Language("XML") String expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "    android:layout_width=\"0dp\"\n" + "    android:layout_height=\"0dp\"\n" + "    android:orientation=\"vertical\">\n" + "\n" + "    <TextView\n" + "        android:id=\"@+id/textView\"\n" + "        android:layout_width=\"match_parent\"\n" + "        android:layout_height=\"wrap_content\"\n" + "        android:text=\"Hello World\" />\n" + "</LinearLayout>\n";
    assertEquals(expected, xmlFile.getText());
}
Also used : Language(org.intellij.lang.annotations.Language) XmlFile(com.intellij.psi.xml.XmlFile) Transferable(java.awt.datatransfer.Transferable) NlModel(com.android.tools.idea.uibuilder.model.NlModel) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel)

Example 2 with SelectionModel

use of com.android.tools.idea.uibuilder.model.SelectionModel in project android by JetBrains.

the class GotoComponentAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ScreenView screenView = mySurface.getCurrentScreenView();
    if (screenView != null) {
        SelectionModel selectionModel = screenView.getSelectionModel();
        NlComponent primary = selectionModel.getPrimary();
        if (primary != null) {
            XmlTag tag = primary.getTag();
            if (tag.isValid()) {
                screenView.getSurface().deactivate();
                PsiNavigateUtil.navigate(tag);
            }
        }
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel) XmlTag(com.intellij.psi.xml.XmlTag)

Example 3 with SelectionModel

use of com.android.tools.idea.uibuilder.model.SelectionModel in project android by JetBrains.

the class DeleteAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ScreenView screenView = mySurface.getCurrentScreenView();
    if (screenView == null) {
        return;
    }
    SelectionModel selectionModel = screenView.getSelectionModel();
    NlModel model = screenView.getModel();
    model.delete(selectionModel.getSelection());
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 4 with SelectionModel

use of com.android.tools.idea.uibuilder.model.SelectionModel in project android by JetBrains.

the class SelectAllAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ScreenView screenView = mySurface.getCurrentScreenView();
    if (screenView != null) {
        SelectionModel selectionModel = screenView.getSelectionModel();
        selectionModel.selectAll(screenView.getModel());
        mySurface.repaint();
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel)

Example 5 with SelectionModel

use of com.android.tools.idea.uibuilder.model.SelectionModel in project android by JetBrains.

the class SelectParentAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ScreenView screenView = mySurface.getCurrentScreenView();
    if (screenView != null) {
        SelectionModel selectionModel = screenView.getSelectionModel();
        List<NlComponent> selection = selectionModel.getSelection();
        if (selection.size() == 1) {
            NlComponent first = selection.get(0);
            NlComponent parent = first.getParent();
            if (parent != null) {
                selectionModel.setSelection(Collections.singletonList(parent));
            }
        }
        mySurface.repaint();
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel)

Aggregations

SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)7 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)6 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)4 NlModel (com.android.tools.idea.uibuilder.model.NlModel)2 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 Update (com.intellij.util.ui.update.Update)1 Transferable (java.awt.datatransfer.Transferable)1 Language (org.intellij.lang.annotations.Language)1