There were two problems by paste of multiple line text. I have submitted the bug fix for the first, but the second one still remains.

If multiple line text is pasted, FreeMind makes a structural paste. That means that the nodes are inserted at different levels.
When the undo - action (cut) is calculated, it is assumed that all new nodes have been pasted at the same level and must be deleted. It is no correct and leads to wrong behavior: the undo tries to delete more nodes than needed.
Actually the best way to calculate the cut - actions is to do it during the nodes are being pasted. So I propose the following solution of the problem:

Currently we have
    public void paste(Transferable t, MindMapNode target, boolean asSibling, boolean isLeft) {
        try {
            PasteNodeAction pasteAction = getPasteNodeAction(t,new NodeCoordinate(target,asSibling, isLeft));
            long amountOfCuts = 1;
               DataFlavorHandler[] dataFlavorHandlerList = getFlavorHandlers();
               for (int i = 0; i < dataFlavorHandlerList.length; i++) {
                DataFlavorHandler handler = dataFlavorHandlerList[i];
                DataFlavor           flavor  = handler.getDataFlavor();
                if(t.isDataFlavorSupported(flavor)) {
                    amountOfCuts = handler.getNumberOfObjects(t.getTransferData(flavor), t);
                    break;
                }
            }
            CompoundAction compound = new CompoundAction();
            for(long i = 0; i < amountOfCuts; ++i) {
                CutNodeAction cutNodeAction = pMindMapController.cut.getCutNodeAction(t, new NodeCoordinate(target,asSibling, isLeft));
                compound.addChoice(cutNodeAction);
            }
            // Undo-action
            pMindMapController.getActionFactory().startTransaction(text);
            pMindMapController.getActionFactory().executeAction(new ActionPair(pasteAction, compound));
            pMindMapController.getActionFactory().endTransaction(text);
        } catch (UnsupportedFlavorException e) {
            freemind.main.Resources.getInstance().logException(e);
        } catch (IOException e) {
            freemind.main.Resources.getInstance().logException(e);
        }
    }
It could look like
    public void paste(Transferable t, MindMapNode target, boolean asSibling, boolean isLeft) {
        try {
            PasteNodeAction pasteAction = getPasteNodeAction(t,new NodeCoordinate(target,asSibling, isLeft));
            // Undo-action
            pMindMapController.getActionFactory().startTransaction(text);
            pMindMapController.getActionFactory().executeAction(new ActionPair(pasteAction, doNothingAction));
            CompoundAction cutNodesAction = pasteAction.getCompoundCutNodesAction();
            pMindMapController.getActionFactory().executeAction(new ActionPair(doNothingAction, cutNodesAction));
            pMindMapController.getActionFactory().endTransaction(text);
        } catch (UnsupportedFlavorException e) {
            freemind.main.Resources.getInstance().logException(e);
        } catch (IOException e) {
            freemind.main.Resources.getInstance().logException(e);
        }
    }

so that the
CompoundAction cutNodesAction could be prepared by the  PasteNodeAction during it is being executed.
doNothingAction is an action with empty "act" method.

Any other solution would require implementing of 
PasteAction.getCompoundCutNodesAction(); which duplicates the logic of the paste action itself, because it would have to parse the string and to count the first depth nodes.

What do you think?

Dimitry



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Freemind-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemind-developer

Reply via email to