Commit db222616 authored by Evan W. Patton's avatar Evan W. Patton

Add check for open project before prompting user

There is a prompt for the user to create or open a project. However,
this is based on whether currentFileEditor is set, which is a problem
is a project load is in process. This commit adds a check to
EditorManager to see if there is an editor even though
currentFileEditor is null, in which case no prompt is shown.

Change-Id: Icf044a638fef19d7fb5660a4783f852c7ccbb6cb
parent b425deb7
......@@ -475,7 +475,7 @@ public class Ode implements EntryPoint {
getTopToolbar().updateFileMenuButtons(currentView);
if (currentFileEditor != null) {
deckPanel.showWidget(designTabIndex);
} else {
} else if (!editorManager.hasOpenEditor()) { // is there a project editor pending visibility?
OdeLog.wlog("No current file editor to show in designer");
ErrorReporter.reportInfo(MESSAGES.chooseProject());
}
......@@ -583,6 +583,13 @@ public class Ode implements EntryPoint {
openYoungAndroidProjectInDesigner(project);
}
}
@Override
public void onProjectsLoaded() {
// we only get here iff onProjectAdded is never called with the target project id
projectManager.removeProjectManagerEventListener(this);
switchToProjectsView(); // the user will need to select a project...
ErrorReporter.reportInfo(MESSAGES.chooseProject());
}
});
}
}
......@@ -1488,7 +1495,7 @@ public class Ode implements EntryPoint {
*/
private void createWelcomeDialog(boolean force) {
if (!shouldShowWelcomeDialog() && !force) {
openProjectsTab();
maybeShowNoProjectsDialog();
return;
}
// Create the UI elements of the DialogBox
......@@ -1515,7 +1522,7 @@ public class Ode implements EntryPoint {
"" + splashConfig.version);
userSettings.saveSettings(null);
}
openProjectsTab();
maybeShowNoProjectsDialog();
}
});
holder.add(ok);
......@@ -1527,22 +1534,19 @@ public class Ode implements EntryPoint {
}
/**
* Load and open the projects tab.
* Check the number of projects for the user and show the "no projects" dialog if no projects
* are present.
*/
private void openProjectsTab() {
getProjectService().getProjects(new AsyncCallback<long[]>() {
@Override
public void onSuccess(long [] projectIds) {
if (projectIds.length == 0 && !templateLoadingFlag) {
createNoProjectsDialog(true);
}
}
@Override
public void onFailure(Throwable projectIds) {
OdeLog.elog("Could not get project list");
private void maybeShowNoProjectsDialog() {
projectManager.addProjectManagerEventListener(new ProjectManagerEventAdapter() {
@Override
public void onProjectsLoaded() {
if (projectManager.projectCount() == 0 && !templateLoadingFlag) {
ErrorReporter.hide(); // hide the "Please choose a project" message
createNoProjectsDialog(true);
}
});
}
});
}
/*
......@@ -1642,7 +1646,7 @@ public class Ode implements EntryPoint {
if (AppInventorFeatures.showSplashScreen() && !isReadOnly) {
createWelcomeDialog(false);
} else {
openProjectsTab();
maybeShowNoProjectsDialog();
}
}
......
......@@ -197,6 +197,15 @@ public final class EditorManager {
scheduleAutoSaveTimer();
}
/**
* Check whether there is an open project editor.
*
* @return true if at least one project is open (or in the process of opening), otherwise false
*/
public boolean hasOpenEditor() {
return openProjectEditors.size() > 0;
}
/**
* Schedules the auto-save timer.
*/
......
......@@ -29,6 +29,11 @@ public final class ProjectManager {
// List of listeners for any project manager events.
private final List<ProjectManagerEventListener> projectManagerEventListeners;
/**
* Flag indicating whether the project infos have all loaded.
*/
private volatile boolean projectsLoaded = false;
/**
* Creates a new projects manager.
*/
......@@ -175,6 +180,10 @@ public final class ProjectManager {
*/
public void addProjectManagerEventListener(ProjectManagerEventListener listener) {
projectManagerEventListeners.add(listener);
if (projectsLoaded) {
// inform the listener that projects have already been loaded
listener.onProjectsLoaded();
}
}
/**
......@@ -186,6 +195,10 @@ public final class ProjectManager {
projectManagerEventListeners.remove(listener);
}
public int projectCount() {
return projectsMap.size();
}
private List<ProjectManagerEventListener> copyProjectManagerEventListeners() {
return new ArrayList<ProjectManagerEventListener>(projectManagerEventListeners);
}
......@@ -212,6 +225,7 @@ public final class ProjectManager {
* Triggers a 'projects loaded' event to be sent to the listener on the listener list.
*/
private void fireProjectsLoaded() {
projectsLoaded = true;
for (ProjectManagerEventListener listener : copyProjectManagerEventListeners()) {
listener.onProjectsLoaded();
}
......
......@@ -22,8 +22,8 @@ public class ProjectManagerEventAdapter implements ProjectManagerEventListener {
}
/**
* Invoked after all projects have been loaded by ProjectManager
*
* Invoked after all projects have been loaded by ProjectManager. If the ProjectManager has
* already finished loading projects, this will be called immediately upon adding the listener.
*/
@Override
public void onProjectsLoaded() { }
......
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