Search in sources :

Example 46 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class GrNewConsoleAction method getModule.

@Nullable
protected Module getModule(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null)
        return null;
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    if (file != null) {
        final Module moduleForFile = ModuleUtilCore.findModuleForFile(file, project);
        if (moduleForFile != null)
            return moduleForFile;
    }
    final List<Module> modules = ModuleChooserUtil.filterGroovyCompatibleModules(Arrays.asList(ModuleManager.getInstance(project).getModules()), APPLICABLE_MODULE);
    return modules.isEmpty() ? null : modules.get(0);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 47 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class GrNewConsoleAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    final Module module = getModule(e);
    if (project == null || module == null)
        return;
    final VirtualFile contentFile = ConsoleHistoryController.getContentFile(GroovyConsoleRootType.getInstance(), GroovyConsoleRootType.CONTENT_ID, ScratchFileService.Option.create_new_always);
    assert contentFile != null;
    GroovyConsole.createConsole(project, contentFile, module);
    FileEditorManager.getInstance(project).openFile(contentFile, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module)

Example 48 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class HgUpdateEnvironment method updateDirectories.

@NotNull
public UpdateSession updateDirectories(@NotNull FilePath[] contentRoots, UpdatedFiles updatedFiles, ProgressIndicator indicator, @NotNull Ref<SequentialUpdatesContext> context) {
    List<VcsException> exceptions = new LinkedList<>();
    boolean result = true;
    for (FilePath contentRoot : contentRoots) {
        if (indicator != null) {
            indicator.checkCanceled();
            indicator.startNonCancelableSection();
        }
        VirtualFile repository = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(contentRoot);
        if (repository == null) {
            continue;
        }
        try {
            HgUpdater updater = new HgRegularUpdater(project, repository, updateConfiguration);
            result &= updater.update(updatedFiles, indicator, exceptions);
        } catch (VcsException e) {
            //TODO include module name where exception occurred
            exceptions.add(e);
        }
        if (indicator != null) {
            indicator.finishNonCancelableSection();
        }
    }
    return new UpdateSessionAdapter(exceptions, !result);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsException(com.intellij.openapi.vcs.VcsException) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class HgPusher method pushSynchronously.

public static void pushSynchronously(@NotNull final Project project, @NotNull HgPushCommand command) {
    final VirtualFile repo = command.getRepo();
    HgCommandResult result = command.executeInCurrentThread();
    if (result == null) {
        return;
    }
    if (result.getExitValue() == PUSH_SUCCEEDED_EXIT_VALUE) {
        int commitsNum = getNumberOfPushedCommits(result);
        String successTitle = "Pushed successfully";
        String successDescription = String.format("Pushed %d %s [%s]", commitsNum, StringUtil.pluralize("commit", commitsNum), repo.getPresentableName());
        VcsNotifier.getInstance(project).notifySuccess(successTitle, successDescription);
    } else if (result.getExitValue() == NOTHING_TO_PUSH_EXIT_VALUE) {
        VcsNotifier.getInstance(project).notifySuccess("Nothing to push");
    } else {
        new HgCommandResultNotifier(project).notifyError(result, "Push failed", "Failed to push to [" + repo.getPresentableName() + "]");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier)

Example 50 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class HgUtil method sortByHgRoots.

@NotNull
public static Map<VirtualFile, Collection<VirtualFile>> sortByHgRoots(@NotNull Project project, @NotNull Collection<VirtualFile> files) {
    Map<VirtualFile, Collection<VirtualFile>> sorted = new HashMap<>();
    HgRepositoryManager repositoryManager = getRepositoryManager(project);
    for (VirtualFile file : files) {
        HgRepository repo = repositoryManager.getRepositoryForFile(file);
        if (repo == null) {
            continue;
        }
        Collection<VirtualFile> filesForRoot = sorted.get(repo.getRoot());
        if (filesForRoot == null) {
            filesForRoot = new HashSet<>();
            sorted.put(repo.getRoot(), filesForRoot);
        }
        filesForRoot.add(file);
    }
    return sorted;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) HgRepository(org.zmlx.hg4idea.repo.HgRepository) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)5465 File (java.io.File)762 Project (com.intellij.openapi.project.Project)720 Nullable (org.jetbrains.annotations.Nullable)720 NotNull (org.jetbrains.annotations.NotNull)703 PsiFile (com.intellij.psi.PsiFile)571 Module (com.intellij.openapi.module.Module)501 IOException (java.io.IOException)327 ArrayList (java.util.ArrayList)260 Document (com.intellij.openapi.editor.Document)244 PsiElement (com.intellij.psi.PsiElement)209 Test (org.junit.Test)196 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)124 PsiDirectory (com.intellij.psi.PsiDirectory)124 XmlFile (com.intellij.psi.xml.XmlFile)124 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)116 Editor (com.intellij.openapi.editor.Editor)115 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)101 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)91 List (java.util.List)90