-
- pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this));
- contextMenu.addItem(pasteItem);
-
- MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
- contextMenu.addItem(upload);
-
- MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
- contextMenu.addItem(refresh);
-
- if (isTrash) {
- MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
- contextMenu.addItem(restore);
-
- MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
- contextMenu.addItem(delete);
- } else {
- cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
- contextMenu.addItem(cutItem);
-
- copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
- contextMenu.addItem(copyItem);
-
- updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
- contextMenu.addItem(updateItem);
-
- trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
- contextMenu.addItem(trashItem);
-
- deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
- contextMenu.addItem(deleteItem);
-
- sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
- contextMenu.addItem(sharingItem);
-
- propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
- contextMenu.addItem(propItem);
-
-
- String[] link = {"", ""};
- gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
- // The command that does some validation before downloading a file.
- Command downloadCmd = new Command() {
-
- @Override
- public void execute() {
- hide();
- GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
- }
- };
- downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
- contextMenu.addItem(downloadItem);
+ Boolean[] permissions = null;
+ boolean canWrite = true;
+ if (selectedFolder != null) {
+ permissions = selectedFolder.getPermissions().get(app.getUsername());
+ canWrite = selectedFolder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
+ }
+ else {
+ for (File f : selectedFiles) {
+ permissions = f.getPermissions().get(app.getUsername());
+ canWrite &= (f.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]));
+ }
+ }
+ boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
+ if (selectedFolder != null) {
+ if (!selectedFolder.isInTrash()) {
+ if (canWrite && app.getClipboard().hasFiles()) {
+ List<File> files = (List<File>) app.getClipboard().getItem();
+ pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, selectedFolder));
+ contextMenu.addItem(pasteItem);
+ }
+
+ if (canWrite) {
+ MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
+ contextMenu.addItem(upload);
+ }
+ if (isFolderTreeSelected) {
+ cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(app, this, selectedFiles));
+ contextMenu.addItem(cutItem);
+ }
+
+
+ if (isFolderTreeSelected) {
+ trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
+ contextMenu.addItem(trashItem);
+ }
+ }
+ else {
+ MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles));
+ contextMenu.addItem(restore);
+ }
+ }
+ copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(app, this, selectedFiles));
+ contextMenu.addItem(copyItem);
+
+ if (isFolderTreeSelected) {
+ deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
+ contextMenu.addItem(deleteItem);
+ }
+
+ if (selectedFolder != null && !selectedFolder.isInTrash()) {
+ if (isFolderTreeSelected && selectedFiles.size() == 1)
+ contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0)));
+
+ }
+ contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</span>", true, new Command() {