Skip to content

Commit

Permalink
add devtools::load_all command
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Jul 12, 2012
1 parent dc7bbc2 commit 4f45d28
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/cpp/session/SessionMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ void handleClientInit(const boost::function<void()>& initFunction,

sessionInfo["build_state"] = modules::build::buildStateAsJson();
sessionInfo["build_restart_context"] = modules::build::buildRestartContext();
sessionInfo["devtools_installed"] = module_context::isPackageInstalled(
"devtools");

// send response (we always set kEventsPending to false so that the client
// won't poll for events until it is ready)
Expand Down
11 changes: 10 additions & 1 deletion src/cpp/session/modules/SessionBuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,14 @@ Error terminateBuild(const json::JsonRpcRequest& request,
return Success();
}

Error devtoolsLoadAllPath(const json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
pResponse->setResult(computeDevtoolsLoadPath());

return Success();
}

} // anonymous namespace


Expand Down Expand Up @@ -819,7 +827,8 @@ Error initialize()
ExecBlock initBlock ;
initBlock.addFunctions()
(bind(registerRpcMethod, "start_build", startBuild))
(bind(registerRpcMethod, "terminate_build", terminateBuild));
(bind(registerRpcMethod, "terminate_build", terminateBuild))
(bind(registerRpcMethod, "devtools_load_all_path", devtoolsLoadAllPath));
return initBlock.execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,13 @@ public void terminateBuild(ServerRequestCallback<Boolean> requestCallback)
sendRequest(RPC_SCOPE, TERMINATE_BUILD, requestCallback);
}

@Override
public void devtoolsLoadAllPath(
ServerRequestCallback<String> requestCallback)
{
sendRequest(RPC_SCOPE, DEVTOOLS_LOAD_ALL_PATH, requestCallback);
}


private String clientId_;
private double clientVersion_ = 0;
Expand Down Expand Up @@ -2832,6 +2839,7 @@ public void terminateBuild(ServerRequestCallback<Boolean> requestCallback)

private static final String START_BUILD = "start_build";
private static final String TERMINATE_BUILD = "terminate_build";
private static final String DEVTOOLS_LOAD_ALL_PATH = "devtools_load_all_path";

private static final String LOG = "log";
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ well as menu structures (for main menu and popup menus).

<menu label="_Build">
<cmd refid="buildAll"/>
<cmd refid="devtoolsLoadAll"/>
<separator/>
<cmd refid="rebuildAll"/>
<cmd refid="cleanAll"/>
Expand Down Expand Up @@ -399,6 +400,7 @@ well as menu structures (for main menu and popup menus).
<shortcut refid="foldAll" value="Alt+A" />
<shortcut refid="unfoldAll" value="Shift+Alt+A"/>
<shortcut refid="buildAll" value="Cmd+Shift+B"/>
<shortcut refid="devtoolsLoadAll" value="Cmd+Shift+L"/>
<shortcut refid="checkPackage" value="Cmd+Shift+E"/>
</shortcuts>

Expand Down Expand Up @@ -1029,7 +1031,7 @@ well as menu structures (for main menu and popup menus).

<cmd id="buildAll"
buttonLabel="Build &amp; Reload"
menuLabel="_Build and Reload Package"
menuLabel="_Build and Reload"
desc="Build and reload the package"/>

<cmd id="rebuildAll"
Expand All @@ -1049,6 +1051,10 @@ well as menu structures (for main menu and popup menus).
menuLabel="Build Binar_y Package"
desc="Build a binary package"/>

<cmd id="devtoolsLoadAll"
menuLabel="_Load All"
desc="Execute devtools::load_all"/>

<cmd id="roxygenizePackage"
menuLabel="Roxygenize"
desc="Run roxygenize for the package"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@

// Build
public abstract AppCommand buildAll();
public abstract AppCommand devtoolsLoadAll();
public abstract AppCommand rebuildAll();
public abstract AppCommand cleanAll();
public abstract AppCommand buildSourcePackage();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,8 @@ public final native BuildState getBuildState() /*-{
public final native BuildRestartContext getBuildRestartContext() /*-{
return this.build_restart_context;
}-*/;

public final native boolean isDevtoolsInstalled() /*-{
return this.devtools_installed;
}-*/;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ protected Toolbar createMainToolbar()
else if (type.equals(SessionInfo.BUILD_TOOLS_PACKAGE))
{
ToolbarPopupMenu buildMenu = new ToolbarPopupMenu();
buildMenu.addItem(commands_.devtoolsLoadAll().createMenuItem(false));
buildMenu.addSeparator();
buildMenu.addItem(commands_.buildSourcePackage().createMenuItem(false));
buildMenu.addItem(commands_.buildBinaryPackage().createMenuItem(false));
buildMenu.addSeparator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
import com.google.gwt.user.client.Command;
import com.google.inject.Inject;

import org.rstudio.core.client.CommandWithArg;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.common.DelayedProgressRequestCallback;
import org.rstudio.studio.client.common.GlobalDisplay;
import org.rstudio.studio.client.common.SimpleRequestCallback;
import org.rstudio.studio.client.workbench.WorkbenchView;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.prefs.events.UiPrefsChangedEvent;
import org.rstudio.studio.client.workbench.prefs.events.UiPrefsChangedHandler;
import org.rstudio.studio.client.workbench.prefs.model.UIPrefs;
import org.rstudio.studio.client.workbench.views.BasePresenter;
import org.rstudio.studio.client.workbench.views.buildtools.events.BuildCompletedEvent;
Expand Down Expand Up @@ -106,6 +110,18 @@ public void onBuildCompleted(BuildCompletedEvent event)
}
});

eventBus.addHandler(UiPrefsChangedEvent.TYPE, new UiPrefsChangedHandler()
{
@Override
public void onUiPrefsChanged(UiPrefsChangedEvent e)
{
// invalidate any devtools load all path we have
// whenever project ui prefs change
if (e.getType().equals(UiPrefsChangedEvent.PROJECT_TYPE))
devtoolsLoadAllPath_ = null;
}
});


view_.stopButton().addClickHandler(new ClickHandler() {
@Override
Expand Down Expand Up @@ -151,6 +167,19 @@ void onBuildAll()
startBuild("build-all");
}

void onDevtoolsLoadAll()
{
withDevtoolsLoadAllPath(new CommandWithArg<String>() {
@Override
public void execute(String loadAllPath)
{
sendLoadCommandToConsole(
"devtools::load_all(\"" + loadAllPath + "\")");
commands_.activateConsole().execute();
}
});
}

void onBuildSourcePackage()
{
startBuild("build-source-package");
Expand Down Expand Up @@ -242,6 +271,29 @@ public void execute()
});
}

private void withDevtoolsLoadAllPath(
final CommandWithArg<String> onAvailable)
{
if (devtoolsLoadAllPath_ != null)
{
onAvailable.execute(devtoolsLoadAllPath_);
}
else
{
server_.devtoolsLoadAllPath(new SimpleRequestCallback<String>() {
@Override
public void onResponseReceived(String loadAllPath)
{
devtoolsLoadAllPath_ = loadAllPath;
onAvailable.execute(devtoolsLoadAllPath_);
}
});
}

}

private String devtoolsLoadAllPath_ = null;

private final GlobalDisplay globalDisplay_;
private final SourceShim sourceShim_;
private final UIPrefs uiPrefs_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public abstract static class Shim extends DelayLoadTabShim<BuildPresenter, Build
@Handler
public abstract void onBuildAll();
@Handler
public abstract void onDevtoolsLoadAll();
@Handler
public abstract void onRebuildAll();
@Handler
public abstract void onCleanAll();
Expand Down Expand Up @@ -91,10 +93,15 @@ public void onSessionInit(SessionInitEvent sie)
{
SessionInfo sessionInfo = session.getSessionInfo();

// remove devtools commands if it isn't installed
if (!sessionInfo.isDevtoolsInstalled())
commands.devtoolsLoadAll().remove();

// adapt or remove package commands if this isn't a package
String type = sessionInfo.getBuildToolsType();
if (!type.equals(SessionInfo.BUILD_TOOLS_PACKAGE))
{
commands.devtoolsLoadAll().remove();
commands.buildSourcePackage().remove();
commands.buildBinaryPackage().remove();
commands.roxygenizePackage().remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ void startBuild(String type,

// terminate any running build
void terminateBuild(ServerRequestCallback<Boolean> requestCallback);


// get the devtools::load_all path
void devtoolsLoadAllPath(ServerRequestCallback<String> requestCallback);
}

0 comments on commit 4f45d28

Please sign in to comment.