Search in sources :

Example 1 with ExporterToTextFile

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;
        }
    };
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) RelativePoint(com.intellij.ui.awt.RelativePoint) ExporterToTextFile(com.intellij.ide.ExporterToTextFile) ChangeListener(javax.swing.event.ChangeListener) TreeUtil(com.intellij.util.ui.tree.TreeUtil)

Example 2 with ExporterToTextFile

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());
}
Also used : ExporterToTextFile(com.intellij.ide.ExporterToTextFile)

Example 3 with ExporterToTextFile

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);
}
Also used : Project(com.intellij.openapi.project.Project) ExporterToTextFile(com.intellij.ide.ExporterToTextFile)

Aggregations

ExporterToTextFile (com.intellij.ide.ExporterToTextFile)3 PresentationData (com.intellij.ide.projectView.PresentationData)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 Project (com.intellij.openapi.project.Project)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 TreeUtil (com.intellij.util.ui.tree.TreeUtil)1 ChangeListener (javax.swing.event.ChangeListener)1