Skip to content

Commit

Permalink
Don't bind encodings to new documents until they're saved (as opposed…
Browse files Browse the repository at this point in the history
… to when they are created)
  • Loading branch information
jcheng5 committed Apr 5, 2011
1 parent 63f6130 commit 88c3680
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 46 deletions.
3 changes: 0 additions & 3 deletions src/cpp/session/modules/SessionSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,15 @@ Error newDocument(const json::JsonRpcRequest& request,
{
// params
std::string type;
std::string encoding;
json::Object properties;
Error error = json::readParams(request.params,
&type,
&encoding,
&properties);
if (error)
return error ;

// create the new doc and write it to the database
SourceDocument doc(type) ;
doc.setEncoding(encoding);

doc.editProperties(properties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,9 @@ public class OpenSourceFileEvent extends GwtEvent<OpenSourceFileHandler>
new GwtEvent.Type<OpenSourceFileHandler>();

public OpenSourceFileEvent(FileSystemItem file, TextFileType fileType)
{
this(file, fileType, null);
}

public OpenSourceFileEvent(FileSystemItem file,
TextFileType fileType,
String encoding)
{
file_ = file;
fileType_ = fileType;

if (!StringUtil.isNullOrEmpty(encoding))
{
encoding_ = encoding;
}
else
{
UIPrefs uiPrefs = RStudioGinjector.INSTANCE.getUIPrefs();
encoding_ = uiPrefs.defaultEncoding().getValue();
}
}

public FileSystemItem getFile()
Expand All @@ -57,11 +40,6 @@ public TextFileType getFileType()
return fileType_;
}

public String getEncoding()
{
return encoding_;
}

@Override
protected void dispatch(OpenSourceFileHandler handler)
{
Expand All @@ -76,5 +54,4 @@ public GwtEvent.Type<OpenSourceFileHandler> getAssociatedType()

private final FileSystemItem file_;
private final TextFileType fileType_;
private final String encoding_;
}
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,12 @@ public void setManipulatorValues(JSONObject values,
}

public void newDocument(String filetype,
String encoding,
JsObject properties,
ServerRequestCallback<SourceDocument> requestCallback)
{
JSONArray params = new JSONArray();
params.set(0, new JSONString(filetype));
params.set(1, new JSONString(StringUtil.notNull(encoding)));
params.set(2, new JSONObject(properties));
params.set(1, new JSONObject(properties));
sendRequest(RPC_SCOPE, NEW_DOCUMENT, params, requestCallback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public void onViewData(ViewDataEvent event)
{
server_.newDocument(
FileTypeRegistry.DATAFRAME.getTypeId(),
null,
JsObject.createJsObject(),
new SimpleRequestCallback<SourceDocument>("Edit Data Frame") {
public void onResponseReceived(SourceDocument response)
Expand Down Expand Up @@ -277,7 +276,6 @@ public void onShowContent(ShowContentEvent event)
ContentItem content = event.getContent();
server_.newDocument(
FileTypeRegistry.URLCONTENT.getTypeId(),
null,
(JsObject) content.cast(),
new SimpleRequestCallback<SourceDocument>("Show")
{
Expand Down Expand Up @@ -308,7 +306,6 @@ public void onShowData(ShowDataEvent event)

server_.newDocument(
FileTypeRegistry.DATAFRAME.getTypeId(),
null,
(JsObject) data.cast(),
new SimpleRequestCallback<SourceDocument>("Show Data Frame")
{
Expand All @@ -324,17 +321,15 @@ public void onResponseReceived(SourceDocument response)
@Handler
public void onNewSourceDoc()
{
newDoc(FileTypeRegistry.R, uiPrefs_.defaultEncoding().getValue(), null);
newDoc(FileTypeRegistry.R, null);
}

private void newDoc(EditableFileType fileType,
String encoding,
final CommandWithArg<EditingTarget> executeOnSuccess)
{
ensureVisible(true);
server_.newDocument(
fileType.getTypeId(),
encoding,
JsObject.createJsObject(),
new SimpleRequestCallback<SourceDocument>(
"Error Creating New Document")
Expand Down Expand Up @@ -458,7 +453,7 @@ public void execute()

public void onOpenSourceFile(final OpenSourceFileEvent event)
{
openFile(event.getFile(), event.getFileType(), event.getEncoding());
openFile(event.getFile(), event.getFileType());
}

// top-level wrapper for opening files. takes care of:
Expand All @@ -469,14 +464,13 @@ public void onOpenSourceFile(final OpenSourceFileEvent event)
// - finally, actually opening the file from the server
// via the call to the lower level openFile method
private void openFile(final FileSystemItem file,
final TextFileType fileType,
final String encoding)
final TextFileType fileType)
{
ensureVisible(true);

if (file == null)
{
newDoc(fileType, encoding, null);
newDoc(fileType, null);
return;
}

Expand Down Expand Up @@ -505,13 +499,13 @@ else if (file.getLength() > target.getLargeFileSize())
confirmOpenLargeFile(file, new Operation() {
public void execute()
{
openFileFromServer(file, fileType, encoding);
openFileFromServer(file, fileType);
}
});
}
else
{
openFileFromServer(file, fileType, encoding);
openFileFromServer(file, fileType);
}
}

Expand Down Expand Up @@ -546,16 +540,15 @@ private void confirmOpenLargeFile(FileSystemItem file,
}

private void openFileFromServer(final FileSystemItem file,
final TextFileType fileType,
String encoding)
final TextFileType fileType)
{
final Command dismissProgress = globalDisplay_.showProgress(
"Opening file...");

server_.openDocument(
file.getPath(),
fileType.getTypeId(),
encoding,
uiPrefs_.defaultEncoding().getValue(),
new ServerRequestCallback<SourceDocument>()
{
@Override
Expand Down Expand Up @@ -671,7 +664,6 @@ public void onInsertSource(final InsertSourceEvent event)
else
{
newDoc(FileTypeRegistry.R,
uiPrefs_.defaultEncoding().getValue(),
new CommandWithArg<EditingTarget>()
{
public void execute(EditingTarget arg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public interface SourceServerOperations
* have never been saved.
*/
void newDocument(String fileType,
String encoding,
JsObject properties,
ServerRequestCallback<SourceDocument> requestCallback);

Expand Down

0 comments on commit 88c3680

Please sign in to comment.