Search in sources :

Example 1 with EntryVisitor

use of org.freeplane.core.ui.menubuilders.generic.EntryVisitor in project freeplane by freeplane.

the class MTextController method createActions.

private void createActions() {
    final ModeController modeController = Controller.getCurrentModeController();
    modeController.addAction(new EditAction());
    modeController.addAction(new UsePlainTextAction());
    modeController.addAction(new EditLongAction());
    modeController.addAction(new SetImageByFileChooserAction());
    modeController.addAction(new EditDetailsAction(false));
    modeController.addAction(new EditDetailsAction(true));
    modeController.addAction(new DeleteDetailsAction());
    modeController.addUiBuilder(Phase.ACTIONS, "splitToWordsActions", new EntryVisitor() {

        @Override
        public void visit(Entry target) {
            final String[] nodeNumbersInLine = ResourceController.getResourceController().getProperty("SplitToWordsAction.nodeNumbersInLine").split("[^\\d]+");
            for (String nodeNumberInLineAsString : nodeNumbersInLine) {
                try {
                    final int nodeNumberInLine = Integer.parseInt(nodeNumberInLineAsString);
                    if (nodeNumberInLine > 0) {
                        final SplitToWordsAction action = new SplitToWordsAction(nodeNumberInLine);
                        new EntryAccessor().addChildAction(target, action);
                        modeController.addAction(action);
                    }
                } catch (NumberFormatException e) {
                }
            }
        }

        @Override
        public boolean shouldSkipChildren(Entry entry) {
            return true;
        }
    });
    modeController.addUiBuilder(Phase.ACTIONS, "joinNodesActions", new EntryVisitor() {

        @Override
        public void visit(Entry target) {
            final String textSeparators = ResourceController.getResourceController().getProperty("JoinNodesAction.textSeparators");
            final Pattern JOIN_NODES_ACTION_SEPARATORS = Pattern.compile("\\{\\{.*?\\}\\}");
            final Matcher matcher = JOIN_NODES_ACTION_SEPARATORS.matcher(textSeparators);
            if (matcher.find()) {
                do {
                    String textSeparator = textSeparators.substring(matcher.start() + 2, matcher.end() - 2);
                    addAction(modeController, target, textSeparator);
                } while (matcher.find());
            } else {
                addAction(modeController, target, textSeparators);
            }
        }

        private void addAction(final ModeController modeController, Entry target, String textSeparator) {
            final JoinNodesAction action = new JoinNodesAction(textSeparator);
            new EntryAccessor().addChildAction(target, action);
            modeController.addAction(action);
            if (target.getChildCount() == 1)
                target.getChild(0).setAttribute(EntryAccessor.ACCELERATOR, target.getAttribute(EntryAccessor.ACCELERATOR));
        }

        @Override
        public boolean shouldSkipChildren(Entry entry) {
            return true;
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntryVisitor(org.freeplane.core.ui.menubuilders.generic.EntryVisitor)

Aggregations

Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Entry (org.freeplane.core.ui.menubuilders.generic.Entry)1 EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)1 EntryVisitor (org.freeplane.core.ui.menubuilders.generic.EntryVisitor)1 ModeController (org.freeplane.features.mode.ModeController)1 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)1