Skip to content

Commit

Permalink
only show svn in project options dialog if the project has an .svn di…
Browse files Browse the repository at this point in the history
…rectory
  • Loading branch information
jjallaire committed Dec 2, 2011
1 parent dd834f9 commit 4f0018d
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/cpp/session/include/session/SessionModuleContext.hpp
Expand Up @@ -289,6 +289,7 @@ bool isGoogleDocsIntegrationEnabled();
void setGoogleDocsIntegrationEnabled(bool enabled);

std::string detectedVcs(const core::FilePath& workingDir);
std::vector<std::string> applicableVcs(const core::FilePath& workingDir);

// persist state accross suspend and resume

Expand Down
16 changes: 16 additions & 0 deletions src/cpp/session/modules/SessionVCS.cpp
Expand Up @@ -149,5 +149,21 @@ std::string detectedVcs(const FilePath& workingDir)
return "none";
}

std::vector<std::string> applicableVcs(const FilePath& workingDir)
{
using namespace session::modules;
using namespace session::modules::source_control;

std::vector<std::string> applicable;

if (isGitInstalled())
applicable.push_back("git");

if (svn::isSvnDirectory(workingDir))
applicable.push_back("svn");

return applicable;
}

} // namespace module_context
} // namespace session
25 changes: 19 additions & 6 deletions src/cpp/session/projects/SessionProjects.cpp
Expand Up @@ -94,22 +94,35 @@ json::Object projectVcsOptionsJson()
return vcsOptionsJson;
}

json::Object projectVcsContextJson()
{
json::Object contextJson;
contextJson["active_vcs"] = module_context::detectedVcs(
s_projectContext.directory());

std::vector<std::string> applicable = module_context::applicableVcs(
s_projectContext.directory());
json::Array applicableJson;
BOOST_FOREACH(const std::string& vcs, applicable)
{
applicableJson.push_back(vcs);
}
contextJson["applicable_vcs"] = applicableJson;

return contextJson;
}

Error readProjectOptions(const json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
// get project config json
json::Object configJson = projectConfigJson(s_projectContext.config());

// get vcs options default json
json::Object vcsOptionsDefaultJson;
vcsOptionsDefaultJson["active_vcs"] = module_context::detectedVcs(
s_projectContext.directory());

// create project options json
json::Object optionsJson;
optionsJson["config"] = configJson;
optionsJson["vcs_options"] = projectVcsOptionsJson();
optionsJson["vcs_options_default"] = vcsOptionsDefaultJson;
optionsJson["vcs_context"] = projectVcsContextJson();

pResponse->setResult(optionsJson);
return Success();
Expand Down
15 changes: 15 additions & 0 deletions src/gwt/src/org/rstudio/core/client/widget/SelectWidget.java
Expand Up @@ -100,6 +100,21 @@ public ListBox getListBox()
{
return listBox_;
}

public void setChoices(String[] options)
{
setChoices(options, options);
}

public void setChoices(String[] options, String[] values)
{
listBox_.clear();
for (int i = 0; i < options.length; i++)
listBox_.addItem(options[i], values[i]);

if (listBox_.getItemCount() > 0)
listBox_.setSelectedIndex(0);
}

public void setEnabled(boolean enabled)
{
Expand Down
Expand Up @@ -44,7 +44,7 @@ public native final RProjectVcsOptions getVcsOptions() /*-{
return this.vcs_options;
}-*/;

public native final RProjectVcsOptionsDefault getVcsOptionsDefault() /*-{
return this.vcs_options_default;
public native final RProjectVcsContext getVcsContext() /*-{
return this.vcs_context;
}-*/;
}
@@ -1,5 +1,5 @@
/*
* RProjectVcsOptionsDefault.java
* RProjectVcsContext.java
*
* Copyright (C) 2009-11 by RStudio, Inc.
*
Expand All @@ -13,14 +13,19 @@
package org.rstudio.studio.client.projects.model;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;

public class RProjectVcsOptionsDefault extends JavaScriptObject
public class RProjectVcsContext extends JavaScriptObject
{
protected RProjectVcsOptionsDefault()
protected RProjectVcsContext()
{
}

public native final String getActiveVcs() /*-{
return this.active_vcs;
}-*/;

public native final JsArrayString getApplicableVcs() /*-{
return this.applicable_vcs;
}-*/;
}
Expand Up @@ -25,13 +25,13 @@
import org.rstudio.studio.client.projects.events.SwitchToProjectEvent;
import org.rstudio.studio.client.projects.model.RProjectOptions;
import org.rstudio.studio.client.projects.model.RProjectVcsOptions;
import org.rstudio.studio.client.projects.model.RProjectVcsOptionsDefault;
import org.rstudio.studio.client.projects.model.RProjectVcsContext;
import org.rstudio.studio.client.server.ServerError;
import org.rstudio.studio.client.server.ServerRequestCallback;
import org.rstudio.studio.client.server.VoidServerRequestCallback;
import org.rstudio.studio.client.workbench.model.Session;
import org.rstudio.studio.client.workbench.model.SessionInfo;

import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.resources.client.ImageResource;
Expand All @@ -51,19 +51,7 @@ public ProjectSourceControlPreferencesPane(final Session session,
eventBus_ = eventBus;
server_ = server;

// populate the vcs selections list
String[] vcsSelections = new String[] { NONE };
SessionInfo sessionInfo = session.getSessionInfo();
if (sessionInfo.isVcsAvailable())
{
String[] availableVcs = sessionInfo.getAvailableVCS();
vcsSelections = new String[availableVcs.length + 1];
vcsSelections[0] = NONE;
for (int i=0; i<availableVcs.length; i++)
vcsSelections[i+1] = availableVcs[i];
}

vcsSelect_ = new SelectWidget("Version control system:", vcsSelections);
vcsSelect_ = new SelectWidget("Version control system:", new String[]{});
extraSpaced(vcsSelect_);
add(vcsSelect_);
vcsSelect_.addChangeHandler(new ChangeHandler() {
Expand All @@ -80,6 +68,10 @@ public void execute()
}
});
}
else
{
promptToRestart();
}
}
});

Expand All @@ -104,14 +96,27 @@ public String getName()
@Override
protected void initialize(RProjectOptions options)
{
defaultVcsOptions_ = options.getVcsOptionsDefault();
RProjectVcsOptions vcsOptions = options.getVcsOptions();
// save the context
vcsContext_ = options.getVcsContext();

// populate the vcs selections list
String[] vcsSelections = new String[] { NONE };
JsArrayString applicableVcs = vcsContext_.getApplicableVcs();
if (applicableVcs.length() > 0)
{
vcsSelections = new String[applicableVcs.length() + 1];
vcsSelections[0] = NONE;
for (int i=0; i<applicableVcs.length(); i++)
vcsSelections[i+1] = applicableVcs.get(i);
}
vcsSelect_.setChoices(vcsSelections);

// set override or default
RProjectVcsOptions vcsOptions = options.getVcsOptions();
if (vcsOptions.getActiveVcsOverride().length() > 0)
setVcsSelection(vcsOptions.getActiveVcsOverride());
else
setVcsSelection(defaultVcsOptions_.getActiveVcs());
setVcsSelection(vcsContext_.getActiveVcs());
}

@Override
Expand All @@ -124,7 +129,7 @@ public void onApply(RProjectOptions options)
private void setVcsOptions(RProjectVcsOptions vcsOptions)
{
String vcsSelection = getVcsSelection();
if (!vcsSelection.equals(defaultVcsOptions_.getActiveVcs()))
if (!vcsSelection.equals(vcsContext_.getActiveVcs()))
vcsOptions.setActiveVcsOverride(vcsSelection);
else
vcsOptions.setActiveVcsOverride("");
Expand Down Expand Up @@ -227,8 +232,8 @@ private void promptToRestart()
globalDisplay_.showYesNoMessage(
MessageDialog.QUESTION,
"Confirm Restart RStudio",
"You need to restart RStudio in order to start working with " +
"the specified version control system. Do you want to do this now?",
"You need to restart RStudio in order for this change to take " +
"effect. Do you want to do this now?",
new Operation()
{
@Override
Expand Down Expand Up @@ -258,7 +263,7 @@ public void execute()

private SelectWidget vcsSelect_;

private RProjectVcsOptionsDefault defaultVcsOptions_;
private RProjectVcsContext vcsContext_;

private static final String NONE = "(None)";
}

0 comments on commit 4f0018d

Please sign in to comment.