Skip to content

Derive icon previews from font files for built-in icons #5820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion flutter-idea/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sourceSets {
]
test.resources.srcDirs = [
"src/main/resources",
"testData/unit",
"testData",
"testSrc/unit"
]
}
Expand All @@ -117,4 +117,10 @@ check.dependsOn verifyPlugin

test {
useJUnit()
testLogging {
events "failed"
exceptionFormat "full"
showCauses true
showStackTraces true
}
}
165 changes: 119 additions & 46 deletions src/io/flutter/editor/FlutterIconLineMarkerProvider.java

Large diffs are not rendered by default.

94 changes: 60 additions & 34 deletions src/io/flutter/sdk/FlutterSdkUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;

public class FlutterSdkUtil {
/**
Expand Down Expand Up @@ -260,40 +259,19 @@ public static void enableDartSdk(@NotNull final Project project) {
@Nullable
public static String guessFlutterSdkFromPackagesFile(@NotNull Module module) {
// First, look for .dart_tool/package_config.json
for (PubRoot pubRoot : PubRoots.forModule(module)) {
final VirtualFile configFile = pubRoot.getPackageConfigFile();
if (configFile == null) {
continue;
}
// parse it
try {
final String contents = new String(configFile.contentsToByteArray(true /* cache contents */));
final JsonElement element = new JsonParser().parse(contents);
if (element == null) {
final JsonArray packages = getPackagesFromPackageConfig(PubRoots.forModule(module));
for (int i = 0; i < packages.size(); i++) {
final JsonObject pack = packages.get(i).getAsJsonObject();
if ("flutter".equals(JsonUtils.getStringMember(pack, "name"))) {
final String uri = JsonUtils.getStringMember(pack, "rootUri");
if (uri == null) {
continue;
}
final JsonObject json = element.getAsJsonObject();
if (JsonUtils.getIntMember(json, "configVersion") < 2) continue;
final JsonArray packages = json.getAsJsonArray("packages");
if (packages == null || packages.size() == 0) {
final String path = extractSdkPathFromUri(uri, false);
if (path == null) {
continue;
}
for (int i = 0; i < packages.size(); i++) {
final JsonObject pack = packages.get(i).getAsJsonObject();
if ("flutter".equals(JsonUtils.getStringMember(pack, "name"))) {
final String uri = JsonUtils.getStringMember(pack, "rootUri");
if (uri == null) {
continue;
}
final String path = extractSdkPathFromUri(uri, false);
if (path == null) {
continue;
}
return path;
}
}
}
catch (IOException ignored) {
return path;
}
}

Expand All @@ -315,6 +293,54 @@ public static String guessFlutterSdkFromPackagesFile(@NotNull Module module) {
return null;
}

@Nullable
public static String getPathToCupertinoIconsPackage(@NotNull Project project) {
final JsonArray packages = getPackagesFromPackageConfig(PubRoots.forProject(project));
for (int i = 0; i < packages.size(); i++) {
final JsonObject pack = packages.get(i).getAsJsonObject();
if ("cupertino_icons".equals(JsonUtils.getStringMember(pack, "name"))) {
final String uri = JsonUtils.getStringMember(pack, "rootUri");
if (uri == null) {
continue;
}
try {
return new URI(uri).getPath();
}
catch (URISyntaxException ignored) {
}
}
}
return null;
}

private static JsonArray getPackagesFromPackageConfig(@NotNull List<PubRoot> pubRoots) {
final JsonArray entries = new JsonArray();
for (PubRoot pubRoot : pubRoots) {
final VirtualFile configFile = pubRoot.getPackageConfigFile();
if (configFile == null) {
continue;
}
// parse it
try {
final String contents = new String(configFile.contentsToByteArray(true /* cache contents */));
final JsonElement element = new JsonParser().parse(contents);
if (element == null) {
continue;
}
final JsonObject json = element.getAsJsonObject();
if (JsonUtils.getIntMember(json, "configVersion") < 2) continue;
final JsonArray packages = json.getAsJsonArray("packages");
if (packages == null || packages.size() == 0) {
continue;
}
entries.addAll(packages);
}
catch (IOException ignored) {
}
}
return entries;
}

@VisibleForTesting
public static String parseFlutterSdkPath(String packagesFileContent) {
for (String line : packagesFileContent.split("\n")) {
Expand Down
Binary file added testData/sdk/assets/CupertinoIcons.ttf
Binary file not shown.
Loading