Search in sources :

Example 1 with SharedProjectDetails

use of org.rstudio.studio.client.projects.model.SharedProjectDetails in project rstudio by rstudio.

the class ProjectPopupMenu method rebuildMenu.

private void rebuildMenu(final JsArray<SharedProjectDetails> sharedProjects, DynamicPopupMenuCallback callback) {
    // clean out existing entries
    clearItems();
    boolean hasSharedProjects = sharedProjects != null && sharedProjects.length() > 0;
    int maxMruEntries = MAX_MRU_ENTRIES;
    // shared projects are always shown, and count against the MRU limit
    if (hasSharedProjects)
        maxMruEntries -= Math.min(sharedProjects.length(), MAX_SHARED_PROJECTS);
    addItem(commands_.newProject().createMenuItem(false));
    // ensure the menu doesn't get too narrow
    addSeparator(225);
    addItem(commands_.openProject().createMenuItem(false));
    if (Desktop.isDesktop())
        addItem(commands_.openProjectInNewWindow().createMenuItem(false));
    addItem(commands_.closeProject().createMenuItem(false));
    addSeparator();
    addItem(commands_.shareProject().createMenuItem(false));
    if (hasSharedProjects)
        addSeparator("Recent Projects");
    else
        addSeparator();
    // add as many MRU items as is appropriate for our screen size and number
    // of shared projects
    AppCommand[] mruCommands = new AppCommand[] { commands_.projectMru0(), commands_.projectMru1(), commands_.projectMru2(), commands_.projectMru3(), commands_.projectMru4(), commands_.projectMru5(), commands_.projectMru6(), commands_.projectMru7(), commands_.projectMru8(), commands_.projectMru9(), commands_.projectMru10(), commands_.projectMru11(), commands_.projectMru12(), commands_.projectMru13(), commands_.projectMru14() };
    for (int i = 0; i < Math.min(maxMruEntries, mruCommands.length); i++) {
        addItem(mruCommands[i].createMenuItem(false));
    }
    // show shared projects if enabled
    if (hasSharedProjects) {
        addSeparator("Shared with Me");
        for (int i = 0; i < Math.min(sharedProjects.length(), MAX_SHARED_PROJECTS); i++) {
            final SharedProjectDetails details = sharedProjects.get(i);
            String menuHtml = AppCommand.formatMenuLabel(null, details.getName(), false, null, commands_.openHtmlExternal().getImageResource(), ProjectMRUList.NEW_SESSION_DESC);
            addItem(new MenuItem(menuHtml, true, new Scheduler.ScheduledCommand() {

                @Override
                public void execute() {
                    ProjectMRUList.openProjectFromMru(events_, details.getProjectFile());
                }
            }));
        }
        // displayed, offer a link
        if (sharedProjects.length() > MAX_SHARED_PROJECTS) {
            addItem(commands_.openSharedProject().createMenuItem(false));
        }
    }
    addSeparator();
    addItem(commands_.clearRecentProjects().createMenuItem(false));
    addSeparator();
    addItem(commands_.projectOptions().createMenuItem(false));
    callback.onPopupMenu(this);
}
Also used : AppCommand(org.rstudio.core.client.command.AppCommand) SharedProjectDetails(org.rstudio.studio.client.projects.model.SharedProjectDetails) MenuItem(com.google.gwt.user.client.ui.MenuItem)

Example 2 with SharedProjectDetails

use of org.rstudio.studio.client.projects.model.SharedProjectDetails in project rstudio by rstudio.

the class ProjectPopupMenu method getDynamicPopupMenu.

@Override
public void getDynamicPopupMenu(final DynamicPopupMenuCallback callback) {
    ProjectMRUList.setOpenInNewWindow(false);
    if (allowSharedProjects_) {
        final GlobalProgressDelayer progress = new GlobalProgressDelayer(RStudioGinjector.INSTANCE.getGlobalDisplay(), 250, "Looking for projects...");
        // if shared projects are on, check for them every time the user drops
        // the menu; we request one more than the maximum we can display so 
        // we can let the user know whether there are more projects than those
        // that can be displayed in the menu
        server_.getSharedProjects(MAX_SHARED_PROJECTS + 1, new ServerRequestCallback<JsArray<SharedProjectDetails>>() {

            @Override
            public void onResponseReceived(JsArray<SharedProjectDetails> result) {
                rebuildMenu(result, callback);
                progress.dismiss();
            }

            @Override
            public void onError(ServerError error) {
                // if we can't get the shared projects, we can at least show
                // the menu without them
                rebuildMenu(null, callback);
                progress.dismiss();
            }
        });
    } else {
        rebuildMenu(null, callback);
    }
}
Also used : JsArray(com.google.gwt.core.client.JsArray) SharedProjectDetails(org.rstudio.studio.client.projects.model.SharedProjectDetails) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer)

Aggregations

SharedProjectDetails (org.rstudio.studio.client.projects.model.SharedProjectDetails)2 JsArray (com.google.gwt.core.client.JsArray)1 MenuItem (com.google.gwt.user.client.ui.MenuItem)1 AppCommand (org.rstudio.core.client.command.AppCommand)1 GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)1 ServerError (org.rstudio.studio.client.server.ServerError)1