* If the mouse has been draggend (from this docuemnt) to another
* window, copy the selection and add it as a new equation in the
* (other) desination document.
*/
private boolean dragToAnotherDocument(Component component, MouseButton mouseButton, Position p) { // Drag to another document.
KetPanel toPanel = getLastDestination();
if (toPanel==null || toPanel==component) {
// Edit within the current ket panel...
// Clear (not needed, but just being careful).
setDestination(null, null); // i.e. clear
return false;
} else if (mouseButton!=MouseButton.LEFT) {
// TODO: Extend.
return true; // Done [nothing].
}
Document toDocument = toPanel.getDocument();
Selection toSelection = toDocument.getSelection();
// Copy argument or equation accross (non-destructively).
Position to = getLastPosition();
Equation toEquation = toPanel.pointToEquation(to);
if (toEquation!=null) {
toSelection.setCurrent(toEquation.getRoot());
}
// Clone and add as a new equation below the selection.
Equation equationCopy = getSelection().getCurrent().getEquation().cloneEquation(); // Include the entire equation: root and label etc.?
toSelection.appendEquation(equationCopy);
setDestination(null, null); // i.e. clear
getKetPanel().updateAndRepaint();
toPanel.updateAndRepaint();
getMathCollection().updateUndoStack();
toDocument.getMathCollection().updateUndoStack();
return true;
}