Java Code Examples for com.intellij.openapi.util.SystemInfo#isWindows()

The following examples show how to use com.intellij.openapi.util.SystemInfo#isWindows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalStorage.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static String getOsPrefix() {
  if (SystemInfo.isWindows) {
    return "win";
  }
  else if (SystemInfo.isMac) {
    return "mac";
  }
  else if (SystemInfo.isLinux) {
    return "linux";
  }
  else if (SystemInfo.isFreeBSD) {
    return "bsd";
  }
  else if (SystemInfo.isUnix) {
    return "unix";
  }
  return "other";
}
 
Example 2
Source File: Restarter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static int scheduleRestart(@Nonnull String... beforeRestart) throws IOException {
  try {
    int restartCode = getRestartCode();
    if (restartCode != 0) {
      runCommand(beforeRestart);
      return restartCode;
    }
    else if (SystemInfo.isWindows) {
      restartOnWindows(beforeRestart);
      return 0;
    }
    else if (SystemInfo.isMac) {
      restartOnMac(beforeRestart);
      return 0;
    }
  }
  catch (Throwable t) {
    throw new IOException("Cannot restart application: " + t.getMessage(), t);
  }

  runCommand(beforeRestart);
  throw new IOException("Cannot restart application: not supported.");
}
 
Example 3
Source File: VMOptions.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static File getWriteFile() {
  String vmOptionsFile = System.getProperty("jb.vmOptionsFile");
  if (vmOptionsFile == null) {
    // launchers should specify a path to an options file used to configure a JVM
    return null;
  }

  vmOptionsFile = new File(vmOptionsFile).getAbsolutePath();
  if (!FileUtil.isAncestor(ContainerPathManager.get().getHomePath(), vmOptionsFile, true)) {
    // a file is located outside the IDE installation - meaning it is safe to overwrite
    return new File(vmOptionsFile);
  }

  File appHomeDirectory = ContainerPathManager.get().getAppHomeDirectory();

  String fileName = ApplicationNamesInfo.getInstance().getProductName().toLowerCase(Locale.US);
  if (SystemInfo.is64Bit && !SystemInfo.isMac) fileName += "64";
  if (SystemInfo.isWindows) fileName += ".exe";
  fileName += ".vmoptions";
  return new File(appHomeDirectory, fileName);
}
 
Example 4
Source File: AbstractExpandableItemsHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean noIntersections(Rectangle bounds) {
  Window owner = SwingUtilities.getWindowAncestor(myComponent);
  Window popup = SwingUtilities.getWindowAncestor(myTipComponent);
  Window focus = TargetAWT.to(WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow());
  if (focus == owner.getOwner()) {
    focus = null; // do not check intersection with parent
  }
  boolean focused = SystemInfo.isWindows || owner.isFocused();
  for (Window other : owner.getOwnedWindows()) {
    if (!focused && !SystemInfo.isWindows) {
      focused = other.isFocused();
    }
    if (popup != other && other.isVisible() && bounds.x + 10 >= other.getX() && bounds.intersects(other.getBounds())) {
      return false;
    }
    if (focus == other) {
      focus = null; // already checked
    }
  }
  return focused && (focus == owner || focus == null || !owner.getBounds().intersects(focus.getBounds()));
}
 
Example 5
Source File: Platform.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@NotNull
public static String getOsPrefix() {
    if (SystemInfo.isWindows) {
        return "w";
    }

    if (SystemInfo.isLinux) {
        return "l";
    }

    if (SystemInfo.isMac) {
        return "o";
    }

    return "";
}
 
Example 6
Source File: FileUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static File renameToTempFileOrDelete(@Nonnull File file) {
  String tempDir = getTempDirectory();
  boolean isSameDrive = true;
  if (SystemInfo.isWindows) {
    String tempDirDrive = tempDir.substring(0, 2);
    String fileDrive = file.getAbsolutePath().substring(0, 2);
    isSameDrive = tempDirDrive.equalsIgnoreCase(fileDrive);
  }

  if (isSameDrive) {
    // the optimization is reasonable only if destination dir is located on the same drive
    final String originalFileName = file.getName();
    File tempFile = getTempFile(originalFileName, tempDir);
    if (file.renameTo(tempFile)) {
      return tempFile;
    }
  }

  delete(file);

  return null;
}
 
Example 7
Source File: OpenTerminalHereAction.java    From OpenTerminalHere with Apache License 2.0 6 votes vote down vote up
/**
 * perform the action
 * @param project
 */
private void perform(@NotNull Project project) {

    VirtualFile selectedFile = FileUtil.getSelectedProjectFile(project);
    if (selectedFile == null) {
        return;
    }

    String targetPath = selectedFile.getPath();
    CommandExecutor executor = null;
    if (SystemInfo.isMac) {
        executor = new MacExecutor(targetPath);
    }
    else if (SystemInfo.isWindows) {
        executor = new WinExecutor(targetPath);
    }

    if (executor == null) {
        NotificationTool.notify(project, PLUGIN_NAME,
                "Your operating system is not supported temporarily.", NotificationType.ERROR);
        return;
    }

    executor.openTerminal();

}
 
Example 8
Source File: LocalFileSystemRefreshWorker.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
static FileAttributes toFileAttributes(@Nonnull Path path, @Nonnull BasicFileAttributes a, boolean isSymlink) {
  if (isSymlink && a == BROKEN_SYMLINK_ATTRIBUTES) {
    return FileAttributes.BROKEN_SYMLINK;
  }

  long lastModified = a.lastModifiedTime().toMillis();
  boolean writable = isWritable(path, a, a.isDirectory());
  if (SystemInfo.isWindows) {
    boolean hidden = path.getParent() != null && ((DosFileAttributes)a).isHidden();
    return new FileAttributes(a.isDirectory(), a.isOther(), isSymlink, hidden, a.size(), lastModified, writable);
  }
  else {
    return new FileAttributes(a.isDirectory(), a.isOther(), isSymlink, false, a.size(), lastModified, writable);
  }
}
 
Example 9
Source File: RunnerWinProcess.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static RunnerWinProcess create(@Nonnull GeneralCommandLine commandLine) throws ExecutionException {
  if (!SystemInfo.isWindows) {
    throw new RuntimeException(RunnerWinProcess.class.getSimpleName() + " works on Windows only!");
  }
  RunnerMediator.injectRunnerCommand(commandLine);
  Process process = commandLine.createProcess();
  return new RunnerWinProcess(process);
}
 
Example 10
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * The following code is a trick! By default Swing uses lightweight and "medium" weight
 * popups to show JPopupMenu. The code below force the creation of real heavyweight menus -
 * this increases speed of popups and allows to get rid of some drawing artifacts.
 */
private static void fixPopupWeight() {
  int popupWeight = OurPopupFactory.WEIGHT_MEDIUM;
  String property = System.getProperty("idea.popup.weight");
  if (property != null) property = property.toLowerCase().trim();
  if (SystemInfo.isMacOSLeopard) {
    // force heavy weight popups under Leopard, otherwise they don't have shadow or any kind of border.
    popupWeight = OurPopupFactory.WEIGHT_HEAVY;
  }
  else if (property == null) {
    // use defaults if popup weight isn't specified
    if (SystemInfo.isWindows) {
      popupWeight = OurPopupFactory.WEIGHT_HEAVY;
    }
  }
  else {
    if ("light".equals(property)) {
      popupWeight = OurPopupFactory.WEIGHT_LIGHT;
    }
    else if ("medium".equals(property)) {
      popupWeight = OurPopupFactory.WEIGHT_MEDIUM;
    }
    else if ("heavy".equals(property)) {
      popupWeight = OurPopupFactory.WEIGHT_HEAVY;
    }
    else {
      LOG.error("Illegal value of property \"idea.popup.weight\": " + property);
    }
  }

  PopupFactory factory = PopupFactory.getSharedInstance();
  if (!(factory instanceof OurPopupFactory)) {
    factory = new OurPopupFactory(factory);
    PopupFactory.setSharedInstance(factory);
  }
  PopupUtil.setPopupType(factory, popupWeight);
}
 
Example 11
Source File: ClipboardSynchronizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Clipboard getClipboard() {
  try {
    return Toolkit.getDefaultToolkit().getSystemClipboard();
  }
  catch (IllegalStateException e) {
    if (SystemInfo.isWindows) {
      LOG.debug("Clipboard is busy");
    }
    else {
      LOG.warn(e);
    }
    return null;
  }
}
 
Example 12
Source File: RecentProjectPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isPathAvailable(String pathStr) {
  Path path = Paths.get(pathStr), pathRoot = path.getRoot();
  if (pathRoot == null) return false;
  if (SystemInfo.isWindows && pathRoot.toString().startsWith("\\\\")) return true;
  for (Path fsRoot : pathRoot.getFileSystem().getRootDirectories()) {
    if (pathRoot.equals(fsRoot)) return Files.exists(path);
  }
  return false;
}
 
Example 13
Source File: BlazeTestCase.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
  if (SystemInfo.isWindows) {
    return new Statement() {
      @Override
      public void evaluate() throws Throwable {
        System.out.println(
            "Test \""
                + description.getDisplayName()
                + "\" does not run on Windows (see http://b.android.com/222904)");
      }
    };
  }
  return base;
}
 
Example 14
Source File: NotificationUtils.java    From freeline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * python提示
 */
public static void pythonNotFound() {
    String tip = "command 'python' not found. ";
    if (SystemInfo.isWindows) {
        tip += "  if first installation python or Set Environment variable, Please restart your computer";
    }
    errorNotification(tip);
}
 
Example 15
Source File: BrowserLauncherAppless.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static List<String> getDefaultBrowserCommand() {
  if (SystemInfo.isWindows) {
    return Arrays.asList(ExecUtil.getWindowsShellName(), "/c", "start", GeneralCommandLine.inescapableQuote(""));
  }
  else if (SystemInfo.isMac) {
    return Collections.singletonList(ExecUtil.getOpenCommandPath());
  }
  else if (SystemInfo.isUnix && SystemInfo.hasXdgOpen()) {
    return Collections.singletonList("xdg-open");
  }
  else {
    return null;
  }
}
 
Example 16
Source File: InspectorService.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static String getFileUriPrefix() {
  return SystemInfo.isWindows ? "file:///" : "file://";
}
 
Example 17
Source File: MasterKeyPasswordSafe.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @return true, if OS protected passwords are supported for the current platform
 */
@SuppressWarnings({"MethodMayBeStatic"})
public boolean isOsProtectedPasswordSupported() {
  // TODO extension point needed?
  return SystemInfo.isWindows;
}
 
Example 18
Source File: DirectoryUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the directory with the given path via PSI, including any
 * necessary but nonexistent parent directories. Must be run in write action.
 * @param path directory path in the local file system; separators must be '/'
 * @return true if path exists or has been created as the result of this method call; false otherwise
 */
public static PsiDirectory mkdirs(PsiManager manager, String path) throws IncorrectOperationException{
  if (File.separatorChar != '/') {
    if (path.indexOf(File.separatorChar) != -1) {
      throw new IllegalArgumentException("separators must be '/'; path is " + path);
    }
  }

  String existingPath = path;

  PsiDirectory directory = null;

  // find longest existing path
  while (existingPath.length() > 0) {
    VirtualFile file = LocalFileSystem.getInstance().findFileByPath(existingPath);
    if (file != null) {
      directory = manager.findDirectory(file);
      if (directory == null) {
        return null;
      }
      break;
    }

    if (StringUtil.endsWithChar(existingPath, '/')) {
      existingPath = existingPath.substring(0, existingPath.length() - 1);
      if (SystemInfo.isWindows && existingPath.length() == 2 && existingPath.charAt(1) == ':') {
        return null;
      }
    }

    int index = existingPath.lastIndexOf('/');
    if (index == -1) {
      // nothing to do more
      return null;
    }

    existingPath = existingPath.substring(0, index);
  }

  if (directory == null) {
    return null;
  }

  if (existingPath.equals(path)) {
    return directory;
  }

  String postfix = path.substring(existingPath.length() + 1, path.length());
  StringTokenizer tokenizer = new StringTokenizer(postfix, "/");
  while (tokenizer.hasMoreTokens()) {
    String name = tokenizer.nextToken();

    PsiDirectory subdirectory = directory.createSubdirectory(name);
    if (subdirectory == null) {
      return null;
    }

    directory = subdirectory;
  }

  return directory;
}
 
Example 19
Source File: ExternalSystemTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
protected static String getRoot() {
  if (SystemInfo.isWindows) return "c:";
  return "";
}
 
Example 20
Source File: IgnoreFilePattern.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
private static boolean isFileSystemCaseSensitive() {
    // This isn't 100% true - you can configure windows file system to be case sensitive.
    return !SystemInfo.isWindows;
}