use of com.intellij.openapi.fileEditor.FileEditorManager in project azure-tools-for-java by Microsoft.
the class UIHelperImpl method getOpenedFile.
@Nullable
@Override
public <T extends StorageServiceTreeItem> Object getOpenedFile(@NotNull Object projectObject, @NotNull String accountName, @NotNull T item) {
FileEditorManager fileEditorManager = FileEditorManager.getInstance((Project) projectObject);
for (VirtualFile editedFile : fileEditorManager.getOpenFiles()) {
T editedItem = editedFile.getUserData((Key<T>) name2Key.get(item.getClass()));
StorageAccount editedStorageAccount = editedFile.getUserData(STORAGE_KEY);
ClientStorageAccount editedClientStorageAccount = editedFile.getUserData(CLIENT_STORAGE_KEY);
if (((editedStorageAccount != null && editedStorageAccount.name().equals(accountName)) || (editedClientStorageAccount != null && editedClientStorageAccount.getName().equals(accountName))) && editedItem != null && editedItem.getName().equals(item.getName())) {
return editedFile;
}
}
return null;
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-plugins by StepicOrg.
the class ProgrammingLanguageUtils method switchProgrammingLanguage.
public static void switchProgrammingLanguage(@NotNull Project project, @NotNull StepNode targetStepNode, @NotNull SupportedLanguages language) {
if (!targetStepNode.getSupportedLanguages().contains(language)) {
return;
}
SupportedLanguages currentLang = targetStepNode.getCurrentLang();
String currentMainFileName = currentLang.getMainFileName();
String mainFilePath = String.join("/", targetStepNode.getPath(), EduNames.SRC, currentMainFileName);
VirtualFile mainFile = project.getBaseDir().findFileByRelativePath(mainFilePath);
boolean mainFileExists = mainFile != null;
if (currentLang == language && mainFileExists) {
return;
}
if (currentMainFileName.equals(language.getMainFileName()) && mainFileExists) {
targetStepNode.setCurrentLang(language);
Metrics.switchLanguage(project, targetStepNode, SUCCESSFUL);
return;
}
PsiDirectory src = getOrCreateSrcPsiDirectory(project, targetStepNode);
if (src == null) {
return;
}
PsiDirectory hide = getOrCreatePsiDirectory(project, src, EduNames.HIDE);
if (hide == null) {
return;
}
PsiFile second = findFile(src, language.getMainFileName());
boolean moveSecond = second == null;
if (moveSecond) {
second = getOrCreateMainFile(project, hide.getVirtualFile(), language, targetStepNode);
if (second == null) {
logger.error("Can't create Main file: " + language.getMainFileName());
return;
}
}
PsiFile first = findFile(hide, currentMainFileName);
boolean moveFirst = first == null;
if (moveFirst) {
first = findFile(src, currentMainFileName);
moveFirst = !second.isEquivalentTo(first);
}
targetStepNode.setCurrentLang(language);
ArrayList<VirtualFile> needClose = closeStepNodeFile(project, targetStepNode);
PsiFile finalSecond = second;
PsiFile finalFirst = first;
boolean finalMoveFirst = moveFirst;
ApplicationManager.getApplication().invokeAndWait(() -> {
FileEditorManager.getInstance(project).openFile(finalSecond.getVirtualFile(), true);
FileEditorManager editorManager = FileEditorManager.getInstance(project);
needClose.forEach(editorManager::closeFile);
exchangeFiles(src, hide, finalFirst, finalSecond, finalMoveFirst, moveSecond);
ProjectView.getInstance(project).selectPsiElement(finalSecond, false);
});
Metrics.switchLanguage(project, targetStepNode, SUCCESSFUL);
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class CCSubtaskChangeListener method subtaskChanged.
@Override
public void subtaskChanged(@NotNull Project project, @NotNull Task task, int oldSubtaskNumber, int newSubtaskNumber) {
VirtualFile taskDir = task.getTaskDir(project);
if (taskDir == null) {
return;
}
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
if (manager == null) {
return;
}
String testFileName = manager.getTestFileName();
if (newSubtaskNumber != 0) {
String nameWithoutExtension = FileUtil.getNameWithoutExtension(testFileName);
String extension = FileUtilRt.getExtension(testFileName);
testFileName = nameWithoutExtension + EduNames.SUBTASK_MARKER + newSubtaskNumber + "." + extension;
}
VirtualFile newTestFile = taskDir.findChild(testFileName);
if (newTestFile == null) {
return;
}
FileEditorManager editorManager = FileEditorManager.getInstance(project);
List<VirtualFile> testFiles = ContainerUtil.filter(taskDir.getChildren(), file -> CCUtils.isTestsFile(project, file) && editorManager.isFileOpen(file));
if (testFiles.isEmpty()) {
return;
}
Editor selectedTextEditor = editorManager.getSelectedTextEditor();
for (VirtualFile testFile : testFiles) {
editorManager.closeFile(testFile);
}
editorManager.openFile(newTestFile, true);
if (selectedTextEditor != null) {
reopenSelectedEditor(editorManager, selectedTextEditor);
}
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class XPathAction method isEnabled.
protected boolean isEnabled(AnActionEvent event, boolean checkAvailable) {
final Project project = event.getProject();
if (project == null) {
// no active project
return false;
}
Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
if (editor == null) {
FileEditorManager fem = FileEditorManager.getInstance(project);
editor = fem.getSelectedTextEditor();
}
if (editor == null) {
return false;
}
// do we have an xml file?
final PsiDocumentManager cem = PsiDocumentManager.getInstance(project);
final PsiFile psiFile = cem.getPsiFile(editor.getDocument());
// this is also true for DTD documents...
if (!(psiFile instanceof XmlFile) || psiFile.getLanguage() == StdFileTypes.DTD.getLanguage()) {
return false;
}
return !checkAvailable || isEnabledAt((XmlFile) psiFile, editor.getCaretModel().getOffset());
}
use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.
the class StudyBasePluginConfigurator method getFileEditorManagerListener.
@NotNull
@Override
public FileEditorManagerListener getFileEditorManagerListener(@NotNull Project project, @NotNull StudyToolWindow toolWindow) {
return new FileEditorManagerListener() {
@Override
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
Task task = getTask(file);
setTaskText(task, StudyUtils.getTaskDir(file));
if (task != null) {
if (task.isChoiceTask()) {
final StudyChoiceVariantsPanel choicePanel = new StudyChoiceVariantsPanel(task);
toolWindow.setBottomComponent(choicePanel);
} else {
toolWindow.setBottomComponent(null);
}
}
}
@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
for (VirtualFile openedFile : source.getOpenFiles()) {
if (StudyUtils.getTaskFile(project, openedFile) != null) {
return;
}
}
toolWindow.setEmptyText(project);
}
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
VirtualFile file = event.getNewFile();
if (file != null) {
Task task = getTask(file);
setTaskText(task, StudyUtils.getTaskDir(file));
}
toolWindow.setBottomComponent(null);
}
@Nullable
private Task getTask(@NotNull VirtualFile file) {
return StudyUtils.getTaskForFile(project, file);
}
private void setTaskText(@Nullable final Task task, @Nullable final VirtualFile taskDirectory) {
String text = StudyUtils.getTaskTextFromTask(taskDirectory, task);
if (text == null) {
toolWindow.setEmptyText(project);
return;
}
toolWindow.setTaskText(text, taskDirectory, project);
}
};
}
Aggregations