Commit 53262352 authored by 皮皮蟹's avatar 皮皮蟹 Committed by Susan Rati Lane

Only show preview context menu on supported file type. (#1908)

parent a194f49a
......@@ -157,6 +157,15 @@ public abstract class ChainableCommand {
*/
protected abstract void execute(ProjectNode node);
/**
* Check if the command can be used for the project node.
* @param node the project node to which the command is applied
* @return
*/
protected boolean isSupported(ProjectNode node) {
return true;
}
/**
* Executes the next command in the chain.
*
......
......@@ -36,6 +36,12 @@ public class PreviewFileCommand extends ChainableCommand {
return false;
}
@Override
public boolean isSupported(final ProjectNode node) {
return StorageUtil.isImageFile(node.getFileId()) || StorageUtil.isAudioFile(node.getFileId())
|| StorageUtil.isVideoFile(node.getFileId());
}
@Override
public void execute(final ProjectNode node) {
final DialogBox dialogBox = new DialogBox();
......@@ -95,7 +101,7 @@ public class PreviewFileCommand extends ChainableCommand {
String fileType = StorageUtil.getContentTypeForFilePath(fileSuffix);
// Support preview for file types that all major browser support
if (fileType.endsWith("png") || fileType.endsWith("jpeg") || fileType.endsWith("gif")
|| fileType.endsWith("bmp")) {
|| fileType.endsWith("bmp") || fileType.endsWith("svg+xml")) {
Image img = new Image(fileUrl);
img.getElement().getStyle().setProperty("maxWidth","600px");
return img;
......@@ -108,7 +114,7 @@ public class PreviewFileCommand extends ChainableCommand {
}
} else if (StorageUtil.isVideoFile(fileSuffix)) { // Video Preview
String fileType = StorageUtil.getContentTypeForFilePath(fileSuffix);
if (fileType.endsWith("mp4") || fileType.endsWith("webm")) {
if (fileType.endsWith("avi") || fileType.endsWith("mp4") || fileType.endsWith("webm")) {
return new HTML("<video width='320' height='240' controls> <source src='" + fileUrl
+ "' type='" + fileType + "'>" + MESSAGES.filePlaybackError() + "</video>");
}
......
......@@ -53,4 +53,8 @@ public final class ProjectNodeCommand {
public void execute(ProjectNode node) {
command.startExecuteChain(actionName, node);
}
public boolean isSupported(ProjectNode node) {
return command.isSupported(node);
}
}
......@@ -45,7 +45,7 @@ public final class ProjectNodeContextMenu {
Window.getScrollTop() + clientY);
for (final CommandRegistry.Entry entry : entries) {
final ProjectNodeCommand cmd = entry.getCommand();
if (cmd.isSupported(node)) {
// Create the menu item.
menu.addItem(cmd.getLabel(), new Command() {
@Override
......@@ -55,6 +55,7 @@ public final class ProjectNodeContextMenu {
}
});
}
}
menu.show();
}
......
......@@ -124,6 +124,9 @@ public class StorageUtil {
if (filePath.endsWith(".webp")) {
return "image/webp";
}
if (filePath.endsWith(".svg")) {
return "image/svg+xml";
}
// Audio File Types
if (filePath.endsWith(".mp3")) {
......@@ -161,6 +164,9 @@ public class StorageUtil {
}
// Video File Types
if (filePath.endsWith(".avi")) {
return "video/avi";
}
if (filePath.endsWith(".mp4")) {
return "video/mp4";
}
......@@ -176,9 +182,6 @@ public class StorageUtil {
if (filePath.endsWith(".mkv")) {
return "video/mkv";
}
if (filePath.endsWith(".svg")) {
return "image/svg+xml";
}
// Other File Types
if (filePath.endsWith(".apk")) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment