Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/actions/ActionUtil.java |
=================================================================== |
--- editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/actions/ActionUtil.java (revision 17863) |
+++ editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/actions/ActionUtil.java (working copy) |
@@ -65,6 +65,8 @@ |
private static final String STRING_SPACE = " "; |
private static final String STRING_TYPE = "type"; |
private static final String STRING_VARIABLE = "variable"; |
+ private static final String STRING_FOR = "For"; |
+ private static final String STRING_DO = "do:"; |
private static final int MAX_NAME_LENGTH = 30; // prevent menus from filling the screen |
public static boolean areProcessable(Shell shell, DartElement[] elements) { |
@@ -82,6 +84,7 @@ |
return true; |
} |
+ // Unused; was needed to put selection in menu item titles. |
public static String constructMenuText(String template, boolean isAdjectivePhrase, |
DartTextSelection selection) { |
StringBuffer text = new StringBuffer(template); |
@@ -123,6 +126,47 @@ |
return text.toString(); |
} |
+ public static String constructSelectionLabel(DartElementSelection selection) { |
+ StringBuffer text = new StringBuffer(STRING_FOR); |
+ String sep = STRING_SPACE; |
+ try { |
+ DartElement[] elements = selection.resolveElementAtOffset(); |
+ if (elements.length == 1) { |
+ String name = elements[0].getElementName(); |
+ text.append(sep); |
+ if (name == null) { |
+ text.append(STRING_SELECTION); |
+ } else if (name.length() > MAX_NAME_LENGTH) { |
+ text.append(findGenericName(elements[0])); |
+ } else { |
+ text.append('\"'); |
+ text.append(name); |
+ text.append('\"'); |
+ } |
+ } else { |
+ DartNode node = getResolvedNodeFromSelection(selection); |
+ String src; |
+ if ((node instanceof com.google.dart.compiler.ast.DartIdentifier) |
+ && ((src = node.toSource()) != null)) { |
+ text.append(sep); |
+ text.append('\"'); |
+ text.append(src); |
+ text.append('\"'); |
+ } else { |
+ text.append(sep); |
+ text.append(STRING_SELECTION); |
+ } |
+ } |
+ } catch (DartModelException ex) { |
+ // should not happen |
+ text.append(sep); |
+ text.append(STRING_SELECTION); |
+ } |
+ text.append(STRING_SPACE); |
+ text.append(STRING_DO); |
+ return text.toString(); |
+ } |
+ |
public static String findGenericName(DartElement element) { |
switch (element.getElementType()) { |
case DartElement.FIELD: |
@@ -368,6 +412,11 @@ |
return false; |
} |
+ public static boolean isSelectionShowing(DartElementSelection selection) { |
+ return isOpenDeclarationAvailable(selection) || isOpenHierarchyAvailable(selection) |
+ || isFindDeclarationsAvailable(selection) || isFindUsesAvailable(selection); |
+ } |
+ |
public static boolean mustDisableDartModelAction(Shell shell, Object element) { |
IResource resource = ResourceUtil.getResource(element); |
if ((resource == null) || (!(resource instanceof IFolder)) || (!resource.isLinked())) { |