Unverified Commit 2cb788cc authored by Chetan Patil's avatar Chetan Patil Committed by GitHub

Move to Trash menu item changes to Delete from Trash (#2116)

parent f2970881
......@@ -423,6 +423,7 @@ public class Ode implements EntryPoint {
*/
public void switchToTrash() {
Ode.getInstance().getTopToolbar().updateMoveToTrash("Delete From Trash");
hideChaff();
hideTutorials();
ProjectListBox.getProjectListBox().loadTrashList();
......
......@@ -129,6 +129,7 @@ public class TopPanel extends Composite {
myProjects.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Ode.getInstance().getTopToolbar().updateMoveToTrash("Move To Trash");
ode.switchToProjectsView();
}
});
......
......@@ -67,6 +67,7 @@ import static com.google.appinventor.client.Ode.MESSAGES;
public class TopToolbar extends Composite {
private static final String WIDGET_NAME_NEW = "New";
private static final String WIDGET_NAME_DELETE = "Delete";
private static final String WIDGET_NAME_DELETE_TRASH = "Delete Trash";
private static final String WIDGET_NAME_DOWNLOAD_KEYSTORE = "DownloadKeystore";
private static final String WIDGET_NAME_UPLOAD_KEYSTORE = "UploadKeystore";
private static final String WIDGET_NAME_DELETE_KEYSTORE = "DeleteKeystore";
......@@ -183,11 +184,23 @@ public class TopToolbar extends Composite {
initWidget(toolbar);
}
public void updateMoveToTrash(String menu_item){
if(menu_item.equals("Move To Trash")){
fileDropDown.setItemVisible(MESSAGES.trashProjectMenuItem(), true);
fileDropDown.setItemVisible(MESSAGES.deleteFromTrashButton(), false);
}
else{
fileDropDown.setItemVisible(MESSAGES.trashProjectMenuItem(), false);
fileDropDown.setItemVisible(MESSAGES.deleteFromTrashButton(), true);
}
}
public void updateMenuState(int numSelectedProjects, int numProjects) {
boolean allowDelete = !isReadOnly && numSelectedProjects > 0;
boolean allowExport = numSelectedProjects > 0;
boolean allowExportAll = numProjects > 0;
fileDropDown.setItemEnabled(MESSAGES.trashProjectMenuItem(), allowDelete);
fileDropDown.setItemEnabled(MESSAGES.deleteFromTrashButton(), allowDelete);
String exportProjectLabel = numSelectedProjects > 1 ?
MESSAGES.exportSelectedProjectsMenuItem(numSelectedProjects) : MESSAGES.exportProjectMenuItem();
fileDropDown.setItemHtmlById(WIDGET_NAME_EXPORTPROJECT, exportProjectLabel);
......@@ -206,6 +219,7 @@ public class TopToolbar extends Composite {
for (DropDownItem i : items) {
menu.addItem(i);
}
fileDropDown.setItemVisible(MESSAGES.deleteFromTrashButton(), false);
}
private void createProjectsMenu() {
......@@ -222,6 +236,8 @@ public class TopToolbar extends Composite {
new ImportTemplateAction()));
fileItems.add(new DropDownItem(WIDGET_NAME_DELETE, MESSAGES.deleteProjectButton(),
new DeleteAction()));
fileItems.add(new DropDownItem(WIDGET_NAME_DELETE_TRASH, MESSAGES.deleteFromTrashButton(),
new DeleteForeverProjectAction()));
fileItems.add(null);
fileItems.add(new DropDownItem(WIDGET_NAME_SAVE, MESSAGES.saveMenuItem(),
new SaveAction()));
......@@ -448,6 +464,7 @@ public class TopToolbar extends Composite {
private static class SwitchToProjectAction implements Command {
@Override
public void execute() {
Ode.getInstance().getTopToolbar().updateMoveToTrash("Move To Trash");
Ode.getInstance().switchToProjectsView();
Ode.getInstance().getTopToolbar().updateFileMenuButtons(0);
}
......@@ -1078,6 +1095,7 @@ public class TopToolbar extends Composite {
}
if (view == 0) { // We are in the Projects view
fileDropDown.setItemEnabled(MESSAGES.deleteProjectButton(), false);
fileDropDown.setItemEnabled(MESSAGES.deleteFromTrashButton(), false);
fileDropDown.setItemEnabled(MESSAGES.trashProjectMenuItem(),
ProjectListBox.getProjectListBox().getProjectList().getMyProjectsCount() == 0);
fileDropDown.setItemEnabled(MESSAGES.exportAllProjectsMenuItem(),
......@@ -1090,7 +1108,7 @@ public class TopToolbar extends Composite {
buildDropDown.setItemEnabled(MESSAGES.downloadToComputerMenuItem(), false);
} else { // We have to be in the Designer/Blocks view
fileDropDown.setItemEnabled(MESSAGES.deleteProjectButton(), true);
fileDropDown.setItemEnabled(MESSAGES.trashProjectMenuItem(), false);
fileDropDown.setItemEnabled(MESSAGES.trashProjectMenuItem(), true);
fileDropDown.setItemEnabled(MESSAGES.exportAllProjectsMenuItem(),
ProjectListBox.getProjectListBox().getProjectList().getMyProjectsCount() > 0);
fileDropDown.setItemEnabledById(WIDGET_NAME_EXPORTPROJECT, true);
......@@ -1188,6 +1206,48 @@ public class TopToolbar extends Composite {
}
}
public static class DeleteForeverProjectAction implements Command {
@Override
public void execute() {
Ode.getInstance().getEditorManager().saveDirtyEditors(new Command() {
@Override
public void execute() {
List<Project> deletedProjects = ProjectListBox.getProjectListBox().getProjectList().getSelectedProjects();
if (deletedProjects.size() > 0) {
// Show one confirmation window for selected projects.
if (deleteConfirmation(deletedProjects)) {
for (Project project : deletedProjects) {
project.deleteFromTrash();
}
}
Ode.getInstance().switchToTrash();
} else {
// The user can select a project to resolve the
// error.
ErrorReporter.reportInfo(MESSAGES.noProjectSelectedForDelete());
}
}
});
}
private boolean deleteConfirmation(List<Project> projects) {
String message;
if (projects.size() == 1) {
message = MESSAGES.confirmDeleteSingleProject(projects.get(0).getProjectName());
} else {
StringBuilder sb = new StringBuilder();
String separator = "";
for (Project project : projects) {
sb.append(separator).append(project.getProjectName());
separator = ", ";
}
String projectNames = sb.toString();
message = MESSAGES.confirmDeleteManyProjects(projectNames);
}
return Window.confirm(message);
}
}
private static native boolean isChromeBook() /*-{
if (/\bCrOS\b/.test(navigator.userAgent)) {
return true;
......
......@@ -9,6 +9,7 @@ package com.google.appinventor.client.explorer.youngandroid;
import com.google.appinventor.client.ErrorReporter;
import com.google.appinventor.client.Ode;
import com.google.appinventor.client.OdeAsyncCallback;
import com.google.appinventor.client.TopToolbar;
import com.google.appinventor.client.boxes.ProjectListBox;
import com.google.appinventor.client.explorer.project.Project;
import com.google.appinventor.client.widgets.Toolbar;
......@@ -61,7 +62,7 @@ public class ProjectToolbar extends Toolbar {
addButton(new ToolbarItem(WIDGET_NAME_RESTORE,MESSAGES.restoreProjectButton(),
new RestoreProjectAction()));
addButton(new ToolbarItem(WIDGET_NAME_DELETE_FROM_TRASH,MESSAGES.deleteFromTrashButton(),
new DeleteForeverProjectAction()));
new TopToolbar.DeleteForeverProjectAction()));
if (galleryEnabled) {
addButton(new ToolbarItem(WIDGET_NAME_LOGINTOGALLERY, MESSAGES.loginToGallery(),
new LoginToGalleryAction()));
......@@ -175,6 +176,7 @@ public class ProjectToolbar extends Toolbar {
Ode.getInstance().getEditorManager().saveDirtyEditors(new Command() {
@Override
public void execute() {
Ode.getInstance().getTopToolbar().updateMoveToTrash("Move To Trash");
Ode.getInstance().switchToProjectsView();
}
});
......@@ -253,47 +255,21 @@ public class ProjectToolbar extends Toolbar {
}
}
//Deleting the projects forever from trash list
private static class DeleteForeverProjectAction implements Command {
@Override
public void execute() {
Ode.getInstance().getEditorManager().saveDirtyEditors(new Command() {
@Override
public void execute() {
List<Project> deletedProjects = ProjectListBox.getProjectListBox().getProjectList().getSelectedProjects();
if (deletedProjects.size() > 0) {
// Show one confirmation window for selected projects.
if (deleteConfirmation(deletedProjects)) {
for (Project project : deletedProjects) {
project.deleteFromTrash();
}
}
Ode.getInstance().switchToTrash();
} else {
// The user can select a project to resolve the
// error.
ErrorReporter.reportInfo(MESSAGES.noProjectSelectedForDelete());
}
}
});
}
private boolean deleteConfirmation(List<Project> projects) {
String message;
if (projects.size() == 1) {
message = MESSAGES.confirmDeleteSingleProject(projects.get(0).getProjectName());
} else {
StringBuilder sb = new StringBuilder();
String separator = "";
for (Project project : projects) {
sb.append(separator).append(project.getProjectName());
separator = ", ";
}
String projectNames = sb.toString();
message = MESSAGES.confirmDeleteManyProjects(projectNames);
private boolean deleteConfirmation(List<Project> projects) {
String message;
if (projects.size() == 1) {
message = MESSAGES.confirmDeleteSingleProject(projects.get(0).getProjectName());
} else {
StringBuilder sb = new StringBuilder();
String separator = "";
for (Project project : projects) {
sb.append(separator).append(project.getProjectName());
separator = ", ";
}
return Window.confirm(message);
String projectNames = sb.toString();
message = MESSAGES.confirmDeleteManyProjects(projectNames);
}
return Window.confirm(message);
}
/**
......
......@@ -241,6 +241,20 @@ public class DropDownButton extends TextButton {
}
}
public void setItemVisible(String itemName, boolean enabled) {
for (MenuItem item : items) {
if (item.getText().equals(itemName)) {
if (enabled == true) {
item.setVisible(true);
}
else{
item.setVisible(false);
}
break;
}
}
}
public void replaceLastItem(DropDownItem item) {
menu.removeItem(items.get(items.size()-1));
items.remove(items.size()-1);
......
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