Skip to content

Commit

Permalink
Create a FeatureEnableService so Layout Preview tab appears in IntelliJ
Browse files Browse the repository at this point in the history
Summary:
This diffs adds a `FeatureEnableService` to the IdeaBuck plugin so that IntelliJ displays the Layout Preview "Design" tab for Android layout XML files.

Without "Design" tab below XML editor:
![layout-xml-without-tabs](https://user-images.githubusercontent.com/3178606/28805673-9ab28d32-7620-11e7-9808-9960e973e680.png)

With "Design" tab below XML editor that provides access to Android Layout Preview:
![layout-xml-with-tabs](https://user-images.githubusercontent.com/3178606/28805674-9ac5cf6e-7620-11e7-8045-f97c92e7d0e3.png)
Closes facebook#1434

Reviewed By: mkillianey, styurin

Pulled By: styurin

fbshipit-source-id: 1399ae1
  • Loading branch information
jbarr21 authored and facebook-github-bot committed Oct 10, 2017
1 parent deda86e commit ee5297b
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .idea/libraries/android.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/com/facebook/buck/intellij/ideabuck/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<change-notes><![CDATA[
<h3>3.4</h3>
<ul>
<li></li>
<li>Enable Layout Preview in Android projects generated by <code>buck project</code>.</li>
</ul>
<h3>3.3</h3>
Expand Down Expand Up @@ -166,11 +166,13 @@
</change-notes>

<!-- please see https://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
<idea-version since-build="171.3019"/>
<idea-version since-build="172.1294"/>

<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.lang</depends>

<depends optional="true">org.jetbrains.android</depends>

<extensions defaultExtensionNs="com.intellij">
<fileTypeFactory implementation="com.facebook.buck.intellij.ideabuck.file.BuckFileTypeFactory"/>
<lang.parserDefinition
Expand Down Expand Up @@ -232,6 +234,10 @@
<runLineMarkerContributor language="JAVA" implementationClass="com.facebook.buck.intellij.ideabuck.actions.select.SelectedTestRunLineMarkerContributor"/>
</extensions>

<extensions defaultExtensionNs="com.android.project">
<featureEnableService implementation="com.facebook.buck.intellij.ideabuck.proj.BuckFeatureEnableService"/>
</extensions>

<actions>
<group id="buck.Menu">
<action
Expand Down
1 change: 1 addition & 0 deletions src/com/facebook/buck/intellij/ideabuck/ideabuck.iml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<orderEntry type="module" module-name="buck" />
<orderEntry type="library" name="test-lib" level="project" />
<orderEntry type="library" name="jackson-mrbean-2.7.8" level="project" />
<orderEntry type="library" scope="PROVIDED" name="android" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2015-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.facebook.buck.intellij.ideabuck.proj;

import com.android.tools.idea.project.FeatureEnableService;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

public class BuckFeatureEnableService extends FeatureEnableService {
@Override
protected boolean isApplicable(@NotNull Project project) {
return BuckProjectInfo.isBuckProject(project) && BuckProjectInfo.hasAndroidModule(project);
}

@Override
public boolean isLayoutEditorEnabled(@NotNull Project project) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2015-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.facebook.buck.intellij.ideabuck.proj;

import com.facebook.buck.intellij.ideabuck.build.BuckBuildManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import java.util.Arrays;
import org.jetbrains.android.facet.AndroidFacet;

public final class BuckProjectInfo {
private BuckProjectInfo() {
throw new AssertionError("No instances");
}

public static boolean isBuckProject(Project project) {
return BuckBuildManager.getInstance(project).isBuckProject(project);
}

public static boolean hasAndroidModule(Project project) {
return Arrays.stream(ModuleManager.getInstance(project).getModules())
.anyMatch(BuckProjectInfo::isAndroidModule);
}

public static boolean isAndroidModule(Module module) {
return AndroidFacet.getInstance(module) != null;
}
}
6 changes: 6 additions & 0 deletions third-party/java/intellij/BUCK
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
java_library(
name = "intellij-plugin-sdk",
exported_deps = [
":android",
":annotations",
":extensions",
":idea",
Expand Down Expand Up @@ -48,3 +49,8 @@ prebuilt_jar(
name = "jdom",
binary_jar = "jdom.jar",
)

prebuilt_jar(
name = "android",
binary_jar = "android.jar",
)
Binary file modified third-party/java/intellij/android.jar
Binary file not shown.
Binary file modified third-party/java/intellij/annotations.jar
Binary file not shown.
Binary file modified third-party/java/intellij/extensions.jar
Binary file not shown.
Binary file modified third-party/java/intellij/idea.jar
Binary file not shown.
Binary file modified third-party/java/intellij/jdom.jar
Binary file not shown.
Binary file modified third-party/java/intellij/openapi.jar
Binary file not shown.
Binary file modified third-party/java/intellij/util.jar
Binary file not shown.

0 comments on commit ee5297b

Please sign in to comment.