*/
String displayReferenceInput(String currentValue);
+ /**
+ * Displays an input dialog where the user can enter an Android resource name of the
+ * given resource type ("id", "string", "drawable", and so on.)
+ *
+ * @param currentValue the current reference to select
+ * @param resourceTypeName resource type, such as "id", "string", and so on (never
+ * null)
+ * @return the resource selected by the user, or null
+ */
+ String displayResourceInput(String resourceTypeName, String currentValue);
}
} else if (fullActionId.equals(EDIT_TEXT_ID)) {
String oldText = node.getStringAttr(ANDROID_URI, ATTR_TEXT);
oldText = ensureValidString(oldText);
- String newText = mRulesEngine.displayReferenceInput(oldText);
+ String newText = mRulesEngine.displayResourceInput("string", oldText); //$NON-NLS-1$
if (newText != null) {
node.editXml("Change text", new PropertySettingNodeHandler(ANDROID_URI,
ATTR_TEXT, newText));
&& IAttributeInfo.Format.REFERENCE.in(attributeInfo.getFormats())) {
return mRulesEngine.displayReferenceInput(oldValue);
} else {
+ // A single resource type? If so use a resource chooser initialized
+ // to this specific type
+ /* This does not work well, because the metadata is a bit misleading:
+ * for example a Button's "text" property and a Button's "onClick" property
+ * both claim to be of type [string], but @string/ is NOT valid for
+ * onClick..
+ if (attributeInfo != null && attributeInfo.getFormats().length == 1) {
+ // Resource chooser
+ Format format = attributeInfo.getFormats()[0];
+ return mRulesEngine.displayResourceInput(format.name(), oldValue);
+ }
+ */
+
+ // Fallback: just edit the raw XML string
String message = String.format("New %1$s Value:", attribute);
return mRulesEngine.displayInput(message, oldValue, null);
}
* "Play Animation" context menu which lists available animations in the project and in
* the framework, as well as a "Create Animation" shortcut, and allows the animation to be
* run on the selection
- * <p>
+ * <p/>
* TODO: Add transport controls for play/rewind/pause/loop, and (if possible) scrubbing
*/
public class PlayAnimationMenu extends SubmenuAction {
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.SimpleElement;
import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElementNode;
import com.android.ide.eclipse.adt.internal.resources.IResourceRepository;
+import com.android.ide.eclipse.adt.internal.resources.ResourceType;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceManager;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.ide.eclipse.adt.internal.sdk.ProjectState;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
import com.android.ide.eclipse.adt.internal.ui.ReferenceChooserDialog;
+import com.android.ide.eclipse.adt.internal.ui.ResourceChooser;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.internal.project.ProjectProperties;
return null;
}
+
+ public String displayResourceInput(String resourceTypeName, String currentValue) {
+ AndroidXmlEditor editor = mEditor.getLayoutEditor();
+ IProject project = editor.getProject();
+ ResourceType type = ResourceType.valueOf(resourceTypeName.toUpperCase());
+ if (project != null) {
+ // get the resource repository for this project and the system resources.
+ IResourceRepository projectRepository = ResourceManager.getInstance()
+ .getProjectResources(project);
+ Shell shell = AdtPlugin.getDisplay().getActiveShell();
+ if (shell == null) {
+ return null;
+ }
+
+ AndroidTargetData data = editor.getTargetData();
+ IResourceRepository systemRepository = data.getSystemResources();
+
+ // open a resource chooser dialog for specified resource type.
+ ResourceChooser dlg = new ResourceChooser(project, type, projectRepository,
+ systemRepository, shell);
+
+ dlg.setCurrentResource(currentValue);
+
+ if (dlg.open() == Window.OK) {
+ return dlg.getCurrentResource();
+ }
+ }
+
+ return null;
+ }
+
}
}
* <li>The project name, valid if it's an android nature.</li>
* <li>The current folder, valid if it's a folder under /res</li>
* <li>An existing filename, in which case the user will be asked whether to override it.</li>
- * <ul>
- * <p>
+ * </ul>
+ * <p/>
* The selection can also be set to a {@link Pair} of {@link IProject} and a workspace
* resource path (where the resource path does not have to exist yet, such as res/anim/).
*
return null;
}
+ public String displayResourceInput(String resourceTypeName, String currentValue) {
+ fail("Not supported in tests yet");
+ return null;
+ }
}
public void testDummy() {