Loading src/com/cyanogenmod/explorer/listeners/OnSelectionListener.java +8 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,14 @@ public interface OnSelectionListener { */ 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. * Loading src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java +73 −5 Original line number Diff line number Diff line Loading @@ -48,7 +48,10 @@ import com.cyanogenmod.explorer.util.SelectionHelper; */ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListener { private final Context mContext; /** * @hide */ final Context mContext; private final boolean mGlobal; /** Loading @@ -56,9 +59,15 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen */ AlertDialog mDialog; private ListView mListView; private final FileSystemObject mFso; /** * @hide */ final FileSystemObject mFso; private OnRequestRefreshListener mOnRequestRefreshListener; /** * @hide */ OnRequestRefreshListener mOnRequestRefreshListener; private OnSelectionListener mOnSelectionListener; Loading Loading @@ -158,13 +167,22 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen } 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 Loading Loading @@ -236,7 +254,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen final InputNameDialog inputNameDialog = new InputNameDialog( this.mContext, this.mOnSelectionListener.onRequestSelectedFiles(), this.mOnSelectionListener.onRequestCurrentItems(), menuItem.getTitle().toString()); inputNameDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override Loading @@ -261,6 +279,56 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen inputNameDialog.show(); } /** * 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} */ Loading src/com/cyanogenmod/explorer/ui/dialogs/InputNameDialog.java +44 −4 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.widget.TextView; 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; Loading @@ -41,13 +42,17 @@ public class InputNameDialog 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; Loading @@ -65,6 +70,20 @@ public class InputNameDialog */ 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 Loading @@ -72,6 +91,7 @@ public class InputNameDialog //Save the files this.mFiles = files; this.mFso = fso; this.mCancelled = true; //Create the Loading @@ -81,7 +101,11 @@ public class InputNameDialog 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); 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); Loading Loading @@ -115,6 +139,17 @@ public class InputNameDialog (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); } }); } } /** Loading Loading @@ -184,19 +219,24 @@ public class InputNameDialog 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( Loading src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java +36 −0 Original line number Diff line number Diff line Loading @@ -451,4 +451,40 @@ public final class ActionsPolicy { }); 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 src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java +8 −0 Original line number Diff line number Diff line Loading @@ -912,6 +912,14 @@ public class NavigationView extends RelativeLayout implements return this.getSelectedFiles(); } /** * {@inheritDoc} */ @Override public List<FileSystemObject> onRequestCurrentItems() { return this.getFiles(); } /** * {@inheritDoc} */ Loading Loading
src/com/cyanogenmod/explorer/listeners/OnSelectionListener.java +8 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,14 @@ public interface OnSelectionListener { */ 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. * Loading
src/com/cyanogenmod/explorer/ui/dialogs/ActionsDialog.java +73 −5 Original line number Diff line number Diff line Loading @@ -48,7 +48,10 @@ import com.cyanogenmod.explorer.util.SelectionHelper; */ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListener { private final Context mContext; /** * @hide */ final Context mContext; private final boolean mGlobal; /** Loading @@ -56,9 +59,15 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen */ AlertDialog mDialog; private ListView mListView; private final FileSystemObject mFso; /** * @hide */ final FileSystemObject mFso; private OnRequestRefreshListener mOnRequestRefreshListener; /** * @hide */ OnRequestRefreshListener mOnRequestRefreshListener; private OnSelectionListener mOnSelectionListener; Loading Loading @@ -158,13 +167,22 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen } 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 Loading Loading @@ -236,7 +254,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen final InputNameDialog inputNameDialog = new InputNameDialog( this.mContext, this.mOnSelectionListener.onRequestSelectedFiles(), this.mOnSelectionListener.onRequestCurrentItems(), menuItem.getTitle().toString()); inputNameDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override Loading @@ -261,6 +279,56 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen inputNameDialog.show(); } /** * 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} */ Loading
src/com/cyanogenmod/explorer/ui/dialogs/InputNameDialog.java +44 −4 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.widget.TextView; 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; Loading @@ -41,13 +42,17 @@ public class InputNameDialog 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; Loading @@ -65,6 +70,20 @@ public class InputNameDialog */ 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 Loading @@ -72,6 +91,7 @@ public class InputNameDialog //Save the files this.mFiles = files; this.mFso = fso; this.mCancelled = true; //Create the Loading @@ -81,7 +101,11 @@ public class InputNameDialog 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); 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); Loading Loading @@ -115,6 +139,17 @@ public class InputNameDialog (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); } }); } } /** Loading Loading @@ -184,19 +219,24 @@ public class InputNameDialog 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( Loading
src/com/cyanogenmod/explorer/ui/policy/ActionsPolicy.java +36 −0 Original line number Diff line number Diff line Loading @@ -451,4 +451,40 @@ public final class ActionsPolicy { }); 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
src/com/cyanogenmod/explorer/ui/widgets/NavigationView.java +8 −0 Original line number Diff line number Diff line Loading @@ -912,6 +912,14 @@ public class NavigationView extends RelativeLayout implements return this.getSelectedFiles(); } /** * {@inheritDoc} */ @Override public List<FileSystemObject> onRequestCurrentItems() { return this.getFiles(); } /** * {@inheritDoc} */ Loading