package com.android.ddms;
import com.android.ddmlib.AndroidDebugBridge;
+import com.android.ddmlib.AndroidDebugBridge.IClientChangeListener;
import com.android.ddmlib.Client;
import com.android.ddmlib.ClientData;
-import com.android.ddmlib.IDevice;
-import com.android.ddmlib.Log;
-import com.android.ddmlib.SyncException;
-import com.android.ddmlib.SyncService;
-import com.android.ddmlib.AndroidDebugBridge.IClientChangeListener;
import com.android.ddmlib.ClientData.IHprofDumpHandler;
import com.android.ddmlib.ClientData.MethodProfilingStatus;
+import com.android.ddmlib.IDevice;
+import com.android.ddmlib.Log;
import com.android.ddmlib.Log.ILogOutput;
import com.android.ddmlib.Log.LogLevel;
+import com.android.ddmlib.SyncException;
+import com.android.ddmlib.SyncService;
import com.android.ddmuilib.AllocationPanel;
import com.android.ddmuilib.DevicePanel;
+import com.android.ddmuilib.DevicePanel.IUiSelectionListener;
import com.android.ddmuilib.EmulatorControlPanel;
import com.android.ddmuilib.HeapPanel;
import com.android.ddmuilib.ITableFocusListener;
import com.android.ddmuilib.SysinfoPanel;
import com.android.ddmuilib.TablePanel;
import com.android.ddmuilib.ThreadPanel;
-import com.android.ddmuilib.DevicePanel.IUiSelectionListener;
import com.android.ddmuilib.actions.ToolItemAction;
import com.android.ddmuilib.explorer.DeviceExplorer;
import com.android.ddmuilib.handler.BaseFileHandler;
deleteAction.item.setText("Delete"); //$NON-NLS-1$
}
+ ToolItemAction createNewFolderAction = new ToolItemAction(toolBar, SWT.PUSH);
+ createNewFolderAction.item.setToolTipText("New Folder");
+ image = mDdmUiLibLoader.loadImage("add.png", mDisplay); //$NON-NLS-1$
+ if (image != null) {
+ createNewFolderAction.item.setImage(image);
+ } else {
+ // this is for debugging purpose when the icon is missing
+ createNewFolderAction.item.setText("New Folder"); //$NON-NLS-1$
+ }
+
// device explorer
mExplorer = new DeviceExplorer();
- mExplorer.setActions(pushAction, pullAction, deleteAction);
+ mExplorer.setActions(pushAction, pullAction, deleteAction, createNewFolderAction);
pullAction.item.addSelectionListener(new SelectionAdapter() {
@Override
});
deleteAction.setEnabled(false);
+ createNewFolderAction.item.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ mExplorer.createNewFolderInSelection();
+ }
+ });
+ createNewFolderAction.setEnabled(false);
+
Composite parent = new Composite(mExplorerShell, SWT.NONE);
parent.setLayoutData(new GridData(GridData.FILL_BOTH));
import com.android.ddmlib.AdbCommandRejectedException;
import com.android.ddmlib.DdmConstants;
import com.android.ddmlib.FileListingService;
+import com.android.ddmlib.FileListingService.FileEntry;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.IShellOutputReceiver;
import com.android.ddmlib.ShellCommandUnresponsiveException;
import com.android.ddmlib.SyncException;
import com.android.ddmlib.SyncService;
-import com.android.ddmlib.TimeoutException;
-import com.android.ddmlib.FileListingService.FileEntry;
import com.android.ddmlib.SyncService.ISyncProgressMonitor;
+import com.android.ddmlib.TimeoutException;
import com.android.ddmuilib.DdmUiPreferences;
import com.android.ddmuilib.ImageLoader;
import com.android.ddmuilib.Panel;
import com.android.ddmuilib.SyncProgressHelper;
-import com.android.ddmuilib.TableHelper;
import com.android.ddmuilib.SyncProgressHelper.SyncRunnable;
+import com.android.ddmuilib.TableHelper;
import com.android.ddmuilib.actions.ICommonAction;
import com.android.ddmuilib.console.DdmConsole;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
private ICommonAction mPushAction;
private ICommonAction mPullAction;
private ICommonAction mDeleteAction;
+ private ICommonAction mCreateNewFolderAction;
private Image mFileImage;
private Image mFolderImage;
* @param pushAction
* @param pullAction
* @param deleteAction
+ * @param createNewFolderAction
*/
public void setActions(ICommonAction pushAction, ICommonAction pullAction,
- ICommonAction deleteAction) {
+ ICommonAction deleteAction, ICommonAction createNewFolderAction) {
mPushAction = pushAction;
mPullAction = pullAction;
mDeleteAction = deleteAction;
+ mCreateNewFolderAction = createNewFolderAction;
}
/**
mPullAction.setEnabled(false);
mPushAction.setEnabled(false);
mDeleteAction.setEnabled(false);
+ mCreateNewFolderAction.setEnabled(false);
return;
}
if (sel instanceof IStructuredSelection) {
mPullAction.setEnabled(true);
mPushAction.setEnabled(selection.size() == 1);
if (selection.size() == 1) {
- setDeleteEnabledState((FileEntry)element);
+ FileEntry entry = (FileEntry) element;
+ setDeleteEnabledState(entry);
+ mCreateNewFolderAction.setEnabled(entry.isDirectory());
} else {
mDeleteAction.setEnabled(false);
}
}
+ public void createNewFolderInSelection() {
+ TreeItem[] items = mTree.getSelection();
+
+ if (items.length != 1) {
+ return;
+ }
+
+ final FileEntry entry = (FileEntry) items[0].getData();
+
+ if (entry.isDirectory()) {
+ InputDialog inputDialog = new InputDialog(mTree.getShell(), "New Folder",
+ "Please enter the new folder name", "New Folder", new IInputValidator() {
+ public String isValid(String newText) {
+ if ((newText != null) && (newText.length() > 0)
+ && (newText.trim().length() > 0)
+ && (newText.indexOf('/') == -1)
+ && (newText.indexOf('\\') == -1)) {
+ return null;
+ } else {
+ return "Invalid name";
+ }
+ }
+ });
+ inputDialog.open();
+ String value = inputDialog.getValue();
+
+ if (value != null) {
+ // create the mkdir command
+ String command = "mkdir " + entry.getFullEscapedPath() //$NON-NLS-1$
+ + FileListingService.FILE_SEPARATOR + FileEntry.escape(value);
+
+ try {
+ mCurrentDevice.executeShellCommand(command, new IShellOutputReceiver() {
+
+ public boolean isCancelled() {
+ return false;
+ }
+
+ public void flush() {
+ mTreeViewer.refresh(entry);
+ }
+
+ public void addOutput(byte[] data, int offset, int length) {
+ String errorMessage;
+ if (data != null) {
+ errorMessage = new String(data);
+ } else {
+ errorMessage = "";
+ }
+ Status status = new Status(IStatus.ERROR,
+ "DeviceExplorer", 0, errorMessage, null); //$NON-NLS-1$
+ ErrorDialog.openError(mTree.getShell(), "New Folder Error",
+ "New Folder Error", status);
+ }
+ });
+ } catch (TimeoutException e) {
+ // adb failed somehow, we do nothing. We should be
+ // displaying the error from the output of the shell
+ // command.
+ } catch (AdbCommandRejectedException e) {
+ // adb failed somehow, we do nothing. We should be
+ // displaying the error from the output of the shell
+ // command.
+ } catch (ShellCommandUnresponsiveException e) {
+ // adb failed somehow, we do nothing. We should be
+ // displaying the error from the output of the shell
+ // command.
+ } catch (IOException e) {
+ // adb failed somehow, we do nothing. We should be
+ // displaying the error from the output of the shell
+ // command.
+ }
+ }
+ }
+ }
+
/**
* Force a full refresh of the explorer.
*/
deleteAction.setImageDescriptor(loader.loadDescriptor("delete.png")); //$NON-NLS-1$
deleteAction.setEnabled(false);
+ CommonAction createNewFolderAction = new CommonAction("New Folder") {
+ @Override
+ public void run() {
+ mExplorer.createNewFolderInSelection();
+ }
+ };
+ createNewFolderAction.setToolTipText("New Folder");
+ createNewFolderAction.setImageDescriptor(loader.loadDescriptor("add.png")); //$NON-NLS-1$
+ createNewFolderAction.setEnabled(false);
+
// set up the actions in the explorer
- mExplorer.setActions(pushAction, pullAction, deleteAction);
+ mExplorer.setActions(pushAction, pullAction, deleteAction, createNewFolderAction);
// and in the ui
IActionBars actionBars = getViewSite().getActionBars();
menuManager.add(pushAction);
menuManager.add(new Separator());
menuManager.add(deleteAction);
+ menuManager.add(new Separator());
+ menuManager.add(createNewFolderAction);
toolBarManager.add(pullAction);
toolBarManager.add(pushAction);
toolBarManager.add(new Separator());
toolBarManager.add(deleteAction);
+ toolBarManager.add(new Separator());
+ toolBarManager.add(createNewFolderAction);
mExplorer.createPanel(parent);