use of com.intellij.openapi.fileEditor.FileDocumentManager in project Intellij-Discord-Integration by Almighty-Alpaca.
the class FileDocumentManagerListener method beforeDocumentSaving.
@Override
public void beforeDocumentSaving(@NotNull Document document) {
LOG.trace("FileDocumentManagerListener#beforeDocumentSaving({})", document);
Editor[] editors = EditorFactory.getInstance().getEditors(document);
FileDocumentManager documentManager = FileDocumentManager.getInstance();
for (Editor editor : editors) {
Project project = editor.getProject();
DiscordIntegrationProjectComponent component = DiscordIntegrationProjectComponent.getInstance(project);
if (component != null)
component.updateTimeAccessed(documentManager.getFile(document));
}
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project Intellij-Discord-Integration by Almighty-Alpaca.
the class VirtualFileListener method propertyChanged.
@Override
public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
VirtualFile file = event.getFile();
FileDocumentManager documentManager = FileDocumentManager.getInstance();
Document document = documentManager.getDocument(file);
if (document != null) {
Editor[] editors = EditorFactory.getInstance().getEditors(document);
for (Editor editor : editors) {
Project project = editor.getProject();
DiscordIntegrationProjectComponent component = DiscordIntegrationProjectComponent.getInstance(project);
if (component != null && component.getFiles().containsKey(file)) {
if ((event.getPropertyName().equals(VirtualFile.PROP_NAME))) {
component.fileUpdateName(file);
} else if ((event.getPropertyName().equals(VirtualFile.PROP_WRITABLE))) {
component.fileUpdateReadOnly(event.getFile());
}
}
}
}
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-plugins by StepicOrg.
the class ProgrammingLanguageUtils method closeStepNodeFile.
private static ArrayList<VirtualFile> closeStepNodeFile(@NotNull Project project, @NotNull StepNode targetStepNode) {
FileDocumentManager documentManager = FileDocumentManager.getInstance();
ArrayList<VirtualFile> needClose = new ArrayList<>();
for (VirtualFile file : FileEditorManager.getInstance(project).getOpenFiles()) {
if (StudyUtils.getStudyNode(project, file) != targetStepNode) {
continue;
}
final Document document = ApplicationManager.getApplication().runReadAction((Computable<Document>) () -> documentManager.getDocument(file));
if (document == null) {
continue;
}
ApplicationManager.getApplication().invokeAndWait(() -> documentManager.saveDocument(document));
needClose.add(file);
}
return needClose;
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-plugins by StepicOrg.
the class StepikResetStepAction method resetFile.
private static void resetFile(@Nullable final Project project) {
StepNode stepNode = getCurrentCodeStepNode(project);
if (stepNode == null) {
return;
}
VirtualFile src = getOrCreateSrcDirectory(project, stepNode, true);
if (src == null) {
return;
}
String mainFileName = stepNode.getCurrentLang().getMainFileName();
VirtualFile mainFile = src.findChild(mainFileName);
if (mainFile != null) {
FileDocumentManager documentManager = FileDocumentManager.getInstance();
Document document = documentManager.getDocument(mainFile);
if (document != null) {
resetDocument(project, document, stepNode);
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
WolfTheProblemSolver.getInstance(project).clearProblems(mainFile);
}
StepikProjectManager.updateSelection(project);
}
}
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project scss-lint-plugin by idok.
the class ActualFile method getOrCreateActualFile.
@Nullable
public static ActualFile getOrCreateActualFile(@NotNull Key<ThreadLocalActualFile> key, @NotNull VirtualFile virtualFile, @Nullable String content) {
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
if (!fileDocumentManager.isFileModified(virtualFile)) {
File file = new File(virtualFile.getPath());
if (file.isFile()) {
return new ActualFile(file);
}
}
ThreadLocalActualFile threadLocal = key.get(virtualFile);
if (threadLocal == null) {
threadLocal = virtualFile.putUserDataIfAbsent(key, new ThreadLocalActualFile(virtualFile));
}
File file = threadLocal.getOrCreateFile();
if (file == null) {
return null;
}
if (content == null) {
Document document = fileDocumentManager.getDocument(virtualFile);
if (document != null) {
content = document.getText();
}
}
if (content == null) {
return null;
}
try {
FileUtil.writeToFile(file, content);
return new ActualFile(new File(virtualFile.getPath()), file);
} catch (IOException e) {
LOG.warn("Can not write to " + file.getAbsolutePath(), e);
}
return null;
}
Aggregations