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);
}
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);
}
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);
}
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() + "]");
}
}
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;
}
Aggregations