diff options
Diffstat (limited to 'src')
3 files changed, 202 insertions, 32 deletions
diff --git a/src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java b/src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java index 058a3f6..3e76c95 100644 --- a/src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java +++ b/src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java @@ -178,7 +178,28 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen case R.id.mnu_actions_rename: // Dialog is dismissed inside showInputNameDialog if (this.mOnSelectionListener != null) { - showFsoInputNameDialog(menuItem, this.mFso); + showFsoInputNameDialog(menuItem, this.mFso, false); + return; + } + break; + + //- Create link + case R.id.mnu_actions_create_link: + // Dialog is dismissed inside showInputNameDialog + if (this.mOnSelectionListener != null) { + showFsoInputNameDialog(menuItem, this.mFso, true); + return; + } + break; + case R.id.mnu_actions_create_link_global: + // Dialog is dismissed inside showInputNameDialog + if (this.mOnSelectionListener != null) { + // The selection must be only 1 item + List<FileSystemObject> selection = + this.mOnSelectionListener.onRequestSelectedFiles(); + if (selection != null && selection.size() == 1) { + showFsoInputNameDialog(menuItem, selection.get(0), true); + } return; } break; @@ -344,8 +365,10 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen * * @param menuItem The item menu associated * @param fso The file system object + * @param allowFsoName If allow that the name of the fso will be returned */ - private void showFsoInputNameDialog(final MenuItem menuItem, final FileSystemObject fso) { + private void showFsoInputNameDialog( + final MenuItem menuItem, final FileSystemObject fso, final boolean allowFsoName) { //Hide the dialog this.mDialog.hide(); @@ -355,6 +378,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen this.mContext, this.mOnSelectionListener.onRequestCurrentItems(), fso, + allowFsoName, menuItem.getTitle().toString()); inputNameDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override @@ -375,12 +399,26 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen if (ActionsDialog.this.mOnSelectionListener != null) { ActionsPolicy.renameFileSystemObject( ActionsDialog.this.mContext, - ActionsDialog.this.mFso, + inputNameDialog.mFso, + name, + ActionsDialog.this.mOnSelectionListener, + ActionsDialog.this.mOnRequestRefreshListener); + } + break; + + case R.id.mnu_actions_create_link: + case R.id.mnu_actions_create_link_global: + // Create a link to the fso + if (ActionsDialog.this.mOnSelectionListener != null) { + ActionsPolicy.createSymlink( + ActionsDialog.this.mContext, + inputNameDialog.mFso, name, ActionsDialog.this.mOnSelectionListener, ActionsDialog.this.mOnRequestRefreshListener); } break; + default: break; } @@ -467,6 +505,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen } // Paste/Move only when have a selection + // Create link if (this.mGlobal) { List<FileSystemObject> selection = null; if (this.mOnSelectionListener != null) { @@ -479,6 +518,10 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen menu.removeItem(R.id.mnu_actions_move_selection); menu.removeItem(R.id.mnu_actions_delete_selection); } + if (selection == null || selection.size() == 0 || selection.size() > 1) { + // Only when one item is selected + menu.removeItem(R.id.mnu_actions_create_link_global); + } } } diff --git a/src/com/cyanogenmod/explorer/ui/dialogs/InputNameDialog.java b/src/com/cyanogenmod/explorer/ui/dialogs/InputNameDialog.java index 0e79343..236e829 100644 --- a/src/com/cyanogenmod/explorer/ui/dialogs/InputNameDialog.java +++ b/src/com/cyanogenmod/explorer/ui/dialogs/InputNameDialog.java @@ -51,8 +51,15 @@ public class InputNameDialog * @hide */ final EditText mEditText; - private final List<FileSystemObject> mFiles; - private final FileSystemObject mFso; + /** + * @hide + */ + final List<FileSystemObject> mFiles; + /** + * @hide + */ + final FileSystemObject mFso; + private final boolean mAllowFsoName; private DialogInterface.OnCancelListener mOnCancelListener; private DialogInterface.OnDismissListener mOnDismissListener; @@ -70,7 +77,7 @@ public class InputNameDialog */ public InputNameDialog( final Context context, List<FileSystemObject> files, String dialogTitle) { - this(context, files, null, dialogTitle); + this(context, files, null, false, dialogTitle); } /** @@ -79,11 +86,12 @@ public class InputNameDialog * @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 allowFsoName If allow that the name of the fso will be returned * @param dialogTitle The dialog title */ public InputNameDialog( - final Context context, List<FileSystemObject> files, - FileSystemObject fso, String dialogTitle) { + final Context context, final List<FileSystemObject> files, + final FileSystemObject fso, boolean allowFsoName, final String dialogTitle) { super(); //Save the context @@ -92,6 +100,7 @@ public class InputNameDialog //Save the files this.mFiles = files; this.mFso = fso; + this.mAllowFsoName = allowFsoName; this.mCancelled = true; //Create the @@ -141,7 +150,7 @@ public class InputNameDialog this.mDialog.setOnDismissListener(this); // Disable accept button, because name is the same as fso - if (this.mFso != null) { + if (this.mFso != null && !this.mAllowFsoName) { this.mEditText.post(new Runnable() { @Override public void run() { @@ -149,6 +158,13 @@ public class InputNameDialog DialogInterface.BUTTON_POSITIVE).setEnabled(false); } }); + } else { + this.mEditText.post(new Runnable() { + @Override + public void run() { + checkName(InputNameDialog.this.mEditText.getText().toString()); + } + }); } } @@ -211,16 +227,25 @@ public class InputNameDialog */ @Override public void afterTextChanged(Editable s) { - String txt = s.toString().trim(); + String name = s.toString().trim(); + checkName(name); + } + + /** + * Method that checks the input name + * @param name + * @hide + */ + void checkName(String name) { //The name is empty - if (txt.length() == 0) { + if (name.length() == 0) { setMsg( InputNameDialog.this.mContext.getString( R.string.input_name_dialog_message_empty_name), false); return; } // The path is invalid - if (txt.indexOf(File.separator) != -1) { + if (name.indexOf(File.separator) != -1) { setMsg( InputNameDialog.this.mContext.getString( R.string.input_name_dialog_message_invalid_path_name, @@ -228,20 +253,20 @@ public class InputNameDialog return; } // No allow . or .. - if (txt.compareTo(FileHelper.CURRENT_DIRECTORY) == 0 || - txt.compareTo(FileHelper.PARENT_DIRECTORY) == 0) { + if (name.compareTo(FileHelper.CURRENT_DIRECTORY) == 0 || + name.compareTo(FileHelper.PARENT_DIRECTORY) == 0) { setMsg( InputNameDialog.this.mContext.getString( R.string.input_name_dialog_message_invalid_name), false); return; } // The same name - if (this.mFso != null && txt.compareTo(this.mFso.getName()) == 0) { + if (this.mFso != null && !this.mAllowFsoName && name.compareTo(this.mFso.getName()) == 0) { setMsg(null, false); return; } // Name exists - if (FileHelper.isNameExists(this.mFiles, txt)) { + if (FileHelper.isNameExists(this.mFiles, name)) { setMsg( InputNameDialog.this.mContext.getString( R.string.input_name_dialog_message_name_exists), false); diff --git a/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java b/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java index 0f3c513..895d389 100644 --- a/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java +++ b/src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java @@ -210,6 +210,16 @@ public final class ActionsPolicy { } } + /** + * @hide + */ + private enum COPY_MOVE_OPERATION { + COPY, + MOVE, + RENAME, + CREATE_COPY, + } + private static final String TAG = "ActionPolicy"; //$NON-NLS-1$ @@ -501,6 +511,7 @@ public final class ActionsPolicy { } onRequestRefreshListener.onRequestRefresh(fso); } + showOperationSuccessMsg(ctx); } catch (Throwable ex) { //Capture the exception @@ -525,6 +536,93 @@ public final class ActionsPolicy { return Boolean.TRUE; } + /** + * {@inheritDoc} + */ + @Override + protected void onPostExecute(Boolean result) { + if (result != null && result.booleanValue()) { + showOperationSuccessMsg(ctx); + } + } + }); + } + ExceptionUtil.translateException(ctx, ex); + } + } + + /** + * Method that remove an existing file system object. + * + * @param ctx The current context + * @param src The source file system object + * @param lnkName The new name of the link + * @param onSelectionListener The listener for obtain selection information (required) + * @param onRequestRefreshListener The listener for request a refresh (optional) + */ + public static void createSymlink( + final Context ctx, + final FileSystemObject src, + final String lnkName, + final OnSelectionListener onSelectionListener, + final OnRequestRefreshListener onRequestRefreshListener) { + + //Create the absolute file name + File newFso = new File( + onSelectionListener.onRequestCurrentDir(), lnkName); + final String link = newFso.getAbsolutePath(); + + try { + if (DEBUG) { + Log.d(TAG, String.format( + "Creating new symlink: %s -> %s", src.getFullPath(), link)); //$NON-NLS-1$ + } + CommandHelper.createLink(ctx, src.getFullPath(), link, null); + + //Operation complete. Show refresh + if (onRequestRefreshListener != null) { + FileSystemObject fso = null; + try { + fso = CommandHelper.getFileInfo(ctx, link, false, null); + } catch (Throwable ex2) { + /**NON BLOCK**/ + } + onRequestRefreshListener.onRequestRefresh(fso); + } + showOperationSuccessMsg(ctx); + + } catch (Throwable ex) { + //Capture the exception + if (ex instanceof RelaunchableException) { + ExceptionUtil.attachAsyncTask(ex, new AsyncTask<Object, Integer, Boolean>() { + /** + * {@inheritDoc} + */ + @Override + protected Boolean doInBackground(Object... params) { + //Operation complete. Show refresh + if (onRequestRefreshListener != null) { + FileSystemObject fso = null; + try { + fso = CommandHelper.getFileInfo(ctx, link, false, null); + } catch (Throwable ex2) { + /**NON BLOCK**/ + } + onRequestRefreshListener.onRequestRefresh(fso); + } + return Boolean.TRUE; + } + + /** + * {@inheritDoc} + */ + @Override + protected void onPostExecute(Boolean result) { + if (result != null && result.booleanValue()) { + showOperationSuccessMsg(ctx); + } + } + }); } ExceptionUtil.translateException(ctx, ex); @@ -785,7 +883,7 @@ public final class ActionsPolicy { File dst = new File(fso.getParent(), newName); File src = new File(fso.getFullPath()); - // Create arguments + // Create arguments LinkedResource linkRes = new LinkedResource(src, dst); List<LinkedResource> files = new ArrayList<ActionsPolicy.LinkedResource>(1); files.add(linkRes); @@ -793,7 +891,7 @@ public final class ActionsPolicy { // Internal copy copyOrMoveFileSystemObjects( ctx, - true, + COPY_MOVE_OPERATION.RENAME, files, onSelectionListener, onRequestRefreshListener); @@ -827,7 +925,7 @@ public final class ActionsPolicy { // Internal copy copyOrMoveFileSystemObjects( ctx, - false, + COPY_MOVE_OPERATION.CREATE_COPY, files, onSelectionListener, onRequestRefreshListener); @@ -849,7 +947,7 @@ public final class ActionsPolicy { // Internal copy copyOrMoveFileSystemObjects( ctx, - false, + COPY_MOVE_OPERATION.COPY, files, onSelectionListener, onRequestRefreshListener); @@ -871,7 +969,7 @@ public final class ActionsPolicy { // Internal move copyOrMoveFileSystemObjects( ctx, - true, + COPY_MOVE_OPERATION.MOVE, files, onSelectionListener, onRequestRefreshListener); @@ -881,14 +979,14 @@ public final class ActionsPolicy { * Method that copy an existing file system object. * * @param ctx The current context - * @param move Indicates if the files are going to be moved (true) or copied (false) + * @param operation Indicates the operation to do * @param files The list of source/destination files to copy * @param onSelectionListener The listener for obtain selection information (required) * @param onRequestRefreshListener The listener for request a refresh (optional) */ private static void copyOrMoveFileSystemObjects( final Context ctx, - final boolean move, + final COPY_MOVE_OPERATION operation, final List<LinkedResource> files, final OnSelectionListener onSelectionListener, final OnRequestRefreshListener onRequestRefreshListener) { @@ -921,7 +1019,7 @@ public final class ActionsPolicy { } } // 3.- Check the operation consistency - if (move) { + if (operation.compareTo(COPY_MOVE_OPERATION.MOVE) == 0) { if (!checkMoveConsistency(ctx, files, currentDirectory)) { return; } @@ -932,7 +1030,7 @@ public final class ActionsPolicy { // The current items private int mCurrent = 0; final Context mCtx = ctx; - final boolean mMove = move; + final COPY_MOVE_OPERATION mOperation = operation; final List<LinkedResource> mFiles = files; final OnRequestRefreshListener mOnRequestRefreshListener = onRequestRefreshListener; @@ -941,7 +1039,8 @@ public final class ActionsPolicy { @Override public int getDialogTitle() { - return this.mMove ? + return this.mOperation.compareTo(COPY_MOVE_OPERATION.MOVE) == 0 || + this.mOperation.compareTo(COPY_MOVE_OPERATION.RENAME) == 0 ? R.string.waiting_dialog_moving_title : R.string.waiting_dialog_copying_title; } @@ -959,7 +1058,8 @@ public final class ActionsPolicy { String progress = this.mCtx.getResources(). getString( - this.mMove ? + this.mOperation.compareTo(COPY_MOVE_OPERATION.MOVE) == 0 || + this.mOperation.compareTo(COPY_MOVE_OPERATION.RENAME) == 0 ? R.string.waiting_dialog_moving_msg : R.string.waiting_dialog_copying_msg, src.getAbsolutePath(), @@ -989,7 +1089,7 @@ public final class ActionsPolicy { File src = this.mFiles.get(i).mSrc; File dst = this.mFiles.get(i).mDst; - doOperation(this.mCtx, src, dst, this.mMove); + doOperation(this.mCtx, src, dst, this.mOperation); // Next file this.mCurrent++; @@ -1005,17 +1105,19 @@ public final class ActionsPolicy { * @param ctx The current context * @param src The source file * @param dst The destination file - * @param move Indicates if the files are going to be moved (true) or copied (false) + * @param operation Indicates the operation to do */ @SuppressWarnings("hiding") private void doOperation( - Context ctx, File src, File dst, boolean move) throws Throwable { + Context ctx, File src, File dst, COPY_MOVE_OPERATION operation) + throws Throwable { // If the source is the same as destiny then don't do the operation if (src.compareTo(dst) == 0) return; try { // Copy or move? - if (move) { + if (operation.compareTo(COPY_MOVE_OPERATION.MOVE) == 0 || + operation.compareTo(COPY_MOVE_OPERATION.RENAME) == 0) { CommandHelper.move( ctx, src.getAbsolutePath(), @@ -1163,7 +1265,7 @@ public final class ActionsPolicy { String dst = linkRes.mDst.getAbsolutePath(); // 1.- Current directory can't be moved - if (currentDirectory.startsWith(src)) { + if (currentDirectory != null && currentDirectory.startsWith(src)) { // Operation not allowed AlertDialog dialog = DialogHelper.createErrorDialog( |
