com.intellij.ide.RecentProjectsManager Java Examples

The following examples show how to use com.intellij.ide.RecentProjectsManager. 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: FlutterProjectCreator.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private VirtualFile getLocationFromModel(@Nullable Project projectToClose, boolean saveLocation) {
  final File location = new File(FileUtil.toSystemDependentName(myModel.projectLocation().get()));
  if (!location.exists() && !location.mkdirs()) {
    String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location.getAbsolutePath());
    Messages.showErrorDialog(projectToClose, message, ActionsBundle.message("action.NewDirectoryProject.title"));
    return null;
  }
  final File baseFile = new File(location, myModel.projectName().get());
  //noinspection ResultOfMethodCallIgnored
  baseFile.mkdirs();
  final VirtualFile baseDir = ApplicationManager.getApplication().runWriteAction(
    (Computable<VirtualFile>)() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(baseFile));
  if (baseDir == null) {
    FlutterUtils.warn(LOG, "Couldn't find '" + location + "' in VFS");
    return null;
  }
  if (saveLocation) {
    RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getPath());
  }
  return baseDir;
}
 
Example #2
Source File: BlazeEditProjectViewControl.java    From intellij with Apache License 2.0 6 votes vote down vote up
private String getDefaultProjectDataDirectory(String projectName) {
  File canonicalProjectDataLocation = workspaceData.canonicalProjectDataLocation();
  if (canonicalProjectDataLocation != null) {
    return canonicalProjectDataLocation.getPath();
  }
  String lastProjectLocation =
      PropertiesComponent.getInstance().getValue(LAST_PROJECT_LOCATION_PROPERTY);
  if (lastProjectLocation == null) {
    // TODO(brendandouglas): remove this temporary fall-back once LAST_PROJECT_LOCATION_PROPERTY
    // is populated
    lastProjectLocation = RecentProjectsManager.getInstance().getLastProjectCreationLocation();
  }
  if (lastProjectLocation == null) {
    return newUniquePath(new File(getDefaultProjectsDirectory(), projectName));
  }
  // Because RecentProjectsManager uses PathUtil.toSystemIndependentName.
  lastProjectLocation = lastProjectLocation.replace('/', File.separatorChar);
  File lastProjectParent = new File(lastProjectLocation);
  if (lastProjectParent.getName().equals(BlazeDataStorage.PROJECT_DATA_SUBDIRECTORY)) {
    lastProjectParent = lastProjectParent.getParentFile();
  }
  return newUniquePath(new File(lastProjectParent, projectName));
}
 
Example #3
Source File: FlutterProjectCreator.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private VirtualFile getLocationFromModel(@Nullable Project projectToClose, boolean saveLocation) {
  final File location = new File(FileUtil.toSystemDependentName(myModel.projectLocation().get()));
  if (!location.exists() && !location.mkdirs()) {
    String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location.getAbsolutePath());
    Messages.showErrorDialog(projectToClose, message, ActionsBundle.message("action.NewDirectoryProject.title"));
    return null;
  }
  final File baseFile = new File(location, myModel.projectName().get());
  //noinspection ResultOfMethodCallIgnored
  baseFile.mkdirs();
  final VirtualFile baseDir = ApplicationManager.getApplication().runWriteAction(
    (Computable<VirtualFile>)() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(baseFile));
  if (baseDir == null) {
    FlutterUtils.warn(LOG, "Couldn't find '" + location + "' in VFS");
    return null;
  }
  if (saveLocation) {
    RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getPath());
  }
  return baseDir;
}
 
Example #4
Source File: ProjectUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void updateLastProjectLocation(final String projectFilePath) {
  File lastProjectLocation = new File(projectFilePath);
  if (lastProjectLocation.isFile()) {
    lastProjectLocation = lastProjectLocation.getParentFile(); // for directory-based project storage
  }
  if (lastProjectLocation == null) { // the immediate parent of the ipr file
    return;
  }
  lastProjectLocation = lastProjectLocation.getParentFile(); // the candidate directory to be saved
  if (lastProjectLocation == null) {
    return;
  }
  String path = lastProjectLocation.getPath();
  try {
    path = FileUtil.resolveShortWindowsName(path);
  }
  catch (IOException e) {
    LOG.info(e);
    return;
  }
  RecentProjectsManager.getInstance().setLastProjectCreationLocation(path.replace(File.separatorChar, '/'));
}
 
Example #5
Source File: WinDockDelegate.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void updateRecentProjectsMenu() {
  if (ApplicationProperties.isInSandbox()) {
    return;
  }

  // we need invoke it in own thread, due we don't want it call inside UI thread, or Write thread (if it separate)
  myExecutorService.execute(() -> {
    final AnAction[] recentProjectActions = RecentProjectsManager.getInstance().getRecentProjectsActions(false);
    RecentTasks.clear();
    String name = ApplicationNamesInfo.getInstance().getProductName().toLowerCase(Locale.US);
    File exePath = new File(ContainerPathManager.get().getAppHomeDirectory(), name + (SystemInfo.is64Bit ? "64" : "") + ".exe");
    if (!exePath.exists()) {
      throw new IllegalArgumentException("Executable is not exists. Path: " + exePath.getPath());
    }
    String launcher = RecentTasks.getShortenPath(exePath.getPath());
    Task[] tasks = new Task[recentProjectActions.length];
    for (int i = 0; i < recentProjectActions.length; i++) {
      ReopenProjectAction rpa = (ReopenProjectAction)recentProjectActions[i];
      tasks[i] = new Task(launcher, RecentTasks.getShortenPath(rpa.getProjectPath()), rpa.getTemplatePresentation().getText());
    }

    RecentTasks.addTasks(tasks);
  });
}
 
Example #6
Source File: MacDockDelegate.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void updateRecentProjectsMenu() {
  RecentProjectsManager projectsManager = RecentProjectsManager.getInstance();
  if (projectsManager == null) return;
  final AnAction[] recentProjectActions = projectsManager.getRecentProjectsActions(false);
  recentProjectsMenu.removeAll();

  for (final AnAction action : recentProjectActions) {
    MenuItem menuItem = new MenuItem(((ReopenProjectAction)action).getProjectName());
    menuItem.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        action.actionPerformed(AnActionEvent.createFromAnAction(action, null, ActionPlaces.DOCK_MENU, DataManager.getInstance().getDataContext((Component)null)));
      }
    });
    recentProjectsMenu.add(menuItem);
  }
}
 
Example #7
Source File: WebWelcomeFrameManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public WebWelcomeFrameManager(Application application, ProjectManager projectManager, RecentProjectsManager recentProjectsManager, DataManager dataManager) {
  super(application);
  myProjectManager = projectManager;
  myRecentProjectsManager = recentProjectsManager;
  myDataManager = dataManager;
}
 
Example #8
Source File: NewProjectAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
private static void generateProjectAsync(Project project, @Nonnull NewProjectPanel panel) {
  // leave current step
  panel.finish();

  NewModuleWizardContext context = panel.getWizardContext();

  final File location = new File(context.getPath());
  final int childCount = location.exists() ? location.list().length : 0;
  if (!location.exists() && !location.mkdirs()) {
    Messages.showErrorDialog(project, "Cannot create directory '" + location + "'", "Create Project");
    return;
  }

  final VirtualFile baseDir = WriteAction.compute(() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location));
  baseDir.refresh(false, true);

  if (childCount > 0) {
    int rc = Messages.showYesNoDialog(project, "The directory '" + location + "' is not empty. Continue?", "Create New Project", Messages.getQuestionIcon());
    if (rc == Messages.NO) {
      return;
    }
  }

  RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getParent());

  UIAccess uiAccess = UIAccess.current();
  ProjectManager.getInstance().openProjectAsync(baseDir, uiAccess).doWhenDone((openedProject) -> {
    uiAccess.give(() -> NewOrImportModuleUtil.doCreate(panel, openedProject, baseDir));
  });
}
 
Example #9
Source File: ProjectUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getBaseDir() {
  final String lastProjectLocation = RecentProjectsManager.getInstance().getLastProjectCreationLocation();
  if (lastProjectLocation != null) {
    return lastProjectLocation.replace('/', File.separatorChar);
  }
  return DefaultPaths.getInstance().getDocumentsDir();
}
 
Example #10
Source File: RecentProjectsWelcomeScreenActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void rebuildRecentProjectDataModel(@Nonnull DefaultListModel model) {
  model.clear();
  for (AnAction action : RecentProjectsManager.getInstance().getRecentProjectsActions(false, true)) {
    //noinspection unchecked
    model.addElement(action);
  }
}
 
Example #11
Source File: MoveProjectToGroupAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  final List<AnAction> elements = getSelectedElements(e);
  for (AnAction element : elements) {
    if (element instanceof ReopenProjectAction) {
      final String path = ((ReopenProjectAction)element).getProjectPath();
      for (ProjectGroup group : RecentProjectsManager.getInstance().getGroups()) {
        group.removeProject(path);
        myGroup.addProject(path);
      }
    }
  }
  rebuildRecentProjectsList(e);
}
 
Example #12
Source File: MoveProjectToGroupActionGroup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent e) {
  removeAll();
  final List<ProjectGroup> groups = new ArrayList<>(RecentProjectsManager.getInstance().getGroups());
  Collections.sort(groups, (o1, o2) -> StringUtil.naturalCompare(o1.getName(), o2.getName()));
  for (ProjectGroup group : groups) {
    if (!group.isTutorials()) add(new MoveProjectToGroupAction(group));
  }
  if (groups.size() > 0) {
    add(AnSeparator.getInstance());
    add(new RemoveSelectedProjectsFromGroupsAction());
  }
}
 
Example #13
Source File: CreateNewProjectGroupAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static ProjectGroup getGroup(String name) {
  for (ProjectGroup group : RecentProjectsManager.getInstance().getGroups()) {
    if (group.getName().equals(name)) {
      return group;
    }
  }
  return null;
}
 
Example #14
Source File: RemoveSelectedProjectsFromGroupsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  final List<AnAction> elements = getSelectedElements(e);
  for (AnAction element : elements) {
    if (element instanceof ReopenProjectAction) {
      for (ProjectGroup group : RecentProjectsManager.getInstance().getGroups()) {
        group.removeProject(((ReopenProjectAction)element).getProjectPath());
      }
    }

  }

  rebuildRecentProjectsList(e);
}
 
Example #15
Source File: Java9DockDelegateImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void updateRecentProjectsMenu() {
  RecentProjectsManager projectsManager = RecentProjectsManager.getInstance();

  final AnAction[] recentProjectActions = projectsManager.getRecentProjectsActions(false);
  recentProjectsMenu.removeAll();

  for (final AnAction action : recentProjectActions) {
    MenuItem menuItem = new MenuItem(((ReopenProjectAction)action).getProjectName());
    menuItem.addActionListener(e -> action.actionPerformed(AnActionEvent.createFromAnAction(action, null, ActionPlaces.DOCK_MENU, DataManager.getInstance().getDataContext((Component)null))));
    recentProjectsMenu.add(menuItem);
  }
}
 
Example #16
Source File: CloseProjectAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Inject
public CloseProjectAction(WelcomeFrameManager welcomeFrameManager, ProjectManager projectManager, RecentProjectsManager recentProjectsManager) {
  myWelcomeFrameManager = welcomeFrameManager;
  myProjectManager = projectManager;
  myRecentProjectsManager = recentProjectsManager;
}
 
Example #17
Source File: RunAnythingRecentProjectProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Collection<AnAction> getValues(@Nonnull DataContext dataContext, @Nonnull String pattern) {
  return Arrays.stream(RecentProjectsManager.getInstance().getRecentProjectsActions(false)).collect(Collectors.toList());
}