use of com.intellij.ide.ExporterToTextFile in project intellij-community by JetBrains.
the class FavoritesTreeViewPanel method createTextExporter.
private ExporterToTextFile createTextExporter() {
return new ExporterToTextFile() {
@Override
public JComponent getSettingsEditor() {
return null;
}
@Override
public void addSettingsChangedListener(ChangeListener listener) throws TooManyListenersException {
}
@Override
public void removeSettingsChangedListener(ChangeListener listener) {
}
@NotNull
@Override
public String getReportText() {
final StringBuilder sb = new StringBuilder();
final Object[] elements = myBuilder.getStructure().getChildElements(myBuilder.getRoot());
final TreeUtil.Traverse traverse = new TreeUtil.Traverse() {
@Override
public boolean accept(Object node) {
if (node instanceof LoadingNode)
return true;
final AbstractTreeNode abstractTreeNode = (AbstractTreeNode) node;
if (sb.length() > 0) {
sb.append('\n');
}
int deepLevel = getDeepLevel((AbstractTreeNode) node);
for (int i = 1; i < deepLevel; i++) {
sb.append('\t');
}
abstractTreeNode.update();
final PresentationData presentation = abstractTreeNode.getPresentation();
sb.append(presentation.getPresentableText());
String locationString = presentation.getLocationString();
if (locationString == null) {
locationString = FavoritesTreeNodeDescriptor.getLocation(abstractTreeNode, myProject);
}
if (locationString != null) {
sb.append(" (").append(locationString).append(")");
}
return true;
}
public int getDeepLevel(AbstractTreeNode node) {
int result = 0;
while (node.getParent() != null) {
result++;
node = node.getParent();
}
return result;
}
};
for (Object element : elements) {
traverseDepth((AbstractTreeNode) element, traverse);
}
return sb.toString();
}
@NotNull
@Override
public String getDefaultFilePath() {
return myProject.getBasePath() + File.separator + "Favorites.txt";
}
@Override
public void exportedTo(String filePath) {
}
@Override
public boolean canExport() {
return true;
}
};
}
use of com.intellij.ide.ExporterToTextFile in project intellij-community by JetBrains.
the class ExportToTextFileAction method update.
public void update(AnActionEvent event) {
Presentation presentation = event.getPresentation();
DataContext dataContext = event.getDataContext();
ExporterToTextFile exporterToTextFile = getExporter(dataContext);
presentation.setEnabled(CommonDataKeys.PROJECT.getData(dataContext) != null && exporterToTextFile != null && exporterToTextFile.canExport());
}
use of com.intellij.ide.ExporterToTextFile in project intellij-community by JetBrains.
the class ExportToTextFileAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Project project = CommonDataKeys.PROJECT.getData(dataContext);
ExporterToTextFile exporterToTextFile = getExporter(dataContext);
if (project == null || exporterToTextFile == null)
return;
if (!exporterToTextFile.canExport())
return;
export(project, exporterToTextFile);
}
Aggregations