Skip to content

Commit

Permalink
Avoiding pasting in same origin folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciotogneri committed Oct 1, 2016
1 parent a46d0c9 commit 6749401
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void updateButtonBar()
{
Clipboard clipboard = mainActivity.clipboard();

mainActivity.buttonBar().displayButtons(adapter.itemsSelected(), !adapter.allItemsSelected(), !clipboard.isEmpty());
mainActivity.buttonBar().displayButtons(adapter.itemsSelected(), !adapter.allItemsSelected(), !clipboard.isEmpty() && !clipboard.hasParent(folder()));
}

public String folderName()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.mauriciotogneri.fileexplorer.models;

import java.io.File;
import java.util.ArrayList;
import java.util.List;


public class Clipboard
{
private File parent = null;
private Mode mode = Mode.NONE;
private List<FileInfo> items = new ArrayList<>();

Expand All @@ -32,12 +33,22 @@ public boolean isCopy()

public void cut(List<FileInfo> items)
{
if (!items.isEmpty())
{
parent = items.get(0).parent();
}

mode = Mode.CUT;
this.items = items;
}

public void copy(List<FileInfo> items)
{
if (!items.isEmpty())
{
parent = items.get(0).parent();
}

mode = Mode.COPY;
this.items = items;
}
Expand Down Expand Up @@ -66,6 +77,7 @@ public boolean paste(FileInfo target)

items.clear();
mode = Mode.NONE;
parent = null;

return allPasted;
}
Expand All @@ -74,4 +86,9 @@ public boolean isEmpty()
{
return items.isEmpty();
}

public boolean hasParent(File parent)
{
return this.parent.compareTo(parent) == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public boolean delete()
return file.delete();
}

public File parent()
{
return file.getParentFile();
}

public String name()
{
if (cachedName == null)
Expand Down

0 comments on commit 6749401

Please sign in to comment.