Merge with 612ee1db5780de03ba2db24aae9513e7f28fea8a
authorDimitris Routsis <droutsis@ebs.gr>
Mon, 15 Jun 2009 09:45:25 +0000 (12:45 +0300)
committerDimitris Routsis <droutsis@ebs.gr>
Mon, 15 Jun 2009 09:45:25 +0000 (12:45 +0300)
1  2 
src/gr/ebs/gss/client/FileContextMenu.java
src/gr/ebs/gss/client/FileMenu.java

@@@ -40,7 -40,6 +40,7 @@@ import com.google.gwt.user.client.ui.Cl
  import com.google.gwt.user.client.ui.MenuBar;
  import com.google.gwt.user.client.ui.MenuItem;
  import com.google.gwt.user.client.ui.PopupPanel;
 +import com.google.gwt.user.client.ui.TreeItem;
  import com.google.gwt.user.client.ui.Widget;
  
  /**
@@@ -71,8 -70,6 +71,8 @@@ public class FileContextMenu extends Po
  
        private MenuItem downloadItem;
  
 +      private MenuItem saveAsItem;
 +
        /**
         * The image bundle for this widget's images that reuses images defined in
         * other menus.
                // The popup's constructor's argument is a boolean specifying that it
                // auto-close itself when the user clicks outside of it.
                super(true);
 +              GSS gss = GSS.get();
                setAnimationEnabled(true);
                images = newImages;
  
                MenuBar contextMenu = new MenuBar(true);
                if (isEmpty) {
                        contextMenu.addItem(pasteItem);
-                       if (gss.getFolders().getCurrent() != null)
-                               if (gss.getFolders().isFileItem(gss.getFolders().getCurrent()))
-                                       contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));
-                               else if (gss.getFolders().isMySharedItem(gss.getFolders().getCurrent()) || GSS  .get()
+                       if (GSS.get().getFolders().getCurrent() != null)
+                               if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent()))
+                                       contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
+                               else if (GSS.get().getFolders().isMySharedItem(GSS.get().getFolders().getCurrent()) || GSS      .get()
                                                                                                                                                                                                                        .getFolders()
                                                                                                                                                                                                                        .isOthersSharedItem(GSS .get()
                                                                                                                                                                                                                                                                        .getFolders()
                                                                                                                                                                                                                                                                        .getCurrent()))
-                                       if(gss.getFolders().getCurrent().getUserObject() instanceof FolderResource)
-                                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));
+                                       if(GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource)
+                                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
                        contextMenu.addItem("<span>" + images.refresh().getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
                } else if (isTrash) {
                        contextMenu.addItem("<span>" + newImages.versions().getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
                        cutItem = new MenuItem("<span>" + newImages.cut().getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
                        copyItem = new MenuItem("<span>" + newImages.copy().getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
  
-                       updateItem = new MenuItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));
+                       updateItem = new MenuItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
  
                        trashItem = new MenuItem("<span>" + newImages.emptyTrash().getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
                        deleteItem = new MenuItem("<span>" + newImages.delete().getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
                        sharingItem = new MenuItem("<span>" + newImages.sharing().getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
                        propItem = new MenuItem("<span>" + newImages.viewText().getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
  
 -                      contextMenu.addItem(updateItem);
 +                      TreeItem currentFolder = gss.getFolders().getCurrent();
 +                      if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
 +                              contextMenu.addItem(updateItem);
                        String[] link = {"", ""};
 -                      GSS.get().getTopPanel().getFileMenu().createDownloadLink(link);
 +                      gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
                        downloadItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
                        contextMenu.addItem(downloadItem);
 +                      gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
 +                      saveAsItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Save file as" + link[1] + "</span>", true, downloadCmd);
 +                      contextMenu.addItem(saveAsItem);
                        contextMenu.addItem(cutItem);
                        contextMenu.addItem(copyItem);
 -                      contextMenu.addItem(pasteItem);
 +                      if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
 +                              contextMenu.addItem(pasteItem);
                        contextMenu.addItem("<span>" + images.unselectAll().getHTML() + "&nbsp;Unselect</span>", true, unselectAllCommand);
                        contextMenu.addItem(trashItem);
                        contextMenu.addItem(deleteItem);
                        contextMenu.addItem(propItem);
                }
                add(contextMenu);
 -              if (GSS.get().getClipboard().hasFileItem())
 +              if (gss.getClipboard().hasFileItem())
                        pasteItem.setVisible(true);
                else
                        pasteItem.setVisible(false);
@@@ -25,7 -25,6 +25,7 @@@ import gr.ebs.gss.client.commands.Refre
  import gr.ebs.gss.client.commands.UploadFileCommand;\r
  import gr.ebs.gss.client.rest.RestCommand;\r
  import gr.ebs.gss.client.rest.resource.FileResource;\r
 +import gr.ebs.gss.client.rest.resource.FolderResource;\r
  import gr.ebs.gss.client.rest.resource.GroupUserResource;\r
  \r
  import com.google.gwt.http.client.URL;\r
@@@ -118,10 -117,8 +118,10 @@@ public class FileMenu extends PopupPane
         * @param link a String array with two elements that is modified so that the\r
         *            first position contains the opening tag and the second one the\r
         *            closing tag\r
 +       * @param forceDownload If true, link will be such that browser should ask for filename\r
 +       *                              and save location\r
         */\r
 -      void createDownloadLink(String[] link) {\r
 +      void createDownloadLink(String[] link, boolean forceDownload) {\r
                GSS app = GSS.get();\r
                Object selection = app.getCurrentSelection();\r
                if (selection != null && selection instanceof FileResource) {\r
                        String dateString = RestCommand.getDate();\r
                        String resource = file.getUri().substring(app.getApiPath().length()-1,file.getUri().length());\r
                        String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken()));\r
 -                      link[0] = "<a class='hidden-link' href='" + file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString) + "' target='_blank'>";\r
 +                      link[0] = "<a class='hidden-link' href='" + file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString)\r
 +                                      + (forceDownload ? "&dl=1" : "") + "' target='_blank'>";\r
                        link[1] = "</a>";\r
                }\r
        }\r
                Folders folders = GSS.get().getFolders();\r
                TreeItem selectedItem = folders.getCurrent();\r
                boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource;\r
 +              boolean uploadVisible = GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource;\r
                boolean propertiesNotVisible = selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource);\r
                contextMenu.addItem("<span>" + images.folderNew().getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));\r
-               if (uploadVisible) contextMenu.addItem("<span>" + images.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));\r
+               contextMenu.addItem("<span>" + images.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));\r
                if (downloadVisible) {\r
                        String[] link = {"", ""};\r
 -                      createDownloadLink(link);\r
 +                      createDownloadLink(link, false);\r
                        contextMenu.addItem("<span>" + link[0] + images.download().getHTML() + "&nbsp;Download" + link[1] + "</span>", true, downloadCmd);\r
 +                      createDownloadLink(link, true);\r
 +                      contextMenu.addItem("<span>" + link[0] + images.download().getHTML() + "&nbsp;Save file as" + link[1] + "</span>", true, downloadCmd);\r
                }\r
                contextMenu.addItem("<span>" + images.emptyTrash().getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));\r
                contextMenu.addItem("<span>" + images.refresh().getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));\r