<!-- Global Actions -->
<group android:id="@+id/mnu_actions_global">
<item
+ android:id="@+id/mnu_actions_properties_current_folder"
+ android:showAsAction="always"
+ android:title="@string/actions_menu_properties_current_folder"/>
+ <item
+ android:id="@+id/mnu_actions_refresh"
+ android:showAsAction="always"
+ android:title="@string/actions_menu_refresh"/>
+ <item
android:id="@+id/mnu_actions_new_directory"
android:showAsAction="always"
android:title="@string/actions_menu_new_directory"/>
<!-- Actions Dialog * Title -->
<string name="actions_dialog_title">Actions</string>
+ <!-- Actions Dialog * Menu * Properties of current folder -->
+ <string name="actions_menu_properties_current_folder">Properties</string>
+ <!-- Actions Dialog * Menu * Refresh -->
+ <string name="actions_menu_refresh">Refresh</string>
<!-- Actions Dialog * Menu * New directory -->
<string name="actions_menu_new_directory">New folder</string>
<!-- Actions Dialog * Menu * New file -->
//Action Bar buttons
//######################
case R.id.ab_actions:
- openActions();
+ openActionsDialog(getCurrentNavigationView().getCurrentDir(), true);
break;
case R.id.ab_bookmarks:
@Override
public void onRequestRefresh(Object o) {
if (o instanceof FileSystemObject) {
+ // Refresh only the item
this.getCurrentNavigationView().refresh((FileSystemObject)o);
+ } else if (o == null) {
+ // Refresh all
+ getCurrentNavigationView().refresh();
}
}
*/
@Override
public void onRequestMenu(NavigationView navView, FileSystemObject item) {
- // Prior to show the dialog, refresh the item reference
- FileSystemObject fso = null;
- try {
- fso = CommandHelper.getFileInfo(this, item.getFullPath(), null);
-
- } catch (Exception e) {
- // Notify the user
- ExceptionUtil.translateException(this, e);
-
- // Remove the object
- if (e instanceof FileNotFoundException || e instanceof NoSuchFileOrDirectory) {
- getCurrentNavigationView().removeItem(item);
- }
- return;
- }
-
- // Show the dialog
- ActionsDialog dialog = new ActionsDialog(this, fso);
- dialog.setOnRequestRefreshListener(this);
- dialog.setOnSelectionListener(getCurrentNavigationView());
- dialog.show();
+ // Show the actions dialog
+ openActionsDialog(item, false);
}
/**
/**
* Method that opens the actions dialog
+ *
+ * @param item The path or the {@link FileSystemObject}
+ * @param global If the menu to display is the one with global actions
*/
- private void openActions() {
- ActionsDialog dialog = new ActionsDialog(this);
+ private void openActionsDialog(Object item, boolean global) {
+ // Resolve the full path
+ String path = String.valueOf(item);
+ if (item instanceof FileSystemObject) {
+ path = ((FileSystemObject)item).getFullPath();
+ }
+
+ // Prior to show the dialog, refresh the item reference
+ FileSystemObject fso = null;
+ try {
+ fso = CommandHelper.getFileInfo(this, path, null);
+
+ } catch (Exception e) {
+ // Notify the user
+ ExceptionUtil.translateException(this, e);
+
+ // Remove the object
+ if (e instanceof FileNotFoundException || e instanceof NoSuchFileOrDirectory) {
+ // If have a FileSystemObject reference then there is no need to search
+ // the path (less resources used)
+ if (item instanceof FileSystemObject) {
+ getCurrentNavigationView().removeItem((FileSystemObject)item);
+ } else {
+ getCurrentNavigationView().removeItem((String)item);
+ }
+ }
+ return;
+ }
+
+ // Show the dialog
+ ActionsDialog dialog = new ActionsDialog(this, fso, global);
dialog.setOnRequestRefreshListener(this);
dialog.setOnSelectionListener(getCurrentNavigationView());
dialog.show();
return;
}
- ActionsDialog dialog = new ActionsDialog(this, fso);
+ ActionsDialog dialog = new ActionsDialog(this, fso, false);
dialog.setOnRequestRefreshListener(this);
dialog.show();
}
*/
@Override
public void onRequestRefresh(Object o) {
- if (o instanceof FileSystemObject) {
- SearchResultAdapter adapter =
- (SearchResultAdapter)this.mSearchListView.getAdapter();
- if (adapter != null) {
+ // Refresh only the item
+ SearchResultAdapter adapter =
+ (SearchResultAdapter)this.mSearchListView.getAdapter();
+ if (adapter != null) {
+ if (o instanceof FileSystemObject) {
+
FileSystemObject fso = (FileSystemObject)o;
int pos = adapter.getPosition(fso);
if (pos >= 0) {
SearchResult sr = adapter.getItem(pos);
sr.setFso(fso);
}
+ } else if (o == null) {
+ // Refresh all
+ List<SearchResult> results = adapter.getData();
+ this.mResultList = new ArrayList<FileSystemObject>(results.size());
+ for (int i=0; i<results.size(); i++) {
+ this.mResultList.add(results.get(i).getFso());
+ }
+ drawResults();
}
}
}
}
/**
+ * Method that returns the {@link FileSystemObject} reference from his path.
+ *
+ * @param path The path of the file system object
+ * @return FileSystemObject The file system object reference
+ */
+ public FileSystemObject getItem(String path) {
+ for (int i = 0; i < getCount(); i++) {
+ //File system object info
+ FileSystemObject fso = getItem(i);
+ if (fso.getFullPath().compareTo(path) == 0) {
+ return fso;
+ }
+ }
+ return null;
+ }
+
+ /**
* Method that process the data before use {@link #getView} method.
*/
private void processData() {
return data;
}
-
-
/**
* Returns the position of the specified item in the array.
*
public class ActionsDialog implements OnItemClickListener, OnItemLongClickListener {
private final Context mContext;
+ private final boolean mGlobal;
private AlertDialog mDialog;
private ListView mListView;
* Constructor of <code>ActionsDialog</code>.
*
* @param context The current context
- */
- public ActionsDialog(Context context) {
- super();
-
- // Initialize data
- this.mFso = null;
- this.mContext = context;
-
- //Initialize dialog
- init(context, R.id.mnu_actions_global);
- }
-
- /**
- * Constructor of <code>ActionsDialog</code>.
- *
- * @param context The current context
* @param fso The file system object associated
+ * @param global If the menu to display will be the global one (Global actions)
*/
- public ActionsDialog(Context context, FileSystemObject fso) {
+ public ActionsDialog(Context context, FileSystemObject fso, boolean global) {
super();
//Save the data
this.mFso = fso;
this.mContext = context;
+ this.mGlobal = global;
//Initialize dialog
- init(context, R.id.mnu_actions_fso);
+ init(context, global ? R.id.mnu_actions_global : R.id.mnu_actions_fso);
}
/**
this.mContext, this.mFso, this.mOnRequestRefreshListener);
return;
+ //- Delete
+ case R.id.mnu_actions_refresh:
+ this.mDialog.dismiss();
+ if (this.mOnRequestRefreshListener != null) {
+ this.mOnRequestRefreshListener.onRequestRefresh(null); //Refresh all
+ }
+ return;
+
//- Select/Deselect
case R.id.mnu_actions_select:
case R.id.mnu_actions_deselect:
//- Properties
case R.id.mnu_actions_properties:
+ case R.id.mnu_actions_properties_current_folder:
ActionsPolicy.showPropertiesDialog(
this.mContext, this.mFso, this.mOnRequestRefreshListener);
break;
*/
private void configureMenu(Menu menu) {
// Check actions that needs a valid reference
- if (this.mFso != null) {
+ if (!this.mGlobal && this.mFso != null) {
//- Select/Deselect -> Only one of them
if (this.mOnSelectionListener != null) {
boolean selected =
}
/**
+ * Method that removes a file system object from his path from the view
+ *
+ * @param path The file system object path
+ */
+ public void removeItem(String path) {
+ FileSystemObject fso = this.mAdapter.getItem(path);
+ if (fso != null) {
+ this.mAdapter.remove(fso);
+ this.mAdapter.notifyDataSetChanged();
+ }
+ }
+
+ /**
* Method that returns the current directory.
*
* @return String The current directory