diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..c73555c489 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +# Line endings: enforce LF in GitHub, convert to native on checkout. +* text=auto +*.dart text +*.java text +*.md text +*.sh text +*.yaml text diff --git a/src/io/flutter/FlutterConstants.java b/src/io/flutter/FlutterConstants.java index 312e395084..e0e06eb196 100644 --- a/src/io/flutter/FlutterConstants.java +++ b/src/io/flutter/FlutterConstants.java @@ -15,6 +15,8 @@ public class FlutterConstants { public static final String FLUTTER_SETTINGS_PAGE_ID = "flutter.settings"; + public static final String INDEPENDENT_PATH_SEPARATOR = "/"; + private FlutterConstants() { } diff --git a/src/io/flutter/actions/DeviceSelectorAction.java b/src/io/flutter/actions/DeviceSelectorAction.java index e2ded65e04..c83978aff6 100644 --- a/src/io/flutter/actions/DeviceSelectorAction.java +++ b/src/io/flutter/actions/DeviceSelectorAction.java @@ -126,6 +126,7 @@ private void updateActions(Presentation presentation, @NotNull Project project) actions.add(new NoDevicesAction()); } + // Show the 'Open iOS Simulator' action. if (SystemInfo.isMac) { boolean simulatorOpen = false; for (AnAction action : actions) { @@ -140,26 +141,26 @@ private void updateActions(Presentation presentation, @NotNull Project project) actions.add(new Separator()); actions.add(new OpenSimulatorAction(!simulatorOpen)); + } + + FlutterUtils.invokeAndWait(() -> { + final FlutterDevice selectedDevice = service.getSelectedDevice(); + for (AnAction action : actions) { + if (action instanceof SelectDeviceAction) { + final SelectDeviceAction deviceAction = (SelectDeviceAction)action; - FlutterUtils.invokeAndWait(() -> { - final FlutterDevice selectedDevice = service.getSelectedDevice(); - for (AnAction action : actions) { - if (action instanceof SelectDeviceAction) { - final SelectDeviceAction deviceAction = (SelectDeviceAction)action; - - if (Objects.equals(deviceAction.device, selectedDevice)) { - final Presentation template = action.getTemplatePresentation(); - presentation.setIcon(template.getIcon()); - presentation.setText(template.getText()); - presentation.setEnabled(true); - return; - } + if (Objects.equals(deviceAction.device, selectedDevice)) { + final Presentation template = action.getTemplatePresentation(); + presentation.setIcon(template.getIcon()); + presentation.setText(template.getText()); + presentation.setEnabled(true); + return; } } + } - presentation.setText(null); - }); - } + presentation.setText(null); + }); } private static class NoDevicesAction extends AnAction implements TransparentUpdate { diff --git a/src/io/flutter/console/FlutterConsoleFolding.java b/src/io/flutter/console/FlutterConsoleFolding.java index e56ff68b00..4039f2aae3 100644 --- a/src/io/flutter/console/FlutterConsoleFolding.java +++ b/src/io/flutter/console/FlutterConsoleFolding.java @@ -7,9 +7,10 @@ import com.intellij.execution.ConsoleFolding; import com.intellij.openapi.util.text.StringUtil; +import io.flutter.FlutterConstants; +import io.flutter.sdk.FlutterSdkUtil; import org.jetbrains.annotations.Nullable; -import java.io.File; import java.util.List; import java.util.regex.Pattern; @@ -18,7 +19,8 @@ * '/Users/.../projects/flutter/flutter/bin/flutter --no-color packages get'. */ public class FlutterConsoleFolding extends ConsoleFolding { - private static final String marker = File.separator + "flutter --no-color "; + private static final String flutterMarker = + FlutterConstants.INDEPENDENT_PATH_SEPARATOR + FlutterSdkUtil.flutterScriptName() + " --no-color "; private boolean isFolding = false; @@ -39,7 +41,7 @@ public class FlutterConsoleFolding extends ConsoleFolding { @Override public boolean shouldFoldLine(String line) { - if (line.contains(marker)) { + if (line.contains(flutterMarker)) { isFolding = false; return true; } @@ -67,7 +69,7 @@ public boolean shouldFoldLine(String line) { @Override public String getPlaceholderText(List lines) { final String fullText = StringUtil.join(lines, "\n"); - final int index = fullText.indexOf(marker); + final int index = fullText.indexOf(flutterMarker); if (index == -1) { final String trimmed = fullText.trim(); @@ -82,7 +84,7 @@ else if (lines.stream().anyMatch((s) -> s.endsWith("}"))) { } } else { - return "flutter " + fullText.substring(index + marker.length()); + return "flutter " + fullText.substring(index + flutterMarker.length()); } } } diff --git a/src/io/flutter/run/FlutterAppState.java b/src/io/flutter/run/FlutterAppState.java index 49ce29a626..a8764d9fc1 100644 --- a/src/io/flutter/run/FlutterAppState.java +++ b/src/io/flutter/run/FlutterAppState.java @@ -19,8 +19,10 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import io.flutter.FlutterConstants; import io.flutter.actions.OpenObservatoryAction; import io.flutter.actions.OpenSimulatorAction; import io.flutter.console.FlutterConsoleFilter; @@ -100,11 +102,15 @@ protected ProcessHandler startProcess() throws ExecutionException { String relativePath = parameters.getFilePath(); if (relativePath != null && relativePath.startsWith(cwd)) { relativePath = relativePath.substring(cwd.length()); - if (relativePath.startsWith(File.separator)) { + if (relativePath.startsWith(FlutterConstants.INDEPENDENT_PATH_SEPARATOR)) { relativePath = relativePath.substring(1); } } + if (relativePath != null) { + relativePath = FileUtil.toSystemDependentName(relativePath); + } + if (device != null) { // Bring simulator to front. if (device.emulator() && Objects.equals(device.platform(), "ios")) { diff --git a/src/io/flutter/sdk/FlutterSdk.java b/src/io/flutter/sdk/FlutterSdk.java index 5a7b74d5cf..24c1756aa8 100644 --- a/src/io/flutter/sdk/FlutterSdk.java +++ b/src/io/flutter/sdk/FlutterSdk.java @@ -23,6 +23,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.content.MessageView; @@ -39,6 +40,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -123,6 +125,7 @@ public void run(@NotNull Command cmd, final String flutterPath = FlutterSdkUtil.pathToFlutterTool(getHomePath()); final String dirPath = workingDir == null ? null : workingDir.getPath(); final GeneralCommandLine command = new GeneralCommandLine().withWorkDirectory(dirPath); + command.setCharset(CharsetToolkit.UTF8_CHARSET); command.setExePath(flutterPath); // Example: [create, foo_bar] String[] toolArgs = ArrayUtil.mergeArrays(cmd.command, args); @@ -170,6 +173,7 @@ public void runProject(@NotNull Project project, throws ExecutionException { final String flutterPath = FlutterSdkUtil.pathToFlutterTool(getHomePath()); final GeneralCommandLine command = new GeneralCommandLine(); + command.setCharset(CharsetToolkit.UTF8_CHARSET); command.setExePath(flutterPath); // Example: [create, foo_bar] final String[] toolArgs = ArrayUtil.prepend("--no-color", args); diff --git a/src/io/flutter/sdk/FlutterSdkUtil.java b/src/io/flutter/sdk/FlutterSdkUtil.java index c7594d18a2..3bd8dca6af 100644 --- a/src/io/flutter/sdk/FlutterSdkUtil.java +++ b/src/io/flutter/sdk/FlutterSdkUtil.java @@ -11,6 +11,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -84,8 +85,12 @@ public static void addKnownSDKPathsToCombo(@NotNull JComboBox combo) { @NotNull public static String pathToFlutterTool(@NotNull String sdkPath) throws ExecutionException { - // TODO: Use flutter.bat on Windows. - return sdkRelativePathTo(sdkPath, "bin", "flutter"); + return sdkRelativePathTo(sdkPath, "bin", flutterScriptName()); + } + + @NotNull + public static String flutterScriptName() { + return SystemInfo.isWindows ? "flutter.bat" : "flutter"; } @NotNull