forked from facebook/buck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a FeatureEnableService so Layout Preview tab appears in IntelliJ
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:  With "Design" tab below XML editor that provides access to Android Layout Preview:  Closes facebook#1434 Reviewed By: mkillianey, styurin Pulled By: styurin fbshipit-source-id: 1399ae1
- Loading branch information
1 parent
deda86e
commit ee5297b
Showing
13 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ellij/ideabuck/src/com/facebook/buck/intellij/ideabuck/proj/BuckFeatureEnableService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../buck/intellij/ideabuck/src/com/facebook/buck/intellij/ideabuck/proj/BuckProjectInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.