private void updateListClosedParts(VirtualFile file) { if (closedParts.isEmpty()) { return; } for (EditorPartPresenter closedEditorPart : closedParts) { Path path = closedEditorPart.getEditorInput().getFile().getLocation(); if (path.equals(file.getLocation())) { closedParts.remove(closedEditorPart); return; } } }
@Override public void onInitializationFailed() { callback.onFailure( new IllegalStateException( "Initialization " + virtualFile.getName() + " in the editor failed")); } });
@Override public void getDocument( @NotNull final VirtualFile file, @NotNull final DocumentCallback callback) { file.getContent() .then( new Operation<String>() { public void apply(String result) throws OperationException { Log.debug( DocumentStorageImpl.class, "Document retrieved (" + file.getLocation() + ")."); try { callback.onDocumentReceived(result); "Could not retrieve document (" + file.getLocation() + ").", arg.getCause());
final VirtualFile file = editorInput.getFile(); file.updateContent(document.getContents()) .then( new Operation<Void>() { public void apply(Void arg) throws OperationException { Log.debug( DocumentStorageImpl.class, "Document saved (" + file.getLocation() + ")."); DocumentStorageImpl.this.eventBus.fireEvent(FileEvent.createFileSavedEvent(file)); try { Log.error( DocumentStorageImpl.class, "Document save failed (" + file.getLocation() + ").", arg.getCause()); try {
@Override public void onResourceChanged(ResourceChangedEvent event) { final ResourceDelta delta = event.getDelta(); if (delta.getKind() == ADDED) { if (!delta.getResource().isFile() || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) { return; } final Resource resource = delta.getResource(); final Path movedFrom = delta.getFromPath(); if (file.getLocation().equals(movedFrom)) { file = (VirtualFile) resource; title.setText(file.getDisplayName()); } } else if (delta.getKind() == UPDATED) { if (!delta.getResource().isFile()) { return; } final Resource resource = delta.getResource(); if (file.getLocation().equals(resource.getLocation())) { file = (VirtualFile) resource; title.setText(file.getDisplayName()); } } }
appContext .getWorkspaceRoot() .getFile(file.getLocation()) .then( optional -> { boolean isReadOnly = editorPart.getEditorInput().getFile().isReadOnly(); editorTab.setReadOnlyMark(isReadOnly);
@Override public String getName() { return file.getDisplayName(); }
@Override public void propertyChanged(PartPresenter source, int propId) { if (!(source instanceof EditorPartPresenter)) { return; } boolean isReadOnly = ((EditorPartPresenter) source).getEditorInput().getFile().isReadOnly(); if (!isReadOnly && propId == EditorPartPresenter.PROP_DIRTY) { editorTab.setUnsavedDataMark(((EditorPartPresenter) source).isDirty()); } } });
@Override public Promise<String> getDocument(@NotNull VirtualFile file) { return file.getContent(); }
/** * Image to display file with image type. * * @return {@link Image} */ private Image getImage() { String contentLink = urlModifier.modify(input.getFile().getContentUrl()); Image image = (contentLink != null) ? new Image(contentLink) : new Image(); image.setStyleName(resources.imageViewerCss().imageViewer()); return image; }
this.file = relatedEditorPart.getEditorInput().getFile(); this.icon = relatedEditorPart.getTitleImage(); this.title.setText(file.getDisplayName()); this.title.getElement().setAttribute("path", file.getLocation().toString()); this.id = title + UUID.uuid(4); if (propId == EditorPartPresenter.PROP_INPUT) { file = relatedEditorPart.getEditorInput().getFile(); title.setText(file.getDisplayName());
@Override public String getName() { return file.getDisplayName(); }
private void finalizeInit( VirtualFile file, EditorPartPresenter editor, EditorProvider editorProvider) { openedEditorsToProviders.put(editor, editorProvider.getId()); editor.addCloseHandler(this); editor.addPropertyListener( (source, propId) -> { if (propId == EditorPartPresenter.PROP_INPUT) { if (editor instanceof HasReadOnlyProperty) { ((HasReadOnlyProperty) editor).setReadOnly(file.isReadOnly()); } if (editor instanceof TextEditor) { editorContentSynchronizer.trackEditor(editor); } } }); }
@Nullable @Override public EditorTab getTabByPath(@NotNull Path path) { for (TabItem tab : parts.keySet()) { EditorTab editorTab = (EditorTab) tab; Path currentPath = editorTab.getFile().getLocation(); if (currentPath.equals(path)) { return editorTab; } } return null; }
@Override public List<String> identifyType(final VirtualFile file) { final String filename = file.getName(); if ("Rakefile".equals(filename) || "Gemfile".equals(filename)) { return Collections.singletonList("text/x-ruby"); } if (contains(new String[] {"Makefile", "makefile", "GNUmakefile"}, filename)) { return Collections.singletonList("text/x-makefile"); } if (contains(new String[] {"SConstruct", "Sconstruct", "sconstruct"}, filename)) { return Collections.singletonList("text/x-python"); } if (filename != null && "VAGRANTFILE".equals(filename.toUpperCase())) { return Collections.singletonList("text/x-ruby"); } if ("Dockerfile".equals(filename)) { return Collections.singletonList("text/x-dockerfile"); } if ("Chefile".equals(filename)) { return Arrays.asList("application/javascript", "text/javascript"); } // not a known file name return null; }
@Override public void onDocumentLoadFailure(final Throwable caught) { notificationManager.notify( "", "Can not to update content for the file " + virtualFile.getDisplayName(), FAIL, EMERGE_MODE); } });
@Override public void onInitializationFailed() { openEditorCallback.onInitializationFailed(); removeFromOpeningFilesList(file.getLocation(), editorPartStack); if (!openingEditorsPathsToStacks.containsKey(editorPartStack) && editorPartStack.getParts().isEmpty()) { editorMultiPartStack.removePartStack(editorPartStack); } } };
private Set<FileType> getFileTypesByFile(VirtualFile file) { String name = file.getName(); if (isNullOrEmpty(name)) { return emptySet(); } Set<FileType> typesByNamePattern = fileTypeRegistry .getFileTypes() .stream() .filter( type -> type.getNamePatterns() .stream() .anyMatch(namePattern -> compile(namePattern).test(name))) .collect(toSet()); String fileExtension = getFileExtension(name); if (isNullOrEmpty(fileExtension)) { return typesByNamePattern; } Set<FileType> fileTypes = typesByNamePattern .stream() .filter(type -> fileExtension.equals(type.getExtension())) .collect(toSet()); fileTypes = fileTypes.isEmpty() ? typesByNamePattern : fileTypes; return fileTypes.isEmpty() ? singleton(fileTypeRegistry.getFileTypeByExtension(fileExtension)) : fileTypes; }
@Nullable public PartPresenter getPartByPath(Path path) { for (TabItem tab : parts.keySet()) { EditorTab editorTab = (EditorTab) tab; Path currentPath = editorTab.getFile().getLocation(); if (currentPath.equals(path)) { return parts.get(tab); } } return null; }
@Override public List<String> identifyType(final VirtualFile file) { final String filename = file.getName(); if (filename != null) { final int dotPos = filename.lastIndexOf('.'); if (dotPos < 1) { // either -1 (not found) or 0 (first position, for example .project or .che etc. Log.debug(ExtensionFileTypeIdentifier.class, "File name has no suffix "); return null; } final String suffix = filename.substring(dotPos + 1); Log.debug(ExtensionFileTypeIdentifier.class, "Looking for a type for suffix " + suffix); List<String> result = mappings.get(suffix); Log.debug(ExtensionFileTypeIdentifier.class, "Found mime-types: " + printList(result)); return result; } return null; }