예제 #1
0
 /*
  * Remove screen name (if it exists) from project projectId
  */
 public void removeScreen(long projectId, String name) {
   if (!projectMap.containsKey(projectId)) {
     OdeLog.wlog(
         "DesignToolbar can't find project "
             + name
             + " with id "
             + projectId
             + " Ignoring removeScreen().");
     return;
   }
   OdeLog.log("DesignToolbar: got removeScreen for project " + projectId + ", screen " + name);
   DesignProject project = projectMap.get(projectId);
   if (!project.screens.containsKey(name)) {
     // already removed this screen
     return;
   }
   if (currentProject == project) {
     // if removing current screen, choose a new screen to show
     if (currentProject.currentScreen.equals(name)) {
       // TODO(sharon): maybe make a better choice than screen1, but for now
       // switch to screen1 because we know it is always there
       switchToScreen(projectId, YoungAndroidSourceNode.SCREEN1_FORM_NAME, View.FORM);
     }
     removeDropDownButtonItem(WIDGET_NAME_SCREENS_DROPDOWN, name);
   }
   project.removeScreen(name);
 }
예제 #2
0
 /*
  * Add a screen name to the drop-down for the project with id projectId.
  * name is the form name, formEditor is the file editor for the form UI,
  * and blocksEditor is the file editor for the form's blocks.
  */
 public void addScreen(
     long projectId, String name, FileEditor formEditor, FileEditor blocksEditor) {
   if (!projectMap.containsKey(projectId)) {
     OdeLog.wlog(
         "DesignToolbar can't find project "
             + name
             + " with id "
             + projectId
             + ". Ignoring addScreen().");
     return;
   }
   DesignProject project = projectMap.get(projectId);
   if (project.addScreen(name, formEditor, blocksEditor)) {
     if (currentProject == project) {
       addDropDownButtonItem(
           WIDGET_NAME_SCREENS_DROPDOWN,
           new ToolbarItem(name, name, new SwitchScreenAction(projectId, name)));
     }
   }
 }
예제 #3
0
 private void doSwitchScreen(long projectId, String screenName, View view) {
   if (!projectMap.containsKey(projectId)) {
     OdeLog.wlog(
         "DesignToolbar: no project with id "
             + projectId
             + ". Ignoring SwitchScreenAction.execute().");
     return;
   }
   DesignProject project = projectMap.get(projectId);
   if (currentProject != project) {
     // need to switch projects first. this will not switch screens.
     if (!switchToProject(projectId, project.name)) {
       return;
     }
     // currentProject == project now
   }
   String newScreenName = screenName;
   if (!currentProject.screens.containsKey(newScreenName)) {
     // Can't find the requested screen in this project. This shouldn't happen, but if it does
     // for some reason, try switching to Screen1 instead.
     OdeLog.wlog(
         "Trying to switch to non-existent screen "
             + newScreenName
             + " in project "
             + currentProject.name
             + ". Trying Screen1 instead.");
     if (currentProject.screens.containsKey(YoungAndroidSourceNode.SCREEN1_FORM_NAME)) {
       newScreenName = YoungAndroidSourceNode.SCREEN1_FORM_NAME;
     } else {
       // something went seriously wrong!
       ErrorReporter.reportError(
           "Something is wrong. Can't find Screen1 for project " + currentProject.name);
       return;
     }
   }
   currentView = view;
   Screen screen = currentProject.screens.get(newScreenName);
   ProjectEditor projectEditor = screen.formEditor.getProjectEditor();
   currentProject.setCurrentScreen(newScreenName);
   setDropDownButtonCaption(WIDGET_NAME_SCREENS_DROPDOWN, newScreenName);
   OdeLog.log("Setting currentScreen to " + newScreenName);
   if (currentView == View.FORM) {
     projectEditor.selectFileEditor(screen.formEditor);
     toggleEditor(false);
   } else { // must be View.BLOCKS
     projectEditor.selectFileEditor(screen.blocksEditor);
     toggleEditor(true);
   }
   // Inform the Blockly Panel which project/screen (aka form) we are working on
   BlocklyPanel.setCurrentForm(projectId + "_" + newScreenName);
   updateButtons();
 }