import com.android.sdklib.SdkConstants;
import org.eclipse.jface.action.Action;
+import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
* <p/>
* This sanitizes the selection, so it must be a copy. It then inserts the
* selection both as text and as {@link SimpleElement}s in the clipboard.
+ * (If there is selected text in the error label, then the error is used
+ * as the text portion of the transferable.)
*
* @param selection A list of selection items to add to the clipboard;
* <b>this should be a copy already - this method will not make a
public void copySelectionToClipboard(List<SelectionItem> selection) {
SelectionManager.sanitize(selection);
+ // The error message area shares the copy action with the canvas. Invoking the
+ // copy action when there are errors visible *AND* the user has selected text there,
+ // should include the error message as the text transferable.
+ String message = null;
+ GraphicalEditorPart graphicalEditor = mCanvas.getLayoutEditor().getGraphicalEditor();
+ StyledText errorLabel = graphicalEditor.getErrorLabel();
+ if (errorLabel.getSelectionCount() > 0) {
+ message = errorLabel.getSelectionText();
+ }
+
if (selection.isEmpty()) {
+ if (message != null) {
+ mClipboard.setContents(
+ new Object[] { message },
+ new Transfer[] { TextTransfer.getInstance() }
+ );
+ }
return;
}
Object[] data = new Object[] {
SelectionItem.getAsElements(selection),
- SelectionItem.getAsText(mCanvas, selection)
+ message != null ? message : SelectionItem.getAsText(mCanvas, selection)
};
Transfer[] types = new Transfer[] {
private static class ClassLinkStyleRange extends StyleRange {}
/**
+ * Returns the error label for the graphical editor (which may not be visible
+ * or showing errors)
+ *
+ * @return the error label, never null
+ */
+ StyledText getErrorLabel() {
+ return mErrorLabel;
+ }
+
+ /**
* Monitor clicks on the error label.
* If the click happens on a style range created by
* {@link GraphicalEditorPart#addClassLink(StyledText, String)}, we assume it's about
String link = mErrorLabel.getText(r.start, r.start + r.length - 1);
createNewClass(link);
}
+
+ LayoutCanvas canvas = getCanvasControl();
+ canvas.updateMenuActionState(canvas.getSelectionManager().getSelections().isEmpty());
}
private void createNewClass(String fqcn) {
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DropTarget;
mSelectAllAction = new Action() {
@Override
public void run() {
+ GraphicalEditorPart graphicalEditor = getLayoutEditor().getGraphicalEditor();
+ StyledText errorLabel = graphicalEditor.getErrorLabel();
+ if (errorLabel.isFocusControl()) {
+ errorLabel.selectAll();
+ return;
+ }
+
mSelectionManager.selectAll();
}
};
* @param hasSelection True iff we have a non-empty selection
*/
/* package */ void updateMenuActionState(boolean hasSelection) {
+ StyledText errorLabel = mLayoutEditor.getGraphicalEditor().getErrorLabel();
mCutAction.setEnabled(hasSelection);
- mCopyAction.setEnabled(hasSelection);
+ mCopyAction.setEnabled(hasSelection || errorLabel.getSelectionCount() > 0);
mDeleteAction.setEnabled(hasSelection);
- mSelectAllAction.setEnabled(hasSelection);
+ mSelectAllAction.setEnabled(hasSelection || errorLabel.isFocusControl());
// The paste operation is only available if we can paste our custom type.
// We do not currently support pasting random text (e.g. XML). Maybe later.