@Override public void setSelected(AnActionEvent e, boolean state) { DataContext context = e.getDataContext(); VirtualFile file = getFile(context); if (file != null) { // 1. Check editor EditorWindow editorWindow = getEditorWindow(context); if (editorWindow != null) { if (!editorWindow.isFileOpen(file)) { file = editorWindow.getSelectedFile(); if (file == null) return; } editorWindow.setFilePinned(file, state); return; } } Content content = getContent(context); // at this point content cannot be null assert content != null : context; content.setPinned(state); }
@Override public boolean isSelected(AnActionEvent e) { DataContext context = e.getDataContext(); VirtualFile file = getFile(context); if (file != null) { // 1. Check editor EditorWindow editorWindow = getEditorWindow(context); if (editorWindow != null) { if (!editorWindow.isFileOpen(file)) { file = editorWindow.getSelectedFile(); if (file == null) return false; } return editorWindow.isFilePinned(file); } } // 2. Check content final Content content = getContent(context); if (content != null) { return content.isPinned(); } else { return false; } }