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 { ...@@ -157,6 +157,15 @@ public abstract class ChainableCommand {
*/ */
protected abstract void execute(ProjectNode node); 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. * Executes the next command in the chain.
* *
......
...@@ -36,6 +36,12 @@ public class PreviewFileCommand extends ChainableCommand { ...@@ -36,6 +36,12 @@ public class PreviewFileCommand extends ChainableCommand {
return false; return false;
} }
@Override
public boolean isSupported(final ProjectNode node) {
return StorageUtil.isImageFile(node.getFileId()) || StorageUtil.isAudioFile(node.getFileId())
|| StorageUtil.isVideoFile(node.getFileId());
}
@Override @Override
public void execute(final ProjectNode node) { public void execute(final ProjectNode node) {
final DialogBox dialogBox = new DialogBox(); final DialogBox dialogBox = new DialogBox();
...@@ -95,7 +101,7 @@ public class PreviewFileCommand extends ChainableCommand { ...@@ -95,7 +101,7 @@ public class PreviewFileCommand extends ChainableCommand {
String fileType = StorageUtil.getContentTypeForFilePath(fileSuffix); String fileType = StorageUtil.getContentTypeForFilePath(fileSuffix);
// Support preview for file types that all major browser support // Support preview for file types that all major browser support
if (fileType.endsWith("png") || fileType.endsWith("jpeg") || fileType.endsWith("gif") 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); Image img = new Image(fileUrl);
img.getElement().getStyle().setProperty("maxWidth","600px"); img.getElement().getStyle().setProperty("maxWidth","600px");
return img; return img;
...@@ -108,7 +114,7 @@ public class PreviewFileCommand extends ChainableCommand { ...@@ -108,7 +114,7 @@ public class PreviewFileCommand extends ChainableCommand {
} }
} else if (StorageUtil.isVideoFile(fileSuffix)) { // Video Preview } else if (StorageUtil.isVideoFile(fileSuffix)) { // Video Preview
String fileType = StorageUtil.getContentTypeForFilePath(fileSuffix); 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 return new HTML("<video width='320' height='240' controls> <source src='" + fileUrl
+ "' type='" + fileType + "'>" + MESSAGES.filePlaybackError() + "</video>"); + "' type='" + fileType + "'>" + MESSAGES.filePlaybackError() + "</video>");
} }
......
...@@ -53,4 +53,8 @@ public final class ProjectNodeCommand { ...@@ -53,4 +53,8 @@ public final class ProjectNodeCommand {
public void execute(ProjectNode node) { public void execute(ProjectNode node) {
command.startExecuteChain(actionName, node); command.startExecuteChain(actionName, node);
} }
public boolean isSupported(ProjectNode node) {
return command.isSupported(node);
}
} }
...@@ -45,15 +45,16 @@ public final class ProjectNodeContextMenu { ...@@ -45,15 +45,16 @@ public final class ProjectNodeContextMenu {
Window.getScrollTop() + clientY); Window.getScrollTop() + clientY);
for (final CommandRegistry.Entry entry : entries) { for (final CommandRegistry.Entry entry : entries) {
final ProjectNodeCommand cmd = entry.getCommand(); final ProjectNodeCommand cmd = entry.getCommand();
if (cmd.isSupported(node)) {
// Create the menu item. // Create the menu item.
menu.addItem(cmd.getLabel(), new Command() { menu.addItem(cmd.getLabel(), new Command() {
@Override @Override
public void execute() { public void execute() {
menu.hide(); menu.hide();
cmd.execute(node); cmd.execute(node);
} }
}); });
}
} }
menu.show(); menu.show();
......
...@@ -124,6 +124,9 @@ public class StorageUtil { ...@@ -124,6 +124,9 @@ public class StorageUtil {
if (filePath.endsWith(".webp")) { if (filePath.endsWith(".webp")) {
return "image/webp"; return "image/webp";
} }
if (filePath.endsWith(".svg")) {
return "image/svg+xml";
}
// Audio File Types // Audio File Types
if (filePath.endsWith(".mp3")) { if (filePath.endsWith(".mp3")) {
...@@ -161,6 +164,9 @@ public class StorageUtil { ...@@ -161,6 +164,9 @@ public class StorageUtil {
} }
// Video File Types // Video File Types
if (filePath.endsWith(".avi")) {
return "video/avi";
}
if (filePath.endsWith(".mp4")) { if (filePath.endsWith(".mp4")) {
return "video/mp4"; return "video/mp4";
} }
...@@ -176,9 +182,6 @@ public class StorageUtil { ...@@ -176,9 +182,6 @@ public class StorageUtil {
if (filePath.endsWith(".mkv")) { if (filePath.endsWith(".mkv")) {
return "video/mkv"; return "video/mkv";
} }
if (filePath.endsWith(".svg")) {
return "image/svg+xml";
}
// Other File Types // Other File Types
if (filePath.endsWith(".apk")) { 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