<string name="input_name_dialog_message_invalid_name">Invalid name. The names \'.\' and
\'..\' are not allowed.</string>
<!-- Enter Name Dialog * Message * Name exists -->
- <string name="input_name_dialog_message_name_exists">The namealready exists.</string>
+ <string name="input_name_dialog_message_name_exists">The name already exists.</string>
<!-- Associations Dialog * Title -->
<string name="associations_dialog_title">Associations</string>
List<FileSystemObject> onRequestSelectedFiles();
/**
+ * Method that request the current directory items
+ *
+ * @return List<FileSystemObject> The array of {@link FileSystemObject} objects of the
+ * current directory.
+ */
+ List<FileSystemObject> onRequestCurrentItems();
+
+ /**
* Method that request the current directory of the selection info.
*
* @return String The current directory of the selection info.
*/
public class ActionsDialog implements OnItemClickListener, OnItemLongClickListener {
- private final Context mContext;
+ /**
+ * @hide
+ */
+ final Context mContext;
private final boolean mGlobal;
/**
*/
AlertDialog mDialog;
private ListView mListView;
- private final FileSystemObject mFso;
+ /**
+ * @hide
+ */
+ final FileSystemObject mFso;
- private OnRequestRefreshListener mOnRequestRefreshListener;
+ /**
+ * @hide
+ */
+ OnRequestRefreshListener mOnRequestRefreshListener;
private OnSelectionListener mOnSelectionListener;
}
break;
+ //- Rename
+ case R.id.mnu_actions_rename:
+ // Dialog is dismissed inside showInputNameDialog
+ if (this.mOnSelectionListener != null) {
+ showFsoInputNameDialog(menuItem, this.mFso);
+ return;
+ }
+ break;
+
//- Delete
case R.id.mnu_actions_delete:
ActionsPolicy.removeFileSystemObject(
this.mContext, this.mFso, this.mOnRequestRefreshListener);
break;
- //- Delete
+ //- Refresh
case R.id.mnu_actions_refresh:
if (this.mOnRequestRefreshListener != null) {
this.mOnRequestRefreshListener.onRequestRefresh(null); //Refresh all
final InputNameDialog inputNameDialog =
new InputNameDialog(
this.mContext,
- this.mOnSelectionListener.onRequestSelectedFiles(),
+ this.mOnSelectionListener.onRequestCurrentItems(),
menuItem.getTitle().toString());
inputNameDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
}
/**
+ * Method that show a new dialog for input a name for an existing fso.
+ *
+ * @param menuItem The item menu associated
+ * @param fso The file system object
+ */
+ private void showFsoInputNameDialog(final MenuItem menuItem, final FileSystemObject fso) {
+ //Hide the dialog
+ this.mDialog.hide();
+
+ //Show the input name dialog
+ final InputNameDialog inputNameDialog =
+ new InputNameDialog(
+ this.mContext,
+ this.mOnSelectionListener.onRequestCurrentItems(),
+ fso,
+ menuItem.getTitle().toString());
+ inputNameDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ //Show the menu again
+ ActionsDialog.this.mDialog.show();
+ }
+ });
+ inputNameDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ //Retrieve the name an execute the action
+ try {
+ String name = inputNameDialog.getName();
+ switch (menuItem.getItemId()) {
+ case R.id.mnu_actions_rename:
+ ActionsPolicy.renameFileSystemObject(
+ ActionsDialog.this.mContext,
+ ActionsDialog.this.mFso,
+ name,
+ ActionsDialog.this.mOnRequestRefreshListener);
+ break;
+ default:
+ break;
+ }
+
+ } finally {
+ ActionsDialog.this.mDialog.dismiss();
+ }
+ }
+ });
+ inputNameDialog.show();
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
import com.cyanogenmod.explorer.R;
import com.cyanogenmod.explorer.model.FileSystemObject;
import com.cyanogenmod.explorer.util.DialogHelper;
+import com.cyanogenmod.explorer.util.FileHelper;
import java.io.File;
import java.util.List;
implements TextWatcher, DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
private final Context mContext;
- private final AlertDialog mDialog;
+ /**
+ * @hide
+ */
+ final AlertDialog mDialog;
private final TextView mMsg;
/**
* @hide
*/
final EditText mEditText;
private final List<FileSystemObject> mFiles;
+ private final FileSystemObject mFso;
private DialogInterface.OnCancelListener mOnCancelListener;
private DialogInterface.OnDismissListener mOnDismissListener;
*/
public InputNameDialog(
final Context context, List<FileSystemObject> files, String dialogTitle) {
+ this(context, files, null, dialogTitle);
+ }
+
+ /**
+ * Constructor of <code>InputNameDialog</code>.
+ *
+ * @param context The current context
+ * @param files The files of the current directory (used to validate the name)
+ * @param fso The original file system object. null if not needed.
+ * @param dialogTitle The dialog title
+ */
+ public InputNameDialog(
+ final Context context, List<FileSystemObject> files,
+ FileSystemObject fso, String dialogTitle) {
super();
//Save the context
//Save the files
this.mFiles = files;
+ this.mFso = fso;
this.mCancelled = true;
//Create the
TextView title = (TextView)v.findViewById(R.id.input_name_dialog_label);
title.setText(R.string.input_name_dialog_label);
this.mEditText = (EditText)v.findViewById(R.id.input_name_dialog_edit);
- this.mEditText.setText(dialogTitle);
+ if (this.mFso != null) {
+ this.mEditText.setText(this.mFso.getName());
+ } else {
+ this.mEditText.setText(dialogTitle);
+ }
this.mEditText.selectAll();
this.mEditText.addTextChangedListener(this);
this.mMsg = (TextView)v.findViewById(R.id.input_name_dialog_message);
(DialogInterface.OnClickListener)null);
this.mDialog.setOnCancelListener(this);
this.mDialog.setOnDismissListener(this);
+
+ // Disable accept button, because name is the same as fso
+ if (this.mFso != null) {
+ this.mEditText.post(new Runnable() {
+ @Override
+ public void run() {
+ InputNameDialog.this.mDialog.getButton(
+ DialogInterface.BUTTON_POSITIVE).setEnabled(false);
+ }
+ });
+ }
}
/**
R.string.input_name_dialog_message_empty_name), false);
return;
}
- if (txt.indexOf("/") != -1) { //$NON-NLS-1$
+ if (txt.indexOf(File.separator) != -1) {
setMsg(
InputNameDialog.this.mContext.getString(
R.string.input_name_dialog_message_invalid_path_name,
File.separator), false);
return;
}
- if (txt.compareTo(".") == 0 || txt.compareTo("..") == 0) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (txt.compareTo(FileHelper.CURRENT_DIRECTORY) == 0 ||
+ txt.compareTo(FileHelper.PARENT_DIRECTORY) == 0) {
setMsg(
InputNameDialog.this.mContext.getString(
R.string.input_name_dialog_message_invalid_name), false);
return;
}
+ if (this.mFso != null && txt.compareTo(this.mFso.getName()) == 0) {
+ setMsg(null, false);
+ return;
+ }
if (isNameExists(txt)) {
setMsg(
InputNameDialog.this.mContext.getString(
});
dialog.show();
}
+
+ /**
+ * Method that remove an existing file system object.
+ *
+ * @param ctx The current context
+ * @param fso The file system object
+ * @param newName The new name of the object
+ * @param onRequestRefreshListener The listener for request a refresh after the new
+ * folder was created (option)
+ */
+ public static void renameFileSystemObject(
+ final Context ctx, final FileSystemObject fso, final String newName,
+ final OnRequestRefreshListener onRequestRefreshListener) {
+ try {
+ File newFile = new File(fso.getParent(), newName);
+ CommandHelper.move(ctx, fso.getFullPath(), newFile.getAbsolutePath(), null);
+
+ // Check that the operation was completed retrieving the fso modified
+ CommandHelper.getFileInfo(ctx, newFile.getAbsolutePath(), null);
+
+ //Operation complete. Refresh
+ if (onRequestRefreshListener != null) {
+ // The reference is not the same, so refresh the complete navigation view
+ onRequestRefreshListener.onRequestRefresh(null);
+ }
+
+ //Operation complete. Refresh
+ if (onRequestRefreshListener != null) {
+ onRequestRefreshListener.onRequestRemove(fso);
+ }
+
+ } catch (Throwable ex) {
+ // Capture the exception
+ ExceptionUtil.translateException(ctx, ex, false, true, null);
+ }
+ }
}
\ No newline at end of file
* {@inheritDoc}
*/
@Override
+ public List<FileSystemObject> onRequestCurrentItems() {
+ return this.getFiles();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String onRequestCurrentDirOfSelectionData() {
return this.mCurrentDir;
}
return o1.compareTo(fso2);
}
+ /**
+ * Method that add to the path the trailing slash
+ *
+ * @param path The path
+ * @return String The path with the trailing slash
+ */
+ public static String addTrailingSlash(String path) {
+ return path.endsWith(File.separator) ? path : path + File.separator;
+ }
+
+ /**
+ * Method that cleans the path and removes the trailing slash
+ *
+ * @param path The path to clean
+ * @return String The path without the trailing slash
+ */
+ public static String removeTrailingSlash(String path) {
+ if (path.trim().compareTo(ROOT_DIRECTORY) == 0) return path;
+ if (path.endsWith(File.separator)) {
+ return path.substring(0, path.length()-1);
+ }
+ return path;
+ }
+
}